use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeHeloResponse1.
/**
* The the encoding and decoding of the response helo
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeHeloResponse1() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloResponse helloPackage = new HelloResponse(sequenceNumber, 2, peerCapabilities);
byte[] encodedVersion = networkPackageToByte(helloPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final HelloResponse decodedPackage = HelloResponse.decodePackage(bb);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertFalse(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertFalse(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeHeloRequest2.
/**
* The the encoding and decoding of the request helo
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeHeloRequest2() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.setGZipCompression();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloRequest helloPackage = new HelloRequest(sequenceNumber, 2, peerCapabilities);
byte[] encodedVersion = networkPackageToByte(helloPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final HelloRequest decodedPackage = HelloRequest.decodeRequest(bb);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertTrue(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertTrue(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.capabilities.PeerCapabilities 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.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestNetworkClasses method encodeAndDecodeHeloRequest1.
/**
* The the encoding and decoding of the request helo
* @throws IOException
* @throws PackageEncodeException
*/
@Test(timeout = 60000)
public void encodeAndDecodeHeloRequest1() throws IOException, PackageEncodeException {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
final short sequenceNumber = sequenceNumberGenerator.getNextSequenceNummber();
final HelloRequest helloPackage = new HelloRequest(sequenceNumber, 2, peerCapabilities);
byte[] encodedVersion = networkPackageToByte(helloPackage);
Assert.assertNotNull(encodedVersion);
final ByteBuffer bb = NetworkPackageDecoder.encapsulateBytes(encodedVersion);
final HelloRequest decodedPackage = HelloRequest.decodeRequest(bb);
Assert.assertEquals(helloPackage, decodedPackage);
Assert.assertFalse(decodedPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertFalse(helloPackage.getPeerCapabilities().hasGZipCompression());
Assert.assertEquals(helloPackage.hashCode(), decodedPackage.hashCode());
Assert.assertEquals(helloPackage.toString(), decodedPackage.toString());
}
use of org.bboxdb.network.capabilities.PeerCapabilities in project bboxdb by jnidzwetzki.
the class TestPeerCapabilities method testPeerCapabilitiesRO1.
/**
* Test the peer capabilities
*/
@Test(expected = IllegalStateException.class)
public void testPeerCapabilitiesRO1() {
final PeerCapabilities peerCapabilities = new PeerCapabilities();
peerCapabilities.freeze();
peerCapabilities.setGZipCompression();
}
Aggregations