From b2ffe2f5101fda2b71efa7faf952f19581a9bed9 Mon Sep 17 00:00:00 2001 From: Oleg Zhurakousky Date: Thu, 11 Oct 2012 15:52:02 -0400 Subject: [PATCH] INT-2280 fixed broken JDBC test Fix JdbcMessageStoreChannelTests.testSendAndActivateWithRollback as well as others by changing poller interval. Poller was polling too quickly, so even the slightest delay before assertion would result in another Message in the Service.messages thus the intermittent assertion error. INT-2280 Polishing Don't add retries to message list. --- .../JdbcMessageStoreChannelTests-context.xml | 2 +- .../jdbc/JdbcMessageStoreChannelTests.java | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml index ba41b34921..151d920697 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests-context.xml @@ -32,7 +32,7 @@ - + diff --git a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java index 225bf8601d..0cf312f54e 100644 --- a/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java +++ b/spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreChannelTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2012 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. @@ -44,7 +44,7 @@ public class JdbcMessageStoreChannelTests { @Autowired private JdbcMessageStore messageStore; - + @BeforeTransaction public void clear() { for (MessageGroup group : messageStore) { @@ -60,7 +60,7 @@ public class JdbcMessageStoreChannelTests { assertEquals(1, Service.messages.size()); assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()); } - + @Test public void testSendAndActivateWithRollback() throws Exception { Service.reset(1); @@ -71,7 +71,7 @@ public class JdbcMessageStoreChannelTests { // After a rollback in the poller the message is still waiting to be delivered assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()); } - + @Test @Transactional public void testSendAndActivateTransactionalSend() throws Exception { @@ -89,13 +89,15 @@ public class JdbcMessageStoreChannelTests { // But inside the transaction the message is still there assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()); } - + public static class Service { private static boolean fail = false; + private static boolean alreadyFailed = false; private static List messages = new CopyOnWriteArrayList(); private static CountDownLatch latch = new CountDownLatch(0); public static void reset(int count) { fail = false; + alreadyFailed = false; messages.clear(); latch = new CountDownLatch(count); } @@ -105,9 +107,12 @@ public class JdbcMessageStoreChannelTests { } } public String echo(String input) { - messages.add(input); - latch.countDown(); + if (!alreadyFailed) { + messages.add(input); + latch.countDown(); + } if (fail) { + alreadyFailed = true; throw new RuntimeException("Planned failure"); } return input;