Search in sources :

Example 6 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestKDtreeSpacePartitioner method testDistributionRegionSplitWithZookeeperPropergate.

/**
 * Test the distribution of changes in the zookeeper structure (reading data from the second object)
 */
@Test(timeout = 60000)
public void testDistributionRegionSplitWithZookeeperPropergate() throws Exception {
    final KDtreeSpacePartitioner adapter1 = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion distributionGroup1 = adapter1.getRootNode();
    final KDtreeSpacePartitioner adapter2 = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion distributionGroup2 = adapter2.getRootNode();
    // Update object 1
    adapter1.splitNode(distributionGroup1, 10);
    // Sleep some seconds to wait for the update
    adapter2.waitForSplitCompleteZookeeperCallback(distributionGroup1, 2);
    // Read update from the second object
    final DistributionRegion firstChild = distributionGroup2.getDirectChildren().get(0);
    Assert.assertEquals(10.0, firstChild.getConveringBox().getCoordinateHigh(0), DELTA);
    // Check region ids
    Assert.assertEquals(0, distributionGroup2.getRegionId());
    Assert.assertEquals(1, distributionGroup2.getDirectChildren().get(0).getRegionId());
    Assert.assertEquals(2, distributionGroup2.getDirectChildren().get(1).getRegionId());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 7 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestKDtreeSpacePartitioner method testDistributionRegionLevel.

/**
 * Test the distribution region level
 * @throws Exception
 */
@Test(timeout = 60000)
public void testDistributionRegionLevel() throws Exception {
    final KDtreeSpacePartitioner kdTreeAdapter = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
    final DistributionRegion rootNode = kdTreeAdapter.getRootNode();
    Assert.assertEquals(1, rootNode.getTotalLevel());
    Assert.assertEquals(0, rootNode.getLevel());
    kdTreeAdapter.splitNode(rootNode, (float) 20.0);
    kdTreeAdapter.waitForSplitCompleteZookeeperCallback(rootNode, 2);
    Assert.assertEquals(2, rootNode.getTotalLevel());
    for (final DistributionRegion region : rootNode.getAllChildren()) {
        Assert.assertEquals(2, region.getTotalLevel());
        Assert.assertEquals(1, region.getLevel());
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 8 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestKDtreeSpacePartitioner method testDistributionRegionSplitWithZookeeperPropergate2.

/**
 * Test the distribution of changes in the zookeeper structure (reading data from the second object)
 * @throws ZookeeperException
 * @throws InterruptedException
 * @throws ZookeeperNotFoundException
 * @throws BBoxDBException
 * @throws ResourceAllocationException
 */
@Test(timeout = 60000)
public void testDistributionRegionSplitWithZookeeperPropergate2() throws Exception {
    System.out.println("== Build KD adapter 1");
    final KDtreeSpacePartitioner adapter1 = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion distributionGroup1 = adapter1.getRootNode();
    Assert.assertEquals(2, distributionGroup1.getConveringBox().getDimension());
    System.out.println("== Build KD adapter 2");
    final KDtreeSpacePartitioner adapter2 = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion distributionGroup2 = adapter2.getRootNode();
    Assert.assertEquals(2, distributionGroup2.getConveringBox().getDimension());
    Assert.assertEquals(0, distributionGroup1.getLevel());
    // Update object 1
    adapter1.splitNode(distributionGroup1, 10);
    final DistributionRegion leftChild = distributionGroup1.getDirectChildren().get(0);
    Assert.assertEquals(1, leftChild.getLevel());
    Assert.assertEquals(1, adapter2.getSplitDimension(leftChild));
    adapter1.splitNode(leftChild, 50);
    // Sleep 2 seconds to wait for the update
    adapter2.waitForSplitCompleteZookeeperCallback(leftChild, 2);
    // Read update from the second object
    final DistributionRegion firstChild = distributionGroup2.getDirectChildren().get(0);
    Assert.assertEquals(10.0, firstChild.getConveringBox().getCoordinateHigh(0), DELTA);
    final DistributionRegion secondChild = firstChild.getDirectChildren().get(0);
    Assert.assertEquals(50.0, secondChild.getConveringBox().getCoordinateHigh(1), DELTA);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 9 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testStatistics2.

/**
 * Test the statistics of child regions
 * @throws Exception
 */
@Test(timeout = 60000)
public void testStatistics2() throws Exception {
    final BBoxDBInstance system1 = new BBoxDBInstance("192.168.1.10:5050");
    final KDtreeSpacePartitioner spaceparitioner = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion region = spaceparitioner.getRootNode();
    final OptionalDouble totalSize1 = RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    Assert.assertFalse(totalSize1.isPresent());
    spaceparitioner.splitNode(region, 12);
    spaceparitioner.waitForSplitCompleteZookeeperCallback(region, 2);
    distributionRegionAdapter.updateRegionStatistics(region.getDirectChildren().get(0), system1, 12, 999);
    distributionRegionAdapter.updateRegionStatistics(region.getDirectChildren().get(1), system1, 33, 999);
    StatisticsHelper.clearHistory();
    final OptionalDouble totalSizeAfterClear = RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    Assert.assertFalse(totalSizeAfterClear.isPresent());
    // Update complete history
    for (int i = 0; i < StatisticsHelper.HISTORY_LENGTH; i++) {
        RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    }
    final OptionalDouble totalSize2 = RegionMergeHelper.getTotalRegionSize(region.getDirectChildren());
    Assert.assertEquals(45, totalSize2.getAsDouble(), DELTA);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test)

Example 10 with KDtreeSpacePartitioner

use of org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testCreateAndDeleteDistributionGroup.

/**
 * Test the deletion and the creation of an instance
 * @throws Exception
 */
@Test(timeout = 60000)
public void testCreateAndDeleteDistributionGroup() throws Exception {
    final KDtreeSpacePartitioner cacheGroup = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
    Assert.assertTrue(cacheGroup.getRootNode().isLeafRegion());
    System.out.println("---> Split");
    final KDtreeSpacePartitioner kdTreeAdapter = (KDtreeSpacePartitioner) getSpacePartitioner();
    kdTreeAdapter.splitNode(kdTreeAdapter.getRootNode(), (float) 20.0);
    System.out.println("---> Split done");
    // Test fresh copy
    final SpacePartitioner freshGroup = getSpacePartitioner();
    final DistributionRegion firstChildFresh = freshGroup.getRootNode().getDirectChildren().get(0);
    Assert.assertEquals(20.0, firstChildFresh.getConveringBox().getCoordinateHigh(0), DELTA);
    distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
    // Test cached instance
    try {
        cacheGroup.getRootNode().getDirectChildren().get(0);
        // This should not happen
        Assert.assertFalse(true);
    } catch (BBoxDBException e) {
    // Unable to get root on a space partitioner after shutdown
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) BBoxDBException(org.bboxdb.misc.BBoxDBException) SpacePartitioner(org.bboxdb.distribution.partitioner.SpacePartitioner) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Aggregations

KDtreeSpacePartitioner (org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner)12 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)12 Test (org.junit.Test)12 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)2 List (java.util.List)1 OptionalDouble (java.util.OptionalDouble)1 DistributionRegionState (org.bboxdb.distribution.partitioner.DistributionRegionState)1 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)1 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)1 DistributionRegionAdapter (org.bboxdb.distribution.zookeeper.DistributionRegionAdapter)1 BBoxDBException (org.bboxdb.misc.BBoxDBException)1 DistributionGroupConfiguration (org.bboxdb.storage.entity.DistributionGroupConfiguration)1