use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TestRoutingHeader method testUnroutedPackageHeader.
/**
* Test the encoding and the decoding of an unrouted package
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testUnroutedPackageHeader() throws IOException, PackageEncodeException {
final RoutingHeader routingHeader = new RoutingHeader(false);
final byte[] encodedBytes = RoutingHeaderParser.encodeHeader(routingHeader);
final ByteArrayInputStream bis = new ByteArrayInputStream(encodedBytes);
final RoutingHeader resultRoutingHeader = RoutingHeaderParser.decodeRoutingHeader(bis);
Assert.assertEquals(routingHeader, resultRoutingHeader);
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TestRoutingHeader method testSetHopInvalid.
/**
* Test set invalid next hops
*/
@Test(expected = IllegalArgumentException.class)
public void testSetHopInvalid() {
final RoutingHeader routingHeader = new RoutingHeader((short) 10, "node1:12,1;node2:23,2");
routingHeader.setHop((short) 2);
}
use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.
the class TestRoutingHeader method testRoutingHopParser3.
/**
* Test the routing hop parser
*/
@Test(timeout = 60000)
public void testRoutingHopParser3() {
final RoutingHeader routingHeader = new RoutingHeader((short) 10, "node1:12,1;node2:23,2");
Assert.assertEquals(2, routingHeader.getRoutingList().size());
Assert.assertEquals(1, routingHeader.getRoutingList().get(0).getDistributionRegions().size());
Assert.assertEquals(1, routingHeader.getRoutingList().get(1).getDistributionRegions().size());
Assert.assertTrue(routingHeader.getRoutingList().get(0).getDistributionRegions().contains(1l));
Assert.assertTrue(routingHeader.getRoutingList().get(1).getDistributionRegions().contains(2l));
}
use of org.bboxdb.network.routing.RoutingHeader 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.network.routing.RoutingHeader 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));
}
Aggregations