Fix Lettuce eval suppressing Exceptions in List return
DATAREDIS-232
This commit is contained in:
@@ -159,6 +159,27 @@ public class LettuceConnection implements RedisConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private class LettuceEvalResultsConverter<T> implements Converter<Object,T> {
|
||||
private ReturnType returnType;
|
||||
|
||||
public LettuceEvalResultsConverter(ReturnType returnType) {
|
||||
this.returnType = returnType;
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
public T convert(Object source) {
|
||||
if(returnType == ReturnType.MULTI) {
|
||||
List resultList = (List) source;
|
||||
for(Object obj: resultList) {
|
||||
if(obj instanceof Exception) {
|
||||
throw convertLettuceAccessException((Exception)obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
return (T) source;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Instantiates a new lettuce connection.
|
||||
*
|
||||
@@ -2738,14 +2759,17 @@ public class LettuceConnection implements RedisConnection {
|
||||
byte[][] args = extractScriptArgs(numKeys, keysAndArgs);
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline(new LettuceResult(getAsyncConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args)));
|
||||
pipeline(new LettuceResult(getAsyncConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args),
|
||||
new LettuceEvalResultsConverter<T>(returnType)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new LettuceTxResult(getConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args)));
|
||||
transaction(new LettuceTxResult(getConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args),
|
||||
new LettuceEvalResultsConverter<T>(returnType)));
|
||||
return null;
|
||||
}
|
||||
return getConnection().eval(script, LettuceConverters.toScriptOutputType(returnType), keys, args);
|
||||
return new LettuceEvalResultsConverter<T>(returnType).convert(getConnection().eval(script,
|
||||
LettuceConverters.toScriptOutputType(returnType), keys, args));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
@@ -2758,15 +2782,16 @@ public class LettuceConnection implements RedisConnection {
|
||||
|
||||
if (isPipelined()) {
|
||||
pipeline(new LettuceResult(getAsyncConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType),
|
||||
keys, args)));
|
||||
keys, args), new LettuceEvalResultsConverter<T>(returnType)));
|
||||
return null;
|
||||
}
|
||||
if (isQueueing()) {
|
||||
transaction(new LettuceTxResult(getConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType),
|
||||
keys, args)));
|
||||
keys, args), new LettuceEvalResultsConverter<T>(returnType)));
|
||||
return null;
|
||||
}
|
||||
return getConnection().evalsha(scriptSha1, LettuceConverters.toScriptOutputType(returnType), keys, args);
|
||||
return new LettuceEvalResultsConverter<T>(returnType).convert(getConnection().evalsha(scriptSha1,
|
||||
LettuceConverters.toScriptOutputType(returnType), keys, args));
|
||||
} catch (Exception ex) {
|
||||
throw convertLettuceAccessException(ex);
|
||||
}
|
||||
|
||||
@@ -188,6 +188,13 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
new String(scriptResults.get(1)) }));
|
||||
}
|
||||
|
||||
@Test(expected=RedisSystemException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1");
|
||||
getResults();
|
||||
}
|
||||
|
||||
@Test(expected = RedisSystemException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaNotFound() {
|
||||
@@ -255,6 +262,14 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 2l }) }));
|
||||
}
|
||||
|
||||
@Test(expected=RedisSystemException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
// Syntax error
|
||||
connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar");
|
||||
getResults();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
|
||||
@@ -110,6 +110,18 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends
|
||||
super.testRestoreExistingKey();
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOpenPipelineTwice() {
|
||||
connection.openPipeline();
|
||||
|
||||
@@ -237,12 +237,24 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
|
||||
connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0);
|
||||
}
|
||||
|
||||
@Test(expected=InvalidDataAccessApiUsageException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected=InvalidDataAccessApiUsageException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaNotFound() {
|
||||
connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2");
|
||||
}
|
||||
|
||||
@Test(expected=InvalidDataAccessApiUsageException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
@Test(expected=InvalidDataAccessApiUsageException.class)
|
||||
public void testExecWithoutMulti() {
|
||||
super.testExecWithoutMulti();
|
||||
|
||||
@@ -319,6 +319,18 @@ public class JedisConnectionPipelineIntegrationTests extends
|
||||
super.testEvalShaNotFound();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalReturnString() {
|
||||
|
||||
@@ -235,6 +235,18 @@ public class JedisConnectionTransactionIntegrationTests extends
|
||||
super.testEvalShaNotFound();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalReturnString() {
|
||||
|
||||
@@ -453,6 +453,18 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
super.testEvalShaNotFound();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected=UnsupportedOperationException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalReturnString() {
|
||||
|
||||
@@ -42,6 +42,18 @@ public class LettuceConnectionPipelineTxIntegrationTests extends
|
||||
super.testRestoreExistingKey();
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
protected void initConnection() {
|
||||
connection.openPipeline();
|
||||
connection.multi();
|
||||
|
||||
@@ -89,6 +89,18 @@ public class SrpConnectionPipelineTxIntegrationTests extends SrpConnectionTransa
|
||||
super.testRestoreBadData();
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalArrayScriptError() {
|
||||
super.testEvalArrayScriptError();
|
||||
}
|
||||
|
||||
@Test(expected=RedisPipelineException.class)
|
||||
@IfProfileValue(name = "redisVersion", value = "2.6")
|
||||
public void testEvalShaArrayError() {
|
||||
super.testEvalShaArrayError();
|
||||
}
|
||||
|
||||
protected void initConnection() {
|
||||
connection.openPipeline();
|
||||
connection.multi();
|
||||
|
||||
Reference in New Issue
Block a user