Skip to content

Commit

Permalink
Fix Unreliable Redis Test
Browse files Browse the repository at this point in the history
https://build.spring.io/browse/INT-B41-JOB1-187/test/case/155732315

Purge the list before testing.

Force `listening` to `false` so `rightPush` is called reliably.
  • Loading branch information
garyrussell authored and artembilan committed Jan 13, 2015
1 parent 48f9801 commit 8896d50
Showing 1 changed file with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2013 the original author or authors
* Copyright 2013-2015 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.
Expand Down Expand Up @@ -72,6 +72,7 @@
/**
* @author Gunnar Hillert
* @author Artem Bilan
* @author Gary Russell
* @since 3.0
*/
@ContextConfiguration
Expand Down Expand Up @@ -227,12 +228,15 @@ public void testInt3442ProperlyStop() throws Exception {
redisTemplate.setValueSerializer(new JdkSerializationRedisSerializer());
redisTemplate.afterPropertiesSet();

while (redisTemplate.boundListOps(queueName).rightPop() != null) {}

RedisQueueMessageDrivenEndpoint endpoint = new RedisQueueMessageDrivenEndpoint(queueName,
this.connectionFactory);
BoundListOperations<String, byte[]> boundListOperations =
TestUtils.getPropertyValue(endpoint, "boundListOperations", BoundListOperations.class);
boundListOperations = Mockito.spy(boundListOperations);
new DirectFieldAccessor(endpoint).setPropertyValue("boundListOperations", boundListOperations);
DirectFieldAccessor dfa = new DirectFieldAccessor(endpoint);
dfa.setPropertyValue("boundListOperations", boundListOperations);
endpoint.setBeanFactory(Mockito.mock(BeanFactory.class));
endpoint.setOutputChannel(new DirectChannel());
endpoint.setReceiveTimeout(1000);
Expand All @@ -244,6 +248,9 @@ public void testInt3442ProperlyStop() throws Exception {
endpoint.afterPropertiesSet();
endpoint.start();

waitListening(endpoint);
dfa.setPropertyValue("listening", false);

redisTemplate.boundListOps(queueName).leftPush("foo");
endpoint.stop();

Expand Down Expand Up @@ -283,16 +290,7 @@ public void publishEvent(ApplicationEvent event) {
endpoint.afterPropertiesSet();
endpoint.start();

int n = 0;
do {
n++;
if (n == 100) {
break;
}
Thread.sleep(100);
} while (!endpoint.isListening());

assertTrue(n < 100);
waitListening(endpoint);

((DisposableBean) this.connectionFactory).destroy();

Expand Down Expand Up @@ -325,4 +323,17 @@ public void publishEvent(ApplicationEvent event) {
endpoint.stop();
}

private void waitListening(RedisQueueMessageDrivenEndpoint endpoint) throws InterruptedException {
int n = 0;
do {
n++;
if (n == 100) {
break;
}
Thread.sleep(100);
} while (!endpoint.isListening());

assertTrue(n < 100);
}

}

0 comments on commit 8896d50

Please sign in to comment.