use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class ListTablesResponse method createBody.
/**
* Create the body as byte array
* @return
* @throws IOException
*/
protected byte[] createBody() throws IOException {
final ByteArrayOutputStream bodyStream = new ByteArrayOutputStream();
// Write total amount of tables
final ByteBuffer totalTables = DataEncoderHelper.intToByteBuffer(tables.size());
bodyStream.write(totalTables.array(), 0, totalTables.array().length);
for (final TupleStoreName table : tables) {
final byte[] tableBytes = table.getFullnameBytes();
// Write table length
final ByteBuffer tableLength = DataEncoderHelper.shortToByteBuffer((short) tableBytes.length);
bodyStream.write(tableLength.array(), 0, tableLength.array().length);
// Write table name
bodyStream.write(tableBytes, 0, tableBytes.length);
}
bodyStream.close();
return bodyStream.toByteArray();
}
use of org.bboxdb.storage.entity.TupleStoreName 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);
}
use of org.bboxdb.storage.entity.TupleStoreName in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testDecodeJoinQuery.
/**
* Test decode bounding box query
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testDecodeJoinQuery() throws IOException, PackageEncodeException {
final List<TupleStoreName> tables = Arrays.asList(new TupleStoreName("3dgroup_table1"), new TupleStoreName("3dgroup_table2"), new TupleStoreName("3dgroup_table3"));
final BoundingBox boundingBox = new BoundingBox(10d, 20d);
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final QueryJoinRequest queryRequest = new QueryJoinRequest(sequenceNumber, ROUTING_HEADER_ROUTED, tables, boundingBox, false, (short) 10);
byte[] encodedPackage = networkPackageToByte(queryRequest);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
boolean result = NetworkPackageDecoder.validateRequestPackageHeader(bb, NetworkConst.REQUEST_TYPE_QUERY);
Assert.assertTrue(result);
final QueryJoinRequest decodedPackage = QueryJoinRequest.decodeTuple(bb);
Assert.assertEquals(queryRequest.getBoundingBox(), decodedPackage.getBoundingBox());
Assert.assertEquals(tables, decodedPackage.getTables());
Assert.assertEquals(queryRequest.isPagingEnabled(), decodedPackage.isPagingEnabled());
Assert.assertEquals(queryRequest.getTuplesPerPage(), decodedPackage.getTuplesPerPage());
Assert.assertEquals(NetworkConst.REQUEST_QUERY_JOIN, NetworkPackageDecoder.getQueryTypeFromRequest(bb));
Assert.assertEquals(queryRequest.toString(), decodedPackage.toString());
}
use of org.bboxdb.storage.entity.TupleStoreName 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);
}
use of org.bboxdb.storage.entity.TupleStoreName 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);
}
Aggregations