Search in sources :

Example 11 with Trigger

use of org.springframework.scheduling.Trigger in project spring-integration by spring-projects.

the class InboundChannelAdapterExpressionTests method fixedDelay.

@Test
public void fixedDelay() {
    SourcePollingChannelAdapter adapter = context.getBean("fixedDelayProducer", SourcePollingChannelAdapter.class);
    assertFalse(adapter.isAutoStartup());
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class);
    assertEquals(PeriodicTrigger.class, trigger.getClass());
    DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger);
    assertEquals(1234L, triggerAccessor.getPropertyValue("period"));
    assertEquals(Boolean.FALSE, triggerAccessor.getPropertyValue("fixedRate"));
    assertEquals(context.getBean("fixedDelayChannel"), adapterAccessor.getPropertyValue("outputChannel"));
    Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class);
    assertEquals("'fixedDelayTest'", expression.getExpressionString());
}
Also used : PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Trigger(org.springframework.scheduling.Trigger) CronTrigger(org.springframework.scheduling.support.CronTrigger) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 12 with Trigger

use of org.springframework.scheduling.Trigger in project spring-integration by spring-projects.

the class InboundChannelAdapterExpressionTests method triggerRef.

@Test
public void triggerRef() {
    SourcePollingChannelAdapter adapter = context.getBean("triggerRefProducer", SourcePollingChannelAdapter.class);
    assertTrue(adapter.isAutoStartup());
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class);
    assertEquals(context.getBean("customTrigger"), trigger);
    assertEquals(context.getBean("triggerRefChannel"), adapterAccessor.getPropertyValue("outputChannel"));
    Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class);
    assertEquals("'triggerRefTest'", expression.getExpressionString());
}
Also used : PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Trigger(org.springframework.scheduling.Trigger) CronTrigger(org.springframework.scheduling.support.CronTrigger) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 13 with Trigger

use of org.springframework.scheduling.Trigger in project spring-integration by spring-projects.

the class InboundChannelAdapterWithDefaultPollerTests method verifyDefaultPollerInUse.

@Test
public void verifyDefaultPollerInUse() {
    Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class);
    assertEquals(PeriodicTrigger.class, trigger.getClass());
    DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger);
    assertEquals(12345L, triggerAccessor.getPropertyValue("period"));
    assertEquals(Boolean.TRUE, triggerAccessor.getPropertyValue("fixedRate"));
}
Also used : PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Trigger(org.springframework.scheduling.Trigger) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 14 with Trigger

use of org.springframework.scheduling.Trigger in project spring-integration by spring-projects.

the class InboundChannelAdapterExpressionTests method fixedRate.

@Test
public void fixedRate() {
    SourcePollingChannelAdapter adapter = context.getBean("fixedRateProducer", SourcePollingChannelAdapter.class);
    assertFalse(adapter.isAutoStartup());
    DirectFieldAccessor adapterAccessor = new DirectFieldAccessor(adapter);
    Trigger trigger = TestUtils.getPropertyValue(adapter, "trigger", Trigger.class);
    assertEquals(PeriodicTrigger.class, trigger.getClass());
    DirectFieldAccessor triggerAccessor = new DirectFieldAccessor(trigger);
    assertEquals(5678L, triggerAccessor.getPropertyValue("period"));
    assertEquals(Boolean.TRUE, triggerAccessor.getPropertyValue("fixedRate"));
    assertEquals(context.getBean("fixedRateChannel"), adapterAccessor.getPropertyValue("outputChannel"));
    Expression expression = TestUtils.getPropertyValue(adapter, "source.expression", Expression.class);
    assertEquals("'fixedRateTest'", expression.getExpressionString());
}
Also used : PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Trigger(org.springframework.scheduling.Trigger) CronTrigger(org.springframework.scheduling.support.CronTrigger) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Test(org.junit.Test)

Example 15 with Trigger

use of org.springframework.scheduling.Trigger in project spring-integration by spring-projects.

the class CronTriggerParserTests method checkConfigWithAttribute.

@Test
public void checkConfigWithAttribute() {
    Object poller = context.getBean("pollerWithAttribute");
    assertEquals(PollerMetadata.class, poller.getClass());
    PollerMetadata metadata = (PollerMetadata) poller;
    Trigger trigger = metadata.getTrigger();
    assertEquals(CronTrigger.class, trigger.getClass());
    DirectFieldAccessor accessor = new DirectFieldAccessor(trigger);
    String expression = (String) new DirectFieldAccessor(accessor.getPropertyValue("sequenceGenerator")).getPropertyValue("expression");
    assertEquals("*/10 * 9-17 * * MON-FRI", expression);
}
Also used : CronTrigger(org.springframework.scheduling.support.CronTrigger) Trigger(org.springframework.scheduling.Trigger) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) PollerMetadata(org.springframework.integration.scheduling.PollerMetadata) Test(org.junit.Test)

Aggregations

Trigger (org.springframework.scheduling.Trigger)17 Test (org.junit.Test)14 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)13 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)10 CronTrigger (org.springframework.scheduling.support.CronTrigger)8 TriggerContext (org.springframework.scheduling.TriggerContext)7 Date (java.util.Date)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)5 OnlyOnceTrigger (org.springframework.integration.test.util.OnlyOnceTrigger)5 Expression (org.springframework.expression.Expression)4 CompoundTriggerAdvice (org.springframework.integration.aop.CompoundTriggerAdvice)4 PollerMetadata (org.springframework.integration.scheduling.PollerMetadata)4 CompoundTrigger (org.springframework.integration.util.CompoundTrigger)4 DynamicPeriodicTrigger (org.springframework.integration.util.DynamicPeriodicTrigger)4 ArrayList (java.util.ArrayList)3 Advice (org.aopalliance.aop.Advice)3 AbstractMessageSourceAdvice (org.springframework.integration.aop.AbstractMessageSourceAdvice)3 SimpleActiveIdleMessageSourceAdvice (org.springframework.integration.aop.SimpleActiveIdleMessageSourceAdvice)3 PollSkipAdvice (org.springframework.integration.scheduling.PollSkipAdvice)3