Search in sources :

Example 6 with InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method encodeAndDecodeInsertTuple2.

/**
 * The the encoding and decoding of an insert tuple package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void encodeAndDecodeInsertTuple2() throws IOException, PackageEncodeException {
    final Tuple tuple = new Tuple("key", new BoundingBox(1.3244343224, 232.232333343, 34324.343, 343243.0), "abc".getBytes(), 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.assertTrue(insertPackage.toString().length() > 10);
}
Also used : BoundingBox(org.bboxdb.commons.math.BoundingBox) 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 InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testCompression2Request.

/**
 * Test the decoding and the encoding of an compressed request package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testCompression2Request() throws IOException, PackageEncodeException {
    final RoutingHeader routingHeader = ROUTING_HEADER_ROUTED;
    final Tuple tuple = new Tuple("abcdefghijklmopqrstuvxyz", BoundingBox.FULL_SPACE, "abcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyzabcdefghijklmopqrstuvxyz".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());
    final CompressionEnvelopeRequest compressionPackage = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(insertPackage));
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    compressionPackage.writeToOutputStream(bos);
    bos.close();
    final byte[] encodedVersion = bos.toByteArray();
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    Assert.assertNotNull(bb);
    final InputStream uncompressedByteStream = CompressionEnvelopeRequest.decodePackage(bb);
    final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
    final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
    final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(uncompressedByteBuffer);
    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 : CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) InputStream(java.io.InputStream) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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 InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testCompression1Request.

/**
 * Test the decoding and the encoding of an compressed request package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testCompression1Request() 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());
    final CompressionEnvelopeRequest compressionPackage = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(insertPackage));
    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    compressionPackage.writeToOutputStream(bos);
    bos.close();
    final byte[] encodedVersion = bos.toByteArray();
    Assert.assertNotNull(encodedVersion);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
    Assert.assertNotNull(bb);
    final InputStream uncompressedByteStream = CompressionEnvelopeRequest.decodePackage(bb);
    final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
    final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
    final InsertTupleRequest decodedPackage = InsertTupleRequest.decodeTuple(uncompressedByteBuffer);
    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 : CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) InputStream(java.io.InputStream) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) 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 9 with InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testDecodePackage.

/**
 * Decode an encoded package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testDecodePackage() throws IOException, PackageEncodeException {
    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_UNROUTED, new TupleStoreName("test"), tuple);
    byte[] encodedPackage = networkPackageToByte(insertPackage);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    boolean result = NetworkPackageDecoder.validateRequestPackageHeader(bb, NetworkConst.REQUEST_TYPE_INSERT_TUPLE);
    Assert.assertTrue(result);
}
Also used : 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 10 with InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testGetSequenceNumber.

/**
 * Get the sequence number from a package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testGetSequenceNumber() throws IOException, PackageEncodeException {
    final Tuple tuple = new Tuple("key", BoundingBox.FULL_SPACE, "abc".getBytes(), 12);
    // Increment to avoid sequenceNumber = 0
    sequenceNumberGenerator.getNextSequenceNummber();
    sequenceNumberGenerator.getNextSequenceNummber();
    final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
    final InsertTupleRequest insertPackage = new InsertTupleRequest(sequenceNumber, ROUTING_HEADER_UNROUTED, new TupleStoreName("test"), tuple);
    final byte[] encodedPackage = networkPackageToByte(insertPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final short packageSequencenNumber = NetworkPackageDecoder.getRequestIDFromRequestPackage(bb);
    Assert.assertEquals(sequenceNumber, packageSequencenNumber);
}
Also used : 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)

Aggregations

InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)13 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)11 Tuple (org.bboxdb.storage.entity.Tuple)10 ByteBuffer (java.nio.ByteBuffer)9 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)9 Test (org.junit.Test)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 CompressionEnvelopeRequest (org.bboxdb.network.packages.request.CompressionEnvelopeRequest)3 InputStream (java.io.InputStream)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Objects (java.util.Objects)1 Collectors (java.util.stream.Collectors)1 RejectedException (org.bboxdb.commons.RejectedException)1 BoundingBox (org.bboxdb.commons.math.BoundingBox)1 NetworkConst (org.bboxdb.network.NetworkConst)1