use of io.fabric8.dosgi.api.ProtobufSerializationStrategy in project fabric8 by jboss-fuse.
the class TransportFailureTest method testInvoke.
@Test
public void testInvoke() throws Exception {
DispatchQueue queue = Dispatch.createQueue();
HashMap<String, SerializationStrategy> map = new HashMap<String, SerializationStrategy>();
map.put("protobuf", new ProtobufSerializationStrategy());
ServerInvokerImpl server = new ServerInvokerImpl("tcp://localhost:0", queue, map);
server.start();
ClientInvokerImpl client = new ClientInvokerImpl(queue, map);
client.start();
try {
server.registerService("service-id", new ServerInvoker.ServiceFactory() {
public Object get() {
return new HelloImpl();
}
public void unget() {
}
}, HelloImpl.class.getClassLoader());
InvocationHandler handler = client.getProxy(server.getConnectAddress(), "service-id", HelloImpl.class.getClassLoader());
Hello hello = (Hello) Proxy.newProxyInstance(HelloImpl.class.getClassLoader(), new Class[] { Hello.class }, handler);
AsyncCallbackFuture<String> future1 = new AsyncCallbackFuture<String>();
hello.hello("Guillaume", future1);
long t0 = System.currentTimeMillis();
try {
assertEquals("Hello Guillaume!", future1.get(MAX_DELAY, TimeUnit.MILLISECONDS));
fail("Should have thrown an exception");
} catch (Exception e) {
// Expected
long t1 = System.currentTimeMillis();
assertTrue(t1 - t0 > SLEEP_TIME / 2);
assertTrue(t1 - t0 < MAX_DELAY / 2);
}
} finally {
server.stop();
client.stop();
}
}
Aggregations