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));
}
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());
}
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));
}
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);
}
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();
}
Aggregations