private SourcePollingChannelAdapter buildChannelAdapter() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setSource(mock(MessageSource.class)); adapter.setOutputChannel(new QueueChannel()); adapter.setTrigger(mock(Trigger.class)); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.setTaskScheduler(mock(TaskScheduler.class)); adapter.afterPropertiesSet(); return adapter; }
@Test public void testDefaultDontSkip() throws Exception { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); final CountDownLatch latch = new CountDownLatch(1); adapter.setSource(() -> { latch.countDown(); return null; }); adapter.setTrigger(new OnlyOnceTrigger()); configure(adapter); List<Advice> adviceChain = new ArrayList<>(); PollSkipAdvice advice = new PollSkipAdvice(); adviceChain.add(advice); adapter.setAdviceChain(adviceChain); adapter.afterPropertiesSet(); adapter.start(); assertTrue(latch.await(10, TimeUnit.SECONDS)); adapter.stop(); }
SourcePollingChannelAdapter adapter = adapterFactory.getObject(); adapter.setTaskScheduler(this.taskScheduler); adapter.afterPropertiesSet(); adapter.start(); assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.afterPropertiesSet(); adapter.start(); assertTrue(latch.get().await(10, TimeUnit.SECONDS));
adapter.setTrigger(trigger); configure(adapter); adapter.afterPropertiesSet(); adapter.start(); assertTrue(latch.await(10, TimeUnit.SECONDS));
adapter.setTrigger(compoundTrigger); configure(adapter); adapter.afterPropertiesSet(); adapter.start(); assertTrue(latch.await(10, TimeUnit.SECONDS));
pollingChannelAdapter.setOutputChannel(new NullChannel()); pollingChannelAdapter.setBeanFactory(mock(BeanFactory.class)); pollingChannelAdapter.afterPropertiesSet();
spca.setBeanFactory(this.beanFactory); spca.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory()); spca.afterPropertiesSet(); this.adapter = spca; this.initialized = true;
adviceChain.add(advice); adapter.setAdviceChain(adviceChain); adapter.afterPropertiesSet(); adapter.start(); assertFalse(latch.await(10, TimeUnit.MILLISECONDS));
@Test public void ensurePollerTaskStopsForAdapter() throws Exception { final CountDownLatch latch = new CountDownLatch(1); QueueChannel channel = new QueueChannel(); SourcePollingChannelAdapterFactoryBean adapterFactory = new SourcePollingChannelAdapterFactoryBean(); PollerMetadata pollerMetadata = new PollerMetadata(); pollerMetadata.setTrigger(new PeriodicTrigger(2000)); adapterFactory.setPollerMetadata(pollerMetadata); //Has to be an explicit implementation - Mockito cannot mock/spy lambdas MessageSource<String> source = spy(new MessageSource<String>() { @Override public Message<String> receive() { latch.countDown(); return new GenericMessage<>("hello"); } }); adapterFactory.setSource(source); adapterFactory.setOutputChannel(channel); adapterFactory.setBeanFactory(mock(ConfigurableBeanFactory.class)); SourcePollingChannelAdapter adapter = adapterFactory.getObject(); adapter.setTaskScheduler(this.taskScheduler); adapter.afterPropertiesSet(); adapter.start(); assertTrue(latch.await(20, TimeUnit.SECONDS)); assertNotNull(channel.receive(100)); adapter.stop(); assertNull(channel.receive(10)); Mockito.verify(source, times(1)).receive(); }
adapter.setOutputChannel(out); adapter.setBeanFactory(mock(BeanFactory.class)); adapter.afterPropertiesSet(); adapter.start(); Message<?> received = out.receive(10000);
private void initializeAdapter() { synchronized (this.initializationMonitor) { if (this.initialized) { return; } Assert.notNull(this.source, "source is required"); Assert.notNull(this.outputChannel, "outputChannel is required"); SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter(); spca.setSource(this.source); spca.setOutputChannel(this.outputChannel); if (this.pollerMetadata == null) { this.pollerMetadata = IntegrationContextUtils.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '" + this.beanName + "', and no default poller is available within the context."); } spca.setTrigger(this.pollerMetadata.getTrigger()); spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); spca.setTransactionManager(this.pollerMetadata.getTransactionManager()); spca.setTransactionDefinition(this.pollerMetadata.getTransactionDefinition()); spca.setAdviceChain(this.pollerMetadata.getAdviceChain()); spca.setAutoStartup(this.autoStartup); spca.setBeanName(this.beanName); spca.setBeanFactory(this.beanFactory); spca.setBeanClassLoader(this.beanClassLoader); spca.afterPropertiesSet(); this.adapter = spca; this.initialized = true; } }
spca.setBeanFactory(this.beanFactory); spca.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory()); spca.afterPropertiesSet(); this.adapter = spca; this.initialized = true;