Search in sources :

Example 6 with PeerCapabilities

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());
}
Also used : HelloResponse(org.bboxdb.network.packages.response.HelloResponse) PeerCapabilities(org.bboxdb.network.capabilities.PeerCapabilities) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 7 with PeerCapabilities

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());
}
Also used : PeerCapabilities(org.bboxdb.network.capabilities.PeerCapabilities) HelloRequest(org.bboxdb.network.packages.request.HelloRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 8 with PeerCapabilities

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());
}
Also used : CompressionEnvelopeResponse(org.bboxdb.network.packages.response.CompressionEnvelopeResponse) InputStream(java.io.InputStream) HelloResponse(org.bboxdb.network.packages.response.HelloResponse) PeerCapabilities(org.bboxdb.network.capabilities.PeerCapabilities) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 9 with PeerCapabilities

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());
}
Also used : PeerCapabilities(org.bboxdb.network.capabilities.PeerCapabilities) HelloRequest(org.bboxdb.network.packages.request.HelloRequest) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 10 with PeerCapabilities

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();
}
Also used : PeerCapabilities(org.bboxdb.network.capabilities.PeerCapabilities) Test(org.junit.Test)

Aggregations

PeerCapabilities (org.bboxdb.network.capabilities.PeerCapabilities)11 Test (org.junit.Test)9 ByteBuffer (java.nio.ByteBuffer)5 HelloResponse (org.bboxdb.network.packages.response.HelloResponse)3 PackageEncodeException (org.bboxdb.network.packages.PackageEncodeException)2 HelloRequest (org.bboxdb.network.packages.request.HelloRequest)2 InputStream (java.io.InputStream)1 CompressionEnvelopeResponse (org.bboxdb.network.packages.response.CompressionEnvelopeResponse)1