use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.
the class LocalBookkeeperEnsembleTest method testStartStop.
@Test
void testStartStop() throws Exception {
final int numBk = 1;
final int zkPort = PortManager.nextFreePort();
final int bkPort = PortManager.nextFreePort();
// Start local Bookies/ZooKeepers and confirm that they are running at specified ports
LocalBookkeeperEnsemble ensemble = new LocalBookkeeperEnsemble(numBk, zkPort, bkPort);
ensemble.start();
assertTrue(ensemble.getZkServer().isRunning());
assertEquals(ensemble.getZkServer().getClientPort(), zkPort);
assertTrue(ensemble.getZkClient().getState().isConnected());
assertTrue(ensemble.getBookies()[0].isRunning());
assertEquals(ensemble.getBookies()[0].getLocalAddress().getPort(), bkPort);
// Stop local Bookies/ZooKeepers and confirm that they are correctly closed
ensemble.stop();
assertFalse(ensemble.getZkServer().isRunning());
assertFalse(ensemble.getZkClient().getState().isConnected());
assertFalse(ensemble.getBookies()[0].isRunning());
}
use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.
the class PulsarStandaloneStarter method start.
void start() throws Exception {
if (config == null) {
System.exit(1);
}
log.debug("--- setup PulsarStandaloneStarter ---");
if (!onlyBroker) {
// Start LocalBookKeeper
bkEnsemble = new LocalBookkeeperEnsemble(numOfBk, zkPort, bkPort, zkDir, bkDir, wipeData);
bkEnsemble.start();
}
if (noBroker) {
return;
}
// Start Broker
broker = new PulsarService(config);
broker.start();
// Create a sample namespace
URL webServiceUrl = new URL(String.format("http://%s:%d", config.getAdvertisedAddress(), config.getWebServicePort()));
String brokerServiceUrl = String.format("pulsar://%s:%d", config.getAdvertisedAddress(), config.getBrokerServicePort());
admin = new PulsarAdmin(webServiceUrl, config.getBrokerClientAuthenticationPlugin(), config.getBrokerClientAuthenticationParameters());
String property = "sample";
String cluster = config.getClusterName();
String namespace = property + "/" + cluster + "/ns1";
try {
ClusterData clusterData = new ClusterData(webServiceUrl.toString(), null, /* serviceUrlTls */
brokerServiceUrl, null);
if (!admin.clusters().getClusters().contains(cluster)) {
admin.clusters().createCluster(cluster, clusterData);
} else {
admin.clusters().updateCluster(cluster, clusterData);
}
if (!admin.properties().getProperties().contains(property)) {
admin.properties().createProperty(property, new PropertyAdmin(Lists.newArrayList(config.getSuperUserRoles()), Sets.newHashSet(cluster)));
}
if (!admin.namespaces().getNamespaces(property).contains(namespace)) {
admin.namespaces().createNamespace(namespace);
}
} catch (PulsarAdminException e) {
log.info(e.getMessage());
}
log.debug("--- setup completed ---");
}
use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.
the class AdvertisedAddressTest method setup.
@Before
public void setup() throws Exception {
bkEnsemble = new LocalBookkeeperEnsemble(3, ZOOKEEPER_PORT, 5001);
bkEnsemble.start();
ServiceConfiguration config = new ServiceConfiguration();
config.setZookeeperServers("127.0.0.1" + ":" + ZOOKEEPER_PORT);
config.setWebServicePort(BROKER_WEBSERVICE_PORT);
config.setClusterName("usc");
config.setBrokerServicePort(BROKER_SERVICE_PORT);
config.setAdvertisedAddress(advertisedAddress);
config.setManagedLedgerMaxEntriesPerLedger(5);
config.setManagedLedgerMinLedgerRolloverTimeMinutes(0);
pulsar = new PulsarService(config);
pulsar.start();
}
use of com.yahoo.pulsar.zookeeper.LocalBookkeeperEnsemble in project pulsar by yahoo.
the class LocalBookkeeperEnsembleTest method testDataDirectoryCreatingAndRemoving.
@Test
void testDataDirectoryCreatingAndRemoving() throws Exception {
final int numBk = 1;
final int zkPort = PortManager.nextFreePort();
final int bkPort = PortManager.nextFreePort();
final String zkDirName = "/tmp/data/zookeeper";
File zkDir = new File(zkDirName);
final String bkDirName = "/tmp/data/bookkeeper";
File bkDir = new File(bkDirName + "0");
// At first delete existing data directories
FileUtils.deleteDirectory(zkDir);
FileUtils.deleteDirectory(bkDir);
assertFalse(zkDir.exists());
assertFalse(bkDir.exists());
// Start local Bookies/ZooKeepers and confirm that specified data directories are created
LocalBookkeeperEnsemble ensemble1 = new LocalBookkeeperEnsemble(numBk, zkPort, bkPort, zkDirName, bkDirName, true);
ensemble1.start();
assertTrue(zkDir.exists());
assertTrue(bkDir.exists());
ensemble1.stop();
// Restart local Bookies/ZooKeepers without refreshing data
LocalBookkeeperEnsemble ensemble2 = new LocalBookkeeperEnsemble(numBk, zkPort, bkPort, zkDirName, bkDirName, false);
ensemble2.start();
assertTrue(ensemble2.getZkServer().isRunning());
assertEquals(ensemble2.getZkServer().getClientPort(), zkPort);
assertTrue(ensemble2.getZkClient().getState().isConnected());
assertTrue(ensemble2.getBookies()[0].isRunning());
assertEquals(ensemble2.getBookies()[0].getLocalAddress().getPort(), bkPort);
// Stop local Bookies/ZooKeepers and confirm that they are correctly closed
ensemble2.stop();
assertFalse(ensemble2.getZkServer().isRunning());
assertFalse(ensemble2.getZkClient().getState().isConnected());
assertFalse(ensemble2.getBookies()[0].isRunning());
// Finaly delete data directories
FileUtils.deleteDirectory(zkDir);
FileUtils.deleteDirectory(bkDir);
}
Aggregations