use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestStorageRegistry method beforeClass.
@BeforeClass
public static void beforeClass() throws InterruptedException, BBoxDBException, ZookeeperException {
storageRegistry = new TupleStoreManagerRegistry();
storageRegistry.init();
final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
final DistributionGroupAdapter adapter = new DistributionGroupAdapter(zookeeperClient);
final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
adapter.createDistributionGroup(RELATION_NAME.getDistributionGroup(), configuration);
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testRegisterInstance1.
/**
* No instance is known - but zookeeper init is called
*/
@Test(timeout = 60000)
public void testRegisterInstance1() throws InterruptedException {
final ZookeeperClient zookeeperClient = getNewZookeeperClient(null);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
Assert.assertTrue(zookeeperClient.isConnected());
Thread.sleep(1000);
Assert.assertTrue(BBoxDBInstanceManager.getInstance().getInstances().isEmpty());
zookeeperClient.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testRegisterUnregister.
/**
* test unregister
*/
@Test(timeout = 60000)
public void testRegisterUnregister() throws InterruptedException {
final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
Assert.assertTrue(zookeeperClient.isConnected());
Thread.sleep(1000);
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
zookeeperClient.shutdown();
Assert.assertTrue(distributedInstanceManager.getInstances().isEmpty());
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testRegisterInstance2.
/**
* One instance is known
*/
@Test(timeout = 60000)
public void testRegisterInstance2() throws InterruptedException {
final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
Assert.assertTrue(zookeeperClient.isConnected());
Thread.sleep(1000);
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
zookeeperClient.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testChangedEventOnChange.
/**
* Test changed event generation
* @throws InterruptedException
* @throws ZookeeperException
*/
@Test(timeout = 30000)
public void testChangedEventOnChange() 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)) {
Assert.assertTrue(instance.getState() == BBoxDBInstanceState.OUTDATED);
changedLatch.countDown();
}
} else {
// Unexpected event
Assert.assertTrue(false);
}
}
});
zookeeperBBoxDBInstanceAdapter2.updateStateData(instance2, BBoxDBInstanceState.OUTDATED);
changedLatch.await();
distributedInstanceManager.removeAllListener();
zookeeperClient1.shutdown();
zookeeperClient2.shutdown();
}
Aggregations