Search in sources :

Example 61 with DistributionRegion

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

the class TestRegionSyncer method testEventTypes.

@Test(timeout = 10000)
public void testEventTypes() throws InterruptedException, ZookeeperException {
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    // Root node is changed on add and remove children
    final CountDownLatch changedLatch = new CountDownLatch(2);
    final DistributionRegionCallback rootNodeChangedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.CHANGED && r.equals(root)) {
            changedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(rootNodeChangedCallback);
    // Two new children will be added
    final CountDownLatch addedLatch = new CountDownLatch(2);
    final DistributionRegionCallback adddedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.ADDED && !r.equals(root)) {
            addedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(adddedCallback);
    // Two children will be removed
    final CountDownLatch removedLatch = new CountDownLatch(2);
    final DistributionRegionCallback removedCallback = (e, r) -> {
        if (e == DistributionRegionEvent.REMOVED && !r.equals(root)) {
            removedLatch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(removedCallback);
    // Mutate tree
    createSplittedRoot(distributionRegionSyncer, root);
    // Wait
    System.out.println("=== Wait for added latch");
    addedLatch.await();
    distributionRegionAdapter.deleteChild(root.getChildNumber(0));
    distributionRegionAdapter.deleteChild(root.getChildNumber(1));
    System.out.println("=== Wait for removed latch");
    removedLatch.await();
    System.out.println("=== Wait for changed latch");
    changedLatch.await();
    distributionRegionSyncer.unregisterCallback(rootNodeChangedCallback);
    distributionRegionSyncer.unregisterCallback(adddedCallback);
    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 62 with DistributionRegion

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

the class TestSampling method testSamplingBasedSplitStrategy1.

/**
 * Test the sampling
 * @throws RejectedException
 * @throws StorageManagerException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testSamplingBasedSplitStrategy1() throws StorageManagerException, RejectedException, BBoxDBException {
    createDummyTable();
    final DistributionRegion rootNode = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP).getRootNode();
    final Collection<BoundingBox> samples = SamplingHelper.getSamplesForRegion(rootNode, storageRegistry);
    Assert.assertFalse(samples.isEmpty());
    final SplitpointStrategy splitpointStrategy = new SamplingBasedSplitStrategy(samples);
    final BoundingBox coveringBox1 = new BoundingBox(1d, 2d, -1d, 20d);
    final double splitPoint0 = splitpointStrategy.getSplitPoint(0, coveringBox1);
    final double splitPoint1 = splitpointStrategy.getSplitPoint(1, coveringBox1);
    Assert.assertTrue(coveringBox1.isCoveringPointInDimension(splitPoint0, 0));
    Assert.assertTrue(coveringBox1.isCoveringPointInDimension(splitPoint1, 1));
    final BoundingBox coveringBox2 = new BoundingBox(1.5d, 2d, -1d, 20d);
    final double splitPoint02 = splitpointStrategy.getSplitPoint(0, coveringBox2);
    final double splitPoint12 = splitpointStrategy.getSplitPoint(1, coveringBox2);
    Assert.assertTrue(coveringBox1.isCoveringPointInDimension(splitPoint02, 0));
    Assert.assertTrue(coveringBox1.isCoveringPointInDimension(splitPoint12, 1));
    final BoundingBox coveringBox3 = new BoundingBox(-1.5d, 2d, -1d, 20d);
    final double splitPoint03 = splitpointStrategy.getSplitPoint(0, coveringBox3);
    final double splitPoint13 = splitpointStrategy.getSplitPoint(1, coveringBox3);
    Assert.assertTrue(coveringBox1.isCoveringPointInDimension(splitPoint03, 0));
    Assert.assertTrue(coveringBox1.isCoveringPointInDimension(splitPoint13, 1));
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) SamplingBasedSplitStrategy(org.bboxdb.distribution.partitioner.regionsplit.SamplingBasedSplitStrategy) SplitpointStrategy(org.bboxdb.distribution.partitioner.regionsplit.SplitpointStrategy) Test(org.junit.Test)

Example 63 with DistributionRegion

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

the class TestSampling method testSampling1.

/**
 * Test the sampling
 * @throws RejectedException
 * @throws StorageManagerException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testSampling1() throws StorageManagerException, RejectedException, BBoxDBException {
    createDummyTable();
    final DistributionRegion rootNode = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP).getRootNode();
    final Collection<BoundingBox> samples = SamplingHelper.getSamplesForRegion(rootNode, storageRegistry);
    Assert.assertFalse(samples.isEmpty());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) Test(org.junit.Test)

Example 64 with DistributionRegion

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

the class TestSampling method testSamplingBasedSplitStrategy2.

/**
 * Test the sampling
 * @throws RejectedException
 * @throws StorageManagerException
 * @throws BBoxDBException
 */
@Test(expected = StorageManagerException.class)
public void testSamplingBasedSplitStrategy2() throws StorageManagerException, RejectedException, BBoxDBException {
    createDummyTable();
    final DistributionRegion rootNode = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP).getRootNode();
    final Collection<BoundingBox> samples = SamplingHelper.getSamplesForRegion(rootNode, storageRegistry);
    Assert.assertFalse(samples.isEmpty());
    final SplitpointStrategy splitpointStrategy = new SamplingBasedSplitStrategy(samples);
    final BoundingBox coveringBox = new BoundingBox(10d, 20d, -1d, 20d);
    final double splitPoint0 = splitpointStrategy.getSplitPoint(0, coveringBox);
    final double splitPoint1 = splitpointStrategy.getSplitPoint(1, coveringBox);
    System.out.println("Split point0: " + splitPoint0);
    System.out.println("Split point1: " + splitPoint1);
    Assert.assertTrue(coveringBox.isCoveringPointInDimension(splitPoint0, 0));
    Assert.assertTrue(coveringBox.isCoveringPointInDimension(splitPoint1, 1));
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) SamplingBasedSplitStrategy(org.bboxdb.distribution.partitioner.regionsplit.SamplingBasedSplitStrategy) SplitpointStrategy(org.bboxdb.distribution.partitioner.regionsplit.SplitpointStrategy) Test(org.junit.Test)

Example 65 with DistributionRegion

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

the class TestTupleSink method testTupleRedistribution2.

/**
 * Test the tuple redistribution
 * @throws Exception
 */
@Test(timeout = 60000)
public void testTupleRedistribution2() throws Exception {
    final DistributionRegion distributionRegion1 = new DistributionRegion(TEST_GROUP, DistributionRegion.ROOT_NODE_ROOT_POINTER, new BoundingBox(0.0, 1.0, 0.0, 1.0, 0.0, 1.0), 1);
    final DistributionRegion distributionRegion2 = new DistributionRegion(TEST_GROUP, DistributionRegion.ROOT_NODE_ROOT_POINTER, new BoundingBox(5.0, 6.0, 5.0, 6.0, 5.0, 6.0), 1);
    final TupleRedistributor tupleRedistributor = createTupleRedistributor();
    final AbstractTupleSink tupleSink1 = Mockito.mock(AbstractTupleSink.class);
    tupleRedistributor.registerRegion(distributionRegion1, Arrays.asList(tupleSink1));
    final AbstractTupleSink tupleSink2 = Mockito.mock(AbstractTupleSink.class);
    tupleRedistributor.registerRegion(distributionRegion2, Arrays.asList(tupleSink2));
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0.0, 1.0, 0.0, 1.0, 0.0, 1.0), "".getBytes());
    tupleRedistributor.redistributeTuple(tuple1);
    (Mockito.verify(tupleSink1, Mockito.times(1))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.never())).sinkTuple(Mockito.any(Tuple.class));
    final Tuple tuple2 = new Tuple("abc", new BoundingBox(5.0, 6.0, 5.0, 6.0, 5.0, 6.0), "".getBytes());
    tupleRedistributor.redistributeTuple(tuple2);
    (Mockito.verify(tupleSink1, Mockito.times(1))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.times(1))).sinkTuple(Mockito.any(Tuple.class));
    final Tuple tuple3 = new Tuple("abc", new BoundingBox(0.0, 6.0, 0.0, 6.0, 0.0, 6.0), "".getBytes());
    tupleRedistributor.redistributeTuple(tuple3);
    (Mockito.verify(tupleSink1, Mockito.atLeast(2))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.atLeast(2))).sinkTuple(Mockito.any(Tuple.class));
    final Tuple tuple4 = new DeletedTuple("abc");
    tupleRedistributor.redistributeTuple(tuple4);
    (Mockito.verify(tupleSink1, Mockito.atLeast(3))).sinkTuple(Mockito.any(Tuple.class));
    (Mockito.verify(tupleSink2, Mockito.atLeast(3))).sinkTuple(Mockito.any(Tuple.class));
    System.out.println(tupleRedistributor.getStatistics());
}
Also used : TupleRedistributor(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) AbstractTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.AbstractTupleSink) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Aggregations

DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)91 Test (org.junit.Test)45 BBoxDBException (org.bboxdb.misc.BBoxDBException)34 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)33 BoundingBox (org.bboxdb.commons.math.BoundingBox)27 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)23 ArrayList (java.util.ArrayList)17 List (java.util.List)17 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)16 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)15 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)15 KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)14 DistributionGroupAdapter (org.bboxdb.distribution.zookeeper.DistributionGroupAdapter)11 ZookeeperClientFactory (org.bboxdb.distribution.zookeeper.ZookeeperClientFactory)11 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)10 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)10 DistributionRegionSyncer (org.bboxdb.distribution.region.DistributionRegionSyncer)10 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)10 RoutingHop (org.bboxdb.network.routing.RoutingHop)10 DistributionGroupConfigurationBuilder (org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder)10