Search in sources :

Example 1 with InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest 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 2 with InsertTupleRequest

use of org.bboxdb.network.packages.request.InsertTupleRequest 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 3 with InsertTupleRequest

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

the class TestNetworkClasses method testGetRequestBodyLength.

/**
 * Read the body length from a request package
 * @throws IOException
 * @throws PackageEncodeException
 */
@Test(timeout = 60000)
public void testGetRequestBodyLength() 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);
    final byte[] encodedPackage = networkPackageToByte(insertPackage);
    Assert.assertNotNull(encodedPackage);
    // 18 Byte package header
    final int calculatedBodyLength = encodedPackage.length - 18;
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final long bodyLength = NetworkPackageDecoder.getBodyLengthFromRequestPackage(bb);
    Assert.assertEquals(calculatedBodyLength, bodyLength);
}
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 4 with InsertTupleRequest

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

the class BBoxDBClient method getInsertTupleFuture.

/**
 * @param table
 * @param tuple
 * @param routingHeader
 * @return
 */
public NetworkOperationFuture getInsertTupleFuture(final String table, final Tuple tuple, final RoutingHeader routingHeader) {
    return new NetworkOperationFuture(connection, () -> {
        final TupleStoreName ssTableName = new TupleStoreName(table);
        final short sequenceNumber = connection.getNextSequenceNumber();
        return new InsertTupleRequest(sequenceNumber, routingHeader, ssTableName, tuple);
    });
}
Also used : NetworkOperationFuture(org.bboxdb.network.client.future.NetworkOperationFuture) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest)

Example 5 with InsertTupleRequest

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

the class TestCompressionRatio method handleCompressedData.

/**
 * Handle compressed packages
 * @param tableName
 * @param buffer
 * @return
 * @throws PackageEncodeException
 * @throws IOException
 */
protected long handleCompressedData(final TupleStoreName tableName, final List<Tuple> buffer) {
    final RoutingHeader routingHeader = new RoutingHeader(false);
    final List<NetworkRequestPackage> packages = buffer.stream().map(t -> new InsertTupleRequest((short) 4, routingHeader, tableName, t)).collect(Collectors.toList());
    final CompressionEnvelopeRequest compressionEnvelopeRequest = new CompressionEnvelopeRequest(NetworkConst.COMPRESSION_TYPE_GZIP, packages);
    buffer.clear();
    return packageToBytes(compressionEnvelopeRequest);
}
Also used : Arrays(java.util.Arrays) PackageEncodeException(org.bboxdb.network.packages.PackageEncodeException) Logger(org.slf4j.Logger) ByteArrayOutputStream(java.io.ByteArrayOutputStream) NetworkConst(org.bboxdb.network.NetworkConst) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) Tuple(org.bboxdb.storage.entity.Tuple) LoggerFactory(org.slf4j.LoggerFactory) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Objects(java.util.Objects) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) List(java.util.List) TupleFileReader(org.bboxdb.tools.TupleFileReader) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) CompressionEnvelopeRequest(org.bboxdb.network.packages.request.CompressionEnvelopeRequest) NetworkRequestPackage(org.bboxdb.network.packages.NetworkRequestPackage) RoutingHeader(org.bboxdb.network.routing.RoutingHeader) InsertTupleRequest(org.bboxdb.network.packages.request.InsertTupleRequest)

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