@Test public void asyncReceiveWithExplicitChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); Future<Message<?>> result = template.asyncReceive(channel); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(10000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertEquals("test", result.get().getPayload()); assertTrue(elapsed >= 200 - safety); }
@Test public void asyncReceiveAndConvertWithExplicitChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); Future<?> result = template.asyncReceiveAndConvert(channel); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(10000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertEquals("test", result.get()); assertTrue(elapsed >= 200 - safety); }
@Test public void asyncReceiveWithDefaultChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setDefaultDestination(channel); Future<Message<?>> result = template.asyncReceive(); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(100000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertEquals("test", result.get().getPayload()); assertTrue(elapsed >= 200 - safety); }
@Test public void asyncReceiveAndConvertWithDefaultChannel() throws Exception { QueueChannel channel = new QueueChannel(); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setDefaultDestination(channel); Future<?> result = template.asyncReceiveAndConvert(); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(10000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertEquals("test", result.get()); assertTrue(elapsed >= 200 - safety); }
@Test public void asyncReceiveWithResolvedChannel() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton("testChannel", QueueChannel.class); context.refresh(); QueueChannel channel = context.getBean("testChannel", QueueChannel.class); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setBeanFactory(context); Future<Message<?>> result = template.asyncReceive("testChannel"); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(10000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertTrue(elapsed >= 200 - safety); assertEquals("test", result.get().getPayload()); }
@Test public void asyncReceiveAndConvertWithResolvedChannel() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton("testChannel", QueueChannel.class); context.refresh(); QueueChannel channel = context.getBean("testChannel", QueueChannel.class); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setBeanFactory(context); Future<?> result = template.asyncReceiveAndConvert("testChannel"); sendMessageAfterDelay(channel, new GenericMessage<String>("test"), 200); long start = System.currentTimeMillis(); assertNotNull(result.get(10000, TimeUnit.MILLISECONDS)); long elapsed = System.currentTimeMillis() - start; assertTrue(elapsed >= 200 - safety); assertEquals("test", result.get()); }