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);
}
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);
}
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);
}
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);
}
Aggregations