use of org.apache.pulsar.broker.PulsarService in project incubator-pulsar by apache.
the class AdminApiTest2 method testLoadReportApi.
/**
* It verifies that pulsar with different load-manager generates different load-report and returned by admin-api
*
* @throws Exception
*/
@Test
public void testLoadReportApi() throws Exception {
this.conf.setLoadManagerClassName(SimpleLoadManagerImpl.class.getName());
MockedPulsarService mockPulsarSetup1 = new MockedPulsarService(this.conf);
mockPulsarSetup1.setup();
PulsarService simpleLoadManager = mockPulsarSetup1.getPulsar();
PulsarAdmin simpleLoadManagerAdmin = mockPulsarSetup1.getAdmin();
assertNotNull(simpleLoadManagerAdmin.brokerStats().getLoadReport());
this.conf.setLoadManagerClassName(ModularLoadManagerImpl.class.getName());
MockedPulsarService mockPulsarSetup2 = new MockedPulsarService(this.conf);
mockPulsarSetup2.setup();
PulsarService modularLoadManager = mockPulsarSetup2.getPulsar();
PulsarAdmin modularLoadManagerAdmin = mockPulsarSetup2.getAdmin();
assertNotNull(modularLoadManagerAdmin.brokerStats().getLoadReport());
simpleLoadManagerAdmin.close();
simpleLoadManager.close();
modularLoadManagerAdmin.close();
modularLoadManager.close();
mockPulsarSetup1.cleanup();
mockPulsarSetup2.cleanup();
}
use of org.apache.pulsar.broker.PulsarService in project incubator-pulsar by apache.
the class BacklogQuotaManagerTest method setup.
@BeforeMethod
void setup() throws Exception {
try {
// start local bookie and zookeeper
bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
bkEnsemble.start();
// start pulsar service
config = new ServiceConfiguration();
config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config.setAdvertisedAddress("localhost");
config.setWebServicePort(BROKER_WEBSERVICE_PORT);
config.setClusterName("usc");
config.setBrokerServicePort(BROKER_SERVICE_PORT);
config.setAuthorizationEnabled(false);
config.setAuthenticationEnabled(false);
config.setBacklogQuotaCheckIntervalInSeconds(TIME_TO_CHECK_BACKLOG_QUOTA);
config.setManagedLedgerMaxEntriesPerLedger(5);
config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
pulsar = new PulsarService(config);
pulsar.start();
adminUrl = new URL("http://127.0.0.1" + ":" + BROKER_WEBSERVICE_PORT);
admin = new PulsarAdmin(adminUrl, (Authentication) null);
admin.clusters().createCluster("usc", new ClusterData(adminUrl.toString()));
admin.properties().createProperty("prop", new PropertyAdmin(Lists.newArrayList("appid1"), Sets.newHashSet("usc")));
admin.namespaces().createNamespace("prop/usc/ns-quota");
admin.namespaces().createNamespace("prop/usc/quotahold");
admin.namespaces().createNamespace("prop/usc/quotaholdasync");
} catch (Throwable t) {
LOG.error("Error setting up broker test", t);
Assert.fail("Broker test setup failed");
}
}
use of org.apache.pulsar.broker.PulsarService in project flink by apache.
the class PulsarEmbeddedRuntime method startPulsarService.
private void startPulsarService() throws Exception {
ServiceConfiguration config;
try (FileInputStream inputStream = new FileInputStream(CONFIG_FILE_PATH)) {
config = PulsarConfigurationLoader.create(inputStream, ServiceConfiguration.class);
} catch (IOException e) {
throw new IllegalStateException(e);
}
// Use runtime dynamic ports for broker.
config.setAdvertisedAddress("127.0.0.1");
config.setClusterName("standalone");
// Use random port.
config.setBrokerServicePort(Optional.of(0));
config.setWebServicePort(Optional.of(0));
// Select available port for bookkeeper and zookeeper.
int zkPort = getZkPort();
String zkConnect = "127.0.0.1" + ":" + zkPort;
config.setZookeeperServers(zkConnect);
config.setConfigurationStoreServers(zkConnect);
config.setRunningStandalone(true);
this.pulsarService = new PulsarService(config);
// Start Pulsar Broker.
pulsarService.start();
// Create sample data environment.
String webServiceUrl = getWebServiceUrl();
String brokerUrl = getBrokerUrl();
try (PulsarAdmin admin = PulsarAdmin.builder().serviceHttpUrl(webServiceUrl).build()) {
ClusterData clusterData = ClusterData.builder().serviceUrl(webServiceUrl).brokerServiceUrl(brokerUrl).build();
String cluster = config.getClusterName();
createSampleNameSpace(admin, clusterData, cluster);
// Create default namespace
createNameSpace(admin, cluster, TopicName.PUBLIC_TENANT, TopicName.PUBLIC_TENANT + "/" + TopicName.DEFAULT_NAMESPACE);
// Create Pulsar system namespace
createNameSpace(admin, cluster, SYSTEM_NAMESPACE.getTenant(), SYSTEM_NAMESPACE.toString());
// Enable transaction
if (config.isTransactionCoordinatorEnabled() && !admin.namespaces().getTopics(SYSTEM_NAMESPACE.toString()).contains(TRANSACTION_COORDINATOR_ASSIGN.getPartition(0).toString())) {
admin.topics().createPartitionedTopic(TRANSACTION_COORDINATOR_ASSIGN.toString(), 1);
}
}
}
Aggregations