Search in sources :

Example 46 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testSingleTupleResponse.

/**
 * Try to encode and decode the single tuple response
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testSingleTupleResponse() throws PackageEncodeException, IOException {
    final String tablename = "table1";
    final Tuple tuple = new Tuple("abc", BoundingBox.FULL_SPACE, "databytes".getBytes());
    final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
    final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertFalse(singleTupleResponse.getTuple() instanceof DeletedTuple);
    Assert.assertTrue(singleTupleResponse.toString().length() > 10);
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 47 with Tuple

use of org.bboxdb.storage.entity.Tuple 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 48 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestNetworkClasses method testSingleTupleDeletedResponse.

/**
 * Try to encode and decode the single tuple response - with deleted tuple
 * @throws PackageEncodeException
 * @throws IOException
 */
@Test(timeout = 60000)
public void testSingleTupleDeletedResponse() throws PackageEncodeException, IOException {
    final String tablename = "table1";
    final Tuple tuple = new DeletedTuple("abc", 12);
    final TupleResponse singleTupleResponse = new TupleResponse((short) 4, tablename, tuple);
    final byte[] encodedPackage = networkPackageToByte(singleTupleResponse);
    Assert.assertNotNull(encodedPackage);
    final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
    final TupleResponse responseDecoded = TupleResponse.decodePackage(bb);
    Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
    Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
    Assert.assertTrue(singleTupleResponse.getTuple() instanceof DeletedTuple);
    Assert.assertEquals(singleTupleResponse.toString(), responseDecoded.toString());
}
Also used : TupleResponse(org.bboxdb.network.packages.response.TupleResponse) JoinedTupleResponse(org.bboxdb.network.packages.response.JoinedTupleResponse) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) ByteBuffer(java.nio.ByteBuffer) JoinedTuple(org.bboxdb.storage.entity.JoinedTuple) Tuple(org.bboxdb.storage.entity.Tuple) DeletedTuple(org.bboxdb.storage.entity.DeletedTuple) Test(org.junit.Test)

Example 49 with Tuple

use of org.bboxdb.storage.entity.Tuple 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 50 with Tuple

use of org.bboxdb.storage.entity.Tuple in project bboxdb by jnidzwetzki.

the class TestNetworkCommunication method testGetByKey.

/**
 * Insert a tuple and request it via key
 * @throws ExecutionException
 * @throws InterruptedException
 * @throws BBoxDBException
 */
@Test(timeout = 60000)
public void testGetByKey() throws InterruptedException, ExecutionException, BBoxDBException {
    System.out.println("=== Running testGetByKey");
    final String table = DISTRIBUTION_GROUP + "_relation12333";
    final BBoxDBConnection bboxdbConnection = connectToServer();
    final BBoxDBClient bboxDBClient = bboxdbConnection.getBboxDBClient();
    // Create table
    final EmptyResultFuture resultCreateTable = bboxDBClient.createTable(table, new TupleStoreConfiguration());
    resultCreateTable.waitForAll();
    Assert.assertFalse(resultCreateTable.isFailed());
    // Inside our bbox query
    final Tuple tuple1 = new Tuple("abc", new BoundingBox(0d, 1d, 0d, 1d), "abc".getBytes());
    final EmptyResultFuture result1 = bboxDBClient.insertTuple(table, tuple1);
    result1.waitForAll();
    final TupleListFuture future = bboxDBClient.queryKey(table, "abc");
    future.waitForAll();
    final List<Tuple> resultList = Lists.newArrayList(future.iterator());
    Assert.assertEquals(1, resultList.size());
    System.out.println("=== End testGetByKey");
    disconnect(bboxDBClient);
}
Also used : BBoxDBClient(org.bboxdb.network.client.BBoxDBClient) TupleStoreConfiguration(org.bboxdb.storage.entity.TupleStoreConfiguration) BoundingBox(org.bboxdb.commons.math.BoundingBox) TupleListFuture(org.bboxdb.network.client.future.TupleListFuture) BBoxDBConnection(org.bboxdb.network.client.BBoxDBConnection) Tuple(org.bboxdb.storage.entity.Tuple) EmptyResultFuture(org.bboxdb.network.client.future.EmptyResultFuture) Test(org.junit.Test)

Aggregations

Tuple (org.bboxdb.storage.entity.Tuple)198 Test (org.junit.Test)123 DeletedTuple (org.bboxdb.storage.entity.DeletedTuple)104 BoundingBox (org.bboxdb.commons.math.BoundingBox)62 JoinedTuple (org.bboxdb.storage.entity.JoinedTuple)58 ArrayList (java.util.ArrayList)41 TupleStoreConfiguration (org.bboxdb.storage.entity.TupleStoreConfiguration)25 TupleStoreName (org.bboxdb.storage.entity.TupleStoreName)24 TupleListFuture (org.bboxdb.network.client.future.TupleListFuture)18 TupleStoreManager (org.bboxdb.storage.tuplestore.manager.TupleStoreManager)18 ByteBuffer (java.nio.ByteBuffer)17 BBoxDBException (org.bboxdb.misc.BBoxDBException)16 EmptyResultFuture (org.bboxdb.network.client.future.EmptyResultFuture)15 SSTableKeyIndexReader (org.bboxdb.storage.sstable.reader.SSTableKeyIndexReader)13 IOException (java.io.IOException)11 List (java.util.List)11 JoinedTupleListFuture (org.bboxdb.network.client.future.JoinedTupleListFuture)11 InsertTupleRequest (org.bboxdb.network.packages.request.InsertTupleRequest)11 StorageManagerException (org.bboxdb.storage.StorageManagerException)11 TupleBuilder (org.bboxdb.tools.converter.tuple.TupleBuilder)11