consumer.setTaskExecutor(new ErrorHandlingTaskExecutor(exec, t -> { })); consumer.setBeanFactory(mock(BeanFactory.class)); consumer.afterPropertiesSet(); consumer.setTaskScheduler(mock(TaskScheduler.class)); consumer.start();
@Before public void init() { this.channelMock = mock(PollableChannel.class); this.endpoint = new PollingConsumer(this.channelMock, this.consumer); this.taskScheduler.setPoolSize(5); this.endpoint.setErrorHandler(this.errorHandler); this.endpoint.setTaskScheduler(this.taskScheduler); this.endpoint.setTrigger(this.trigger); this.endpoint.setBeanFactory(mock(BeanFactory.class)); this.endpoint.setReceiveTimeout(-1); this.endpoint.afterPropertiesSet(); this.taskScheduler.afterPropertiesSet(); }
@Test public void ensurePollerTaskStops() throws Exception { final CountDownLatch latch = new CountDownLatch(1); QueueChannel channel = new QueueChannel(); channel.send(new GenericMessage<>("foo")); //Has to be an explicit implementation - Mockito cannot mock/spy lambdas MessageHandler handler = Mockito.spy(new MessageHandler() { @Override public void handleMessage(Message<?> message) throws MessagingException { latch.countDown(); } }); PollingConsumer consumer = new PollingConsumer(channel, handler); consumer.setTrigger(new PeriodicTrigger(0)); consumer.setErrorHandler(errorHandler); consumer.setTaskScheduler(taskScheduler); consumer.setBeanFactory(mock(BeanFactory.class)); consumer.afterPropertiesSet(); consumer.start(); assertTrue(latch.await(2, TimeUnit.SECONDS)); Mockito.verify(handler, times(1)).handleMessage(Mockito.any(Message.class)); consumer.stop(); Mockito.reset(handler); for (int i = 0; i < 10; i++) { channel.send(new GenericMessage<>("foo")); } Mockito.verify(handler, atMost(1)).handleMessage(Mockito.any(Message.class)); }
endpoint.setBeanFactory(getBeanFactory()); endpoint.setReceiveTimeout(this.replyTimeout); endpoint.afterPropertiesSet(); correlator = endpoint;
consumer.afterPropertiesSet(); consumer.start();
private void registerReplyMessageCorrelator() { synchronized (this.replyMessageCorrelatorMonitor) { if (this.replyMessageCorrelator != null) { return; } AbstractEndpoint correlator = null; MessageHandler handler = new AbstractReplyProducingMessageHandler() { @Override protected void handleRequestMessage(Message<?> message, ReplyMessageHolder replyHolder) { replyHolder.set(message); } }; if (this.replyChannel instanceof SubscribableChannel) { correlator = new EventDrivenConsumer( (SubscribableChannel) this.replyChannel, handler); } else if (this.replyChannel instanceof PollableChannel) { PollingConsumer endpoint = new PollingConsumer( (PollableChannel) this.replyChannel, handler); endpoint.setTrigger(new IntervalTrigger(10)); endpoint.setBeanFactory(this.getBeanFactory()); endpoint.afterPropertiesSet(); correlator = endpoint; } if (this.isRunning() && correlator instanceof Lifecycle) { ((Lifecycle) correlator).start(); } this.replyMessageCorrelator = correlator; } }
endpoint.setBeanFactory(getBeanFactory()); endpoint.setReceiveTimeout(this.replyTimeout); endpoint.afterPropertiesSet(); correlator = endpoint;