|
15 | 15 | */ |
16 | 16 | package org.springframework.data.redis.listener; |
17 | 17 |
|
18 | | -import java.util.Arrays; |
| 18 | +import java.util.ArrayList; |
19 | 19 | import java.util.Collection; |
20 | 20 |
|
| 21 | +import org.junit.runners.model.Statement; |
| 22 | + |
21 | 23 | import org.springframework.data.redis.ObjectFactory; |
22 | 24 | import org.springframework.data.redis.Person; |
23 | 25 | import org.springframework.data.redis.PersonObjectFactory; |
24 | 26 | import org.springframework.data.redis.RawObjectFactory; |
25 | 27 | import org.springframework.data.redis.SettingsUtils; |
26 | 28 | import org.springframework.data.redis.StringObjectFactory; |
| 29 | +import org.springframework.data.redis.connection.RedisClusterConfiguration; |
27 | 30 | import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; |
28 | 31 | import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; |
29 | 32 | import org.springframework.data.redis.connection.lettuce.LettuceTestClientResources; |
30 | 33 | import org.springframework.data.redis.core.RedisTemplate; |
31 | 34 | import org.springframework.data.redis.core.StringRedisTemplate; |
| 35 | +import org.springframework.data.redis.test.util.RedisClusterRule; |
32 | 36 |
|
33 | 37 | /** |
34 | 38 | * @author Costin Leau |
@@ -76,8 +80,49 @@ public static Collection<Object[]> testParams() { |
76 | 80 | rawTemplateLtc.setConnectionFactory(lettuceConnFactory); |
77 | 81 | rawTemplateLtc.afterPropertiesSet(); |
78 | 82 |
|
79 | | -return Arrays.asList(new Object[][] { { stringFactory, stringTemplate }, { personFactory, personTemplate }, |
80 | | -{ rawFactory, rawTemplate }, { stringFactory, stringTemplateLtc }, { personFactory, personTemplateLtc }, |
81 | | -{ rawFactory, rawTemplateLtc } }); |
| 83 | +Collection<Object[]> parameters = new ArrayList<>(); |
| 84 | +parameters.add(new Object[] { stringFactory, stringTemplate }); |
| 85 | +parameters.add(new Object[] { personFactory, personTemplate }); |
| 86 | +parameters.add(new Object[] { stringFactory, stringTemplateLtc }); |
| 87 | +parameters.add(new Object[] { personFactory, personTemplateLtc }); |
| 88 | +parameters.add(new Object[] { rawFactory, rawTemplateLtc }); |
| 89 | + |
| 90 | +if (clusterAvailable()) { |
| 91 | + |
| 92 | +RedisClusterConfiguration configuration = new RedisClusterConfiguration().clusterNode("127.0.0.1", 7379); |
| 93 | + |
| 94 | +// add Jedis |
| 95 | +JedisConnectionFactory jedisClusterFactory = new JedisConnectionFactory(configuration); |
| 96 | +jedisClusterFactory.afterPropertiesSet(); |
| 97 | + |
| 98 | +RedisTemplate<String, String> jedisClusterStringTemplate = new StringRedisTemplate(jedisClusterFactory); |
| 99 | + |
| 100 | +// add Lettuce |
| 101 | +LettuceConnectionFactory lettuceClusterFactory = new LettuceConnectionFactory(configuration); |
| 102 | +lettuceClusterFactory.setClientResources(LettuceTestClientResources.getSharedClientResources()); |
| 103 | +lettuceClusterFactory.afterPropertiesSet(); |
| 104 | + |
| 105 | +RedisTemplate<String, String> lettuceClusterStringTemplate = new StringRedisTemplate(lettuceClusterFactory); |
| 106 | + |
| 107 | +parameters.add(new Object[] { stringFactory, jedisClusterStringTemplate }); |
| 108 | +parameters.add(new Object[] { stringFactory, lettuceClusterStringTemplate }); |
| 109 | +} |
| 110 | + |
| 111 | +return parameters; |
| 112 | +} |
| 113 | + |
| 114 | +private static boolean clusterAvailable() { |
| 115 | + |
| 116 | +try { |
| 117 | +new RedisClusterRule().apply(new Statement() { |
| 118 | +@Override |
| 119 | +public void evaluate() { |
| 120 | + |
| 121 | +} |
| 122 | +}, null).evaluate(); |
| 123 | +} catch (Throwable throwable) { |
| 124 | +return false; |
| 125 | +} |
| 126 | +return true; |
82 | 127 | } |
83 | 128 | } |
0 commit comments