Search in sources :

Example 6 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method encodeAndDecodeDeletedTuple1.

/**
 * The the encoding and decoding of an insert tuple package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeDeletedTuple1() throws IOException, PackageEncodeException {
    final Tuple tuple = new DeletedTuple("key", 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_UNROUTED, new TupleStoreName("test"), tuple);
    byte[] encodedVersion = networkPackageToByte(insertPackage);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(bb);
    Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
    Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
    Assert.assertEquals(insertPackage.getRoutingHeader(), new RoutingHeader(false));
    Assert.assertEquals(insertPackage, decodedPackage);
    Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertEquals(insertPackage.toString(), decodedPackage.toString());
    Assert.assertTrue(TupleHelper.isDeletedTuple(decodedPackage.getTuple()));
}
Also used : DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 7 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method encodeAndDecodeInsertTupleWithCustomHeader.

/**
 * The the encoding and decoding of an insert tuple package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeInsertTupleWithCustomHeader() throws IOException, PackageEncodeException {
    final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
    final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_ROUTED, new TupleStoreName("test"), tuple);
    Assert.assertEquals(routingHeader, insertPackage.getRoutingHeader());
    byte[] encodedVersion = networkPackageToByte(insertPackage);
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(bb);
    Assert.assertEquals(insertPackage.getTuple(), decodedPackage.getTuple());
    Assert.assertEquals(insertPackage.getTable(), decodedPackage.getTable());
    Assert.assertEquals(routingHeader, decodedPackage.getRoutingHeader());
    Assert.assertFalse(insertPackage.getRoutingHeader().equals(new RoutingHeader(false)));
    Assert.assertEquals(insertPackage, decodedPackage);
    Assert.assertEquals(insertPackage.hashCode(), decodedPackage.hashCode());
    Assert.assertTrue(insertPackage.toString().length() > 10);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) Test(org.junit.Test)

Example 8 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class TestRoutingHeader method testSetHopValid.

/**
 * Test set valid next hops
 */
@Test(timeout = 60000)
public void testSetHopValid() {
    final RoutingHeader routingHeader = new RoutingHeader((short) 10, "node1:12,2;node2:23,1");
    routingHeader.setHop((short) 0);
    routingHeader.setHop((short) 1);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Test(org.junit.Test)

Example 9 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class TestRoutingHeader method testRoutedPackageHeader1.

/**
 * Test the encoding and the decoding of an routed package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testRoutedPackageHeader1() throws IOException, PackageEncodeException {
    final RoutingHeader routingHeader = new RoutingHeader((short) 10, "node1:12,1;node2:23,2");
    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 10 with RoutingHeader

use of org.bboxdb.network.routing.RoutingHeader in project bboxdb by jnidzwetzki.

the class TestRoutingHeader method testRoutedPackageHeader3.

/**
 * Test the encoding and the decoding of an routed package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testRoutedPackageHeader3() throws IOException, PackageEncodeException {
    final RoutingHeader routingHeader = new RoutingHeader((short) 10, "node1:12,1;node2:23,2");
    final byte[] encodedBytes = RoutingHeaderParser.encodeHeader(routingHeader);
    final ByteBuffer bb = ByteBuffer.wrap(encodedBytes);
    bb.order(Const.APPLICATION_BYTE_ORDER);
    Assert.assertEquals(0, bb.position());
    final RoutingHeader resultRoutingHeader = RoutingHeaderParser.decodeRoutingHeader(bb);
    Assert.assertEquals(0, bb.remaining());
    Assert.assertEquals(routingHeader, resultRoutingHeader);
    Assert.assertEquals(routingHeader.hashCode(), resultRoutingHeader.hashCode());
    Assert.assertTrue(routingHeader.toString().length() > 10);
}
Also used : RoutingHeader(org.bboxdb.network.routing.RoutingHeader) ByteBuffer(java.nio.ByteBuffer) 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