add more tests for pipeline execution

This commit is contained in:
Costin Leau
2012-06-25 21:48:27 +03:00
parent 8a6aa7e494
commit d00d7143bd
5 changed files with 46 additions and 4 deletions

View File

@@ -144,7 +144,7 @@ public class RjcConnection implements RedisConnection {
public List<Object> closePipeline() {
if (pipeline != null) {
try {
List execute = client.getAll();
return RjcUtils.maybeConvert(client.getAll());
} catch (Exception ex) {
throw new RedisPipelineException(convertRjcAccessException(ex));
}

View File

@@ -25,20 +25,20 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.idevlab.rjc.Client.LIST_POSITION;
import org.idevlab.rjc.ElementScore;
import org.idevlab.rjc.RedisException;
import org.idevlab.rjc.SortingParams;
import org.idevlab.rjc.ZParams;
import org.idevlab.rjc.Client.LIST_POSITION;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.SortParameters;
import org.springframework.data.redis.connection.SortParameters.Order;
import org.springframework.data.redis.connection.SortParameters.Range;
import org.springframework.data.redis.connection.util.DecodeUtils;
@@ -236,4 +236,14 @@ public abstract class RjcUtils {
System.arraycopy(two, 0, result, one.length, two.length);
return result;
}
static List<Object> maybeConvert(List<Object> result) {
for (int i = 0; i < result.size(); i++) {
Object obj = result.get(i);
if (obj instanceof String) {
result.set(i, encode((String) obj));
}
}
return result;
}
}

View File

@@ -369,6 +369,8 @@ public abstract class AbstractConnectionIntegrationTests {
connection.execute("GET", key2);
List<Object> result = connection.closePipeline();
assertEquals(4, result.size());
System.out.println(result.get(2));
System.out.println(result.get(3));
assertArrayEquals(value1.getBytes(), (byte[]) result.get(2));
assertArrayEquals(value2.getBytes(), (byte[]) result.get(3));
}

View File

@@ -95,4 +95,13 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
public void exceptionExecuteNativeWithPipeline() throws Exception {
}
@Test(expected = UnsupportedOperationException.class)
public void testExceptionExecuteNativeWithPipeline() throws Exception {
super.testExceptionExecuteNativeWithPipeline();
}
@Test(expected = UnsupportedOperationException.class)
public void testExecuteNativeWithPipeline() throws Exception {
super.testExecuteNativeWithPipeline();
}
}

View File

@@ -15,12 +15,16 @@
*/
package org.springframework.data.redis.connection.rjc;
import static org.junit.Assert.assertEquals;
import java.util.List;
import java.util.UUID;
import org.idevlab.rjc.Session;
import org.junit.Test;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.rjc.RjcConnectionFactory;
/**
* @author Costin Leau
@@ -52,4 +56,21 @@ public class RjcConnectionIntegrationTests extends AbstractConnectionIntegration
jr.set("foobar", "barfoo");
System.out.println(jr.get("foobar"));
}
// override test to address the encoding issue (the bytes[] in raw format differ)
@Test
public void testExecuteNativeWithPipeline() throws Exception {
String key1 = getClass() + "#ExecuteNativeWithPipeline#1";
String value1 = UUID.randomUUID().toString();
String key2 = getClass() + "#ExecuteNativeWithPipeline#2";
String value2 = UUID.randomUUID().toString();
connection.openPipeline();
connection.execute("SET", key1, value1);
connection.execute("SET", key2, value2);
connection.execute("GET", key1);
connection.execute("GET", key2);
List<Object> result = connection.closePipeline();
assertEquals(4, result.size());
}
}