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