use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class ConnectDialog method getConnectAction.
/**
* Get the connect action
* @return
*/
/**
* Get the connect action
* @return
*/
protected Action getConnectAction() {
final AbstractAction connectAction = new AbstractAction() {
/**
*/
private static final long serialVersionUID = 2908534701228350424L;
@Override
public void actionPerformed(ActionEvent e) {
final String guiHosts = hosts.getText();
if (guiHosts == null) {
return;
}
final String[] hostList = guiHosts.split(",");
final List<String> zookeeperHosts = Arrays.asList(hostList);
final String cluster = clustername.getText();
final ZookeeperClient zookeeperClient = new ZookeeperClient(zookeeperHosts, cluster);
zookeeperClient.init();
ZookeeperClientFactory.setDefaultZookeeperClient(zookeeperClient);
showMainDialog(zookeeperClient);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
mainframe.dispose();
}
/**
* Show the main dialog
*
* @param distributionGroup
* @param zookeeperClient
*/
protected void showMainDialog(final ZookeeperClient zookeeperClient) {
final GuiModel guiModel = new GuiModel(zookeeperClient);
final BBoxDBGui bboxDBGUI = new BBoxDBGui(guiModel);
guiModel.setBBoxDBGui(bboxDBGUI);
bboxDBGUI.run();
}
};
return connectAction;
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestNetworkCommunication method testSendDeletePackage.
/**
* Send a delete package to the server
* @throws InterruptedException
* @throws ExecutionException
* @throws ZookeeperException
* @throws BBoxDBException
*/
@Test(timeout = 60000)
public void testSendDeletePackage() throws InterruptedException, ExecutionException, ZookeeperException, BBoxDBException {
System.out.println("=== Running sendDeletePackage");
final BBoxDBConnection bboxdbConnection = connectToServer();
final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
final String tableName = DISTRIBUTION_GROUP + "_relation3";
final TupleStoreName tupleStoreName = new TupleStoreName(tableName);
final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
final TupleStoreAdapter tupleStoreAdapter = zookeeperClient.getTupleStoreAdapter();
Assert.assertFalse(tupleStoreAdapter.isTableKnown(tupleStoreName));
// Create table
final TupleStoreConfiguration configuration = TupleStoreConfigurationBuilder.create().build();
final EmptyResultFuture createFuture = bboxDBClient.createTable(tableName, configuration);
createFuture.waitForAll();
Assert.assertTrue(createFuture.isDone());
Assert.assertFalse(createFuture.isFailed());
Assert.assertTrue(tupleStoreAdapter.isTableKnown(tupleStoreName));
// Delete table
final EmptyResultFuture deleteResult1 = bboxDBClient.deleteTable(tableName);
deleteResult1.waitForAll();
Assert.assertTrue(deleteResult1.isDone());
Assert.assertFalse(deleteResult1.isFailed());
Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
Assert.assertFalse(tupleStoreAdapter.isTableKnown(tupleStoreName));
// Second call
final EmptyResultFuture deleteResult2 = bboxDBClient.deleteTable(tableName);
deleteResult2.waitForAll();
Assert.assertTrue(deleteResult2.isDone());
Assert.assertFalse(deleteResult2.isFailed());
Assert.assertTrue(bboxdbConnection.getConnectionState().isInRunningState());
Assert.assertFalse(tupleStoreAdapter.isTableKnown(tupleStoreName));
// Disconnect
disconnect(bboxDBClient);
Assert.assertFalse(bboxDBClient.isConnected());
System.out.println("=== End sendDeletePackage");
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testAddEvent.
/**
* Test add event generation
* @throws InterruptedException
* @throws ZookeeperException
*/
@Test(timeout = 30000)
public void testAddEvent() throws InterruptedException {
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
final BBoxDBInstance instance1 = new BBoxDBInstance("node4:5050");
final BBoxDBInstance instance2 = new BBoxDBInstance("node5:5050");
final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
Thread.sleep(5000);
final CountDownLatch changedLatch = new CountDownLatch(1);
distributedInstanceManager.registerListener(new BiConsumer<DistributedInstanceEvent, BBoxDBInstance>() {
@Override
public void accept(final DistributedInstanceEvent event, final BBoxDBInstance instance) {
if (event == DistributedInstanceEvent.ADD) {
if (instance.socketAddressEquals(instance2)) {
changedLatch.countDown();
}
} else {
// Unexpected event
System.out.println("Got unexpeceted event: " + event);
Assert.assertTrue(false);
}
}
});
final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
changedLatch.await();
distributedInstanceManager.removeAllListener();
zookeeperClient1.shutdown();
zookeeperClient2.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testChangedEventOnDeletion.
/**
* Test delete event generation
* @throws InterruptedException
* @throws ZookeeperException
*/
@Test(timeout = 30000)
public void testChangedEventOnDeletion() throws InterruptedException, ZookeeperException {
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
final BBoxDBInstance instance1 = new BBoxDBInstance("node6:5050");
final BBoxDBInstance instance2 = new BBoxDBInstance("node7:5050");
final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter1 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient1);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter2 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient2);
zookeeperBBoxDBInstanceAdapter1.updateStateData(instance1, BBoxDBInstanceState.READY);
zookeeperBBoxDBInstanceAdapter2.updateStateData(instance2, BBoxDBInstanceState.READY);
Thread.sleep(5000);
final CountDownLatch changedLatch = new CountDownLatch(1);
distributedInstanceManager.registerListener(new BiConsumer<DistributedInstanceEvent, BBoxDBInstance>() {
@Override
public void accept(final DistributedInstanceEvent event, final BBoxDBInstance instance) {
if (event == DistributedInstanceEvent.CHANGED) {
if (instance.socketAddressEquals(instance2)) {
changedLatch.countDown();
}
} else {
System.out.println("Got unexpeced event: " + event);
// Unexpected event
Assert.assertTrue(false);
}
}
});
zookeeperClient2.shutdown();
changedLatch.await();
distributedInstanceManager.removeAllListener();
zookeeperClient1.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testRegisterInstance3.
/**
* One instance is known and changes
* @throws ZookeeperException
*/
@Test(timeout = 60000)
public void testRegisterInstance3() throws InterruptedException, ZookeeperException {
final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
Assert.assertTrue(zookeeperClient.isConnected());
Thread.sleep(1000);
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient);
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
Assert.assertTrue(BBoxDBInstanceState.FAILED == distributedInstanceManager.getInstances().get(0).getState());
zookeeperBBoxDBInstanceAdapter.updateStateData(instance, BBoxDBInstanceState.OUTDATED);
Thread.sleep(2000);
System.out.println(distributedInstanceManager.getInstances());
Assert.assertTrue(BBoxDBInstanceState.OUTDATED == distributedInstanceManager.getInstances().get(0).getState());
zookeeperBBoxDBInstanceAdapter.updateStateData(instance, BBoxDBInstanceState.READY);
Thread.sleep(1000);
Assert.assertTrue(BBoxDBInstanceState.READY == distributedInstanceManager.getInstances().get(0).getState());
zookeeperClient.shutdown();
}
Aggregations