use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-integration by spring-projects.
the class FileTailingMessageProducerTests method canHandleFilenameHavingSpecialCharacters.
@Test
@TailAvailable
public void canHandleFilenameHavingSpecialCharacters() throws Exception {
File file = File.createTempFile("foo bar", " -c 1");
file.delete();
OSDelegatingFileTailingMessageProducer adapter = new OSDelegatingFileTailingMessageProducer();
adapter.setOptions(TAIL_OPTIONS_FOLLOW_NAME_ALL_LINES);
adapter.setFile(file);
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
taskScheduler.afterPropertiesSet();
adapter.setTaskScheduler(taskScheduler);
QueueChannel outputChannel = new QueueChannel();
adapter.setOutputChannel(outputChannel);
adapter.setTailAttemptsDelay(500);
adapter.setBeanFactory(mock(BeanFactory.class));
adapter.afterPropertiesSet();
adapter.start();
waitForField(adapter, "stdOutReader");
FileOutputStream fos = new FileOutputStream(file);
fos.write(("hello foobar\n").getBytes());
fos.close();
Message<?> message = outputChannel.receive(10000);
assertThat(message).as("expected a non-null message").isNotNull();
assertThat(message.getPayload()).isEqualTo("hello foobar");
adapter.stop();
file.delete();
taskScheduler.destroy();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-integration by spring-projects.
the class OutboundGatewayFunctionTests method testContainerWithDestNoCorrelation.
@Test
public void testContainerWithDestNoCorrelation() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setBeanFactory(beanFactory);
gateway.setConnectionFactory(connectionFactory);
gateway.setRequestDestination(requestQueue2);
gateway.setReplyDestination(replyQueue2);
gateway.setUseReplyContainer(true);
gateway.afterPropertiesSet();
gateway.start();
final AtomicReference<Object> reply = new AtomicReference<>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
latch1.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo")));
} finally {
latch2.countDown();
}
});
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(connectionFactory);
template.setReceiveTimeout(10000);
jakarta.jms.Message request = template.receive(requestQueue2);
assertThat(request).isNotNull();
final jakarta.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> {
jmsReply.setJMSCorrelationID(jmsReply.getJMSMessageID());
return jmsReply;
});
assertThat(latch2.await(20, TimeUnit.SECONDS)).isTrue();
assertThat(reply.get()).isNotNull();
gateway.stop();
scheduler.destroy();
exec.shutdownNow();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-integration by spring-projects.
the class OutboundGatewayFunctionTests method testContainerWithDest.
@Test
public void testContainerWithDest() throws Exception {
BeanFactory beanFactory = mock(BeanFactory.class);
when(beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)).thenReturn(true);
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
scheduler.initialize();
when(beanFactory.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, TaskScheduler.class)).thenReturn(scheduler);
final JmsOutboundGateway gateway = new JmsOutboundGateway();
gateway.setBeanFactory(beanFactory);
gateway.setConnectionFactory(connectionFactory);
gateway.setRequestDestination(requestQueue1);
gateway.setReplyDestination(replyQueue1);
gateway.setCorrelationKey("JMSCorrelationID");
gateway.setUseReplyContainer(true);
gateway.afterPropertiesSet();
gateway.start();
final AtomicReference<Object> reply = new AtomicReference<>();
final CountDownLatch latch1 = new CountDownLatch(1);
final CountDownLatch latch2 = new CountDownLatch(1);
ExecutorService exec = Executors.newSingleThreadExecutor();
exec.execute(() -> {
latch1.countDown();
try {
reply.set(gateway.handleRequestMessage(new GenericMessage<>("foo")));
} finally {
latch2.countDown();
}
});
assertThat(latch1.await(10, TimeUnit.SECONDS)).isTrue();
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(connectionFactory);
template.setReceiveTimeout(10000);
jakarta.jms.Message request = template.receive(requestQueue1);
assertThat(request).isNotNull();
final jakarta.jms.Message jmsReply = request;
template.send(request.getJMSReplyTo(), session -> jmsReply);
assertThat(latch2.await(10, TimeUnit.SECONDS)).isTrue();
assertThat(reply.get()).isNotNull();
gateway.stop();
scheduler.destroy();
exec.shutdown();
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-integration by spring-projects.
the class ByteStreamWritingMessageHandlerTests method initialize.
@Before
public void initialize() {
stream = new ByteArrayOutputStream();
handler = new ByteStreamWritingMessageHandler(stream);
this.channel = new QueueChannel(10);
this.endpoint = new PollingConsumer(channel, handler);
scheduler = new ThreadPoolTaskScheduler();
this.endpoint.setTaskScheduler(scheduler);
scheduler.afterPropertiesSet();
trigger.reset();
endpoint.setTrigger(trigger);
endpoint.setBeanFactory(mock(BeanFactory.class));
}
use of org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler in project spring-integration by spring-projects.
the class CharacterStreamWritingMessageHandlerTests method initialize.
@Before
public void initialize() {
writer = new StringWriter();
handler = new CharacterStreamWritingMessageHandler(writer);
this.channel = new QueueChannel(10);
trigger.reset();
this.endpoint = new PollingConsumer(channel, handler);
scheduler = new ThreadPoolTaskScheduler();
this.endpoint.setTaskScheduler(scheduler);
scheduler.afterPropertiesSet();
trigger.reset();
endpoint.setTrigger(trigger);
endpoint.setBeanFactory(mock(BeanFactory.class));
}
Aggregations