use of org.springframework.integration.scheduling.PollerMetadata in project spring-integration by spring-projects.
the class SourcePollingChannelAdapterFactoryBeanTests method testTransactionalAdviceChain.
@Test
public void testTransactionalAdviceChain() throws Throwable {
SourcePollingChannelAdapterFactoryBean factoryBean = new SourcePollingChannelAdapterFactoryBean();
QueueChannel outputChannel = new QueueChannel();
TestApplicationContext context = TestUtils.createTestApplicationContext();
factoryBean.setBeanFactory(context.getBeanFactory());
factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
factoryBean.setOutputChannel(outputChannel);
factoryBean.setSource(() -> new GenericMessage<>("test"));
PollerMetadata pollerMetadata = new PollerMetadata();
List<Advice> adviceChain = new ArrayList<Advice>();
final AtomicBoolean adviceApplied = new AtomicBoolean(false);
adviceChain.add((MethodInterceptor) invocation -> {
adviceApplied.set(true);
return invocation.proceed();
});
pollerMetadata.setTrigger(new PeriodicTrigger(5000));
pollerMetadata.setMaxMessagesPerPoll(1);
final AtomicInteger count = new AtomicInteger();
final MethodInterceptor txAdvice = mock(MethodInterceptor.class);
adviceChain.add((MethodInterceptor) invocation -> {
count.incrementAndGet();
return invocation.proceed();
});
when(txAdvice.invoke(any(MethodInvocation.class))).thenAnswer(invocation -> {
count.incrementAndGet();
return ((MethodInvocation) invocation.getArgument(0)).proceed();
});
pollerMetadata.setAdviceChain(adviceChain);
factoryBean.setPollerMetadata(pollerMetadata);
factoryBean.setAutoStartup(true);
factoryBean.afterPropertiesSet();
context.registerEndpoint("testPollingEndpoint", factoryBean.getObject());
context.refresh();
Message<?> message = outputChannel.receive(5000);
assertEquals("test", message.getPayload());
assertEquals(1, count.get());
assertTrue("adviceChain was not applied", adviceApplied.get());
}
use of org.springframework.integration.scheduling.PollerMetadata in project spring-integration by spring-projects.
the class SourcePollingChannelAdapterFactoryBeanTests method testAdviceChain.
@Test
public void testAdviceChain() throws Exception {
SourcePollingChannelAdapterFactoryBean factoryBean = new SourcePollingChannelAdapterFactoryBean();
QueueChannel outputChannel = new QueueChannel();
TestApplicationContext context = TestUtils.createTestApplicationContext();
factoryBean.setBeanFactory(context.getBeanFactory());
factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader());
factoryBean.setOutputChannel(outputChannel);
factoryBean.setSource(() -> new GenericMessage<>("test"));
PollerMetadata pollerMetadata = new PollerMetadata();
List<Advice> adviceChain = new ArrayList<Advice>();
final AtomicBoolean adviceApplied = new AtomicBoolean(false);
adviceChain.add((MethodInterceptor) invocation -> {
adviceApplied.set(true);
return invocation.proceed();
});
pollerMetadata.setTrigger(new PeriodicTrigger(5000));
pollerMetadata.setMaxMessagesPerPoll(1);
pollerMetadata.setAdviceChain(adviceChain);
factoryBean.setPollerMetadata(pollerMetadata);
factoryBean.setAutoStartup(true);
factoryBean.afterPropertiesSet();
context.registerEndpoint("testPollingEndpoint", factoryBean.getObject());
context.refresh();
Message<?> message = outputChannel.receive(5000);
assertEquals("test", message.getPayload());
assertTrue("adviceChain was not applied", adviceApplied.get());
}
use of org.springframework.integration.scheduling.PollerMetadata in project paascloud-master by paascloud.
the class CustomPollerConfiguration method customPoller.
/**
* Custom poller poller metadata.
*
* @return the poller metadata
*/
@Bean(name = StreamSpanReporter.POLLER)
PollerMetadata customPoller() {
PollerMetadata poller = new PollerMetadata();
poller.setMaxMessagesPerPoll(500);
poller.setTrigger(new PeriodicTrigger(5000L));
return poller;
}
use of org.springframework.integration.scheduling.PollerMetadata in project spring-integration by spring-projects.
the class PollerParserTests method pollerWithReceiveTimeoutAndTimeunit.
@Test
public void pollerWithReceiveTimeoutAndTimeunit() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("pollerWithReceiveTimeout.xml", PollerParserTests.class);
Object poller = context.getBean("poller");
assertNotNull(poller);
PollerMetadata metadata = (PollerMetadata) poller;
assertEquals(1234, metadata.getReceiveTimeout());
PeriodicTrigger trigger = (PeriodicTrigger) metadata.getTrigger();
assertEquals(TimeUnit.SECONDS.toString(), TestUtils.getPropertyValue(trigger, "timeUnit").toString());
context.close();
}
use of org.springframework.integration.scheduling.PollerMetadata in project spring-integration by spring-projects.
the class PollerParserTests method pollerWithTriggerReference.
@Test
public void pollerWithTriggerReference() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("pollerWithTriggerReference.xml", PollerParserTests.class);
Object poller = context.getBean("poller");
assertNotNull(poller);
PollerMetadata metadata = (PollerMetadata) poller;
assertTrue(metadata.getTrigger() instanceof TestTrigger);
context.close();
}
Aggregations