Search in sources :

Example 41 with TupleStoreName

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();
}
Also used : TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteBuffer(java.nio.ByteBuffer)

Example 42 with TupleStoreName

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);
}
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 43 with TupleStoreName

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());
}
Also used : QueryJoinRequest(org.bboxdb.network.packages.request.QueryJoinRequest) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleStoreName(org.bboxdb.storage.entity.TupleStoreName) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 44 with TupleStoreName

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);
}
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 45 with TupleStoreName

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

Aggregations

TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)77 Test (org.junit.Test)25 Tuple (org.bboxdb.storage.entity.Tuple)18 StorageManagerException (org.bboxdb.storage.StorageManagerException)15 ArrayList (java.util.ArrayList)14 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)14 SpacePartitioner (org.bboxdb.distribution.partitioner.SpacePartitioner)13 ByteBuffer (java.nio.ByteBuffer)12 BoundingBox (org.bboxdb.commons.math.BoundingBox)12 DistributionRegionIdMapper (org.bboxdb.distribution.region.DistributionRegionIdMapper)12 BBoxDBException (org.bboxdb.misc.BBoxDBException)12 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)12 RoutingHeader (org.bboxdb.network.routing.RoutingHeader)12 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)12 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)11 List (java.util.List)10 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)10 TupleStoreManagerRegistry (org.bboxdb.storage.tuplestore.manager.TupleStoreManagerRegistry)10 ErrorResponse (org.bboxdb.network.packages.response.ErrorResponse)9 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)9