Search in sources :

Example 6 with TaskExecutor

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);
}
Also used : AbstractTaskletStepBuilder(org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder) TaskExecutor(org.springframework.core.task.TaskExecutor) AbstractTaskletStepBuilder(org.springframework.batch.core.step.builder.AbstractTaskletStepBuilder) SimpleStepBuilder(org.springframework.batch.core.step.builder.SimpleStepBuilder) StepBuilder(org.springframework.batch.core.step.builder.StepBuilder) SimpleStepBuilder(org.springframework.batch.core.step.builder.SimpleStepBuilder) StepBuilderFactory(org.springframework.batch.core.configuration.annotation.StepBuilderFactory) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) Step(org.springframework.batch.core.Step) TaskletStep(org.springframework.batch.core.step.tasklet.TaskletStep) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) Test(org.junit.Test)

Example 7 with TaskExecutor

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);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 8 with 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);
}
Also used : ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) ThreadPoolTaskExecutor(org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) AsyncExecutor(org.activiti.engine.impl.asyncexecutor.AsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) SpringAsyncExecutor(org.activiti.spring.SpringAsyncExecutor) Test(org.junit.Test) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest)

Example 9 with TaskExecutor

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);
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MessagingException(org.springframework.messaging.MessagingException) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) Test(org.junit.Test)

Example 10 with TaskExecutor

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);
}
Also used : SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) TaskExecutor(org.springframework.core.task.TaskExecutor) StaticApplicationContext(org.springframework.context.support.StaticApplicationContext) MessagingException(org.springframework.messaging.MessagingException) SimpleAsyncTaskExecutor(org.springframework.core.task.SimpleAsyncTaskExecutor) Test(org.junit.Test)

Aggregations

TaskExecutor (org.springframework.core.task.TaskExecutor)14 Test (org.junit.Test)6 Test (org.junit.jupiter.api.Test)5 ThreadPoolTaskExecutor (org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor)5 SimpleAsyncTaskExecutor (org.springframework.core.task.SimpleAsyncTaskExecutor)4 HashMap (java.util.HashMap)2 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)2 ISender (nl.nn.adapterframework.core.ISender)2 SenderException (nl.nn.adapterframework.core.SenderException)2 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)2 Guard (nl.nn.adapterframework.util.Guard)2 XmlBuilder (nl.nn.adapterframework.util.XmlBuilder)2 AsyncExecutor (org.activiti.engine.impl.asyncexecutor.AsyncExecutor)2 SpringAsyncExecutor (org.activiti.spring.SpringAsyncExecutor)2 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)2 StaticApplicationContext (org.springframework.context.support.StaticApplicationContext)2 MessagingException (org.springframework.messaging.MessagingException)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 ISenderWithParameters (nl.nn.adapterframework.core.ISenderWithParameters)1 StatisticsKeeper (nl.nn.adapterframework.statistics.StatisticsKeeper)1