use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testReconnect.
/**
* Test the reconnect
* @throws ZookeeperException
*/
@Test(timeout = 60000)
public void testReconnect() throws InterruptedException, ZookeeperException {
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
Assert.assertTrue(zookeeperClient.isConnected());
Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
Thread.sleep(1000);
// Disconnect
zookeeperClient.shutdown();
Assert.assertEquals(0, distributedInstanceManager.getInstances().size());
// Reconnect
Assert.assertFalse(zookeeperClient.isConnected());
zookeeperClient.init();
Assert.assertTrue(zookeeperClient.isConnected());
// Wait for instances read
Thread.sleep(1000);
Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method before.
/**
* Delete all old information on zookeeper
*
* @throws ZookeeperException
*/
@Before
public void before() throws ZookeeperException {
ZookeeperClient zookeeperClient = getNewZookeeperClient(null);
zookeeperClient.deleteCluster();
zookeeperClient.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testRegisterInstance4.
/**
* Two instances are known and changing
* @throws ZookeeperException
*/
@Test(timeout = 60000)
public void testRegisterInstance4() throws InterruptedException, ZookeeperException {
final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
final BBoxDBInstance instance1 = new BBoxDBInstance("node1:5050");
final BBoxDBInstance instance2 = new BBoxDBInstance("node2:5050");
final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter1 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient1);
final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter2 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient2);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
Thread.sleep(1000);
Assert.assertEquals(2, distributedInstanceManager.getInstances().size());
Assert.assertTrue(BBoxDBInstanceState.FAILED == distributedInstanceManager.getInstances().get(0).getState());
Assert.assertTrue(BBoxDBInstanceState.FAILED == distributedInstanceManager.getInstances().get(1).getState());
// Change instance 1
zookeeperBBoxDBInstanceAdapter1.updateStateData(instance1, BBoxDBInstanceState.OUTDATED);
Thread.sleep(1000);
for (final BBoxDBInstance instance : distributedInstanceManager.getInstances()) {
if (instance.socketAddressEquals(instance1)) {
Assert.assertTrue(instance.getState() == BBoxDBInstanceState.OUTDATED);
} else {
Assert.assertTrue(instance.getState() == BBoxDBInstanceState.FAILED);
}
}
// Change instance 2
zookeeperBBoxDBInstanceAdapter2.updateStateData(instance2, BBoxDBInstanceState.READY);
Thread.sleep(2000);
for (final BBoxDBInstance instance : distributedInstanceManager.getInstances()) {
if (instance.socketAddressEquals(instance1)) {
Assert.assertTrue(instance.getState() == BBoxDBInstanceState.OUTDATED);
} else {
Assert.assertTrue(instance.getState() == BBoxDBInstanceState.READY);
}
}
zookeeperClient1.shutdown();
zookeeperClient2.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testRegisterUnregister2.
/**
* test unregister
*/
@Test(timeout = 60000)
public void testRegisterUnregister2() 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());
final BBoxDBInstance instance2 = new BBoxDBInstance("node1:5050");
final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient2);
Assert.assertTrue(zookeeperClient2.isConnected());
Thread.sleep(1000);
Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
zookeeperClient2.shutdown();
}
use of org.bboxdb.distribution.zookeeper.ZookeeperClient in project bboxdb by jnidzwetzki.
the class TestDistributedInstanceManager method testWriteSystemInfo.
/**
* Test write the system info
*/
@Test(timeout = 60000)
public void testWriteSystemInfo() {
final BBoxDBInstance instance1 = new BBoxDBInstance("node6:5050");
final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
final List<BBoxDBInstance> distributedInstances = BBoxDBInstanceManager.getInstance().getInstances();
Assert.assertEquals(1, distributedInstances.size());
final BBoxDBInstance instance = distributedInstances.get(0);
Assert.assertEquals(SystemInfo.getAvailableMemory(), instance.getMemory());
Assert.assertEquals(SystemInfo.getCPUCores(), instance.getCpuCores());
final BBoxDBConfiguration bboxDBConfiguration = BBoxDBConfigurationManager.getConfiguration();
final List<String> directories = bboxDBConfiguration.getStorageDirectories();
Assert.assertEquals(directories.size(), instance.getNumberOfStorages());
Assert.assertEquals(directories.size(), instance.getAllTotalSpaceLocations().size());
Assert.assertEquals(directories.size(), instance.getAllFreeSpaceLocations().size());
for (final String directory : directories) {
final File path = new File(directory);
Assert.assertEquals(SystemInfo.getFreeDiskspace(path), (long) instance.getAllFreeSpaceLocations().get(directory), 1000000);
Assert.assertEquals(SystemInfo.getTotalDiskspace(path), (long) instance.getAllTotalSpaceLocations().get(directory), 1000000);
}
zookeeperClient1.shutdown();
}
Aggregations