use of net.morimekta.test.providence.thrift.map.RemoteMap in project providence by morimekta.
the class NonblockingSocketServerTest method testWithProvidenceClient.
@Test
public void testWithProvidenceClient() throws IOException, ExecutionException, InterruptedException, TimeoutException {
try (NonblockingSocketClientHandler handler = new NonblockingSocketClientHandler(serializer, new InetSocketAddress("localhost", port))) {
RemoteMap.Client client = new RemoteMap.Client(handler);
Future<Boolean> a = executor.submit(() -> client.put("a", "1234"));
Thread.sleep(3);
Future<Boolean> b = executor.submit(() -> client.put("b", "2345"));
Thread.sleep(3);
Future<Boolean> c = executor.submit(() -> client.put("c", "3456"));
Future<String> f = executor.submit(() -> client.get("f"));
Thread.sleep(3);
Future<Boolean> d = executor.submit(() -> client.put("d", "4567"));
Thread.sleep(3);
Future<Boolean> e = executor.submit(() -> client.put("e", "5678"));
assertThat(a.get(1, TimeUnit.SECONDS), is(false));
assertThat(b.get(1, TimeUnit.SECONDS), is(false));
assertThat(c.get(1, TimeUnit.SECONDS), is(false));
assertThat(d.get(1, TimeUnit.SECONDS), is(false));
assertThat(e.get(1, TimeUnit.SECONDS), is(false));
try {
f.get(1, TimeUnit.SECONDS);
fail("no exception");
} catch (ExecutionException ee) {
assertThat(ee.getCause(), is(instanceOf(NotFound.class)));
}
assertThat(remoteMap, is(ImmutableMap.of("a", "1234", "b", "2345", "c", "3456", "d", "4567", "e", "5678")));
}
}
use of net.morimekta.test.providence.thrift.map.RemoteMap in project providence by morimekta.
the class NonblockingSocketServerTest method testWithPlainThriftClient.
@Test
public void testWithPlainThriftClient() throws IOException, TException, NotFound, InterruptedException {
try (TSocket socket = new TSocket("localhost", port);
TFramedTransport transport = new TFramedTransport(socket)) {
socket.open();
TProtocol protocol = factory.getProtocol(transport);
net.morimekta.test.thrift.thrift.map.RemoteMap.Client client = new net.morimekta.test.thrift.thrift.map.RemoteMap.Client(protocol);
client.put("a", "b");
client.put("b", "");
try {
client.get("c");
fail("no exception");
} catch (net.morimekta.test.thrift.thrift.map.NotFound nfe) {
// nothing to check.
}
verify(instrumentation, times(3)).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(instrumentation);
assertThat(remoteMap, is(ImmutableMap.of("a", "b", "b", "")));
}
reset(instrumentation);
remoteMap.clear();
try (TSocket socket = new TSocket("localhost", port);
TFramedTransport transport = new TFramedTransport(socket)) {
socket.open();
TProtocol protocol = factory.getProtocol(transport);
net.morimekta.test.thrift.thrift.map.RemoteMap.Client client = new net.morimekta.test.thrift.thrift.map.RemoteMap.Client(protocol);
client.put("a", "b123");
client.put("b", "a2345");
try {
client.get("c");
fail("no exception");
} catch (net.morimekta.test.thrift.thrift.map.NotFound nfe) {
// nothing to check.
}
verify(instrumentation, times(3)).onComplete(anyDouble(), any(PServiceCall.class), any(PServiceCall.class));
verifyNoMoreInteractions(instrumentation);
assertThat(remoteMap, is(ImmutableMap.of("a", "b123", "b", "a2345")));
}
}
use of net.morimekta.test.providence.thrift.map.RemoteMap in project providence by morimekta.
the class NonblockingSocketServerTest method testWithNonblockingThriftClient.
@Test
public void testWithNonblockingThriftClient() throws IOException, TException, ExecutionException, InterruptedException, TimeoutException {
CompletableFuture<Boolean> a = new CompletableFuture<>();
CompletableFuture<Boolean> b = new CompletableFuture<>();
TAsyncClientManager manager = new TAsyncClientManager();
try (TNonblockingSocket socket_a = new TNonblockingSocket("localhost", port);
TNonblockingSocket socket_b = new TNonblockingSocket("localhost", port)) {
socket_a.startConnect();
socket_a.finishConnect();
socket_b.startConnect();
socket_b.finishConnect();
net.morimekta.test.thrift.thrift.map.RemoteMap.AsyncClient client_a = new net.morimekta.test.thrift.thrift.map.RemoteMap.AsyncClient(factory, manager, socket_a);
client_a.put("a", "bb", new AsyncMethodCallback<Boolean>() {
@Override
public void onComplete(Boolean response) {
a.complete(response);
}
@Override
public void onError(Exception exception) {
a.completeExceptionally(exception);
}
});
// Since thrift clients does not support handling multiple requests at
// the same time (yes, even the AsyncClient does not support parallel
// execution).
net.morimekta.test.thrift.thrift.map.RemoteMap.AsyncClient client_b = new net.morimekta.test.thrift.thrift.map.RemoteMap.AsyncClient(factory, manager, socket_b);
client_b.put("b", "aaa", new AsyncMethodCallback<Boolean>() {
@Override
public void onComplete(Boolean response) {
b.complete(response);
}
@Override
public void onError(Exception exception) {
b.completeExceptionally(exception);
}
});
assertThat(a.get(1, TimeUnit.SECONDS), is(Boolean.FALSE));
assertThat(b.get(1, TimeUnit.SECONDS), is(Boolean.FALSE));
assertThat(remoteMap, is(ImmutableMap.of("a", "bb", "b", "aaa")));
}
}
Aggregations