use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class ProactorStreamProcessingStrategyTestCase method cpuIntensiveRejectedExecution.
@Test
@Description("If CPU INTENSIVE pool is busy OVERLOAD error is thrown")
public void cpuIntensiveRejectedExecution() throws Exception {
Scheduler cpuIntensiveSchedulerSpy = spy(cpuIntensive);
Scheduler rejectingSchedulerSpy = spy(new RejectingScheduler(cpuIntensiveSchedulerSpy));
flow = flowBuilder.get().processors(cpuIntensiveProcessor).processingStrategyFactory((context, prefix) -> new ProactorStreamProcessingStrategy(() -> ringBuffer, DEFAULT_BUFFER_SIZE, 1, DEFAULT_WAIT_STRATEGY, () -> cpuLight, () -> blocking, () -> rejectingSchedulerSpy, 1, 2)).build();
flow.initialise();
flow.start();
processFlow(testEvent());
verify(rejectingSchedulerSpy, times(11)).submit(any(Callable.class));
verify(cpuIntensiveSchedulerSpy, times(1)).submit(any(Callable.class));
assertThat(threads, hasSize(1));
assertThat(threads.stream().filter(name -> name.startsWith(CPU_INTENSIVE)).count(), equalTo(1l));
assertThat(threads, not(hasItem(startsWith(CPU_LIGHT))));
assertThat(threads, not(hasItem(startsWith(IO))));
assertThat(threads, not(hasItem(startsWith(CUSTOM))));
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class ProactorStreamProcessingStrategyTestCase method blockingRejectedExecution.
@Test
@Description("If IO pool is busy OVERLOAD error is thrown")
public void blockingRejectedExecution() throws Exception {
Scheduler blockingSchedulerSpy = spy(blocking);
Scheduler rejectingSchedulerSpy = spy(new RejectingScheduler(blockingSchedulerSpy));
flow = flowBuilder.get().processors(blockingProcessor).processingStrategyFactory((context, prefix) -> new ProactorStreamProcessingStrategy(() -> ringBuffer, DEFAULT_BUFFER_SIZE, 1, DEFAULT_WAIT_STRATEGY, () -> cpuLight, () -> rejectingSchedulerSpy, () -> cpuIntensive, 1, 2)).build();
flow.initialise();
flow.start();
processFlow(testEvent());
verify(rejectingSchedulerSpy, times(11)).submit(any(Callable.class));
verify(blockingSchedulerSpy, times(1)).submit(any(Callable.class));
assertThat(threads, hasSize(1));
assertThat(threads.stream().filter(name -> name.startsWith(IO)).count(), equalTo(1l));
assertThat(threads, not(hasItem(startsWith(CPU_LIGHT))));
assertThat(threads, not(hasItem(startsWith(CPU_INTENSIVE))));
assertThat(threads, not(hasItem(startsWith(CUSTOM))));
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class DefaultEventContextTestCase method asyncChild.
@Test
@Description("Parent EventContext only completes once response publisher completes with a value and all child contexts are complete, even when child is run async with a delay.")
public void asyncChild() throws Exception {
child = addChild(parent);
CoreEvent event = testEvent();
Scheduler testScheduler = muleContext.getSchedulerService().ioScheduler();
Latch latch1 = new Latch();
try {
testScheduler.submit(() -> {
child.success(event);
latch1.countDown();
return null;
});
assertParent(is(nullValue()), is(nullValue()), false, false);
parent.success(event);
latch1.await();
assertChild(is(event), is(nullValue()), true);
assertParent(is(event), is(nullValue()), true, true);
} finally {
testScheduler.stop();
}
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class MuleObjectStoreManager method getMonitorablePartition.
@SuppressWarnings({ "rawtypes", "unchecked" })
private <T extends ObjectStore<? extends Serializable>> T getMonitorablePartition(String name, ObjectStore baseStore, T store, ObjectStoreSettings settings) {
if (baseStore instanceof PartitionableExpirableObjectStore) {
Scheduler scheduler = schedulerService.customScheduler(muleContext.getSchedulerBaseConfig().withName("ObjectStoreManager-Monitor-" + name).withMaxConcurrentTasks(1));
scheduler.scheduleWithFixedDelay(new Monitor(name, (PartitionableExpirableObjectStore) baseStore, settings.getEntryTTL().orElse(0L), settings.getMaxEntries().orElse(UNBOUNDED)), 0, settings.getExpirationInterval(), MILLISECONDS);
expirationSchedulers.put(name, scheduler);
return store;
} else {
MonitoredObjectStoreWrapper monObjectStore;
// or putting an uninitialised ObjectStore
synchronized (this) {
monObjectStore = new MonitoredObjectStoreWrapper(store, settings);
monObjectStore.setMuleContext(muleContext);
try {
monObjectStore.initialise();
} catch (InitialisationException e) {
throw new MuleRuntimeException(e);
}
}
return (T) monObjectStore;
}
}
use of org.mule.runtime.api.scheduler.Scheduler in project mule by mulesoft.
the class LifecycleAwareConfigurationInstance method testConnectivity.
private void testConnectivity() throws MuleException {
ConnectionProvider provider = connectionProvider.get();
if (provider instanceof NoConnectivityTest) {
return;
}
Scheduler retryScheduler = schedulerService.ioScheduler();
RetryPolicyTemplate retryTemplate = connectionManager.getRetryTemplateFor(provider);
ReconnectionConfig reconnectionConfig = connectionManager.getReconnectionConfigFor(provider);
RetryCallback retryCallback = new RetryCallback() {
@Override
public void doWork(RetryContext context) throws Exception {
Lock lock = testConnectivityLock;
if (lock != null) {
final boolean lockAcquired = lock.tryLock();
if (lockAcquired) {
LOGGER.info("Doing testConnectivity() for config " + getName());
try {
ConnectionValidationResult result = connectionManager.testConnectivity(LifecycleAwareConfigurationInstance.this);
if (result.isValid()) {
context.setOk();
} else {
if ((reconnectionConfig.isFailsDeployment())) {
context.setFailed(result.getException());
throw new ConnectionException(format("Connectivity test failed for config '%s'", getName()), result.getException());
} else {
if (LOGGER.isInfoEnabled()) {
LOGGER.info(format("Connectivity test failed for config '%s'. Application deployment will continue. Error was: ", getName(), result.getMessage()), result.getException());
}
}
}
} finally {
lock.unlock();
}
} else {
LOGGER.warn("There is a testConnectivity() already running for config " + getName());
}
}
}
@Override
public String getWorkDescription() {
return format("Testing connectivity for config '%s'", getName());
}
@Override
public Object getWorkOwner() {
return value;
}
};
try {
retryTemplate.execute(retryCallback, retryScheduler);
} catch (Exception e) {
throw new DefaultMuleException(createStaticMessage(format("Could not perform connectivity testing for config '%s'", getName())), e);
} finally {
if (retryScheduler != null) {
retryScheduler.stop();
}
}
}
Aggregations