Search in sources :

Example 51 with BBoxDBInstance

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

the class PackageRouter method checkLocalSystemNameMatches.

/**
 * Ensure that the package is routed to the correct system
 * @param localHop
 * @return
 * @throws BBoxDBException
 */
public static boolean checkLocalSystemNameMatches(final RoutingHop localHop) throws BBoxDBException {
    final BBoxDBInstance localInstanceName = ZookeeperClientFactory.getLocalInstanceName();
    final BBoxDBInstance routingInstanceName = localHop.getDistributedInstance();
    return (localInstanceName.socketAddressEquals(routingInstanceName));
}
Also used : BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance)

Example 52 with BBoxDBInstance

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

the class TestRoutingHeader method testDispatchHeader.

/**
 * Test header dispatch
 */
@Test(timeout = 60000)
public void testDispatchHeader() {
    final RoutingHop hop1 = new RoutingHop(new BBoxDBInstance("host1:50500"), Arrays.asList(123l));
    final RoutingHop hop2 = new RoutingHop(new BBoxDBInstance("host2:50500"), Arrays.asList(456l));
    final List<RoutingHop> routingList = Arrays.asList(new RoutingHop[] { hop1, hop2 });
    final RoutingHeader routingHeader = new RoutingHeader((short) 0, routingList);
    Assert.assertEquals(0, routingHeader.getHop());
    Assert.assertFalse(routingHeader.reachedFinalInstance());
    Assert.assertEquals(hop1, routingHeader.getRoutingHop());
    final boolean res1 = routingHeader.dispatchToNextHop();
    Assert.assertTrue(res1);
    Assert.assertTrue(routingHeader.reachedFinalInstance());
    Assert.assertEquals(1, routingHeader.getHop());
    Assert.assertEquals(hop2, routingHeader.getRoutingHop());
    final boolean res2 = routingHeader.dispatchToNextHop();
    Assert.assertFalse(res2);
    Assert.assertTrue(routingHeader.reachedFinalInstance());
    Assert.assertEquals(1, routingHeader.getHop());
    final boolean res3 = routingHeader.dispatchToNextHop();
    Assert.assertFalse(res3);
    Assert.assertTrue(routingHeader.reachedFinalInstance());
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 53 with BBoxDBInstance

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

the class TestRoutingHeader method testRoutingHeaderHopParser2.

/**
 * Test the hop parser
 */
@Test(timeout = 60000)
public void testRoutingHeaderHopParser2() {
    final RoutingHop hop1 = new RoutingHop(new BBoxDBInstance("host1:50500"), Arrays.asList(123l));
    final RoutingHop hop2 = new RoutingHop(new BBoxDBInstance("host2:50500"), Arrays.asList(456l));
    final RoutingHop hop3 = new RoutingHop(new BBoxDBInstance("host3:50500"), Arrays.asList(789l));
    final List<RoutingHop> routingList = new ArrayList<>();
    routingList.add(hop1);
    routingList.add(hop2);
    routingList.add(hop3);
    final RoutingHeader routingHeader = new RoutingHeader((short) 0, routingList);
    // Get routing list as string and parse list
    final String stringRoutingList = routingHeader.getRoutingListAsString();
    routingHeader.setRoutingList(stringRoutingList);
    final List<RoutingHop> parsedRoutingList = routingHeader.getRoutingList();
    Assert.assertEquals(3, parsedRoutingList.size());
    Assert.assertTrue(parsedRoutingList.contains(hop1));
    Assert.assertTrue(parsedRoutingList.contains(hop2));
    Assert.assertTrue(parsedRoutingList.contains(hop3));
}
Also used : ArrayList(java.util.ArrayList) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) RoutingHop(org.bboxdb.network.routing.RoutingHop) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 54 with BBoxDBInstance

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

the class TestBBoxDBInstance method testToString.

@Test(timeout = 60000)
public void testToString() {
    final BBoxDBInstance bBoxDBInstance1 = new BBoxDBInstance("127.0.0.1:10000");
    Assert.assertTrue(bBoxDBInstance1.getStringValue().length() > 0);
    Assert.assertTrue(bBoxDBInstance1.toGUIString(false).length() > 0);
    Assert.assertTrue(bBoxDBInstance1.toGUIString(true).length() > 0);
}
Also used : BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) Test(org.junit.Test)

Example 55 with BBoxDBInstance

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

the class TestDistributedInstanceManager method testAddEvent.

/**
 * Test add event generation
 * @throws InterruptedException
 * @throws ZookeeperException
 */
@Test(timeout = 30000)
public void testAddEvent() throws InterruptedException {
    final BBoxDBInstanceManager distributedInstanceManager = BBoxDBInstanceManager.getInstance();
    final BBoxDBInstance instance1 = new BBoxDBInstance("node4:5050");
    final BBoxDBInstance instance2 = new BBoxDBInstance("node5:5050");
    final ZookeeperClient zookeeperClient1 = getNewZookeeperClient(instance1);
    BBoxDBInstanceManager.getInstance().startMembershipObserver(zookeeperClient1);
    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.ADD) {
                if (instance.socketAddressEquals(instance2)) {
                    changedLatch.countDown();
                }
            } else {
                // Unexpected event
                System.out.println("Got unexpeceted event: " + event);
                Assert.assertTrue(false);
            }
        }
    });
    final ZookeeperClient zookeeperClient2 = getNewZookeeperClient(instance2);
    changedLatch.await();
    distributedInstanceManager.removeAllListener();
    zookeeperClient1.shutdown();
    zookeeperClient2.shutdown();
}
Also used : ZookeeperClient(org.bboxdb.distribution.zookeeper.ZookeeperClient) BBoxDBInstanceManager(org.bboxdb.distribution.membership.BBoxDBInstanceManager) BBoxDBInstance(org.bboxdb.distribution.membership.BBoxDBInstance) DistributedInstanceEvent(org.bboxdb.distribution.membership.DistributedInstanceEvent) CountDownLatch(java.util.concurrent.CountDownLatch) 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