use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class StandardTwoPhaseCommitBotTest method before.
/**
* This is run before each @TestD method.
*/
@Before
public void before() {
// create a bot instance and auto-wire it
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
this.bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(this.bot, "mybot");
this.bot = (MyBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
this.bot.setTrigger(trigger);
}
use of org.springframework.scheduling.support.PeriodicTrigger in project webofneeds by researchstudio-sat.
the class StandardTwoPhaseCommitNoVoteBotTest method before.
/**
* This is run before each @TestD method.
*/
@Before
public void before() {
// create a bot instance and auto-wire it
// create a bot instance and auto-wire it
AutowireCapableBeanFactory beanFactory = applicationContext.getAutowireCapableBeanFactory();
this.bot = (MyBot) beanFactory.autowire(MyBot.class, AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE, false);
Object botBean = beanFactory.initializeBean(this.bot, "mybot");
this.bot = (MyBot) botBean;
// the bot also needs a trigger so its act() method is called regularly.
// (there is no trigger bean in the context)
PeriodicTrigger trigger = new PeriodicTrigger(ACT_LOOP_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
trigger.setInitialDelay(ACT_LOOP_INITIAL_DELAY_MILLIS);
this.bot.setTrigger(trigger);
}
use of org.springframework.scheduling.support.PeriodicTrigger 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.scheduling.support.PeriodicTrigger in project spring-integration by spring-projects.
the class ContentEnricherTests method replyChannelReplyTimingOut.
/**
* In this test a {@link Target} message is passed into a {@link ContentEnricher}.
* The Enricher passes the message to a "request-channel" that is backed by a
* {@link QueueChannel}. The consumer of the "request-channel" takes a long
* time to execute, longer actually than the specified "replyTimeout" set on
* the {@link ContentEnricher}.
*
* Due to the occurring replyTimeout, a Null replyMessage is returned and because
* "requiresReply" is set to "true" on the {@link ContentEnricher}, a
* {@link ReplyRequiredException} is raised.
*/
@Test
public void replyChannelReplyTimingOut() throws Exception {
final long requestTimeout = 500L;
final long replyTimeout = 100L;
final DirectChannel replyChannel = new DirectChannel();
final QueueChannel requestChannel = new QueueChannel(1);
final ContentEnricher enricher = new ContentEnricher();
enricher.setRequestChannel(requestChannel);
enricher.setReplyChannel(replyChannel);
enricher.setOutputChannel(new NullChannel());
enricher.setRequestTimeout(requestTimeout);
enricher.setReplyTimeout(replyTimeout);
final ExpressionFactoryBean expressionFactoryBean = new ExpressionFactoryBean("payload");
expressionFactoryBean.setSingleton(false);
expressionFactoryBean.afterPropertiesSet();
final Map<String, Expression> expressions = new HashMap<String, Expression>();
expressions.put("name", new LiteralExpression("cartman"));
expressions.put("child.name", expressionFactoryBean.getObject());
enricher.setPropertyExpressions(expressions);
enricher.setRequiresReply(true);
enricher.setBeanName("Enricher");
enricher.setBeanFactory(mock(BeanFactory.class));
enricher.afterPropertiesSet();
final AbstractReplyProducingMessageHandler handler = new AbstractReplyProducingMessageHandler() {
@Override
protected Object handleRequestMessage(Message<?> requestMessage) {
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
fail(e.getMessage());
}
return new Target("child");
}
};
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();
final PollingConsumer consumer = new PollingConsumer(requestChannel, handler);
final TestErrorHandler errorHandler = new TestErrorHandler();
consumer.setTrigger(new PeriodicTrigger(0));
consumer.setErrorHandler(errorHandler);
consumer.setTaskScheduler(taskScheduler);
consumer.setBeanFactory(mock(BeanFactory.class));
consumer.afterPropertiesSet();
consumer.start();
final Target target = new Target("replace me");
Message<?> requestMessage = MessageBuilder.withPayload(target).setReplyChannel(replyChannel).build();
try {
enricher.handleMessage(requestMessage);
} catch (ReplyRequiredException e) {
assertEquals("No reply produced by handler 'Enricher', and its 'requiresReply' property is set to true.", e.getMessage());
return;
}
fail("ReplyRequiredException expected.");
}
use of org.springframework.scheduling.support.PeriodicTrigger in project spring-integration by spring-projects.
the class ApplicationContextMessageBusTests method errorChannelWithFailedDispatch.
@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.stop();
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());
}
Aggregations