use of org.bboxdb.network.packages.response.TupleResponse 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.network.packages.response.TupleResponse 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.network.packages.response.TupleResponse in project bboxdb by jnidzwetzki.
the class ClientConnectionHandler method writeResultTuple.
/**
* Send a new result tuple to the client
* @param packageSequence
* @param requestTable
* @param tuple
* @throws PackageEncodeException
* @throws IOException
*/
public void writeResultTuple(final short packageSequence, final JoinedTuple joinedTuple) throws IOException, PackageEncodeException {
if (joinedTuple.getNumberOfTuples() == 1) {
final TupleResponse responsePackage = new TupleResponse(packageSequence, joinedTuple.getTupleStoreName(0), joinedTuple.getTuple(0));
writeResultPackage(responsePackage);
} else {
final JoinedTupleResponse responsePackage = new JoinedTupleResponse(packageSequence, joinedTuple);
writeResultPackage(responsePackage);
}
}
use of org.bboxdb.network.packages.response.TupleResponse in project bboxdb by jnidzwetzki.
the class TupleHandler method handleServerResult.
/**
* Handle a single tuple as result
* @return
*/
@Override
public boolean handleServerResult(final BBoxDBConnection bBoxDBConnection, final ByteBuffer encodedPackage, final NetworkOperationFuture future) throws PackageEncodeException {
if (logger.isDebugEnabled()) {
logger.debug("Handle tuple package");
}
final TupleResponse singleTupleResponse = TupleResponse.decodePackage(encodedPackage);
final short sequenceNumber = singleTupleResponse.getSequenceNumber();
// Tuple is part of a multi tuple result
final Map<Short, List<PagedTransferableEntity>> resultBuffer = bBoxDBConnection.getResultBuffer();
if (resultBuffer.containsKey(sequenceNumber)) {
final List<PagedTransferableEntity> packageResult = resultBuffer.get(sequenceNumber);
packageResult.add(singleTupleResponse.getTuple());
// tuple result or a multiple tuple result
return false;
}
// Single tuple is returned
if (future != null) {
future.setOperationResult(Arrays.asList(singleTupleResponse.getTuple()));
future.fireCompleteEvent();
}
return true;
}
use of org.bboxdb.network.packages.response.TupleResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testCompressionReponse1.
/**
* Test the compression response
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testCompressionReponse1() throws IOException, PackageEncodeException {
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 CompressionEnvelopeResponse compressionEnvelopeResponse = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(singleTupleResponse));
final byte[] encodedPackage = networkPackageToByte(compressionEnvelopeResponse);
Assert.assertNotNull(encodedPackage);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedPackage);
final InputStream uncompressedByteStream = CompressionEnvelopeResponse.decodePackage(bb);
final byte[] uncompressedBytes = ByteStreams.toByteArray(uncompressedByteStream);
final ByteBuffer uncompressedByteBuffer = NetworkPackageDecoder.encapsulateBytes(uncompressedBytes);
final TupleResponse responseDecoded = TupleResponse.decodePackage(uncompressedByteBuffer);
Assert.assertEquals(singleTupleResponse.getTable(), responseDecoded.getTable());
Assert.assertEquals(singleTupleResponse.getTuple(), responseDecoded.getTuple());
Assert.assertTrue(singleTupleResponse.toString().length() > 10);
}
Aggregations