|
1 | 1 | package redis.clients.jedis.tests.commands; |
2 | 2 |
|
3 | | -import static org.junit.Assert.assertArrayEquals; |
4 | | -import static org.junit.Assert.assertEquals; |
5 | | -import static org.junit.Assert.assertTrue; |
6 | | -import static redis.clients.jedis.Protocol.Command.*; |
7 | | - |
8 | | -import java.util.ArrayList; |
9 | | -import java.util.HashMap; |
10 | 3 | import java.util.HashSet; |
11 | | -import java.util.List; |
12 | 4 | import java.util.Set; |
13 | 5 |
|
14 | 6 | import org.junit.After; |
15 | 7 | import org.junit.AfterClass; |
16 | 8 | import org.junit.Before; |
17 | | -import org.junit.Test; |
18 | 9 |
|
19 | 10 | import redis.clients.jedis.HostAndPort; |
20 | 11 | import redis.clients.jedis.Jedis; |
21 | 12 | import redis.clients.jedis.JedisCluster; |
22 | 13 | import redis.clients.jedis.JedisPoolConfig; |
23 | 14 | import redis.clients.jedis.tests.HostAndPortUtil; |
24 | 15 | import redis.clients.jedis.util.JedisClusterCRC16; |
25 | | -import redis.clients.jedis.util.SafeEncoder; |
26 | 16 |
|
27 | | -public class ClusterBinaryJedisCommandsTest { |
| 17 | +public abstract class ClusterJedisCommandsTestBase { |
28 | 18 | private Jedis node1; |
29 | 19 | private static Jedis node2; |
30 | 20 | private static Jedis node3; |
@@ -103,102 +93,6 @@ public void tearDown() { |
103 | 93 | node3.clusterDelSlots(slotsToDelete); |
104 | 94 | } |
105 | 95 |
|
106 | | - @SuppressWarnings("unchecked") |
107 | | - @Test |
108 | | - public void testBinaryGetAndSet() { |
109 | | - byte[] byteKey = "foo".getBytes(); |
110 | | - byte[] byteValue = "2".getBytes(); |
111 | | - jedisCluster.set(byteKey, byteValue); |
112 | | - assertArrayEquals(byteValue, jedisCluster.get(byteKey)); |
113 | | - } |
114 | | - |
115 | | - @SuppressWarnings("unchecked") |
116 | | - @Test |
117 | | - public void testIncr() { |
118 | | - byte[] byteKey = "foo".getBytes(); |
119 | | - byte[] byteValue = "2".getBytes(); |
120 | | - jedisCluster.set(byteKey, byteValue); |
121 | | - jedisCluster.incr(byteKey); |
122 | | - assertArrayEquals("3".getBytes(), jedisCluster.get(byteKey)); |
123 | | - } |
124 | | - |
125 | | - @SuppressWarnings("unchecked") |
126 | | - @Test |
127 | | - public void testSadd() { |
128 | | - byte[] byteKey = "languages".getBytes(); |
129 | | - byte[] firstLanguage = "java".getBytes(); |
130 | | - byte[] secondLanguage = "python".getBytes(); |
131 | | - byte[][] listLanguages = { firstLanguage, secondLanguage }; |
132 | | - jedisCluster.sadd(byteKey, listLanguages); |
133 | | - Set<byte[]> setLanguages = jedisCluster.smembers(byteKey); |
134 | | - List<String> languages = new ArrayList<>(); |
135 | | - for (byte[] language : setLanguages) { |
136 | | - languages.add(new String(language)); |
137 | | - } |
138 | | - assertTrue(languages.contains("java")); |
139 | | - assertTrue(languages.contains("python")); |
140 | | - } |
141 | | - |
142 | | - @SuppressWarnings("unchecked") |
143 | | - @Test |
144 | | - public void testHmset() { |
145 | | - byte[] key = "jedis".getBytes(); |
146 | | - byte[] field = "language".getBytes(); |
147 | | - byte[] value = "java".getBytes(); |
148 | | - HashMap<byte[], byte[]> map = new HashMap(); |
149 | | - map.put(field, value); |
150 | | - jedisCluster.hmset(key, map); |
151 | | - List<byte[]> listResults = jedisCluster.hmget(key, field); |
152 | | - for (byte[] result : listResults) { |
153 | | - assertArrayEquals(value, result); |
154 | | - } |
155 | | - } |
156 | | - |
157 | | - @SuppressWarnings("unchecked") |
158 | | - @Test |
159 | | - public void testRpush() { |
160 | | - byte[] value1 = "value1".getBytes(); |
161 | | - byte[] value2 = "value2".getBytes(); |
162 | | - byte[] key = "key1".getBytes(); |
163 | | - jedisCluster.del(key); |
164 | | - jedisCluster.rpush(key, value1); |
165 | | - jedisCluster.rpush(key, value2); |
166 | | - assertEquals(2, (long) jedisCluster.llen(key)); |
167 | | - } |
168 | | - |
169 | | - @Test |
170 | | - public void testKeys() { |
171 | | - assertEquals(0, jedisCluster.keys("{f}o*".getBytes()).size()); |
172 | | - jedisCluster.set("{f}oo1".getBytes(), "bar".getBytes()); |
173 | | - jedisCluster.set("{f}oo2".getBytes(), "bar".getBytes()); |
174 | | - jedisCluster.set("{f}oo3".getBytes(), "bar".getBytes()); |
175 | | - assertEquals(3, jedisCluster.keys("{f}o*".getBytes()).size()); |
176 | | - } |
177 | | - |
178 | | - @Test |
179 | | - public void testBinaryGeneralCommand(){ |
180 | | - byte[] key = "x".getBytes(); |
181 | | - byte[] value = "1".getBytes(); |
182 | | - jedisCluster.sendCommand("z".getBytes(), SET, key, value); |
183 | | - jedisCluster.sendCommand("y".getBytes(), INCR, key); |
184 | | - Object returnObj = jedisCluster.sendCommand("w".getBytes(), GET, key); |
185 | | - assertEquals("2", SafeEncoder.encode((byte[])returnObj)); |
186 | | - } |
187 | | - |
188 | | - @Test |
189 | | - public void testGeneralCommand(){ |
190 | | - jedisCluster.sendCommand("z", SET, "x", "1"); |
191 | | - jedisCluster.sendCommand("y", INCR, "x"); |
192 | | - Object returnObj = jedisCluster.sendCommand("w", GET, "x"); |
193 | | - assertEquals("2", SafeEncoder.encode((byte[])returnObj)); |
194 | | - } |
195 | | - |
196 | | - |
197 | | - @Test(expected = IllegalArgumentException.class) |
198 | | - public void failKeys() { |
199 | | - jedisCluster.keys("*".getBytes()); |
200 | | - } |
201 | | - |
202 | 96 | private static String getNodeId(String infoOutput) { |
203 | 97 | for (String infoLine : infoOutput.split("\n")) { |
204 | 98 | if (infoLine.contains("myself")) { |
|
0 commit comments