use of org.mule.runtime.api.scheduler.SchedulerService in project mule by mulesoft.
the class AbstractMuleContextTestCase method recordSchedulersOnInit.
protected static void recordSchedulersOnInit(MuleContext context) {
if (context != null) {
final SchedulerService serviceImpl = context.getSchedulerService();
schedulersOnInit = serviceImpl.getSchedulers();
} else {
schedulersOnInit = emptyList();
}
}
use of org.mule.runtime.api.scheduler.SchedulerService in project mule by mulesoft.
the class AbstractMuleContextTestCase method verifyAndStopSchedulers.
protected static void verifyAndStopSchedulers() throws MuleException {
final SchedulerService serviceImpl = muleContext.getSchedulerService();
Set<String> schedulersOnInitNames = schedulersOnInit.stream().map(s -> s.getName()).collect(toSet());
try {
assertThat(muleContext.getSchedulerService().getSchedulers().stream().filter(s -> !schedulersOnInitNames.contains(s.getName())).collect(toList()), empty());
} finally {
if (serviceImpl instanceof SimpleUnitTestSupportSchedulerService) {
stopIfNeeded(serviceImpl);
}
}
}
use of org.mule.runtime.api.scheduler.SchedulerService in project mule by mulesoft.
the class MuleContextUtils method mockContextWithServices.
/**
* Creates and configures a mock {@link MuleContext} to return testing services implementations.
*
* @return the created {@code muleContext}.
*/
public static MuleContextWithRegistries mockContextWithServices() {
final MuleContextWithRegistries muleContext = mockMuleContext();
SchedulerService schedulerService = spy(new SimpleUnitTestSupportSchedulerService());
when(muleContext.getSchedulerService()).thenReturn(schedulerService);
ErrorTypeRepository errorTypeRepository = mock(ErrorTypeRepository.class);
when(muleContext.getErrorTypeRepository()).thenReturn(errorTypeRepository);
when(errorTypeRepository.getErrorType(any(ComponentIdentifier.class))).thenReturn(of(mock(ErrorType.class)));
final MuleRegistry registry = muleContext.getRegistry();
NotificationListenerRegistry notificationListenerRegistry = mock(NotificationListenerRegistry.class);
ConfigurationProperties configProps = mock(ConfigurationProperties.class);
when(configProps.resolveBooleanProperty(any())).thenReturn(empty());
ConfigurationComponentLocator configurationComponentLocator = mock(ConfigurationComponentLocator.class);
when(configurationComponentLocator.find(any(Location.class))).thenReturn(empty());
when(configurationComponentLocator.find(any(ComponentIdentifier.class))).thenReturn(emptyList());
try {
when(registry.lookupObject(NotificationListenerRegistry.class)).thenReturn(notificationListenerRegistry);
Map<Class, Object> injectableObjects = new HashMap<>();
injectableObjects.put(MuleContext.class, muleContext);
injectableObjects.put(SchedulerService.class, schedulerService);
injectableObjects.put(ErrorTypeRepository.class, errorTypeRepository);
injectableObjects.put(ExtendedExpressionManager.class, muleContext.getExpressionManager());
injectableObjects.put(StreamingManager.class, muleContext.getRegistry().lookupObject(StreamingManager.class));
injectableObjects.put(ObjectStoreManager.class, muleContext.getRegistry().lookupObject(OBJECT_STORE_MANAGER));
injectableObjects.put(NotificationDispatcher.class, muleContext.getRegistry().lookupObject(NotificationDispatcher.class));
injectableObjects.put(NotificationListenerRegistry.class, notificationListenerRegistry);
injectableObjects.put(ConfigurationComponentLocator.class, configurationComponentLocator);
injectableObjects.put(ConfigurationProperties.class, configProps);
// Ensure injection of consistent mock objects
when(muleContext.getInjector()).thenReturn(new MocksInjector(injectableObjects));
} catch (RegistrationException e1) {
throw new MuleRuntimeException(e1);
}
return muleContext;
}
use of org.mule.runtime.api.scheduler.SchedulerService 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();
}
use of org.mule.runtime.api.scheduler.SchedulerService in project mule by mulesoft.
the class DefaultMuleContext method getSchedulerService.
@Override
public SchedulerService getSchedulerService() {
if (this.schedulerService == null) {
try {
this.schedulerService = this.getRegistry().lookupObject(SchedulerService.class);
requireNonNull(schedulerService);
} catch (RegistrationException e) {
throw new MuleRuntimeException(e);
}
}
return this.schedulerService;
}
Aggregations