use of org.bboxdb.distribution.region.DistributionRegionCallback in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method buildSyncer.
/**
* Build a new syncer
*/
private DistributionRegionSyncer buildSyncer() {
final Set<DistributionRegionCallback> callbacks = new CopyOnWriteArraySet<>();
final DistributionRegionIdMapper distributionRegionIdMapper = new DistributionRegionIdMapper(GROUP);
final SpacePartitionerContext spacePartitionerContext = new SpacePartitionerContext("", GROUP, ZookeeperClientFactory.getZookeeperClient(), callbacks, distributionRegionIdMapper);
return new DistributionRegionSyncer(spacePartitionerContext);
}
use of org.bboxdb.distribution.region.DistributionRegionCallback in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method createSplittedRoot.
/**
* Create a splitted root
* @param distributionRegionSyncer
* @param root
* @return
* @throws ZookeeperException
* @throws InterruptedException
*/
private String createSplittedRoot(final DistributionRegionSyncer distributionRegionSyncer, final DistributionRegion root) throws ZookeeperException, InterruptedException {
final BoundingBox leftBoundingBox = root.getConveringBox().splitAndGetLeft(0, 0, true);
final BoundingBox rightBoundingBox = root.getConveringBox().splitAndGetRight(0, 0, true);
final String regionPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(root);
final CountDownLatch latchLevel0 = new CountDownLatch(1);
final DistributionRegionCallback level0Callback = (e, r) -> {
if (root.getDirectChildren().size() == 2) {
latchLevel0.countDown();
}
};
distributionRegionSyncer.registerCallback(level0Callback);
distributionRegionAdapter.createNewChild(regionPath, 0, leftBoundingBox, GROUP);
distributionRegionAdapter.createNewChild(regionPath, 1, rightBoundingBox, GROUP);
latchLevel0.await();
distributionRegionSyncer.unregisterCallback(level0Callback);
Assert.assertEquals(2, root.getDirectChildren().size());
Assert.assertTrue(root.getChildNumber(0) != null);
Assert.assertTrue(root.getChildNumber(1) != null);
return GROUP;
}
use of org.bboxdb.distribution.region.DistributionRegionCallback in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method waitForSystemsCallback.
@Test(timeout = 10000)
public void waitForSystemsCallback() throws ZookeeperException, InterruptedException {
final CountDownLatch latch = new CountDownLatch(1);
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
Assert.assertEquals(0, root.getHighestChildNumber());
final DistributionRegionCallback callback = (e, r) -> {
if (r.equals(root)) {
latch.countDown();
}
};
distributionRegionSyncer.registerCallback(callback);
final BBoxDBInstance newInstance = new BBoxDBInstance("localhost:8443");
final String path = distributionRegionAdapter.getZookeeperPathForDistributionRegion(root);
distributionRegionAdapter.addSystemToDistributionRegion(path, newInstance);
latch.await();
distributionRegionSyncer.unregisterCallback(callback);
Assert.assertTrue(root.getSystems().contains(newInstance));
}
use of org.bboxdb.distribution.region.DistributionRegionCallback in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method testEventOnDelete.
@Test(timeout = 10000)
public void testEventOnDelete() throws InterruptedException, ZookeeperException {
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
createSplittedRoot(distributionRegionSyncer, root);
// Tree children will be removed
final CountDownLatch removedLatch = new CountDownLatch(3);
final DistributionRegionCallback removedCallback = (e, r) -> {
if (e == DistributionRegionEvent.REMOVED) {
removedLatch.countDown();
}
};
distributionRegionSyncer.registerCallback(removedCallback);
distributionGroupAdapter.deleteDistributionGroup(GROUP);
System.out.println("=== testEventOnDelete: Wait for removed latch");
removedLatch.await();
distributionRegionSyncer.unregisterCallback(removedCallback);
}
use of org.bboxdb.distribution.region.DistributionRegionCallback in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method testChangeState1.
@Test(timeout = 10000)
public void testChangeState1() throws InterruptedException, ZookeeperException {
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
Assert.assertEquals(DistributionRegionState.ACTIVE, root.getState());
final CountDownLatch latch = new CountDownLatch(1);
final DistributionRegionCallback callback = (e, r) -> {
if (r.getState() == DistributionRegionState.ACTIVE_FULL) {
latch.countDown();
}
};
distributionRegionSyncer.registerCallback(callback);
distributionRegionAdapter.setStateForDistributionRegion(root, DistributionRegionState.ACTIVE_FULL);
latch.await();
distributionRegionSyncer.unregisterCallback(callback);
Assert.assertEquals(DistributionRegionState.ACTIVE_FULL, root.getState());
}
Aggregations