Remove System.out/.err Calls From All Tests

This commit is contained in:
Gary Russell
2016-04-14 16:22:45 -04:00
parent e5bf0187eb
commit 4027b38da8
32 changed files with 164 additions and 89 deletions

View File

@@ -277,7 +277,7 @@ public class MessagingAnnotationsWithBeanAnnotationTests {
@Filter(inputChannel = "skippedChannel5")
@Profile("foo")
public MessageHandler skippedMessageHandler() {
return System.out::println;
return m -> { };
}
@Bean

View File

@@ -23,6 +23,8 @@ import static org.mockito.Mockito.verify;
import java.lang.reflect.Field;
import java.util.UUID;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
@@ -43,6 +45,8 @@ import org.springframework.util.StopWatch;
*/
public class MessageIdGenerationTests {
private final Log logger = LogFactory.getLog(getClass());
@Test
public void testCustomIdGenerationWithParentRegistrar() throws Exception {
ClassPathXmlApplicationContext parent = new ClassPathXmlApplicationContext("MessageIdGenerationTests-context-withGenerator.xml", this.getClass());
@@ -155,6 +159,7 @@ public class MessageIdGenerationTests {
Field idGeneratorField = ReflectionUtils.findField(MessageHeaders.class, "idGenerator");
ReflectionUtils.makeAccessible(idGeneratorField);
ReflectionUtils.setField(idGeneratorField, null, new IdGenerator() {
@Override
public UUID generateId() {
return TimeBasedUUIDGenerator.generateId();
}
@@ -167,12 +172,12 @@ public class MessageIdGenerationTests {
watch.stop();
double timebasedGeneratorElapsedTime = watch.getTotalTimeSeconds();
System.out.println("Generated " + times + " messages using default UUID generator " +
logger.info("Generated " + times + " messages using default UUID generator " +
"in " + defaultGeneratorElapsedTime + " seconds");
System.out.println("Generated " + times + " messages using Timebased UUID generator " +
logger.info("Generated " + times + " messages using Timebased UUID generator " +
"in " + timebasedGeneratorElapsedTime + " seconds");
System.out.println("Time-based ID generator is " + defaultGeneratorElapsedTime / timebasedGeneratorElapsedTime + " times faster");
logger.info("Time-based ID generator is " + defaultGeneratorElapsedTime / timebasedGeneratorElapsedTime + " times faster");
}
private void assertDestroy() throws Exception {
@@ -183,6 +188,7 @@ public class MessageIdGenerationTests {
public static class SampleIdGenerator implements IdGenerator {
@Override
public UUID generateId() {
return UUID.nameUUIDFromBytes(((System.currentTimeMillis() - System.nanoTime()) + "").getBytes());
}

View File

@@ -26,13 +26,15 @@ import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.BeanCreationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.MessageRejectedException;
import org.springframework.integration.channel.DirectChannel;
@@ -48,26 +50,33 @@ import org.springframework.util.StopWatch;
* @author Oleg Zhurakousky
* @author Gunnar Hillert
* @author Artem Bilan
* @author Gary Russell
*/
public class MessageHistoryIntegrationTests {
private final Log logger = LogFactory.getLog(getClass());
@Test
public void testNoHistoryAwareMessageHandler() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml",
MessageHistoryIntegrationTests.class);
Map<String, ConsumerEndpointFactoryBean> cefBeans = ac.getBeansOfType(ConsumerEndpointFactoryBean.class);
for (ConsumerEndpointFactoryBean cefBean : cefBeans.values()) {
DirectFieldAccessor bridgeAccessor = new DirectFieldAccessor(cefBean);
String handlerClassName = bridgeAccessor.getPropertyValue("handler").getClass().getName();
assertFalse("org.springframework.integration.config.MessageHistoryWritingMessageHandler".equals(handlerClassName));
}
ac.close();
}
@Test
public void testMessageHistoryWithHistoryWriter() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriter.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriter.xml",
MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) {
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
@@ -140,14 +149,17 @@ public class MessageHistoryIntegrationTests {
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
assertNotNull(result);
//assertEquals("hello", result);
ac.close();
}
@Test
public void testMessageHistoryWithoutHistoryWriter() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithoutHistoryWriter.xml",
MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) {
assertNull(message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class));
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
@@ -157,16 +169,20 @@ public class MessageHistoryIntegrationTests {
endOfThePipeChannel.subscribe(handler);
gateway.echo("hello");
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
ac.close();
}
@Test
public void testMessageHistoryParser() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(
"messageHistoryWithHistoryWriterNamespace.xml", MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) {
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
Iterator<Properties> historyIterator = message.getHeaders()
.get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
assertTrue(historyIterator.hasNext());
MessageChannel replyChannel = (MessageChannel) message.getHeaders().getReplyChannel();
replyChannel.send(message);
@@ -175,14 +191,17 @@ public class MessageHistoryIntegrationTests {
endOfThePipeChannel.subscribe(handler);
gateway.echo("hello");
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
ac.close();
}
@Test
public void testMessageHistoryParserWithNamePatterns() {
ApplicationContext ac = new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespaceAndPatterns.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext ac = new ClassPathXmlApplicationContext(
"messageHistoryWithHistoryWriterNamespaceAndPatterns.xml", MessageHistoryIntegrationTests.class);
SampleGateway gateway = ac.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = ac.getBean("endOfThePipeChannel", DirectChannel.class);
MessageHandler handler = Mockito.spy(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) {
Iterator<Properties> historyIterator = message.getHeaders().get(MessageHistory.HEADER_NAME, MessageHistory.class).iterator();
assertTrue(historyIterator.hasNext());
@@ -199,21 +218,26 @@ public class MessageHistoryIntegrationTests {
endOfThePipeChannel.subscribe(handler);
gateway.echo("hello");
Mockito.verify(handler, Mockito.times(1)).handleMessage(Mockito.any(Message.class));
ac.close();
}
@Test(expected = BeanCreationException.class)
public void testMessageHistoryMoreThanOneNamespaceFail() {
new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace-fail.xml", MessageHistoryIntegrationTests.class);
new ClassPathXmlApplicationContext("messageHistoryWithHistoryWriterNamespace-fail.xml",
MessageHistoryIntegrationTests.class).close();
}
@Test @Ignore
public void testMessageHistoryWithHistoryPerformance() {
ApplicationContext acWithHistory = new ClassPathXmlApplicationContext("perfWithMessageHistory.xml", MessageHistoryIntegrationTests.class);
ApplicationContext acWithoutHistory = new ClassPathXmlApplicationContext("perfWithoutMessageHistory.xml", MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext acWithHistory = new ClassPathXmlApplicationContext("perfWithMessageHistory.xml",
MessageHistoryIntegrationTests.class);
ConfigurableApplicationContext acWithoutHistory = new ClassPathXmlApplicationContext(
"perfWithoutMessageHistory.xml", MessageHistoryIntegrationTests.class);
SampleGateway gatewayHistory = acWithHistory.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannelHistory = acWithHistory.getBean("endOfThePipeChannel", DirectChannel.class);
endOfThePipeChannelHistory.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
@@ -225,6 +249,7 @@ public class MessageHistoryIntegrationTests {
SampleGateway gateway = acWithoutHistory.getBean("sampleGateway", SampleGateway.class);
DirectChannel endOfThePipeChannel = acWithoutHistory.getBean("endOfThePipeChannel", DirectChannel.class);
endOfThePipeChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message)
throws MessageRejectedException, MessageHandlingException,
MessageDeliveryException {
@@ -239,14 +264,16 @@ public class MessageHistoryIntegrationTests {
gatewayHistory.echo("hello");
}
stopWatch.stop();
System.out.println("Elapsed time with history 10000 calls: " + stopWatch.getTotalTimeSeconds());
logger.info("Elapsed time with history 10000 calls: " + stopWatch.getTotalTimeSeconds());
stopWatch = new StopWatch();
stopWatch.start();
for (int i = 0; i < 10000; i++) {
gateway.echo("hello");
}
stopWatch.stop();
System.out.println("Elapsed time without history 10000 calls: " + stopWatch.getTotalTimeSeconds());
logger.info("Elapsed time without history 10000 calls: " + stopWatch.getTotalTimeSeconds());
acWithHistory.close();
acWithoutHistory.close();
}
public interface SampleGateway {

View File

@@ -131,7 +131,6 @@ public class ExponentialMovingAverageRateTests {
Thread.sleep(22L);
history.increment();
Thread.sleep(18L);
// System.err.println(history);
assertTrue("Standard deviation should be non-zero: " + history, history.getStandardDeviation() > 0);
}