Search in sources :

Example 1 with DistributionRegionCallback

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);
}
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 DistributionRegionCallback

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;
}
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 DistributionRegionCallback

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));
}
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)

Example 4 with DistributionRegionCallback

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);
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 5 with DistributionRegionCallback

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());
}
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) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Aggregations

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