Refactored all task scheduling and poller triggering to use functionality now included in the Spring 3.0 core, and removed Spring Integration specific code that is now handled by that corresponding code in the core.
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,11 @@
|
||||
|
||||
package org.springframework.integration.aggregator;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
@@ -23,10 +28,6 @@ import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.After;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
@@ -38,8 +39,7 @@ import org.springframework.integration.core.MessageHeaders;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageHandlingException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.SimpleTaskScheduler;
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -49,7 +49,7 @@ public class AggregatorEndpointTests {
|
||||
|
||||
private TaskExecutor taskExecutor;
|
||||
|
||||
private TaskScheduler taskScheduler;
|
||||
private ThreadPoolTaskScheduler taskScheduler;
|
||||
|
||||
private AbstractMessageAggregator aggregator;
|
||||
|
||||
@@ -57,10 +57,10 @@ public class AggregatorEndpointTests {
|
||||
@Before
|
||||
public void configureAggregator() {
|
||||
this.taskExecutor = new SimpleAsyncTaskExecutor();
|
||||
this.taskScheduler = new SimpleTaskScheduler(taskExecutor);
|
||||
this.taskScheduler = new ThreadPoolTaskScheduler();
|
||||
this.taskScheduler.afterPropertiesSet();
|
||||
this.aggregator = new TestAggregator();
|
||||
this.aggregator.setTaskScheduler(this.taskScheduler);
|
||||
this.taskScheduler.start();
|
||||
this.aggregator.start();
|
||||
}
|
||||
|
||||
@@ -342,7 +342,7 @@ public class AggregatorEndpointTests {
|
||||
|
||||
@After
|
||||
public void stopTaskScheduler() {
|
||||
this.taskScheduler.stop();
|
||||
this.taskScheduler.destroy();
|
||||
this.aggregator.stop();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,12 +25,13 @@ import static org.junit.Assert.assertThat;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.integration.util.TestUtils;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
|
||||
/**
|
||||
* @author Marius Bogoevici
|
||||
@@ -40,7 +41,7 @@ public class ResequencerTests {
|
||||
|
||||
private Resequencer resequencer;
|
||||
|
||||
private TaskScheduler taskScheduler;
|
||||
private ThreadPoolTaskScheduler taskScheduler;
|
||||
|
||||
|
||||
@Before
|
||||
@@ -48,7 +49,7 @@ public class ResequencerTests {
|
||||
this.resequencer = new Resequencer();
|
||||
this.taskScheduler = TestUtils.createTaskScheduler(10);
|
||||
this.resequencer.setTaskScheduler(taskScheduler);
|
||||
taskScheduler.start();
|
||||
this.taskScheduler.afterPropertiesSet();
|
||||
this.resequencer.start();
|
||||
}
|
||||
|
||||
@@ -250,6 +251,7 @@ public class ResequencerTests {
|
||||
@After
|
||||
public void stopTaskScheduler() {
|
||||
this.resequencer.stop();
|
||||
this.taskScheduler.stop();
|
||||
this.taskScheduler.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,9 +27,6 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.ChannelResolver;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
@@ -191,9 +188,6 @@ public class ApplicationContextMessageBusTests {
|
||||
channelAdapter.setTrigger(new IntervalTrigger(1000));
|
||||
channelAdapter.setOutputChannel(outputChannel);
|
||||
context.registerEndpoint("testChannel", channelAdapter);
|
||||
ChannelResolver channelResolver = new BeanFactoryChannelResolver(context);
|
||||
MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(channelResolver);
|
||||
errorHandler.setDefaultErrorChannel(errorChannel);
|
||||
context.refresh();
|
||||
latch.await(2000, TimeUnit.MILLISECONDS);
|
||||
Message<?> message = errorChannel.receive(5000);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.channel;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
@@ -21,9 +22,9 @@ import static org.mockito.Matchers.anyObject;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.never;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
@@ -37,6 +38,7 @@ import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.runners.MockitoJUnit44Runner;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
@@ -52,22 +54,31 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
*/
|
||||
@RunWith(MockitoJUnit44Runner.class)
|
||||
public class MixedDispatcherConfigurationScenarioTests {
|
||||
|
||||
private static final int TOTAL_EXECUTIONS = 40;
|
||||
|
||||
private ThreadPoolTaskExecutor scheduler = new ThreadPoolTaskExecutor();
|
||||
|
||||
private CountDownLatch allDone;
|
||||
private CountDownLatch start;
|
||||
private AtomicBoolean failed;
|
||||
|
||||
@Mock
|
||||
private List<Exception> exceptionRegistry;
|
||||
|
||||
private ApplicationContext ac;
|
||||
|
||||
@Mock
|
||||
private MessageHandler handlerA;
|
||||
|
||||
@Mock
|
||||
private MessageHandler handlerB;
|
||||
|
||||
@Mock
|
||||
private MessageHandler handlerC;
|
||||
|
||||
@Mock
|
||||
private Message message;
|
||||
private Message<?> message;
|
||||
|
||||
@Before
|
||||
public void initialize() throws Exception {
|
||||
@@ -145,7 +156,7 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
dispatcher.addHandler(handlerA);
|
||||
dispatcher.addHandler(handlerB);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
RuntimeException e = new RuntimeException();
|
||||
allDone.countDown();
|
||||
@@ -155,7 +166,7 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
}
|
||||
}).when(handlerA).handleMessage(message);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
allDone.countDown();
|
||||
return null;
|
||||
@@ -273,7 +284,7 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
final CountDownLatch allDone = new CountDownLatch(TOTAL_EXECUTIONS);
|
||||
final Message<?> message = this.message;
|
||||
final AtomicBoolean failed = new AtomicBoolean(false);
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
failed.set(true);
|
||||
RuntimeException e = new RuntimeException();
|
||||
@@ -282,13 +293,13 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
throw e;
|
||||
}
|
||||
}).when(handlerA).handleMessage(message);
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
allDone.countDown();
|
||||
return null;
|
||||
}
|
||||
}).when(handlerB).handleMessage(message);
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
allDone.countDown();
|
||||
return null;
|
||||
@@ -403,7 +414,7 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
dispatcher.addHandler(handlerB);
|
||||
dispatcher.addHandler(handlerC);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
RuntimeException e = new RuntimeException();
|
||||
failed.set(true);
|
||||
@@ -411,13 +422,13 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
throw e;
|
||||
}
|
||||
}).when(handlerA).handleMessage(message);
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
allDone.countDown();
|
||||
return null;
|
||||
}
|
||||
}).when(handlerB).handleMessage(message);
|
||||
doAnswer(new Answer() {
|
||||
doAnswer(new Answer<Object>() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
allDone.countDown();
|
||||
return null;
|
||||
@@ -439,7 +450,7 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
}
|
||||
start.countDown();
|
||||
allDone.await();
|
||||
// Mockiti threads migt still be lingering, so wait till they are all finished to avoid
|
||||
// Mockito threads might still be lingering, so wait till they are all finished to avoid
|
||||
// Mockito concurrency
|
||||
this.waitTillAllFinished((SimpleAsyncTaskExecutor) ac.getBean("taskExecutor"));
|
||||
|
||||
@@ -447,6 +458,7 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
verify(handlerB, times(TOTAL_EXECUTIONS)).handleMessage(message);
|
||||
verify(handlerC, never()).handleMessage(message);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param taskExecutor
|
||||
@@ -454,7 +466,6 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
private void waitTillAllFinished(SimpleAsyncTaskExecutor taskExecutor){
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
if (taskExecutor.getThreadGroup().activeCount() == 0){
|
||||
//System.out.println("breaking");
|
||||
break;
|
||||
}
|
||||
try {
|
||||
@@ -462,4 +473,5 @@ public class MixedDispatcherConfigurationScenarioTests {
|
||||
} catch (InterruptedException e) {/*ignore*/}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.core.SpringVersion;
|
||||
import org.springframework.core.task.SyncTaskExecutor;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,8 +29,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.integration.util.ErrorHandlingTaskExecutor;
|
||||
import org.springframework.scheduling.support.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,10 +16,11 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.integration.scheduling.Trigger;
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -30,21 +31,24 @@ public class StubTaskScheduler implements TaskScheduler {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void execute(Runnable task) {
|
||||
public ScheduledFuture<?> schedule(Runnable task, Date startTime) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean prefersShortLivedTasks() {
|
||||
return true;
|
||||
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, long period) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isRunning() {
|
||||
return false;
|
||||
public ScheduledFuture<?> scheduleAtFixedRate(Runnable task, Date startTime, long period) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,7 +16,7 @@
|
||||
|
||||
package org.springframework.integration.config;
|
||||
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.scheduling.support.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -26,7 +26,7 @@ public class TestErrorHandler implements ErrorHandler {
|
||||
private volatile Throwable lastError;
|
||||
|
||||
|
||||
public void handle(Throwable t) {
|
||||
public void handleError(Throwable t) {
|
||||
this.lastError = t;
|
||||
}
|
||||
|
||||
|
||||
@@ -17,18 +17,19 @@
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.scheduling.SimpleTaskScheduler;
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@@ -45,20 +46,26 @@ public class DefaultConfiguringBeanFactoryPostProcessorTests {
|
||||
|
||||
@Test
|
||||
public void errorChannelRegistered() {
|
||||
MessageChannel errorChannel = (MessageChannel) context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
Object errorChannel = context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
|
||||
assertNotNull(errorChannel);
|
||||
assertEquals(PublishSubscribeChannel.class, errorChannel.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullChannelRegistered() {
|
||||
MessageChannel nullChannel = (MessageChannel) context.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
|
||||
Object nullChannel = context.getBean(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
|
||||
assertNotNull(nullChannel);
|
||||
assertEquals(NullChannel.class, nullChannel.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void taskSchedulerRegistered() {
|
||||
TaskScheduler taskScheduler = (TaskScheduler) context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
|
||||
assertEquals(SimpleTaskScheduler.class, taskScheduler.getClass());
|
||||
Object taskScheduler = context.getBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME);
|
||||
assertEquals(ThreadPoolTaskScheduler.class, taskScheduler.getClass());
|
||||
Object errorHandler = new DirectFieldAccessor(taskScheduler).getPropertyValue("errorHandler");
|
||||
assertEquals(MessagePublishingErrorHandler.class, errorHandler.getClass());
|
||||
Object defaultErrorChannel = new DirectFieldAccessor(errorHandler).getPropertyValue("defaultErrorChannel");
|
||||
assertEquals(context.getBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME), defaultErrorChannel);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
@@ -28,6 +29,7 @@ import junit.framework.Assert;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.BeanDefinitionStoreException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
@@ -47,10 +49,9 @@ import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@@ -70,16 +71,19 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
String configProperty = testConfigurations.getProperty("splitter-inner-success-with-poller");
|
||||
this.bootStrap(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerSplitterDefinitionSuccessWithPollerReversedOrder(){
|
||||
String configProperty = testConfigurations.getProperty("splitter-inner-success-with-poller-reversed-order");
|
||||
this.bootStrap(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSplitterDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("splitter-ref-success");
|
||||
this.testSplitterDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testInnerSplitterDefinitionFailureRefAndInner(){
|
||||
String xmlConfig = testConfigurations.getProperty("splitter-failure-refAndBean");
|
||||
@@ -91,6 +95,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
String configProperty = testConfigurations.getProperty("transformer-inner-success");
|
||||
this.testTransformerDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefTransformerDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("transformer-ref-success");
|
||||
@@ -108,6 +113,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
String configProperty = testConfigurations.getProperty("router-inner-success");
|
||||
this.testRouterDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefRouterDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("router-ref-success");
|
||||
@@ -125,11 +131,13 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
String configProperty = testConfigurations.getProperty("sa-inner-success");
|
||||
this.testSADefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefSADefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("sa-ref-success");
|
||||
this.testSADefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testInnerSADefinitionFailureRefAndInner(){
|
||||
String xmlConfig = testConfigurations.getProperty("sa-failure-refAndBean");
|
||||
@@ -141,21 +149,25 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
String configProperty = testConfigurations.getProperty("aggregator-inner-success");
|
||||
this.testAggregatorDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerConcurrentAggregatorDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("aggregator-inner-concurrent-success");
|
||||
this.testAggregatorDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInnerConcurrentAggregatorDefinitionSuccessReorderBeanPoller(){
|
||||
String configProperty = testConfigurations.getProperty("aggregator-inner-concurrent-success-reorder-bean-poller");
|
||||
this.testAggregatorDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRefAggregatorDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("aggregator-ref-success");
|
||||
this.testAggregatorDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testInnerAggregatorDefinitionFailureRefAndInner(){
|
||||
String xmlConfig = testConfigurations.getProperty("aggregator-failure-refAndBean");
|
||||
@@ -171,9 +183,9 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
@Test
|
||||
public void testRefFilterDefinitionSuccess(){
|
||||
String configProperty = testConfigurations.getProperty("filter-ref-success");
|
||||
System.out.println(configProperty);
|
||||
this.testFilterDefinitionSuccess(configProperty);
|
||||
}
|
||||
|
||||
@Test(expected=BeanDefinitionStoreException.class)
|
||||
public void testInnerFilterDefinitionFailureRefAndInner(){
|
||||
String xmlConfig = testConfigurations.getProperty("filter-failure-refAndBean");
|
||||
@@ -184,8 +196,8 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
ApplicationContext ac = this.bootStrap(configProperty);
|
||||
EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testSplitter");
|
||||
Assert.assertNotNull(splitter);
|
||||
MessageBuilder inChannelMessageBuilder = MessageBuilder.withPayload(new String[]{"One","Two"});
|
||||
Message inMessage = inChannelMessageBuilder.build();
|
||||
MessageBuilder<String[]> inChannelMessageBuilder = MessageBuilder.withPayload(new String[]{"One","Two"});
|
||||
Message<String[]> inMessage = inChannelMessageBuilder.build();
|
||||
MessageChannel inChannel = (MessageChannel) ac.getBean("inChannel");
|
||||
inChannel.send(inMessage);
|
||||
PollableChannel outChannel = (PollableChannel) ac.getBean("outChannel");
|
||||
@@ -198,20 +210,21 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
ApplicationContext ac = this.bootStrap(configProperty);
|
||||
EventDrivenConsumer transformer = (EventDrivenConsumer) ac.getBean("testTransformer");
|
||||
Assert.assertNotNull(transformer);
|
||||
MessageBuilder inChannelMessageBuilder = MessageBuilder.withPayload(new String[]{"One","Two"});
|
||||
Message inMessage = inChannelMessageBuilder.build();
|
||||
MessageBuilder<String[]> inChannelMessageBuilder = MessageBuilder.withPayload(new String[]{"One","Two"});
|
||||
Message<String[]> inMessage = inChannelMessageBuilder.build();
|
||||
DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
|
||||
inChannel.send(inMessage);
|
||||
PollableChannel outChannel = (PollableChannel) ac.getBean("outChannel");
|
||||
String payload = (String) outChannel.receive().getPayload();
|
||||
Assert.assertTrue(payload.equals("One,Two"));
|
||||
}
|
||||
|
||||
private void testRouterDefinitionSuccess(String configProperty){
|
||||
ApplicationContext ac = this.bootStrap(configProperty);
|
||||
EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testRouter");
|
||||
Assert.assertNotNull(splitter);
|
||||
MessageBuilder inChannelMessageBuilder = MessageBuilder.withPayload("1");
|
||||
Message inMessage = inChannelMessageBuilder.build();
|
||||
MessageBuilder<String> inChannelMessageBuilder = MessageBuilder.withPayload("1");
|
||||
Message<String> inMessage = inChannelMessageBuilder.build();
|
||||
DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
|
||||
inChannel.send(inMessage);
|
||||
PollableChannel channel1 = (PollableChannel) ac.getBean("channel1");
|
||||
@@ -222,28 +235,31 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
PollableChannel channel2 = (PollableChannel) ac.getBean("channel2");
|
||||
Assert.assertTrue(channel2.receive().getPayload().equals("2"));
|
||||
}
|
||||
|
||||
private void testSADefinitionSuccess(String configProperty){
|
||||
ApplicationContext ac = this.bootStrap(configProperty);
|
||||
EventDrivenConsumer splitter = (EventDrivenConsumer) ac.getBean("testServiceActivator");
|
||||
Assert.assertNotNull(splitter);
|
||||
MessageBuilder inChannelMessageBuilder = MessageBuilder.withPayload("1");
|
||||
Message inMessage = inChannelMessageBuilder.build();
|
||||
MessageBuilder<String> inChannelMessageBuilder = MessageBuilder.withPayload("1");
|
||||
Message<String> inMessage = inChannelMessageBuilder.build();
|
||||
DirectChannel inChannel = (DirectChannel) ac.getBean("inChannel");
|
||||
inChannel.send(inMessage);
|
||||
PollableChannel channel1 = (PollableChannel) ac.getBean("outChannel");
|
||||
Assert.assertTrue(channel1.receive().getPayload().equals("1"));
|
||||
}
|
||||
|
||||
private void testAggregatorDefinitionSuccess(String configProperty){
|
||||
ApplicationContext ac = this.bootStrap(configProperty);
|
||||
MessageChannel inChannel = (MessageChannel) ac.getBean("inChannel");
|
||||
for (int i = 0; i < 5; i++) {
|
||||
Map<String, Object> headers = stubHeaders(i, 5, 1);
|
||||
Message message = new GenericMessage<Integer>(i, headers);
|
||||
Message<Integer> message = new GenericMessage<Integer>(i, headers);
|
||||
inChannel.send(message);
|
||||
}
|
||||
PollableChannel output = (PollableChannel) ac.getBean("outChannel");
|
||||
assertEquals(0 + 1 + 2 + 3 + 4, output.receive().getPayload());
|
||||
}
|
||||
|
||||
private void testFilterDefinitionSuccess(String configProperty){
|
||||
ApplicationContext ac = this.bootStrap(configProperty);
|
||||
MessageChannel input = (MessageChannel) ac.getBean("inChannel");
|
||||
@@ -262,6 +278,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
ac.refresh();
|
||||
return ac;
|
||||
}
|
||||
|
||||
private Map<String, Object> stubHeaders(int sequenceNumber, int sequenceSize, int correllationId) {
|
||||
Map<String, Object> headers = new HashMap<String, Object>();
|
||||
headers.put(MessageHeaders.SEQUENCE_NUMBER, sequenceNumber);
|
||||
@@ -271,8 +288,9 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
return headers;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static class TestSplitter{
|
||||
public Collection split(String[] payload){
|
||||
public Collection<String> split(String[] payload) {
|
||||
return CollectionUtils.arrayToList(payload);
|
||||
}
|
||||
}
|
||||
@@ -288,6 +306,7 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
return (value.equals("1")) ? "channel1" : "channel2";
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestServiceActivator{
|
||||
public String foo(String value) {
|
||||
return value;
|
||||
@@ -303,9 +322,9 @@ public class InnerDefinitionHandlerAwareEndpointParserTests {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class TestMessageFilter{
|
||||
public boolean filter(String value) {
|
||||
System.out.println(">>>> Filtering");
|
||||
return value.equals("foo");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,15 +34,15 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.task.SimpleAsyncTaskExecutor;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.message.MessageHandler;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.SimpleTaskScheduler;
|
||||
import org.springframework.integration.scheduling.Trigger;
|
||||
import org.springframework.integration.util.ErrorHandler;
|
||||
import org.springframework.scheduling.Trigger;
|
||||
import org.springframework.scheduling.TriggerContext;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.support.ErrorHandler;
|
||||
|
||||
/**
|
||||
* @author Iwein Fuld
|
||||
@@ -65,25 +65,26 @@ public class PollingConsumerEndpointTests {
|
||||
|
||||
private PollableChannel channelMock = createMock(PollableChannel.class);
|
||||
|
||||
private SimpleTaskScheduler taskScheduler = new SimpleTaskScheduler(new SimpleAsyncTaskExecutor());
|
||||
private ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
|
||||
|
||||
@Before
|
||||
public void init() throws InterruptedException {
|
||||
public void init() throws Exception {
|
||||
consumer.counter.set(0);
|
||||
trigger.reset();
|
||||
endpoint = new PollingConsumer(channelMock, consumer);
|
||||
endpoint.setTaskScheduler(taskScheduler);
|
||||
taskScheduler.setPoolSize(5);
|
||||
taskScheduler.setErrorHandler(errorHandler);
|
||||
taskScheduler.start();
|
||||
endpoint.setTaskScheduler(taskScheduler);
|
||||
endpoint.setTrigger(trigger);
|
||||
endpoint.setReceiveTimeout(-1);
|
||||
taskScheduler.afterPropertiesSet();
|
||||
reset(channelMock);
|
||||
}
|
||||
|
||||
@After
|
||||
public void stop() {
|
||||
taskScheduler.stop();
|
||||
public void stop() throws Exception {
|
||||
taskScheduler.destroy();
|
||||
}
|
||||
|
||||
|
||||
@@ -125,6 +126,15 @@ public class PollingConsumerEndpointTests {
|
||||
verify(channelMock);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void heavierLoadTest() throws Exception {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
this.init();
|
||||
this.multipleMessages();
|
||||
this.stop();
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = MessageRejectedException.class)
|
||||
public void rejectedMessage() throws Throwable {
|
||||
expect(channelMock.receive()).andReturn(badMessage);
|
||||
@@ -198,7 +208,7 @@ public class PollingConsumerEndpointTests {
|
||||
private volatile CountDownLatch latch = new CountDownLatch(1);
|
||||
|
||||
|
||||
public Date getNextRunTime(Date lastScheduledRunTime, Date lastCompleteTime) {
|
||||
public Date nextExecutionTime(TriggerContext triggerContext) {
|
||||
if (!this.hasRun.getAndSet(true)) {
|
||||
return new Date();
|
||||
}
|
||||
@@ -229,7 +239,7 @@ public class PollingConsumerEndpointTests {
|
||||
|
||||
private volatile Throwable lastError;
|
||||
|
||||
public void handle(Throwable t) {
|
||||
public void handleError(Throwable t) {
|
||||
this.lastError = t;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,6 +25,9 @@ import java.util.GregorianCalendar;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.scheduling.support.CronTrigger;
|
||||
import org.springframework.scheduling.support.SimpleTriggerContext;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mark Fisher
|
||||
@@ -54,7 +57,9 @@ public class CronTriggerTests {
|
||||
@Test
|
||||
public void testMatchAll() throws Exception {
|
||||
CronTrigger trigger = new CronTrigger("* * * * * *");
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,7 +84,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.SECOND, 10);
|
||||
Date date = calendar.getTime();
|
||||
calendar.add(Calendar.SECOND, 1);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,7 +95,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.SECOND, 11);
|
||||
Date date = calendar.getTime();
|
||||
calendar.add(Calendar.SECOND, 59);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,7 +116,9 @@ public class CronTriggerTests {
|
||||
Date date = calendar.getTime();
|
||||
calendar.add(Calendar.MINUTE, 1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -117,9 +128,13 @@ public class CronTriggerTests {
|
||||
Date date = calendar.getTime();
|
||||
calendar.add(Calendar.MINUTE, 1);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext1 = new SimpleTriggerContext();
|
||||
triggerContext1.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(triggerContext1));
|
||||
calendar.add(Calendar.MINUTE, 1);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext2 = new SimpleTriggerContext();
|
||||
triggerContext2.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date=trigger.nextExecutionTime(triggerContext2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -129,7 +144,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
Date date = calendar.getTime();
|
||||
calendar.add(Calendar.MINUTE, 59);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -143,9 +160,13 @@ public class CronTriggerTests {
|
||||
Date date = calendar.getTime();
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 12);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext1 = new SimpleTriggerContext();
|
||||
triggerContext1.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(triggerContext1));
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 13);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext2 = new SimpleTriggerContext();
|
||||
triggerContext2.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -157,10 +178,14 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext1 = new SimpleTriggerContext();
|
||||
triggerContext1.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(triggerContext1));
|
||||
assertEquals(2, calendar.get(Calendar.DAY_OF_MONTH));
|
||||
calendar.add(Calendar.DAY_OF_MONTH, 1);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext2 = new SimpleTriggerContext();
|
||||
triggerContext2.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext2));
|
||||
assertEquals(3, calendar.get(Calendar.DAY_OF_MONTH));
|
||||
}
|
||||
|
||||
@@ -173,7 +198,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -186,7 +213,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -200,9 +229,13 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext1 = new SimpleTriggerContext();
|
||||
triggerContext1.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(triggerContext1));
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 2);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext2 = new SimpleTriggerContext();
|
||||
triggerContext2.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,10 +248,14 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 31);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext1 = new SimpleTriggerContext();
|
||||
triggerContext1.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(triggerContext1));
|
||||
calendar.set(Calendar.MONTH, 10); // November
|
||||
calendar.set(Calendar.DAY_OF_MONTH, 1);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext2 = new SimpleTriggerContext();
|
||||
triggerContext2.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -232,9 +269,13 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
calendar.set(Calendar.MONTH, 10);
|
||||
assertEquals(calendar.getTime(), date=trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext1 = new SimpleTriggerContext();
|
||||
triggerContext1.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), date = trigger.nextExecutionTime(triggerContext1));
|
||||
calendar.set(Calendar.MONTH, 11);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext2 = new SimpleTriggerContext();
|
||||
triggerContext2.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,7 +288,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -261,7 +304,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,7 +318,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
assertEquals(Calendar.TUESDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
@@ -286,7 +333,9 @@ public class CronTriggerTests {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||
calendar.set(Calendar.MINUTE, 0);
|
||||
calendar.set(Calendar.SECOND, 0);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
assertEquals(Calendar.TUESDAY, calendar.get(Calendar.DAY_OF_WEEK));
|
||||
}
|
||||
|
||||
@@ -368,7 +417,9 @@ public class CronTriggerTests {
|
||||
private void assertMatchesNextSecond(CronTrigger trigger, Calendar calendar) {
|
||||
Date date = calendar.getTime();
|
||||
roundup(calendar);
|
||||
assertEquals(calendar.getTime(), trigger.getNextRunTime(null, date));
|
||||
SimpleTriggerContext triggerContext = new SimpleTriggerContext();
|
||||
triggerContext.update(null, null, date);
|
||||
assertEquals(calendar.getTime(), trigger.nextExecutionTime(triggerContext));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,14 +26,15 @@ import org.springframework.beans.factory.BeanNameAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
import org.springframework.integration.channel.BeanFactoryChannelResolver;
|
||||
import org.springframework.integration.channel.MessagePublishingErrorHandler;
|
||||
import org.springframework.integration.context.IntegrationContextUtils;
|
||||
import org.springframework.integration.core.MessageChannel;
|
||||
import org.springframework.integration.endpoint.AbstractEndpoint;
|
||||
import org.springframework.integration.endpoint.AbstractPollingEndpoint;
|
||||
import org.springframework.integration.scheduling.IntervalTrigger;
|
||||
import org.springframework.integration.scheduling.SimpleTaskScheduler;
|
||||
import org.springframework.integration.scheduling.TaskScheduler;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.scheduling.support.ErrorHandler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -70,16 +71,19 @@ public abstract class TestUtils {
|
||||
|
||||
public static TestApplicationContext createTestApplicationContext() {
|
||||
TestApplicationContext context = new TestApplicationContext();
|
||||
registerBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, createTaskScheduler(10), context);
|
||||
ErrorHandler errorHandler = new MessagePublishingErrorHandler(new BeanFactoryChannelResolver(context));
|
||||
ThreadPoolTaskScheduler scheduler = createTaskScheduler(10);
|
||||
scheduler.setErrorHandler(errorHandler);
|
||||
registerBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME, scheduler, context);
|
||||
return context;
|
||||
}
|
||||
|
||||
public static TaskScheduler createTaskScheduler(int poolSize) {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setCorePoolSize(poolSize);
|
||||
executor.setRejectedExecutionHandler(new CallerRunsPolicy());
|
||||
executor.afterPropertiesSet();
|
||||
return new SimpleTaskScheduler(executor);
|
||||
public static ThreadPoolTaskScheduler createTaskScheduler(int poolSize) {
|
||||
ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();
|
||||
scheduler.setPoolSize(poolSize);
|
||||
scheduler.setRejectedExecutionHandler(new CallerRunsPolicy());
|
||||
scheduler.afterPropertiesSet();
|
||||
return scheduler;
|
||||
}
|
||||
|
||||
private static void registerBean(String beanName, Object bean, BeanFactory beanFactory) {
|
||||
|
||||
Reference in New Issue
Block a user