Search in sources :

Example 41 with RoutingHeader

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);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Test(org.junit.Test)

Example 42 with RoutingHeader

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);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Test(org.junit.Test)

Example 43 with RoutingHeader

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));
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Test(org.junit.Test)

Example 44 with RoutingHeader

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());
}
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 45 with RoutingHeader

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

Aggregations

RoutingHeader (org.bboxdb.network.routing.RoutingHeader)52 Test (org.junit.Test)18 NetworkOperationFuture (org.bboxdb.network.client.future.NetworkOperationFuture)16 RoutingHop (org.bboxdb.network.routing.RoutingHop)15 ArrayList (java.util.ArrayList)12 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)12 BBoxDBInstance (org.bboxdb.distribution.membership.BBoxDBInstance)11 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)11 Tuple (org.bboxdb.storage.entity.Tuple)11 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 List (java.util.List)10 DistributionRegion (org.bboxdb.distribution.region.DistributionRegion)10 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)10 ByteBuffer (java.nio.ByteBuffer)9 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9 DoNothingDuplicateResolver (org.bboxdb.storage.sstable.duplicateresolver.DoNothingDuplicateResolver)8 BoundingBox (org.bboxdb.commons.math.BoundingBox)6 BBoxDBException (org.bboxdb.misc.BBoxDBException)6 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)6