Search in sources :

Example 1 with CompoundTriggerAdvice

use of org.springframework.integration.aop.CompoundTriggerAdvice in project spring-integration by spring-projects.

the class PollerAdviceTests method testCompoundTriggerAdvice.

@Test
public void testCompoundTriggerAdvice() throws Exception {
    SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
    final CountDownLatch latch = new CountDownLatch(5);
    final LinkedList<Object> overridePresent = new LinkedList<Object>();
    final CompoundTrigger compoundTrigger = new CompoundTrigger(new PeriodicTrigger(10));
    Trigger override = spy(new PeriodicTrigger(5));
    final CompoundTriggerAdvice advice = new CompoundTriggerAdvice(compoundTrigger, override);
    adapter.setSource(() -> {
        overridePresent.add(TestUtils.getPropertyValue(compoundTrigger, "override"));
        Message<Object> m = null;
        if (latch.getCount() % 2 == 0) {
            m = new GenericMessage<>("foo");
        }
        latch.countDown();
        return m;
    });
    adapter.setAdviceChain(Collections.singletonList(advice));
    adapter.setTrigger(compoundTrigger);
    configure(adapter);
    adapter.afterPropertiesSet();
    adapter.start();
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    adapter.stop();
    while (overridePresent.size() > 5) {
        overridePresent.removeLast();
    }
    assertThat(overridePresent, contains(null, override, null, override, null));
    verify(override, atLeast(2)).nextExecutionTime(any(TriggerContext.class));
}
Also used : CompoundTrigger(org.springframework.integration.util.CompoundTrigger) DynamicPeriodicTrigger(org.springframework.integration.util.DynamicPeriodicTrigger) OnlyOnceTrigger(org.springframework.integration.test.util.OnlyOnceTrigger) Trigger(org.springframework.scheduling.Trigger) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) CompoundTrigger(org.springframework.integration.util.CompoundTrigger) TriggerContext(org.springframework.scheduling.TriggerContext) CountDownLatch(java.util.concurrent.CountDownLatch) LinkedList(java.util.LinkedList) CompoundTriggerAdvice(org.springframework.integration.aop.CompoundTriggerAdvice) DynamicPeriodicTrigger(org.springframework.integration.util.DynamicPeriodicTrigger) PeriodicTrigger(org.springframework.scheduling.support.PeriodicTrigger) Test(org.junit.Test)

Aggregations

LinkedList (java.util.LinkedList)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 CompoundTriggerAdvice (org.springframework.integration.aop.CompoundTriggerAdvice)1 OnlyOnceTrigger (org.springframework.integration.test.util.OnlyOnceTrigger)1 CompoundTrigger (org.springframework.integration.util.CompoundTrigger)1 DynamicPeriodicTrigger (org.springframework.integration.util.DynamicPeriodicTrigger)1 Trigger (org.springframework.scheduling.Trigger)1 TriggerContext (org.springframework.scheduling.TriggerContext)1 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)1