Search in sources :

Example 56 with BBoxDBInstance

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

the class TestDistributedInstanceManager method testChangedEventOnDeletion.

/**
 * Test delete event generation
 * @throws InterruptedException
 * @throws ZookeeperException
 */
@Test(timeout = 30000)
public void testChangedEventOnDeletion() throws InterruptedException, ZookeeperException {
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final BBoxDBInstance instance1 = new BBoxDBInstance("node6:5050");
    final BBoxDBInstance instance2 = new BBoxDBInstance("node7:5050");
    final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
    final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter1 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient1);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
    final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
    final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter2 = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient2);
    zookeeperBBoxDBInstanceAdapter1.updateStateData(instance1, BBoxDBInstanceState.READY);
    zookeeperBBoxDBInstanceAdapter2.updateStateData(instance2, BBoxDBInstanceState.READY);
    Thread.sleep(5000);
    final CountDownLatch changedLatch = new CountDownLatch(1);
    distributedInstanceManager.registerListener(new BiConsumer<DistributedInstanceEvent, BBoxDBInstance>() {

        @Override
        public void accept(final DistributedInstanceEvent event, final BBoxDBInstance instance) {
            if (event == DistributedInstanceEvent.CHANGED) {
                if (instance.socketAddressEquals(instance2)) {
                    changedLatch.countDown();
                }
            } else {
                System.out.println("Got unexpeced event: " + event);
                // Unexpected event
                Assert.assertTrue(false);
            }
        }
    });
    zookeeperClient2.shutdown();
    changedLatch.await();
    distributedInstanceManager.removeAllListener();
    zookeeperClient1.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperBBoxDBInstanceAdapter(org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter) DistributedInstanceEvent(org.bboxdb.distribution.membership.DistributedInstanceEvent) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 57 with BBoxDBInstance

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

the class TestDistributedInstanceManager method testRegisterInstance3.

/**
 * One instance is known and changes
 * @throws ZookeeperException
 */
@Test(timeout = 60000)
public void testRegisterInstance3() throws InterruptedException, ZookeeperException {
    final BBoxDBInstance instance = new BBoxDBInstance("node1:5050");
    final ZookeeperClient zookeeperClient = getNewZookeeperClient(instance);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient);
    Assert.assertTrue(zookeeperClient.isConnected());
    Thread.sleep(1000);
    final ZookeeperBBoxDBInstanceAdapter zookeeperBBoxDBInstanceAdapter = new ZookeeperBBoxDBInstanceAdapter(zookeeperClient);
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    Assert.assertTrue(BBoxDBInstanceState.FAILED == distributedInstanceManager.getInstances().get(0).getState());
    zookeeperBBoxDBInstanceAdapter.updateStateData(instance, BBoxDBInstanceState.OUTDATED);
    Thread.sleep(2000);
    System.out.println(distributedInstanceManager.getInstances());
    Assert.assertTrue(BBoxDBInstanceState.OUTDATED == distributedInstanceManager.getInstances().get(0).getState());
    zookeeperBBoxDBInstanceAdapter.updateStateData(instance, BBoxDBInstanceState.READY);
    Thread.sleep(1000);
    Assert.assertTrue(BBoxDBInstanceState.READY == distributedInstanceManager.getInstances().get(0).getState());
    zookeeperClient.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) ZookeeperBBoxDBInstanceAdapter(org.bboxdb.distribution.membership.ZookeeperBBoxDBInstanceAdapter) Test(org.junit.Test)

Example 58 with BBoxDBInstance

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

the class TestZookeeperIntegration method testStatistics1.

/**
 * Test the statistics for a given region
 * @throws ZookeeperException
 * @throws ZookeeperNotFoundException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testStatistics1() throws ZookeeperException, ZookeeperNotFoundException, BBoxDBException {
    final BBoxDBInstance system1 = new BBoxDBInstance("192.168.1.10:5050");
    final BBoxDBInstance system2 = new BBoxDBInstance("192.168.1.11:5050");
    final DistributionRegion region = getSpacePartitioner().getRootNode();
    final OptionalDouble size1 = StatisticsHelper.getAndUpdateStatistics(region);
    Assert.assertFalse(size1.isPresent());
    final Map<BBoxDBInstance, Map<String, Long>> statistics1 = distributionRegionAdapter.getRegionStatistics(region);
    Assert.assertTrue(statistics1.isEmpty());
    distributionRegionAdapter.updateRegionStatistics(region, system1, 12, 999);
    final Map<BBoxDBInstance, Map<String, Long>> statistics2 = distributionRegionAdapter.getRegionStatistics(region);
    Assert.assertEquals(1, statistics2.size());
    Assert.assertEquals(12, statistics2.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE).longValue());
    Assert.assertEquals(999, statistics2.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES).longValue());
    final OptionalDouble size2 = StatisticsHelper.getAndUpdateStatistics(region);
    Assert.assertEquals(12, size2.getAsDouble(), DELTA);
    distributionRegionAdapter.updateRegionStatistics(region, system2, 33, 1234);
    final Map<BBoxDBInstance, Map<String, Long>> statistics3 = distributionRegionAdapter.getRegionStatistics(region);
    Assert.assertEquals(2, statistics3.size());
    Assert.assertEquals(12, statistics3.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE).longValue());
    Assert.assertEquals(999, statistics3.get(system1).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES).longValue());
    Assert.assertEquals(33, statistics3.get(system2).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_SIZE).longValue());
    Assert.assertEquals(1234, statistics3.get(system2).get(ZookeeperNodeNames.NAME_STATISTICS_TOTAL_TUPLES).longValue());
    final OptionalDouble size3 = StatisticsHelper.getAndUpdateStatistics(region);
    Assert.assertEquals(33, size3.getAsDouble(), DELTA);
}
Also used : DistributionRegion(org.bboxdb.distribution.region.DistributionRegion) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Map(java.util.Map) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test)

Example 59 with BBoxDBInstance

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

the class CLI method actionShowInstances.

/**
 * Show all discovered instances
 * @param line
 */
protected void actionShowInstances(final CommandLine line) {
    System.out.println("Show all discovered BBoxDB instances");
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final List<BBoxDBInstance> allInstances = distributedInstanceManager.getInstances();
    allInstances.sort((i1, i2) -> i1.getIp().compareTo(i2.getIp()));
    System.out.println();
    System.out.println("#######");
    allInstances.forEach(i -> System.out.println(i));
    System.out.println("#######");
}
Also used : BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 60 with BBoxDBInstance

use of org.bboxdb.distribution.membership.BBoxDBInstance 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)

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