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