Search in sources :

Example 1 with ImmutableRawValue

use of org.msgpack.value.ImmutableRawValue in project fluency by komamitsu.

the class FluencyTest method testWithoutAckResponse.

@Theory
public void testWithoutAckResponse(final boolean sslEnabled) throws Throwable {
    Exception exception = new ConfigurableTestServer(sslEnabled).run(new ConfigurableTestServer.WithClientSocket() {

        @Override
        public void run(Socket clientSocket) throws Exception {
            MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream());
            assertEquals(3, unpacker.unpackArrayHeader());
            assertEquals("foo.bar", unpacker.unpackString());
            ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
            Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
            assertEquals(1, map.size());
            assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
            unpacker.close();
        }
    }, new ConfigurableTestServer.WithServerPort() {

        @Override
        public void run(int serverPort) throws Exception {
            Fluency fluency = Fluency.defaultFluency(serverPort, new Fluency.Config().setSslEnabled(sslEnabled));
            fluency.emit("foo.bar", new HashMap<String, Object>());
            fluency.close();
        }
    }, 5000);
    assertNull(exception);
}
Also used : HashMap(java.util.HashMap) ImmutableRawValue(org.msgpack.value.ImmutableRawValue) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) MessageUnpacker(org.msgpack.core.MessageUnpacker) Map(java.util.Map) HashMap(java.util.HashMap) Socket(java.net.Socket) Theory(org.junit.experimental.theories.Theory)

Example 2 with ImmutableRawValue

use of org.msgpack.value.ImmutableRawValue in project fluency by komamitsu.

the class FluencyTest method testWithAckResponseWithProperToken.

@Theory
public void testWithAckResponseWithProperToken(final boolean sslEnabled) throws Throwable {
    Exception exception = new ConfigurableTestServer(sslEnabled).run(new ConfigurableTestServer.WithClientSocket() {

        @Override
        public void run(Socket clientSocket) throws Exception {
            MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream());
            assertEquals(3, unpacker.unpackArrayHeader());
            assertEquals("foo.bar", unpacker.unpackString());
            ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
            Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
            assertEquals(2, map.size());
            assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
            String ackResponseToken = map.get(KEY_OPTION_CHUNK).asRawValue().asString();
            assertNotNull(ackResponseToken);
            MessagePacker packer = MessagePack.newDefaultPacker(clientSocket.getOutputStream());
            packer.packMapHeader(1).packString("ack").packString(ackResponseToken).close();
            // Close the input stream after closing the output stream to avoid closing a socket too early
            unpacker.close();
        }
    }, new ConfigurableTestServer.WithServerPort() {

        @Override
        public void run(int serverPort) throws Exception {
            Fluency fluency = Fluency.defaultFluency(serverPort, new Fluency.Config().setSslEnabled(sslEnabled).setAckResponseMode(true));
            fluency.emit("foo.bar", new HashMap<String, Object>());
            fluency.close();
        }
    }, 5000);
    assertNull(exception);
}
Also used : HashMap(java.util.HashMap) ImmutableRawValue(org.msgpack.value.ImmutableRawValue) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) MessagePacker(org.msgpack.core.MessagePacker) MessageUnpacker(org.msgpack.core.MessageUnpacker) Map(java.util.Map) HashMap(java.util.HashMap) Socket(java.net.Socket) Theory(org.junit.experimental.theories.Theory)

Example 3 with ImmutableRawValue

use of org.msgpack.value.ImmutableRawValue in project fluency by komamitsu.

the class FluencyTest method testWithAckResponseButNotReceiveToken.

@Theory
public void testWithAckResponseButNotReceiveToken(final boolean sslEnabled) throws Throwable {
    Exception exception = new ConfigurableTestServer(sslEnabled).run(new ConfigurableTestServer.WithClientSocket() {

        @Override
        public void run(Socket clientSocket) throws Exception {
            MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream());
            assertEquals(3, unpacker.unpackArrayHeader());
            assertEquals("foo.bar", unpacker.unpackString());
            ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
            Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
            assertEquals(2, map.size());
            assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
            assertNotNull(map.get(KEY_OPTION_CHUNK).asRawValue().asString());
            unpacker.close();
        }
    }, new ConfigurableTestServer.WithServerPort() {

        @Override
        public void run(int serverPort) throws Exception {
            Fluency fluency = Fluency.defaultFluency(serverPort, new Fluency.Config().setSslEnabled(sslEnabled).setAckResponseMode(true));
            fluency.emit("foo.bar", new HashMap<String, Object>());
            fluency.close();
        }
    }, 5000);
    assertEquals(exception.getClass(), TimeoutException.class);
}
Also used : HashMap(java.util.HashMap) ImmutableRawValue(org.msgpack.value.ImmutableRawValue) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) MessageUnpacker(org.msgpack.core.MessageUnpacker) Map(java.util.Map) HashMap(java.util.HashMap) Socket(java.net.Socket) Theory(org.junit.experimental.theories.Theory)

Example 4 with ImmutableRawValue

use of org.msgpack.value.ImmutableRawValue in project fluency by komamitsu.

the class FluencyTest method testWithAckResponseButWrongReceiveToken.

@Theory
public void testWithAckResponseButWrongReceiveToken(final boolean sslEnabled) throws Throwable {
    Exception exception = new ConfigurableTestServer(sslEnabled).run(new ConfigurableTestServer.WithClientSocket() {

        @Override
        public void run(Socket clientSocket) throws Exception {
            MessageUnpacker unpacker = MessagePack.newDefaultUnpacker(clientSocket.getInputStream());
            assertEquals(3, unpacker.unpackArrayHeader());
            assertEquals("foo.bar", unpacker.unpackString());
            ImmutableRawValue rawValue = unpacker.unpackValue().asRawValue();
            Map<Value, Value> map = unpacker.unpackValue().asMapValue().map();
            assertEquals(2, map.size());
            assertEquals(rawValue.asByteArray().length, map.get(KEY_OPTION_SIZE).asIntegerValue().asInt());
            assertNotNull(map.get(KEY_OPTION_CHUNK).asRawValue().asString());
            MessagePacker packer = MessagePack.newDefaultPacker(clientSocket.getOutputStream());
            packer.packMapHeader(1).packString("ack").packString(UUID.randomUUID().toString()).close();
            // Close the input stream after closing the output stream to avoid closing a socket too early
            unpacker.close();
        }
    }, new ConfigurableTestServer.WithServerPort() {

        @Override
        public void run(int serverPort) throws Exception {
            Fluency fluency = Fluency.defaultFluency(serverPort, new Fluency.Config().setSslEnabled(sslEnabled).setAckResponseMode(true));
            fluency.emit("foo.bar", new HashMap<String, Object>());
            fluency.close();
        }
    }, 5000);
    assertEquals(exception.getClass(), TimeoutException.class);
}
Also used : HashMap(java.util.HashMap) ImmutableRawValue(org.msgpack.value.ImmutableRawValue) TimeoutException(java.util.concurrent.TimeoutException) IOException(java.io.IOException) MessagePacker(org.msgpack.core.MessagePacker) MessageUnpacker(org.msgpack.core.MessageUnpacker) Map(java.util.Map) HashMap(java.util.HashMap) Socket(java.net.Socket) Theory(org.junit.experimental.theories.Theory)

Aggregations

IOException (java.io.IOException)4 Socket (java.net.Socket)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 TimeoutException (java.util.concurrent.TimeoutException)4 Theory (org.junit.experimental.theories.Theory)4 MessageUnpacker (org.msgpack.core.MessageUnpacker)4 ImmutableRawValue (org.msgpack.value.ImmutableRawValue)4 MessagePacker (org.msgpack.core.MessagePacker)2