use of org.bboxdb.distribution.region.DistributionRegionSyncer 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.DistributionRegionSyncer 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());
}
use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method testMerge.
@Test(timeout = 10000)
public void testMerge() throws ZookeeperException, InterruptedException {
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
createSplittedRoot(distributionRegionSyncer, root);
// Delete child 1
System.out.println("=== Delete child 1");
final CountDownLatch deleteLatch1 = new CountDownLatch(1);
final DistributionRegionCallback callback1 = (e, r) -> {
if (root.getAllChildren().size() == 1) {
deleteLatch1.countDown();
}
};
distributionRegionSyncer.registerCallback(callback1);
distributionRegionAdapter.deleteChild(root.getChildNumber(1));
deleteLatch1.await();
distributionRegionSyncer.unregisterCallback(callback1);
Assert.assertEquals(1, root.getAllChildren().size());
// Delete child 2
System.out.println("=== Delete child 2");
final CountDownLatch deleteLatch2 = new CountDownLatch(1);
final DistributionRegionCallback callback2 = (e, r) -> {
if (root.getAllChildren().size() == 0) {
deleteLatch2.countDown();
}
};
distributionRegionSyncer.registerCallback(callback2);
distributionRegionAdapter.deleteChild(root.getChildNumber(0));
deleteLatch2.await();
distributionRegionSyncer.unregisterCallback(callback2);
Assert.assertEquals(0, root.getAllChildren().size());
}
use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method testSplit.
@Test(timeout = 10000)
public void testSplit() throws ZookeeperException, InterruptedException {
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
final String fullname = createSplittedRoot(distributionRegionSyncer, root);
System.out.println("==== Creating subchild");
final DistributionRegion level1Child = root.getChildNumber(0);
final BoundingBox leftBoundingBoxChild = level1Child.getConveringBox().splitAndGetLeft(0, 1, true);
final CountDownLatch latchLevel1 = new CountDownLatch(1);
final String level1ChildPath = distributionRegionAdapter.getZookeeperPathForDistributionRegion(level1Child);
final DistributionRegionCallback level1Callback = (e, r) -> {
if (root.getAllChildren().size() == 3) {
latchLevel1.countDown();
}
};
distributionRegionSyncer.registerCallback(level1Callback);
distributionRegionAdapter.createNewChild(level1ChildPath, 0, leftBoundingBoxChild, fullname);
latchLevel1.await();
distributionRegionSyncer.unregisterCallback(level1Callback);
Assert.assertTrue(root.getChildNumber(0).getChildNumber(0) != null);
Assert.assertEquals(0, root.getRegionId());
Assert.assertEquals(1, root.getChildNumber(0).getRegionId());
Assert.assertEquals(3, root.getChildNumber(0).getChildNumber(0).getRegionId());
Assert.assertEquals(3, root.getAllChildren().size());
Assert.assertEquals(0, root.getLevel());
Assert.assertEquals(1, level1Child.getLevel());
Assert.assertEquals(2, root.getChildNumber(0).getChildNumber(0).getLevel());
// Reread data from zookeeper
System.out.println("== clear in memory data");
distributionRegionSyncer.clear();
final DistributionRegion root2 = distributionRegionSyncer.getRootNode();
Assert.assertTrue(root2.getChildNumber(0).getChildNumber(0) != null);
Assert.assertEquals(0, root2.getRegionId());
Assert.assertEquals(1, root2.getChildNumber(0).getRegionId());
Assert.assertEquals(3, root2.getChildNumber(0).getChildNumber(0).getRegionId());
Assert.assertEquals(3, root2.getAllChildren().size());
Assert.assertEquals(0, root2.getLevel());
Assert.assertEquals(2, root2.getChildNumber(0).getChildNumber(0).getLevel());
}
use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.
the class TestRegionSyncer method testChangeState2.
@Test(timeout = 10000)
public void testChangeState2() throws InterruptedException, ZookeeperException {
final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
final DistributionRegion root = distributionRegionSyncer.getRootNode();
createSplittedRoot(distributionRegionSyncer, root);
final CountDownLatch latch = new CountDownLatch(1);
final DistributionRegionCallback callback = (e, r) -> {
if (r == root.getChildNumber(1) && r.getState() == DistributionRegionState.MERGING) {
latch.countDown();
}
};
distributionRegionSyncer.registerCallback(callback);
distributionRegionAdapter.setStateForDistributionRegion(root.getChildNumber(0), DistributionRegionState.MERGING);
distributionRegionAdapter.setStateForDistributionRegion(root.getChildNumber(1), DistributionRegionState.MERGING);
latch.await();
distributionRegionSyncer.unregisterCallback(callback);
Assert.assertEquals(2, root.getDirectChildren().size());
Assert.assertEquals(DistributionRegionState.MERGING, root.getChildNumber(0).getState());
Assert.assertEquals(DistributionRegionState.MERGING, root.getChildNumber(1).getState());
// Reread state from zookeeper
System.out.println("== clear in memory data");
distributionRegionSyncer.clear();
final DistributionRegion root2 = distributionRegionSyncer.getRootNode();
Assert.assertEquals(2, root2.getDirectChildren().size());
Assert.assertEquals(DistributionRegionState.MERGING, root2.getChildNumber(0).getState());
Assert.assertEquals(DistributionRegionState.MERGING, root2.getChildNumber(1).getState());
}
Aggregations