INT-2918: Fix 'Redis available' for ROGTests

This commit is contained in:
Artem Bilan
2014-03-31 18:44:42 +03:00
committed by Gary Russell
parent 5f51d191e4
commit d74b4dba73
3 changed files with 12 additions and 11 deletions

View File

@@ -58,7 +58,7 @@
<constructor-arg ref="redisConnectionFactory"/>
</bean>
<bean id="atomicInteger" class="org.springframework.data.redis.support.atomic.RedisAtomicInteger">
<bean id="atomicInteger" class="org.springframework.data.redis.support.atomic.RedisAtomicInteger" lazy-init="true">
<constructor-arg value="si.test.RedisAtomicInteger"/>
<constructor-arg ref="redisConnectionFactory"/>
<constructor-arg value="10"/>

View File

@@ -29,9 +29,9 @@ import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.support.atomic.RedisAtomicInteger;
import org.springframework.integration.handler.ReplyRequiredException;
import org.springframework.integration.redis.rules.RedisAvailable;
import org.springframework.integration.redis.rules.RedisAvailableTests;
@@ -53,6 +53,9 @@ import com.lambdaworks.redis.protocol.CommandType;
@RunWith(SpringJUnit4ClassRunner.class)
public class RedisOutboundGatewayTests extends RedisAvailableTests {
@Autowired
private BeanFactory beanFactory;
@Autowired
private PollableChannel replyChannel;
@@ -65,9 +68,6 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
@Autowired
private MessageChannel incrementAtomicIntegerChannel;
@Autowired
private RedisAtomicInteger atomicInteger;
@Autowired
private MessageChannel setDelCommandChannel;
@@ -110,12 +110,17 @@ public class RedisOutboundGatewayTests extends RedisAvailableTests {
@Test
@RedisAvailable
public void testIncrementAtomicCommand() {
// Since 'atomicInteger' is lazy-init to avoid early Redis connection, we have to initialize it before send the INCR command.
this.beanFactory.getBean("atomicInteger");
this.incrementAtomicIntegerChannel.send(MessageBuilder.withPayload(CommandType.INCR).build());
System.out.println();
Message<?> receive = this.replyChannel.receive(1000);
assertNotNull(receive);
assertEquals(11L, receive.getPayload());
assertEquals(11, this.atomicInteger.get());
this.getCommandChannel.send(MessageBuilder.withPayload("si.test.RedisAtomicInteger").build());
receive = this.replyChannel.receive(1000);
assertNotNull(receive);
assertEquals("11", new String((byte[]) receive.getPayload()));
}
@Test

View File

@@ -68,8 +68,6 @@ public class RedisAvailableTests {
while (n++ < 100 && !connection.isSubscribed()) {
Thread.sleep(100);
}
// TODO: remove this additional delay when/if https://jira.springsource.org/browse/DATAREDIS-242 is resolved
Thread.sleep(250);
assertTrue("RedisMessageListenerContainer Failed to Subscribe", n < 100);
}
@@ -82,8 +80,6 @@ public class RedisAvailableTests {
while (n++ < 100 && connection.getSubscription().getPatterns().size() == 0) {
Thread.sleep(100);
}
// TODO: remove this additional delay when/if https://jira.springsource.org/browse/DATAREDIS-242 is resolved
Thread.sleep(250);
assertTrue("RedisMessageListenerContainer Failed to Subscribe with patterns", n < 100);
}