@Override public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) { String channelName = MessagingAnnotationUtils .resolveAttribute(annotations, AnnotationUtils.VALUE, String.class); Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty."); MessageSource<?> messageSource = null; try { messageSource = createMessageSource(bean, beanName, method); } catch (NoSuchBeanDefinitionException e) { if (this.logger.isDebugEnabled()) { this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation."); } return null; } SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setOutputChannelName(channelName); adapter.setSource(messageSource); configurePollingEndpoint(adapter, annotations); return adapter; }
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(); }
@Test public void testMixedAdvice() throws Exception { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); final List<String> callOrder = new ArrayList<>(); final AtomicReference<CountDownLatch> latch = new AtomicReference<>(new CountDownLatch(4));
@Test public void testCompoundTriggerAdvice() throws Exception { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); final CountDownLatch latch = new CountDownLatch(5); final LinkedList<Object> overridePresent = new LinkedList<>();
@Test public void testActiveIdleAdvice() throws Exception { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); final CountDownLatch latch = new CountDownLatch(5); final LinkedList<Long> triggerPeriods = new LinkedList<>();
}; SourcePollingChannelAdapter pollingChannelAdapter = new SourcePollingChannelAdapter(); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.setWaitForTasksToCompleteOnShutdown(true);
@Test public void testInt2777CustomTransactionSynchronizationFactoryWithoutDealWithIntegrationResourceHolder() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter(); spca.setSource(this.source);
source.setBeanFactory(mock(BeanFactory.class)); source.setHeaderExpressions(headerExpressions); SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setSource(source); adapter.setTaskScheduler(scheduler);
@Test public void testSkipSimple() throws Exception { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); class LocalSource implements MessageSource<Object> {
@Test public void testInt2777UnboundResourceAfterTransactionComplete() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); adapter.setSource(() -> null); TransactionSynchronizationManager.setActualTransactionActive(true); doPoll(adapter); TransactionSynchronizationManager.setActualTransactionActive(false); // Before INT-2777 this test was failed here TransactionSynchronizationManager.setActualTransactionActive(true); doPoll(adapter); TransactionSynchronizationManager.setActualTransactionActive(false); }
StringReader reader = new StringReader("test"); CharacterStreamReadingMessageSource source = new CharacterStreamReadingMessageSource(reader, -1, true); SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); CountDownLatch latch = new CountDownLatch(2); source.setApplicationEventPublisher(e -> {
SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
transactionTemplate.execute(status -> { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
@Test public void testCommit() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
@Test public void errorChannelWithFailedDispatch() throws InterruptedException { TestApplicationContext context = TestUtils.createTestApplicationContext(); QueueChannel errorChannel = new QueueChannel(); QueueChannel outputChannel = new QueueChannel(); context.registerChannel("errorChannel", errorChannel); CountDownLatch latch = new CountDownLatch(1); SourcePollingChannelAdapter channelAdapter = new SourcePollingChannelAdapter(); channelAdapter.setSource(new FailingSource(latch)); PollerMetadata pollerMetadata = new PollerMetadata(); pollerMetadata.setTrigger(new PeriodicTrigger(1000)); channelAdapter.setOutputChannel(outputChannel); context.registerEndpoint("testChannel", channelAdapter); context.refresh(); latch.await(2000, TimeUnit.MILLISECONDS); Message<?> message = errorChannel.receive(5000); context.close(); assertNull(outputChannel.receive(100)); assertNotNull("message should not be null", message); assertTrue(message instanceof ErrorMessage); Throwable exception = ((ErrorMessage) message).getPayload(); assertEquals("intentional test failure", exception.getCause().getMessage()); }
transactionTemplate.execute(status -> { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
TransactionTemplate transactionTemplate = new TransactionTemplate(new PseudoTransactionManager()); transactionTemplate.execute(status -> { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();
@Test public void testRollback() { SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter(); ExpressionEvaluatingTransactionSynchronizationProcessor syncProcessor = new ExpressionEvaluatingTransactionSynchronizationProcessor();