Search in sources :

Example 1 with DefaultSchedulerMessageSource

use of org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource in project mule by mulesoft.

the class DefaultSchedulerMessageSourceTestCase method createMessageSource.

private DefaultSchedulerMessageSource createMessageSource() throws Exception {
    createAndRegisterFlow(muleContext, APPLE_FLOW, componentLocator);
    schedulerMessageSource = new DefaultSchedulerMessageSource(muleContext, scheduler(), false);
    schedulerMessageSource.setAnnotations(getAppleFlowComponentLocationAnnotations());
    schedulerMessageSource.initialise();
    return schedulerMessageSource;
}
Also used : DefaultSchedulerMessageSource(org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource)

Example 2 with DefaultSchedulerMessageSource

use of org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource in project mule by mulesoft.

the class DefaultSchedulerMessageSourceTestCase method simplePoll.

@Test
public void simplePoll() throws Exception {
    DefaultSchedulerMessageSource schedulerMessageSource = createMessageSource();
    SensingNullMessageProcessor flow = getSensingNullMessageProcessor();
    schedulerMessageSource.setListener(flow);
    schedulerMessageSource.setAnnotations(singletonMap(LOCATION_KEY, TEST_CONNECTOR_LOCATION));
    schedulerMessageSource.trigger();
    new PollingProber(RECEIVE_TIMEOUT, 100).check(new Probe() {

        @Override
        public boolean isSatisfied() {
            return flow.event != null;
        }

        @Override
        public String describeFailure() {
            return "flow event never set by the source flow";
        }
    });
}
Also used : DefaultSchedulerMessageSource(org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource) PollingProber(org.mule.tck.probe.PollingProber) Probe(org.mule.tck.probe.Probe) SensingNullMessageProcessor(org.mule.tck.SensingNullMessageProcessor) Test(org.junit.Test)

Example 3 with DefaultSchedulerMessageSource

use of org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource in project mule by mulesoft.

the class DefaultSchedulerMessageSourceTestCase method disposeScheduler.

@Test
public void disposeScheduler() throws Exception {
    SchedulerService schedulerService = muleContext.getSchedulerService();
    reset(schedulerService);
    AtomicReference<Scheduler> pollScheduler = new AtomicReference<>();
    doAnswer(invocation -> {
        Scheduler scheduler = (Scheduler) invocation.callRealMethod();
        pollScheduler.set(scheduler);
        return scheduler;
    }).when(schedulerService).cpuLightScheduler();
    DefaultSchedulerMessageSource schedulerMessageSource = createMessageSource();
    verify(schedulerService).cpuLightScheduler();
    schedulerMessageSource.start();
    verify(pollScheduler.get()).scheduleAtFixedRate(any(), anyLong(), anyLong(), any());
    schedulerMessageSource.stop();
    schedulerMessageSource.dispose();
    verify(pollScheduler.get()).stop();
}
Also used : SchedulerService(org.mule.runtime.api.scheduler.SchedulerService) DefaultSchedulerMessageSource(org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource) Scheduler(org.mule.runtime.api.scheduler.Scheduler) FixedFrequencyScheduler(org.mule.runtime.core.api.source.scheduler.FixedFrequencyScheduler) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.Test)

Aggregations

DefaultSchedulerMessageSource (org.mule.runtime.core.internal.source.scheduler.DefaultSchedulerMessageSource)3 Test (org.junit.Test)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Scheduler (org.mule.runtime.api.scheduler.Scheduler)1 SchedulerService (org.mule.runtime.api.scheduler.SchedulerService)1 FixedFrequencyScheduler (org.mule.runtime.core.api.source.scheduler.FixedFrequencyScheduler)1 SensingNullMessageProcessor (org.mule.tck.SensingNullMessageProcessor)1 PollingProber (org.mule.tck.probe.PollingProber)1 Probe (org.mule.tck.probe.Probe)1