Search in sources :

Example 71 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion 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)

Example 72 with DistributionRegion

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

the class TestDynamicgridSpacePartitioner method testRootElement.

@Test(timeout = 60000)
public void testRootElement() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final DynamicgridSpacePartitioner spacePartitioner = getSpacePartitioner();
    final DistributionRegion rootElement = spacePartitioner.getRootNode();
    Assert.assertEquals(rootElement.getState(), DistributionRegionState.SPLIT);
    final BoundingBox box = rootElement.getConveringBox();
    Assert.assertEquals(new BoundingBox(0.0, 5.0, 0.0, 6.0), box);
}
Also used : DynamicgridSpacePartitioner(org.bboxdb.distribution.partitioner.DynamicgridSpacePartitioner) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) Test(org.junit.Test)

Example 73 with DistributionRegion

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

the class TestDynamicgridSpacePartitioner method createGridCells.

@Test(timeout = 60000)
public void createGridCells() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final DynamicgridSpacePartitioner spacePartitioner = getSpacePartitioner();
    final DistributionRegion rootElement = spacePartitioner.getRootNode();
    final long regions = rootElement.getThisAndChildRegions().stream().map(r -> r.getState()).filter(DistributionRegionHelper.PREDICATE_REGIONS_FOR_WRITE).count();
    Assert.assertEquals(12, regions);
}
Also used : DynamicgridSpacePartitioner(org.bboxdb.distribution.partitioner.DynamicgridSpacePartitioner) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) Test(org.junit.Test)

Example 74 with DistributionRegion

use of org.bboxdb.distribution.region.DistributionRegion 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 75 with DistributionRegion

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

the class TestQuadtreeSpacePartitioner method testRestrictedSpace.

/**
 * Test the restricted space
 * @throws ZookeeperException
 * @throws BBoxDBException
 * @throws ZookeeperNotFoundException
 */
@Test(timeout = 60000)
public void testRestrictedSpace() throws ZookeeperException, BBoxDBException, ZookeeperNotFoundException {
    final BoundingBox completeSpace = new BoundingBox(0d, 10d, 0d, 10d);
    final DistributionGroupConfiguration configuration = DistributionGroupConfigurationBuilder.create(2).withSpacePartitioner("org.bboxdb.distribution.partitioner.QuadtreeSpacePartitioner", completeSpace.toCompactString()).withPlacementStrategy("org.bboxdb.distribution.placement.DummyResourcePlacementStrategy", "").build();
    distributionGroupZookeeperAdapter.deleteDistributionGroup(TEST_GROUP);
    distributionGroupZookeeperAdapter.createDistributionGroup(TEST_GROUP, configuration);
    final QuadtreeSpacePartitioner spacepartitionier = getSpacePartitioner();
    final DistributionRegion rootNode = spacepartitionier.getRootNode();
    Assert.assertEquals(completeSpace, rootNode.getConveringBox());
    spacepartitionier.splitRegion(rootNode, new HashSet<>());
    Assert.assertEquals("[[0.0,5.0):[0.0,5.0)]", rootNode.getChildNumber(0).getConveringBox().toCompactString());
    Assert.assertEquals("[[5.0,10.0]:[0.0,5.0)]", rootNode.getChildNumber(1).getConveringBox().toCompactString());
    Assert.assertEquals("[[0.0,5.0):[5.0,10.0]]", rootNode.getChildNumber(2).getConveringBox().toCompactString());
    Assert.assertEquals("[[5.0,10.0]:[5.0,10.0]]", rootNode.getChildNumber(3).getConveringBox().toCompactString());
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BoundingBox(org.bboxdb.commons.math.BoundingBox) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) QuadtreeSpacePartitioner(org.bboxdb.distribution.partitioner.QuadtreeSpacePartitioner) 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