DATAREDIS-285 - LettuceConnection.execute should fully read response.
'LettuceConnection' used 'ByteArrayOutput' as default for execute which did not fully read all values that might be included in the response. To overcome this issue 'TypeHints' have been added which map a given 'CommandType' to the most recent 'CommandOutput'. As not all commands could be mapped that way due to the result depending on input parameters in some cases, it might be required to manually provide the type hint when calling execute. Additional tests have been added to assert 'execute' works properly for 'jedis', 'jredis' and 'srp'. Original Pull Request: #49
This commit is contained in:
committed by
Thomas Darimont
parent
9cf484d25a
commit
a3ac8d0899
@@ -19,13 +19,17 @@ package org.springframework.data.redis.connection.jedis;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.BlockingDeque;
|
||||
import java.util.concurrent.LinkedBlockingDeque;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.hamcrest.core.AllOf;
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.matchers.IsCollectionContaining;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
@@ -313,4 +317,20 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
|
||||
factory2.getConnection().dbSize();
|
||||
factory2.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-285
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteShouldConvertArrayReplyCorrectly() {
|
||||
connection.set("spring", "awesome");
|
||||
connection.set("data", "cool");
|
||||
connection.set("redis", "supercalifragilisticexpialidocious");
|
||||
|
||||
assertThat(
|
||||
connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()),
|
||||
AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(),
|
||||
"cool".getBytes(), "supercalifragilisticexpialidocious".getBytes())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,17 @@ import static org.junit.Assert.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.commons.pool.impl.GenericObjectPool.Config;
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.jredis.JRedis;
|
||||
import org.jredis.protocol.BulkResponse;
|
||||
import org.jredis.ri.alphazero.protocol.SyncProtocol.SyncMultiBulkResponse;
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.matchers.IsCollectionContaining;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.RedisConnectionFailureException;
|
||||
@@ -778,4 +782,23 @@ public class JRedisConnectionIntegrationTests extends AbstractConnectionIntegrat
|
||||
super.testGetTimeShouldRequestServerTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-285
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteShouldConvertArrayReplyCorrectly() {
|
||||
connection.set("spring", "awesome");
|
||||
connection.set("data", "cool");
|
||||
connection.set("redis", "supercalifragilisticexpialidocious");
|
||||
|
||||
Object result = connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes());
|
||||
|
||||
assertThat(result, IsInstanceOf.instanceOf(SyncMultiBulkResponse.class));
|
||||
|
||||
List<byte[]> data = ((SyncMultiBulkResponse) result).getMultiBulkData();
|
||||
assertThat(
|
||||
data,
|
||||
IsCollectionContaining.hasItems("awesome".getBytes(), "cool".getBytes(),
|
||||
"supercalifragilisticexpialidocious".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,13 @@ import static org.junit.Assume.*;
|
||||
import static org.springframework.data.redis.SpinBarrier.*;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.hamcrest.core.AllOf;
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.junit.Test;
|
||||
import org.junit.internal.matchers.IsCollectionContaining;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.data.redis.RedisSystemException;
|
||||
@@ -276,4 +280,20 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
|
||||
factory2.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-285
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testExecuteShouldConvertArrayReplyCorrectly() {
|
||||
connection.set("spring", "awesome");
|
||||
connection.set("data", "cool");
|
||||
connection.set("redis", "supercalifragilisticexpialidocious");
|
||||
|
||||
assertThat(
|
||||
connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes()),
|
||||
AllOf.allOf(IsInstanceOf.instanceOf(List.class), IsCollectionContaining.hasItems("awesome".getBytes(),
|
||||
"cool".getBytes(), "supercalifragilisticexpialidocious".getBytes())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,10 @@ package org.springframework.data.redis.connection.srp;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.hamcrest.core.Is;
|
||||
import org.hamcrest.core.IsInstanceOf;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
|
||||
@@ -27,6 +30,8 @@ import org.springframework.test.annotation.IfProfileValue;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import redis.reply.Reply;
|
||||
|
||||
/**
|
||||
* Integration test of {@link SrpConnection}
|
||||
*
|
||||
@@ -75,4 +80,23 @@ public class SrpConnectionIntegrationTests extends AbstractConnectionIntegration
|
||||
ReturnType.MULTI, 0));
|
||||
verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "OK", "OK" }) }));
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAREDIS-285
|
||||
*/
|
||||
@Test
|
||||
public void testExecuteShouldConvertArrayReplyCorrectly() {
|
||||
connection.set("spring", "awesome");
|
||||
connection.set("data", "cool");
|
||||
connection.set("redis", "supercalifragilisticexpialidocious");
|
||||
|
||||
Object result = connection.execute("MGET", "spring".getBytes(), "data".getBytes(), "redis".getBytes());
|
||||
Assert.assertThat(result, IsInstanceOf.instanceOf(Reply[].class));
|
||||
|
||||
Reply<?>[] replies = (Reply[]) result;
|
||||
|
||||
Assert.assertThat(replies[0].data(), Is.<Object> is("awesome".getBytes()));
|
||||
Assert.assertThat(replies[1].data(), Is.<Object> is("cool".getBytes()));
|
||||
Assert.assertThat(replies[2].data(), Is.<Object> is("supercalifragilisticexpialidocious".getBytes()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user