Skip to content

Commit cfdfa62

Browse files
committed
Fix some latest test failures
https://build.spring.io/browse/INT-B43-164/ * Fix CheckStyle for `System. out .println(` expression commenting out such a code line * Fix generics in the `JdbcMessageStoreTests` * Increase receive timeout in the `FileMessageHistoryTests` * Change the `AsyncAmqpGatewayTests` logic to deal with the same channel for both `ack/nack`. The `timeout` case without reply may end up with the `Consumer cancel`, therefore `nack` not `ack` like we expected
1 parent 286c421 commit cfdfa62

File tree

4 files changed

+30
-19
lines changed

4 files changed

+30
-19
lines changed

spring-integration-amqp/src/test/java/org/springframework/integration/amqp/outbound/AsyncAmqpGatewayTests.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import static org.junit.Assert.assertNotNull;
2222
import static org.junit.Assert.assertNull;
2323
import static org.junit.Assert.assertThat;
24+
import static org.mockito.BDDMockito.willAnswer;
2425
import static org.mockito.Matchers.any;
26+
import static org.mockito.Matchers.anyBoolean;
2527
import static org.mockito.Matchers.anyString;
2628
import static org.mockito.Mockito.doReturn;
2729
import static org.mockito.Mockito.mock;
@@ -34,6 +36,7 @@
3436
import org.junit.AfterClass;
3537
import org.junit.ClassRule;
3638
import org.junit.Test;
39+
import org.mockito.Mockito;
3740

3841
import org.springframework.amqp.core.AmqpReplyTimeoutException;
3942
import org.springframework.amqp.core.MessageListener;
@@ -43,6 +46,7 @@
4346
import org.springframework.amqp.rabbit.core.RabbitTemplate;
4447
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
4548
import org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter;
49+
import org.springframework.amqp.rabbit.support.CorrelationData;
4650
import org.springframework.amqp.support.AmqpHeaders;
4751
import org.springframework.beans.DirectFieldAccessor;
4852
import org.springframework.beans.factory.BeanFactory;
@@ -58,6 +62,8 @@
5862

5963
/**
6064
* @author Gary Russell
65+
* @author Artem Bilan
66+
*
6167
* @since 4.3
6268
*
6369
*/
@@ -66,10 +72,6 @@ public class AsyncAmqpGatewayTests {
6672
@ClassRule
6773
public static BrokerRunning brokerRunning = BrokerRunning.isRunningWithEmptyQueues("asyncQ1", "asyncRQ1");
6874

69-
// @Rule
70-
// public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE, "org.springframework.integration",
71-
// "org.springframework.amqp");
72-
7375
@AfterClass
7476
public static void tearDown() {
7577
brokerRunning.removeTestQueues();
@@ -89,6 +91,11 @@ public void testConfirmsAndReturns() {
8991
AsyncRabbitTemplate asyncTemplate = spy(new AsyncRabbitTemplate(template, container));
9092
asyncTemplate.setEnableConfirms(true);
9193
asyncTemplate.setMandatory(true);
94+
95+
willAnswer(Mockito.CALLS_REAL_METHODS)
96+
.given(asyncTemplate)
97+
.confirm(any(CorrelationData.class), anyBoolean(), anyString());
98+
9299
asyncTemplate.start();
93100

94101
SimpleMessageListenerContainer receiver = new SimpleMessageListenerContainer(ccf);
@@ -120,14 +127,12 @@ public String handleMessage(String foo) {
120127
returnChannel.setBeanName("returns");
121128
QueueChannel ackChannel = new QueueChannel();
122129
ackChannel.setBeanName("acks");
123-
QueueChannel nackChannel = new QueueChannel();
124-
nackChannel.setBeanName("nacks");
125130
QueueChannel errorChannel = new QueueChannel();
126131
errorChannel.setBeanName("errors");
127132
gateway.setOutputChannel(outputChannel);
128133
gateway.setReturnChannel(returnChannel);
129134
gateway.setConfirmAckChannel(ackChannel);
130-
gateway.setConfirmNackChannel(nackChannel);
135+
gateway.setConfirmNackChannel(ackChannel);
131136
gateway.setConfirmCorrelationExpressionString("#this");
132137
gateway.setExchangeName("");
133138
gateway.setRoutingKey("asyncQ1");
@@ -150,6 +155,7 @@ public String handleMessage(String foo) {
150155

151156
// timeout
152157
asyncTemplate.setReceiveTimeout(100);
158+
153159
receiver.setMessageListener(new MessageListener() {
154160

155161
@Override
@@ -158,7 +164,7 @@ public void onMessage(org.springframework.amqp.core.Message message) {
158164

159165
});
160166
gateway.handleMessage(message);
161-
assertNull(errorChannel.receive(1000));
167+
assertNull(errorChannel.receive(10));
162168
ack = ackChannel.receive(10000);
163169
assertNotNull(ack);
164170

@@ -169,7 +175,7 @@ public void onMessage(org.springframework.amqp.core.Message message) {
169175
assertThat(received, instanceOf(ErrorMessage.class));
170176
ErrorMessage error = (ErrorMessage) received;
171177
assertThat(error.getPayload(), instanceOf(MessagingException.class));
172-
assertThat(((MessagingException) error.getPayload()).getCause(), instanceOf(AmqpReplyTimeoutException.class));
178+
assertThat(error.getPayload().getCause(), instanceOf(AmqpReplyTimeoutException.class));
173179
asyncTemplate.setReceiveTimeout(30000);
174180
receiver.setMessageListener(messageListener);
175181
ack = ackChannel.receive(10000);
@@ -213,7 +219,7 @@ public void handleMessage(Message<?> message) throws MessagingException {
213219

214220
gateway.handleMessage(message);
215221

216-
ack = nackChannel.receive(10000);
222+
ack = ackChannel.receive(10000);
217223
assertNotNull(ack);
218224
assertEquals("foo", ack.getPayload());
219225
assertEquals("nacknack", ack.getHeaders().get(AmqpHeaders.PUBLISH_CONFIRM_NACK_CAUSE));

spring-integration-file/src/test/java/org/springframework/integration/file/config/FileMessageHistoryTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
import org.junit.Test;
3131
import org.junit.rules.TemporaryFolder;
3232

33-
import org.springframework.context.ApplicationContext;
3433
import org.springframework.context.support.ClassPathXmlApplicationContext;
3534
import org.springframework.integration.history.MessageHistory;
3635
import org.springframework.integration.test.util.TestUtils;
@@ -41,26 +40,32 @@
4140
* @author Oleg Zhurakousky
4241
* @author Iwein Fuld
4342
* @author Gunnar Hillert
43+
* @author Artem Bilan
4444
*/
4545
public class FileMessageHistoryTests {
4646

4747

4848
@Test
4949
public void testMessageHistory() throws Exception {
50-
ApplicationContext context = new ClassPathXmlApplicationContext("file-message-history-context.xml", this.getClass());
50+
ClassPathXmlApplicationContext context =
51+
new ClassPathXmlApplicationContext("file-message-history-context.xml", getClass());
52+
5153
TemporaryFolder input = context.getBean(TemporaryFolder.class);
5254
File file = input.newFile("FileMessageHistoryTest.txt");
5355
BufferedWriter out = new BufferedWriter(new FileWriter(file));
5456
out.write("hello");
5557
out.close();
5658

5759
PollableChannel outChannel = context.getBean("outChannel", PollableChannel.class);
58-
Message<?> message = outChannel.receive(1000);
60+
Message<?> message = outChannel.receive(10000);
5961
assertThat(message, is(notNullValue()));
6062
MessageHistory history = MessageHistory.read(message);
6163
assertThat(history, is(notNullValue()));
6264
Properties componentHistoryRecord = TestUtils.locateComponentInHistory(history, "fileAdapter", 0);
6365
assertNotNull(componentHistoryRecord);
6466
assertEquals("file:inbound-channel-adapter", componentHistoryRecord.get("type"));
67+
68+
context.close();
6569
}
70+
6671
}

spring-integration-jdbc/src/test/java/org/springframework/integration/jdbc/JdbcMessageStoreTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,17 +241,17 @@ public void testAddAndRemoveMessageFromMessageGroup() throws Exception {
241241
@Test
242242
public void testAddAndRemoveMessagesFromMessageGroup() throws Exception {
243243
String groupId = "X";
244-
messageStore.setRemoveBatchSize(10);
244+
this.messageStore.setRemoveBatchSize(10);
245245
List<Message<?>> messages = new ArrayList<Message<?>>();
246246
for (int i = 0; i < 25; i++) {
247247
Message<String> message = MessageBuilder.withPayload("foo").setCorrelationId(groupId).build();
248248
messages.add(message);
249249
}
250-
messageStore.addMessagesToGroup(groupId, messages.toArray(new Message[messages.size()]));
251-
MessageGroup group = messageStore.getMessageGroup(groupId);
250+
this.messageStore.addMessagesToGroup(groupId, messages.toArray(new Message<?>[messages.size()]));
251+
MessageGroup group = this.messageStore.getMessageGroup(groupId);
252252
assertEquals(25, group.size());
253-
messageStore.removeMessagesFromGroup(groupId, messages);
254-
group = messageStore.getMessageGroup(groupId);
253+
this.messageStore.removeMessagesFromGroup(groupId, messages);
254+
group = this.messageStore.getMessageGroup(groupId);
255255
assertEquals(0, group.size());
256256
}
257257

spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageGroupStoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void messageGroupStoreLazyLoadPerformance() throws Exception {
8989

9090
performLazyLoadEagerTest(watch, sequenceSize, false);
9191

92-
System. out .println(watch.prettyPrint()); // checkstyle
92+
// System. out .println(watch.prettyPrint()); // checkstyle
9393
}
9494

9595
private void performLazyLoadEagerTest(StopWatch watch, int sequenceSize, boolean lazyLoad) {

0 commit comments

Comments
 (0)