@Test public void integrationTest() throws Exception { TestingUtilities.waitListening(serverCf, null); outbound.send(new GenericMessage<String>("Hello, world!")); Message<?> m = inbound.receive(1000); assertNotNull(m); String connectionId = m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class); // assert we use the same connection from the pool outbound.send(new GenericMessage<String>("Hello, world!")); m = inbound.receive(1000); assertNotNull(m); assertEquals(connectionId, m.getHeaders().get(IpHeaders.CONNECTION_ID, String.class)); }
@Test public void gatewayIntegrationTest() throws Exception { final List<String> connectionIds = new ArrayList<String>(); final AtomicBoolean okToRun = new AtomicBoolean(true); Executors.newSingleThreadExecutor() .execute( new Runnable() { @Override public void run() { while (okToRun.get()) { Message<?> m = inbound.receive(1000); if (m != null) { connectionIds.add((String) m.getHeaders().get(IpHeaders.CONNECTION_ID)); replies.send( MessageBuilder.withPayload("foo:" + new String((byte[]) m.getPayload())) .copyHeaders(m.getHeaders()) .build()); } } } }); TestingUtilities.waitListening(serverCf, null); toGateway.send(new GenericMessage<String>("Hello, world!")); Message<?> m = fromGateway.receive(1000); assertNotNull(m); assertEquals("foo:" + "Hello, world!", new String((byte[]) m.getPayload())); // wait a short time to allow the connection to be returned to the pool Thread.sleep(1000); // assert we use the same connection from the pool toGateway.send(new GenericMessage<String>("Hello, world2!")); m = fromGateway.receive(1000); assertNotNull(m); assertEquals("foo:" + "Hello, world2!", new String((byte[]) m.getPayload())); assertEquals(2, connectionIds.size()); assertEquals(connectionIds.get(0), connectionIds.get(1)); okToRun.set(false); }