Search in sources :

Example 11 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class TestDistributedInstanceManager method testRegisterUnregister2.

/**
 * test unregister
 */
@Test(timeout = 60000)
public void testRegisterUnregister2() throws InterruptedException {
    final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
    final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
    Assert.assertTrue(zookeeperClient.isConnected());
    Thread.sleep(1000);
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
    Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
    Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
    zookeeperClient.shutdown();
    Assert.assertTrue(distributedInstanceManager.getInstances().isEmpty());
    final BBoxDBInstance instance2 = new BBoxDBInstance("node1:5050");
    final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient2);
    Assert.assertTrue(zookeeperClient2.isConnected());
    Thread.sleep(1000);
    Assert.assertFalse(distributedInstanceManager.getInstances().isEmpty());
    Assert.assertEquals(1, distributedInstanceManager.getInstances().size());
    Assert.assertEquals(instance.getInetSocketAddress(), distributedInstanceManager.getInstances().get(0).getInetSocketAddress());
    zookeeperClient2.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 12 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class TestDistributedInstanceManager method testWriteSystemInfo.

/**
 * Test write the system info
 */
@Test(timeout = 60000)
public void testWriteSystemInfo() {
    final BBoxDBInstance instance1 = new BBoxDBInstance("node6:5050");
    final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
    final List<BBoxDBInstance> distributedInstances = BBoxDBInstanceManager.getInstance().getInstances();
    Assert.assertEquals(1, distributedInstances.size());
    final BBoxDBInstance instance = distributedInstances.get(0);
    Assert.assertEquals(SystemInfo.getAvailableMemory(), instance.getMemory());
    Assert.assertEquals(SystemInfo.getCPUCores(), instance.getCpuCores());
    final BBoxDBConfiguration bboxDBConfiguration = BBoxDBConfigurationManager.getConfiguration();
    final List<String> directories = bboxDBConfiguration.getStorageDirectories();
    Assert.assertEquals(directories.size(), instance.getNumberOfStorages());
    Assert.assertEquals(directories.size(), instance.getAllTotalSpaceLocations().size());
    Assert.assertEquals(directories.size(), instance.getAllFreeSpaceLocations().size());
    for (final String directory : directories) {
        final File path = new File(directory);
        Assert.assertEquals(SystemInfo.getFreeDiskspace(path), (long) instance.getAllFreeSpaceLocations().get(directory), 1000000);
        Assert.assertEquals(SystemInfo.getTotalDiskspace(path), (long) instance.getAllTotalSpaceLocations().get(directory), 1000000);
    }
    zookeeperClient1.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBConfiguration(org.bboxdb.misc.BBoxDBConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) File(java.io.File) Test(org.junit.Test)

Example 13 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class TestRegionSyncer method waitForSystemsCallback.

@Test(timeout = 10000)
public void waitForSystemsCallback() throws ZookeeperException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final DistributionRegionSyncer distributionRegionSyncer = buildSyncer();
    final DistributionRegion root = distributionRegionSyncer.getRootNode();
    Assert.assertEquals(0, root.getHighestChildNumber());
    final DistributionRegionCallback callback = (e, r) -> {
        if (r.equals(root)) {
            latch.countDown();
        }
    };
    distributionRegionSyncer.registerCallback(callback);
    final BBoxDBInstance newInstance = new BBoxDBInstance("localhost:8443");
    final String path = distributionRegionAdapter.getZookeeperPathForDistributionRegion(root);
    distributionRegionAdapter.addSystemToDistributionRegion(path, newInstance);
    latch.await();
    distributionRegionSyncer.unregisterCallback(callback);
    Assert.assertTrue(root.getSystems().contains(newInstance));
}
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) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) CountDownLatch(java.util.concurrent.CountDownLatch) DistributionRegionSyncer(org.bboxdb.distribution.region.DistributionRegionSyncer) Test(org.junit.Test)

Example 14 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class TestTupleSink method testTupleSink.

/**
 * Test the tuple sinks
 * @throws StorageManagerException
 * @throws BBoxDBException
 * @throws ZookeeperException
 * @throws InterruptedException
 */
@Test(timeout = 60000)
public void testTupleSink() throws StorageManagerException, BBoxDBException, ZookeeperException, InterruptedException {
    final DistributionRegion distributionRegion = SpacePartitionerCache.getInstance().getSpacePartitionerForGroupName(TEST_GROUP).getRootNode();
    tupleStoreAdapter.deleteTable(TABLENAME);
    tupleStoreAdapter.writeTuplestoreConfiguration(TABLENAME, new TupleStoreConfiguration());
    final List<BBoxDBInstance> systems = Arrays.asList(new BBoxDBInstance("10.0.0.1:10000"), new BBoxDBInstance("10.0.0.2:10000"), ZookeeperClientFactory.getLocalInstanceName());
    distributionRegion.setSystems(systems);
    final TupleRedistributor tupleRedistributor = createTupleRedistributor();
    tupleRedistributor.registerRegion(distributionRegion);
    final Map<DistributionRegion, List<AbstractTupleSink>> map = tupleRedistributor.getRegionMap();
    Assert.assertEquals(1, map.size());
    final long networkSinks = map.values().stream().flatMap(e -> e.stream()).filter(s -> s instanceof NetworkTupleSink).count();
    Assert.assertEquals(2, networkSinks);
    final long localSinks = map.values().stream().flatMap(e -> e.stream()).filter(s -> s instanceof LocalTupleSink).count();
    Assert.assertEquals(1, localSinks);
}
Also used : TupleRedistributor(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor) Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) TupleStoreAdapter(org.bboxdb.distribution.zookeeper.TupleStoreAdapter) LocalTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.LocalTupleSink) Tuple(org.bboxdb.storage.entity.Tuple) BoundingBox(org.bboxdb.commons.math.BoundingBox) ArrayList(java.util.ArrayList) ZookeeperException(org.bboxdb.distribution.zookeeper.ZookeeperException) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) Map(java.util.Map) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) StorageManagerException(org.bboxdb.storage.StorageManagerException) DistributionGroupConfiguration(org.bboxdb.storage.entity.DistributionGroupConfiguration) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperClientFactory(org.bboxdb.distribution.zookeeper.ZookeeperClientFactory) NetworkTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.NetworkTupleSink) DistributionGroupConfigurationBuilder(org.bboxdb.storage.entity.DistributionGroupConfigurationBuilder) Test(org.junit.Test) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) TupleStoreManagerRegistry(org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry) Mockito(org.mockito.Mockito) List(java.util.List) AbstractTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.AbstractTupleSink) BBoxDBException(org.bboxdb.misc.BBoxDBException) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) DistributionGroupAdapter(org.bboxdb.distribution.zookeeper.DistributionGroupAdapter) SpacePartitionerCache(org.bboxdb.distribution.partitioner.SpacePartitionerCache) TupleRedistributor(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.TupleRedistributor) Assert(org.junit.Assert) DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) LocalTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.LocalTupleSink) NetworkTupleSink(org.bboxdb.distribution.partitioner.regionsplit.tuplesink.NetworkTupleSink) ArrayList(java.util.ArrayList) List(java.util.List) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 15 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance in project bboxdb by jnidzwetzki.

the class TestZookeeperIntegration method testSystemCheckpoint2.

/**
 * Test the set and get checkpoint methods
 * @throws Exception
 */
@Test(timeout = 60000)
public void testSystemCheckpoint2() throws Exception {
    final BBoxDBInstance systemName1 = new BBoxDBInstance("192.168.1.10:5050");
    final BBoxDBInstance systemName2 = new BBoxDBInstance("192.168.1.20:5050");
    final KDtreeSpacePartitioner distributionGroupAdapter = (KDtreeSpacePartitioner) getSpacePartitioner();
    final DistributionRegion region = distributionGroupAdapter.getRootNode();
    distributionGroupAdapter.splitNode(region, 50);
    final DistributionRegion region1 = region.getDirectChildren().get(0);
    final String path1 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(region1);
    final DistributionRegion region2 = region.getDirectChildren().get(1);
    final String path2 = distributionRegionAdapter.getZookeeperPathForDistributionRegion(region2);
    distributionRegionAdapter.addSystemToDistributionRegion(path1, systemName1);
    distributionRegionAdapter.addSystemToDistributionRegion(path1, systemName2);
    distributionRegionAdapter.addSystemToDistributionRegion(path2, systemName1);
    distributionRegionAdapter.addSystemToDistributionRegion(path2, systemName2);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region1, systemName1, 1);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region1, systemName2, 2);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region2, systemName1, 3);
    distributionRegionAdapter.setCheckpointForDistributionRegion(region2, systemName2, 4);
    final long checkpoint1 = distributionRegionAdapter.getCheckpointForDistributionRegion(region1, systemName1);
    final long checkpoint2 = distributionRegionAdapter.getCheckpointForDistributionRegion(region1, systemName2);
    final long checkpoint3 = distributionRegionAdapter.getCheckpointForDistributionRegion(region2, systemName1);
    final long checkpoint4 = distributionRegionAdapter.getCheckpointForDistributionRegion(region2, systemName2);
    Assert.assertEquals(1, checkpoint1);
    Assert.assertEquals(2, checkpoint2);
    Assert.assertEquals(3, checkpoint3);
    Assert.assertEquals(4, checkpoint4);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) KDtreeSpacePartitioner(org.bboxdb.distribution.partitioner.KDtreeSpacePartitioner) Test(org.junit.Test)

Aggregations

BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)78 Test (org.junit.Test)36 ArrayList (java.util.ArrayList)28 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)25 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 ZookeeperClient (org.bboxdb.distribution.zookeeper.ZookeeperClient)14 List (java.util.List)13 RoutingHop (org.bboxdb.network.routing.RoutingHop)13 BBoxDBInstanceManager (org.bboxdb.distribution.membership.BBoxDBInstanceManager)11 ZookeeperException (org.bboxdb.distribution.zookeeper.ZookeeperException)11 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)11 BoundingBox (org.bboxdb.commons.math.BoundingBox)9 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)8 Map (java.util.Map)7 HashMap (java.util.HashMap)6 ZookeeperBBoxDBInstanceAdapter (org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter)6 ZookeeperNotFoundException (org.bboxdb.distribution.zookeeper.ZookeeperNotFoundException)6 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)6 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)6 OptionalDouble (java.util.OptionalDouble)4