@Test public void testRequestNoResponse() { Integer payload = new Integer(1); Request request = new Request(UUID.randomUUID(), SettableFuture.create()); Message message = new Message(request, payload); channel.writeOutbound(message); channel.runPendingTasks(); // assert request not in map assertNull(codec.getRequest(codec.getMapping(channel), message)); // assert two objects written in the correct order assertEquals(payload, channel.outboundMessages().poll()); assertEquals(message, channel.outboundMessages().poll()); }
@Test public void testRequestExpectedResponse() { Integer payload = new Integer(1); Request request = new Request(UUID.randomUUID(), SettableFuture.create(), SettableFuture.create()); Message message = new Message(request, payload); channel.writeOutbound(message); channel.runPendingTasks(); // assert request in map assertEquals(request, codec.getRequest(codec.getMapping(channel), message)); // assert two objects written in the correct order assertEquals(payload, channel.outboundMessages().poll()); assertEquals(message, channel.outboundMessages().poll()); }
@Test public void testExpectedResponse() throws Exception { Request request = new Request(UUID.randomUUID(), SettableFuture.create(), SettableFuture.create()); codec.setRequest(codec.getMapping(channel), request); Integer payload = new Integer(1); Message message = Message.buildResponse(request.getId()); channel.writeInbound(payload); channel.writeInbound(message); channel.runPendingTasks(); Response response = request.getResponseFuture().get(1, TimeUnit.SECONDS); assertEquals(request.getId(), response.getInResponseTo()); assertEquals(payload, response.getPayload()); }