use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class QueuedFileMessageWriterTest method testAFewWrites_serviceCalls.
@Test
@SuppressWarnings("unchecked")
public void testAFewWrites_serviceCalls() throws IOException, InterruptedException {
setDefaultPollDelay(new Duration(10, TimeUnit.MILLISECONDS));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
QueuedMessageWriter writer = new QueuedMessageWriter(target);
ExecutorService executorService = Executors.newFixedThreadPool(11);
for (int i = 0; i < 10; ++i) {
executorService.submit(() -> {
MessageGenerator generator = new MessageGenerator();
for (int j = 0; j < 10; ++j) {
try {
if (j > 0)
sleep(1L);
PServiceCall tmp = new PServiceCall("test", PServiceCallType.CALL, j, generator.generate(CompactFields.kDescriptor));
writer.write(tmp);
} catch (IOException e) {
throw new UncheckedIOException(e.getMessage(), e);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
});
}
sleep(10L);
executorService.shutdown();
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
sleep(1L);
writer.close();
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class QueuedFileMessageWriterTest method testAFewWrites.
@Test
@SuppressWarnings("unchecked")
public void testAFewWrites() throws IOException, InterruptedException {
setDefaultPollDelay(new Duration(10, TimeUnit.MILLISECONDS));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
IOMessageWriter target = new IOMessageWriter(baos, new BinarySerializer());
QueuedMessageWriter writer = new QueuedMessageWriter(target);
ExecutorService executorService = Executors.newFixedThreadPool(11);
for (int i = 0; i < 10; ++i) {
executorService.submit(() -> {
MessageGenerator generator = new MessageGenerator();
for (int j = 0; j < 10; ++j) {
try {
if (j > 0)
sleep(1L);
writer.write(generator.generate(CompactFields.kDescriptor));
} catch (IOException e) {
throw new UncheckedIOException(e.getMessage(), e);
} catch (InterruptedException e) {
e.printStackTrace();
Thread.currentThread().interrupt();
}
}
});
}
sleep(10L);
executorService.shutdown();
assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS));
sleep(1L);
writer.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
List<CompactFields> result = MessageStreams.stream(bais, new BinarySerializer(), CompactFields.kDescriptor).collect(Collectors.toList());
assertThat(result, hasSize(100));
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class NonblockingSocketClientHandlerTest method setUpServer.
@Before
public void setUpServer() throws Exception {
setDefaultPollDelay(10, TimeUnit.MILLISECONDS);
serializer = new BinarySerializer();
TProtocolFactory factory = new TBinaryProtocol.Factory();
impl = Mockito.mock(Iface.class);
TNonblockingServerTransport transport = new TNonblockingServerSocket(0);
server = new TNonblockingServer(new TNonblockingServer.Args(transport).protocolFactory(factory).processor(new Processor<>(impl)));
port = ((TNonblockingServerSocket) transport).getPort();
executor = Executors.newSingleThreadExecutor();
executor.submit(server::serve);
address = new InetSocketAddress("localhost", port);
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class SocketClientHandlerTest method setUpServer.
@BeforeClass
public static void setUpServer() throws Exception {
Awaitility.setDefaultPollDelay(2, TimeUnit.MILLISECONDS);
impl = Mockito.mock(Iface.class);
TServerSocket transport = new TServerSocket(0);
server = new TSimpleServer(new TServer.Args(transport).protocolFactory(new TBinaryProtocol.Factory()).processor(new Processor<>(impl)));
executor = Executors.newSingleThreadExecutor();
executor.submit(server::serve);
serializer = new BinarySerializer();
port = transport.getServerSocket().getLocalPort();
address = new InetSocketAddress("localhost", port);
}
use of net.morimekta.providence.serializer.BinarySerializer in project providence by morimekta.
the class SocketServerTest method setUpClass.
@BeforeClass
public static void setUpClass() {
setDefaultPollDelay(20, TimeUnit.MILLISECONDS);
impl = mock(Iface.class);
instrumentation = mock(ServiceCallInstrumentation.class);
server = SocketServer.builder(new Processor(impl)).withSerializer(new BinarySerializer(true)).withInstrumentation(instrumentation).withMaxBacklog(1).withThreadFactory(new ThreadFactoryBuilder().setDaemon(true).setNameFormat("test-%d").build()).withWorkerThreads(1).withClientTimeout(200).start();
port = server.getPort();
}
Aggregations