Search in sources :

Example 11 with KDtreeSpacePartitioner

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

the class TestKDtreeSpacePartitioner method testGetMergeCandidates.

/**
 * Test get merge candidates
 * @throws BBoxDBException
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 * @throws ResourceAllocationException
 */
@Test(timeout = 60000)
public void testGetMergeCandidates() throws ZookeeperException, BBoxDBException, ZookeeperNotFoundException, ResourceAllocationException {
    createNewDistributionGroup(2);
    final KDtreeSpacePartitioner spacepartitionier = getSpacePartitioner();
    final DistributionRegion rootNode = spacepartitionier.getRootNode();
    spacepartitionier.splitNode(rootNode, 10);
    spacepartitionier.waitForSplitCompleteZookeeperCallback(rootNode, 2);
    spacepartitionier.splitComplete(rootNode, rootNode.getDirectChildren());
    spacepartitionier.waitUntilNodeStateIs(rootNode, DistributionRegionState.SPLIT);
    Assert.assertEquals(rootNode.getState(), DistributionRegionState.SPLIT);
    final DistributionRegion childNumber0 = rootNode.getChildNumber(0);
    final DistributionRegion childNumber1 = rootNode.getChildNumber(1);
    Assert.assertTrue(spacepartitionier.getMergeCandidates(childNumber0).isEmpty());
    Assert.assertTrue(spacepartitionier.getMergeCandidates(childNumber1).isEmpty());
    spacepartitionier.splitNode(childNumber0, 10);
    spacepartitionier.waitForSplitCompleteZookeeperCallback(childNumber0, 2);
    spacepartitionier.splitComplete(childNumber0, childNumber0.getDirectChildren());
    spacepartitionier.waitUntilNodeStateIs(childNumber0, DistributionRegionState.SPLIT);
    Assert.assertEquals(childNumber0.getState(), DistributionRegionState.SPLIT);
    Assert.assertTrue(spacepartitionier.getMergeCandidates(childNumber0.getChildNumber(0)).isEmpty());
    Assert.assertTrue(spacepartitionier.getMergeCandidates(childNumber0.getChildNumber(1)).isEmpty());
    final List<List<DistributionRegion>> mergeCandidates0 = spacepartitionier.getMergeCandidates(childNumber0);
    Assert.assertFalse(mergeCandidates0.isEmpty());
    Assert.assertTrue(spacepartitionier.getMergeCandidates(childNumber1).isEmpty());
    for (final List<DistributionRegion> regions : mergeCandidates0) {
        Assert.assertTrue(regions.size() == 2);
    }
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) List(java.util.List) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Example 12 with KDtreeSpacePartitioner

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

the class TestSpacePartitionerCache method testRootNodeRefresh.

@Test(timeout = 60000)
public void testRootNodeRefresh() throws Exception {
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
    distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
    distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
    final KDtreeSpacePartitioner oldSpacepartitionier = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
    final DistributionRegion oldRootNode = oldSpacepartitionier.getRootNode();
    final DistributionRegionIdMapper mapper = oldSpacepartitionier.getDistributionRegionIdMapper();
    Assert.assertEquals(0, mapper.getAllRegionIds().size());
    mapper.addMapping(3, BoundingBox.FULL_SPACE);
    Assert.assertEquals(1, mapper.getAllRegionIds().size());
    distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
    distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
    final KDtreeSpacePartitioner newSpacepartitionier1 = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
    final DistributionRegion newRootNode = newSpacepartitionier1.getRootNode();
    Assert.assertFalse(oldRootNode == newRootNode);
    Assert.assertEquals(0, mapper.getAllRegionIds().size());
    distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
    distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
    Thread.sleep(1000);
    final KDtreeSpacePartitioner newSpacepartitionier2 = (KDtreeSpacePartitioner) SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP);
    final DistributionRegion newRootNode2 = newSpacepartitionier2.getRootNode();
    Assert.assertFalse(newRootNode2 == newRootNode);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) DistributionRegionIdMapper(org.bboxdb.distribution.region.DistributionRegionIdMapper) 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