DATAREDIS-749 - Polishing.
Upgrade to Jedis 3.0. Remove reflective sendCommand calls in favor of public Jedis sendCommand API. Invocations with null arguments by introducing overloads with argument defaulting. Fix exception translation because of a changed exception hierarchy. Fix tests and adapt tests to new transactional results that return null values instead if empty collections for nested array responses. Reformat code. Add author tags. Add note to reference docs. Original pull request: #374.
This commit is contained in:
@@ -64,11 +64,6 @@ import org.springframework.data.redis.RedisVersionUtils;
|
||||
import org.springframework.data.redis.TestCondition;
|
||||
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
|
||||
import org.springframework.data.redis.connection.RedisListCommands.Position;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
|
||||
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
|
||||
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
|
||||
@@ -77,7 +72,11 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
|
||||
import org.springframework.data.redis.connection.SortParameters.Order;
|
||||
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
|
||||
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
|
||||
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
|
||||
import org.springframework.data.redis.connection.stream.Consumer;
|
||||
import org.springframework.data.redis.connection.stream.MapRecord;
|
||||
import org.springframework.data.redis.connection.stream.ReadOffset;
|
||||
import org.springframework.data.redis.connection.stream.RecordId;
|
||||
import org.springframework.data.redis.connection.stream.StreamOffset;
|
||||
import org.springframework.data.redis.core.Cursor;
|
||||
import org.springframework.data.redis.core.ScanOptions;
|
||||
import org.springframework.data.redis.core.StringRedisTemplate;
|
||||
@@ -844,14 +843,9 @@ public abstract class AbstractConnectionIntegrationTests {
|
||||
actual.add(connection.exec());
|
||||
actual.add(connection.get("testitnow"));
|
||||
|
||||
if (connectionFactory instanceof JedisConnectionFactory) {
|
||||
verifyResults(Arrays.asList(new Object[] { true, Collections.emptyList(), "something" }));
|
||||
} else {
|
||||
verifyResults(Arrays.asList(new Object[] { true, null, "something" }));
|
||||
}
|
||||
verifyResults(Arrays.asList(new Object[] { true, null, "something" }));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testUnwatch() throws Exception {
|
||||
|
||||
|
||||
@@ -201,37 +201,29 @@ public class JedisConvertersUnitTests {
|
||||
JedisConverters.boundaryToBytesForZRange(Range.range().gt(new Date()).getMin(), null);
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandExPxOptionShouldReturnEXforSeconds() {
|
||||
assertThat(JedisConverters.toSetCommandExPxArgument(Expiration.seconds(100)),
|
||||
equalTo(JedisConverters.toBytes("EX")));
|
||||
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.seconds(100))), equalTo("ex 100"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandExPxOptionShouldReturnEXforMilliseconds() {
|
||||
|
||||
assertThat(JedisConverters.toSetCommandExPxArgument(Expiration.milliseconds(100)),
|
||||
equalTo(SetParams.setParams().px(100)));
|
||||
assertThat(toString(JedisConverters.toSetCommandExPxArgument(Expiration.milliseconds(100))), equalTo("px 100"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316
|
||||
public void toSetCommandExPxOptionShouldReturnEmptyArrayForNull() {
|
||||
assertThat(JedisConverters.toSetCommandExPxArgument(null), equalTo(SetParams.setParams()));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandNxXxOptionShouldReturnNXforAbsent() {
|
||||
assertThat(JedisConverters.toSetCommandNxXxArgument(SetOption.ifAbsent()), equalTo(SetParams.setParams().nx()));
|
||||
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifAbsent())), equalTo("nx"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandNxXxOptionShouldReturnXXforAbsent() {
|
||||
assertThat(JedisConverters.toSetCommandNxXxArgument(SetOption.ifPresent()), equalTo(SetParams.setParams().xx()));
|
||||
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.ifPresent())), equalTo("xx"));
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-316
|
||||
@Test // DATAREDIS-316, DATAREDIS-749
|
||||
public void toSetCommandNxXxOptionShouldReturnEmptyArrayforUpsert() {
|
||||
assertThat(JedisConverters.toSetCommandNxXxArgument(SetOption.upsert()), equalTo(SetParams.setParams()));
|
||||
assertThat(toString(JedisConverters.toSetCommandNxXxArgument(SetOption.upsert())), equalTo(""));
|
||||
}
|
||||
|
||||
private void verifyRedisServerInfo(RedisServer server, Map<String, String> values) {
|
||||
@@ -241,6 +233,22 @@ public class JedisConvertersUnitTests {
|
||||
}
|
||||
}
|
||||
|
||||
private static String toString(SetParams setParams) {
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
for (byte[] parameter : setParams.getByteParams()) {
|
||||
|
||||
if (builder.length() != 0) {
|
||||
builder.append(' ');
|
||||
}
|
||||
|
||||
builder.append(new String(parameter));
|
||||
}
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
private Map<String, String> getRedisServerInfoMap(String name, int port) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("name", name);
|
||||
|
||||
@@ -19,15 +19,14 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.redis.SettingsUtils;
|
||||
import org.springframework.data.redis.connection.AbstractTransactionalTestBase;
|
||||
import org.springframework.data.redis.connection.jedis.TransactionalJedisItegrationTests.JedisContextConfiguration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
|
||||
/**
|
||||
* @author Christoph Strobl
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
@ContextConfiguration(classes = { JedisContextConfiguration.class })
|
||||
public class TransactionalJedisItegrationTests extends AbstractTransactionalTestBase {
|
||||
@ContextConfiguration
|
||||
public class TransactionalJedisIntegrationTests extends AbstractTransactionalTestBase {
|
||||
|
||||
@Configuration
|
||||
public static class JedisContextConfiguration extends RedisContextConfiguration {
|
||||
Reference in New Issue
Block a user