use of org.bboxdb.network.packages.response.CompressionEnvelopeResponse in project bboxdb by jnidzwetzki.
the class ClientConnectionHandler method flushPendingCompressionPackages.
/**
* Write all pending compression packages to server, called by the maintainance thread
*/
protected void flushPendingCompressionPackages() {
final List<NetworkResponsePackage> packagesToWrite = new ArrayList<>();
synchronized (pendingCompressionPackages) {
if (pendingCompressionPackages.isEmpty()) {
return;
}
packagesToWrite.addAll(pendingCompressionPackages);
pendingCompressionPackages.clear();
}
if (logger.isDebugEnabled()) {
logger.debug("Chunk size is: {}", packagesToWrite.size());
}
final NetworkResponsePackage compressionEnvelopeRequest = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, packagesToWrite);
try {
writePackageToSocket(compressionEnvelopeRequest);
} catch (PackageEncodeException | IOException e) {
logger.error("Got an exception while write pending compression packages to client", e);
}
}
use of org.bboxdb.network.packages.response.CompressionEnvelopeResponse in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method testCompressionReponse2.
/**
* Test the compression response
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void testCompressionReponse2() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.setGZipCompression();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
final CompressionEnvelopeResponse compressionEnvelopeResponse = new CompressionEnvelopeResponse(NetworkConst.COMPRESSION_TYPE_GZIP, Arrays.asList(helloPackage));
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 HelloResponse decodedPackage = HelloResponse.decodePackage(uncompressedByteBuffer);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertTrue(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertTrue(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.packages.response.CompressionEnvelopeResponse 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