use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class IOMessageRWTest method testBinary.
@Test
public void testBinary() throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (MessageWriter writer = new IOMessageWriter(baos, new BinarySerializer())) {
writer.write(m1);
writer.separator();
writer.write(m2);
}
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
try (MessageReader reader = new IOMessageReader(bais, new BinarySerializer())) {
assertThat(m1, is(equalTo(reader.read(CompactFields.kDescriptor))));
assertThat(m2, is(equalTo(reader.read(OptionalFields.kDescriptor))));
}
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class QueuedFileMessageWriterTest method testClose_noQueue.
@Test
public void testClose_noQueue() throws IOException, InterruptedException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
ExecutorService executor = mock(ExecutorService.class);
when(executor.isShutdown()).thenReturn(false);
when(executor.awaitTermination(1000L, TimeUnit.MILLISECONDS)).thenReturn(false);
QueuedMessageWriter writer = new QueuedMessageWriter(target, executor);
writer.close();
verify(executor).submit(any(Runnable.class));
verify(executor).isShutdown();
verify(executor).shutdown();
verify(executor).awaitTermination(1000L, TimeUnit.MILLISECONDS);
verify(executor).shutdownNow();
verifyNoMoreInteractions(executor);
assertThat(baos.toByteArray(), is(new byte[] {}));
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class QueuedFileMessageWriterTest method testSeparator.
@Test
public void testSeparator() throws IOException {
setDefaultPollDelay(new Duration(10, TimeUnit.MILLISECONDS));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
QueuedMessageWriter writer = new QueuedMessageWriter(target);
assertThat(writer.separator(), is(0));
writer.close();
assertThat(baos.size(), is(0));
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class NonblockingSocketClientHandlerTest method testSimpleRequest_cannotConnect.
@Test
public void testSimpleRequest_cannotConnect() throws IOException, Failure {
Serializer serializer = new BinarySerializer();
InetSocketAddress address = new InetSocketAddress("localhost", port - 10);
try (NonblockingSocketClientHandler handler = new NonblockingSocketClientHandler(serializer, address)) {
MyService.Iface client = new MyService.Client(handler);
try {
client.test(Request.builder().setText("test").build());
fail("no exception");
} catch (ConnectException e) {
// The exception message is entirely localized, so it's impossible to reliably match against.
// assertThat(e.getMessage(), startsWith("Connection refused"));
}
verifyZeroInteractions(impl);
}
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class SocketClientHandlerTest method testSimpleRequest_cannotConnect.
@Test
public void testSimpleRequest_cannotConnect() throws IOException, Failure, InterruptedException {
Serializer serializer = new BinarySerializer();
InetSocketAddress address = new InetSocketAddress("localhost", port - 10);
MyService.Iface client = new MyService.Client(new SocketClientHandler(serializer, address));
try {
client.test(new Request(null));
fail("no exception");
} catch (ConnectException e) {
assertThat(e.getMessage(), containsString("Connection refused"));
}
Thread.sleep(10L);
verifyZeroInteractions(impl);
}
Aggregations