Search in sources :

Example 1 with DistributionRegionSyncer

use of org.bboxdb.distribution.region.DistributionRegionSyncer 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);
}
Also used : SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer)

Example 2 with DistributionRegionSyncer

use of org.bboxdb.distribution.region.DistributionRegionSyncer 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;
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 3 with DistributionRegionSyncer

use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method getExistingRoot.

@Test(timeout = 60000)
public void getExistingRoot() throws ZookeeperException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    Assert.assertTrue(root != null);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 4 with DistributionRegionSyncer

use of org.bboxdb.distribution.region.DistributionRegionSyncer in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method getNonExistingRoot.

@Test(timeout = 60000)
public void getNonExistingRoot() throws ZookeeperException {
    distributionGroupAdapter.deleteDistributionGroup(GROUP);
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    Assert.assertEquals(null, root);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 5 with DistributionRegionSyncer

use of org.bboxdb.distribution.region.DistributionRegionSyncer 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));
}
Also used : DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) SpacePartitionerContext(org.bboxdb.distribution.partitioner.SpacePartitionerContext) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) Set(java.util.Set) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) DistributionRegionState(org.bboxdb.distribution.partitioner.DistributionRegionState) CopyOnWriteArraySet(java.util.concurrent.CopyOnWriteArraySet) BoundingBox(org.bboxdb.commons.math.BoundingBox) CountDownLatch(java.util.concurrent.CountDownLatch) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionRegionEvent(org.bboxdb.distribution.region.DistributionRegionEvent) BBoxDBException(org.bboxdb.misc.BBoxDBException) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) DistributionRegionAdapter(org.bboxdb.distribution.zookeeper.DistributionRegionAdapter) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) Assert(org.junit.Assert) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Before(org.junit.Before) DistributionRegionCallback(org.bboxdb.distribution.region.DistributionRegionCallback) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Aggregations

DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)12 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 Test (org.junit.Test)10 CopyOnWriteArraySet (java.util.concurrent.CopyOnWriteArraySet)9 SpacePartitionerContext (org.bboxdb.distribution.partitioner.SpacePartitionerContext)9 DistributionRegionCallback (org.bboxdb.distribution.region.DistributionRegionCallback)9 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)9 BBoxDBException (org.bboxdb.misc.BBoxDBException)9 Set (java.util.Set)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)8 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)8 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)8 DistributionRegionEvent (org.bboxdb.distribution.region.DistributionRegionEvent)8 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)8 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)8 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)8 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)8 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)8 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)8