use of org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter 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.membership.ZookeeperBBoxDBInstanceAdapter 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();
}
use of org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter in project bboxdb by jnidzwetzki.
the class StatisticsUpdateRunnable method updateNodeStats.
/**
* Update the local node stats (diskspace, memory)
* @throws ZookeeperException
*/
private void updateNodeStats() {
try {
final BBoxDBInstance instance = ZookeeperClientFactory.getLocalInstanceName();
logger.debug("Update zookeeper node stats");
final ZookeeperClient zookeeperClient = ZookeeperClientFactory.getZookeeperClient();
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient);
zookeeperBBoxDBInstanceAdapter.updateNodeInfo(instance);
} catch (ZookeeperException e) {
logger.error("Got exception while updating local node stats", e);
}
}
Aggregations