Fix broken U tests
This commit is contained in:
@@ -1,10 +1,12 @@
|
|||||||
package redis.clients.jedis.tests;
|
package redis.clients.jedis.tests;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Iterator;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.junit.Assert;
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
import redis.clients.jedis.Protocol;
|
import redis.clients.jedis.Protocol;
|
||||||
@@ -41,4 +43,26 @@ public class JedisTest extends JedisCommandTestBase {
|
|||||||
Jedis jedis = new Jedis(shardInfo);
|
Jedis jedis = new Jedis(shardInfo);
|
||||||
jedis.get("foo");
|
jedis.get("foo");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("rawtypes")
|
||||||
|
public static void compareList(List expected, List result) {
|
||||||
|
final Iterator expectedit = expected.iterator();
|
||||||
|
final Iterator responseit = result.iterator();
|
||||||
|
while(expectedit.hasNext()) {
|
||||||
|
final Object exp = expectedit.next();
|
||||||
|
final Object resp = responseit.next();
|
||||||
|
if(exp instanceof byte[]) {
|
||||||
|
final byte[] bexp = (byte[]) exp;
|
||||||
|
final byte[] bresp = (byte[]) resp;
|
||||||
|
Assert.assertArrayEquals(bexp, bresp);
|
||||||
|
} else if (exp instanceof List) {
|
||||||
|
final List subexp = (List) exp;
|
||||||
|
final List subresp = (List) resp;
|
||||||
|
compareList(subexp, subresp);
|
||||||
|
} else {
|
||||||
|
assertEquals(exp, resp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,9 +7,11 @@ import java.io.InputStream;
|
|||||||
import java.io.PipedInputStream;
|
import java.io.PipedInputStream;
|
||||||
import java.io.PipedOutputStream;
|
import java.io.PipedOutputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import junit.framework.Assert;
|
import org.junit.Assert;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@@ -87,32 +89,52 @@ public class ProtocolTest extends Assert {
|
|||||||
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
"*4\r\n$3\r\nfoo\r\n$3\r\nbar\r\n$5\r\nHello\r\n$5\r\nWorld\r\n"
|
||||||
.getBytes());
|
.getBytes());
|
||||||
Protocol protocol = new Protocol();
|
Protocol protocol = new Protocol();
|
||||||
List<String> response = (List<String>) (List<?>) protocol
|
List<byte[]> response = (List<byte[]>) protocol.read(new RedisInputStream(is));
|
||||||
.read(new RedisInputStream(is));
|
List<byte[]> expected = new ArrayList<byte[]>();
|
||||||
List<String> expected = new ArrayList<String>();
|
expected.add("foo".getBytes(Protocol.UTF8));
|
||||||
expected.add("foo");
|
expected.add("bar".getBytes(Protocol.UTF8));
|
||||||
expected.add("bar");
|
expected.add("Hello".getBytes(Protocol.UTF8));
|
||||||
expected.add("Hello");
|
expected.add("World".getBytes(Protocol.UTF8));
|
||||||
expected.add("World");
|
|
||||||
|
|
||||||
assertEquals(expected, response);
|
assertEquals(expected.size(), response.size());
|
||||||
|
JedisTest.compareList(expected, response);
|
||||||
|
// final Iterator<byte[]> expectedit = expected.iterator();
|
||||||
|
// final Iterator<byte[]> responseit = response.iterator();
|
||||||
|
// while(expectedit.hasNext()) {
|
||||||
|
// final byte[] exp = expectedit.next();
|
||||||
|
// final byte[] resp = responseit.next();
|
||||||
|
// assertArrayEquals(exp, resp);
|
||||||
|
// }
|
||||||
|
|
||||||
is = new ByteArrayInputStream(
|
is = new ByteArrayInputStream(
|
||||||
"*4\r\n$3\r\nfoo\r\n+OK\r\n:1000\r\n*2\r\n$3\r\nfoo\r\n$3\r\nbar"
|
"*4\r\n$3\r\nfoo\r\n+OK\r\n:1000\r\n*2\r\n$3\r\nfoo\r\n$3\r\nbar"
|
||||||
.getBytes());
|
.getBytes());
|
||||||
protocol = new Protocol();
|
protocol = new Protocol();
|
||||||
List<Object> response2 = (List<Object>) protocol
|
List<Object> response2 = (List<Object>) protocol.read(new RedisInputStream(is));
|
||||||
.read(new RedisInputStream(is));
|
|
||||||
List<Object> expected2 = new ArrayList<Object>();
|
List<Object> expected2 = new ArrayList<Object>();
|
||||||
expected2.add("foo");
|
expected2.add("foo".getBytes(Protocol.UTF8));
|
||||||
expected2.add("OK");
|
expected2.add("OK");
|
||||||
expected2.add(1000);
|
expected2.add(1000);
|
||||||
List<Object> sub = new ArrayList<Object>();
|
List<Object> sub = new ArrayList<Object>();
|
||||||
sub.add("foo");
|
sub.add("foo".getBytes(Protocol.UTF8));
|
||||||
sub.add("bar");
|
sub.add("bar".getBytes(Protocol.UTF8));
|
||||||
expected2.add(sub);
|
expected2.add(sub);
|
||||||
|
|
||||||
assertEquals(expected2, response2);
|
assertEquals(expected2.size(), response2.size());
|
||||||
|
JedisTest.compareList(expected2, response2);
|
||||||
|
// final Iterator<Object> expectedit2 = expected2.iterator();
|
||||||
|
// final Iterator<Object> responseit2 = response2.iterator();
|
||||||
|
// while(expectedit2.hasNext()) {
|
||||||
|
// final Object exp = expectedit2.next();
|
||||||
|
// final Object resp = responseit2.next();
|
||||||
|
// if(exp instanceof byte[]) {
|
||||||
|
// final byte[] bexp = (byte[]) exp;
|
||||||
|
// final byte[] bresp = (byte[]) resp;
|
||||||
|
// assertArrayEquals(bexp, bresp);
|
||||||
|
// } else {
|
||||||
|
// assertEquals(exp, resp);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.junit.Test;
|
|||||||
|
|
||||||
import redis.clients.jedis.Jedis;
|
import redis.clients.jedis.Jedis;
|
||||||
import redis.clients.jedis.JedisShardInfo;
|
import redis.clients.jedis.JedisShardInfo;
|
||||||
|
import redis.clients.jedis.Protocol;
|
||||||
import redis.clients.jedis.ShardedJedis;
|
import redis.clients.jedis.ShardedJedis;
|
||||||
import redis.clients.jedis.ShardedJedisPipeline;
|
import redis.clients.jedis.ShardedJedisPipeline;
|
||||||
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
import redis.clients.jedis.tests.HostAndPortUtil.HostAndPort;
|
||||||
@@ -141,7 +142,12 @@ public class ShardedJedisTest extends Assert {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
assertEquals("a", results.get(0));
|
List<Object> expected = new ArrayList<Object>(2);
|
||||||
assertEquals("b", results.get(1));
|
expected.add("a".getBytes(Protocol.UTF8));
|
||||||
|
expected.add("b".getBytes(Protocol.UTF8));
|
||||||
|
|
||||||
|
JedisTest.compareList(expected, results);
|
||||||
|
// assertArrayEquals("a".getBytes(Protocol.UTF8), results.get(0));
|
||||||
|
// assertArrayEquals("b".getBytes(Protocol.UTF8), results.get(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user