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