use of org.springframework.core.task.TaskExecutor in project hub-alert by blackducksoftware.
the class CommonConfigTest method testCreateStep.
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testCreateStep() {
final StepBuilderFactory stepBuilderFactory = Mockito.mock(StepBuilderFactory.class);
final TaskExecutor taskExecutor = Mockito.mock(TaskExecutor.class);
final PlatformTransactionManager transactionManager = Mockito.mock(PlatformTransactionManager.class);
final C config = getConfigWithParams(stepBuilderFactory, taskExecutor, transactionManager);
final R reader = getMockReader();
final P processor = getMockProcessor();
final W writer = getMockWriter();
final StepBuilder stepBuilder = Mockito.mock(StepBuilder.class);
final SimpleStepBuilder simpleStepBuilder = Mockito.mock(SimpleStepBuilder.class);
final AbstractTaskletStepBuilder abstractTaskletStepBuilder = Mockito.mock(AbstractTaskletStepBuilder.class);
Mockito.when(stepBuilderFactory.get(Mockito.anyString())).thenReturn(stepBuilder);
Mockito.when(stepBuilder.chunk(Mockito.anyInt())).thenReturn(simpleStepBuilder);
Mockito.when(simpleStepBuilder.reader(reader)).thenReturn(simpleStepBuilder);
Mockito.when(simpleStepBuilder.processor(processor)).thenReturn(simpleStepBuilder);
Mockito.when(simpleStepBuilder.writer(writer)).thenReturn(simpleStepBuilder);
Mockito.when(simpleStepBuilder.taskExecutor(taskExecutor)).thenReturn(abstractTaskletStepBuilder);
Mockito.when(abstractTaskletStepBuilder.transactionManager(transactionManager)).thenReturn(abstractTaskletStepBuilder);
Mockito.when(abstractTaskletStepBuilder.build()).thenReturn(new TaskletStep());
final Step step = config.createStep(reader, processor, writer);
assertNotNull(step);
}
use of org.springframework.core.task.TaskExecutor in project herd by FINRAOS.
the class ActivitiProcessEngineConfigurationTest method testActivitiThreadPoolIsIsolatedFromGenericAsyncPool.
/**
* Ensure that the Activiti's thread pool is separate from the application's generic thread pool.
*/
@Test
public void testActivitiThreadPoolIsIsolatedFromGenericAsyncPool() {
AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
SpringAsyncExecutor springAsyncExecutor = (SpringAsyncExecutor) asyncExecutor;
TaskExecutor taskExecutor = springAsyncExecutor.getTaskExecutor();
assertTrue(genericTaskExecutor != taskExecutor);
}
use of org.springframework.core.task.TaskExecutor in project herd by FINRAOS.
the class ActivitiProcessEngineConfigurationTest method testActivitiThreadPoolUsesConfiguredValues.
/**
* Ensure that the Activiti's thread pool uses the correct configuration value.
*
* This assertion is limited in that the configuration values must be set before Spring application context is initialized, which we cannot control easily
* in unit test.
*/
@Test
public void testActivitiThreadPoolUsesConfiguredValues() {
AsyncExecutor asyncExecutor = processEngineConfiguration.getAsyncExecutor();
SpringAsyncExecutor springAsyncExecutor = (SpringAsyncExecutor) asyncExecutor;
TaskExecutor taskExecutor = springAsyncExecutor.getTaskExecutor();
ThreadPoolTaskExecutor threadPoolTaskExecutor = (ThreadPoolTaskExecutor) taskExecutor;
Integer corePoolSize = threadPoolTaskExecutor.getCorePoolSize();
Integer maxPoolSize = threadPoolTaskExecutor.getMaxPoolSize();
Integer keepAliveSeconds = threadPoolTaskExecutor.getKeepAliveSeconds();
// No real easy way of getting the queue capacity from the already constructed thread pool
Integer remainingCapacity = ((LinkedBlockingQueue<?>) threadPoolTaskExecutor.getThreadPoolExecutor().getQueue()).remainingCapacity();
assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_CORE_POOL_SIZE, Integer.class), corePoolSize);
assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_MAX_POOL_SIZE, Integer.class), maxPoolSize);
assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_KEEP_ALIVE_SECS, Integer.class), keepAliveSeconds);
assertEquals(configurationHelper.getProperty(ConfigurationValue.ACTIVITI_THREAD_POOL_QUEUE_CAPACITY, Integer.class), remainingCapacity);
}
use of org.springframework.core.task.TaskExecutor in project spring-integration by spring-projects.
the class DispatchingChannelErrorHandlingTests method handlerThrowsExceptionExecutorChannel.
@Test
public void handlerThrowsExceptionExecutorChannel() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
context.refresh();
DirectChannel defaultErrorChannel = (DirectChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
TaskExecutor executor = new SimpleAsyncTaskExecutor();
ExecutorChannel channel = new ExecutorChannel(executor);
channel.setBeanFactory(context);
channel.afterPropertiesSet();
ResultHandler resultHandler = new ResultHandler();
defaultErrorChannel.subscribe(resultHandler);
channel.subscribe(message -> {
throw new MessagingException(message, new UnsupportedOperationException("intentional test failure"));
});
Message<?> message = MessageBuilder.withPayload("test").build();
channel.send(message);
this.waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessagingException.class, errorMessage.getPayload().getClass());
MessagingException exceptionPayload = (MessagingException) errorMessage.getPayload();
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertSame(message, exceptionPayload.getFailedMessage());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
use of org.springframework.core.task.TaskExecutor in project spring-integration by spring-projects.
the class DispatchingChannelErrorHandlingTests method handlerThrowsExceptionPublishSubscribeWithExecutor.
@Test
public void handlerThrowsExceptionPublishSubscribeWithExecutor() {
StaticApplicationContext context = new StaticApplicationContext();
context.registerSingleton(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME, DirectChannel.class);
context.refresh();
DirectChannel defaultErrorChannel = (DirectChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
TaskExecutor executor = new SimpleAsyncTaskExecutor();
PublishSubscribeChannel channel = new PublishSubscribeChannel(executor);
channel.setBeanFactory(context);
channel.afterPropertiesSet();
ResultHandler resultHandler = new ResultHandler();
defaultErrorChannel.subscribe(resultHandler);
channel.subscribe(message -> {
throw new MessagingException(message, new UnsupportedOperationException("intentional test failure"));
});
Message<?> message = MessageBuilder.withPayload("test").build();
channel.send(message);
this.waitForLatch(10000);
Message<?> errorMessage = resultHandler.lastMessage;
assertEquals(MessagingException.class, errorMessage.getPayload().getClass());
MessagingException exceptionPayload = (MessagingException) errorMessage.getPayload();
assertEquals(UnsupportedOperationException.class, exceptionPayload.getCause().getClass());
assertSame(message, exceptionPayload.getFailedMessage());
assertNotSame(Thread.currentThread(), resultHandler.lastThread);
}
Aggregations