@Test public void asyncConvertSendAndReceiveWithDefaultChannelAndMessagePostProcessor() throws Exception { DirectChannel channel = new DirectChannel(); channel.subscribe(new EchoHandler(200)); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setDefaultDestination(channel); long start = System.currentTimeMillis(); Future<String> result = template.asyncConvertSendAndReceive(123, new TestMessagePostProcessor()); assertNotNull(result.get()); long elapsed = System.currentTimeMillis() - start; assertTrue(elapsed >= 200 - safety); assertEquals("123-bar", result.get()); }
@Test public void asyncConvertSendAndReceiveWithResolvedChannelAndMessagePostProcessor() throws Exception { StaticApplicationContext context = new StaticApplicationContext(); context.registerSingleton("testChannel", DirectChannel.class); context.refresh(); DirectChannel channel = context.getBean("testChannel", DirectChannel.class); channel.subscribe(new EchoHandler(200)); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); template.setBeanFactory(context); long start = System.currentTimeMillis(); Future<String> result = template.asyncConvertSendAndReceive("testChannel", "test", new TestMessagePostProcessor()); assertNotNull(result.get()); long elapsed = System.currentTimeMillis() - start; assertTrue(elapsed >= 200 - safety); assertEquals("TEST-bar", result.get()); }
@Test public void asyncConvertSendAndReceiveWithExplicitChannelAndMessagePostProcessor() throws Exception { DirectChannel channel = new DirectChannel(); channel.subscribe(new EchoHandler(200)); AsyncMessagingTemplate template = new AsyncMessagingTemplate(); long start = System.currentTimeMillis(); Future<String> result = template.asyncConvertSendAndReceive(channel, "test", new TestMessagePostProcessor()); assertNotNull(result.get()); long elapsed = System.currentTimeMillis() - start; assertTrue(elapsed >= 200 - safety); assertEquals("TEST-bar", result.get()); }