DATAREDIS-1233 - Introduce and use Junit5 based ParameterizedRedisTest.

This commit is contained in:
Mark Paluch
2020-10-20 10:59:55 +02:00
committed by Christoph Strobl
parent 2511aa18c0
commit fff1d3e691
190 changed files with 7605 additions and 8107 deletions

View File

@@ -27,7 +27,7 @@ import org.springframework.data.redis.core.RedisOperations;
/**
* @author Costin Leau
*/
class PropertyEditorsTest {
class PropertyEditorsIntegrationTests {
private GenericXmlApplicationContext ctx;

View File

@@ -1,156 +0,0 @@
/*
* Copyright 2011-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis;
import java.io.IOException;
import org.springframework.data.redis.connection.jedis.JedisConverters;
import org.springframework.test.annotation.ProfileValueSource;
import redis.clients.jedis.Jedis;
/**
* Implementation of {@link ProfileValueSource} that handles profile value name "redisVersion" by checking the current
* version of Redis. 2.4.x will be returned as "2.4" and 2.6.x will be returned as "2.6". Any other version found will
* cause an {@link UnsupportedOperationException} System property values will be returned for any key other than
* "redisVersion"
*
* @author Jennifer Hickey
* @author Christoph Strobl
* @author Thomas Darimont
* @author Mark Paluch
*/
public class RedisTestProfileValueSource implements ProfileValueSource {
private static final String REDIS_24 = "2.4";
private static final String REDIS_26 = "2.6";
private static final String REDIS_28 = "2.8";
private static final String REDIS_30 = "3.0";
private static final String REDIS_32 = "3.2";
private static final String REDIS_50 = "5.0";
private static final String REDIS_60 = "6.0";
private static final String REDIS_606 = "6.0.6";
private static final String REDIS_VERSION_KEY = "redisVersion";
private static RedisTestProfileValueSource INSTANCE;
private static final Version redisVersion;
static {
redisVersion = tryDetectRedisVersionOrReturn(new Version(9, 9, 9));
}
private static Version tryDetectRedisVersionOrReturn(Version fallbackVersion) {
Version version = fallbackVersion;
Jedis jedis = null;
try {
jedis = new Jedis(SettingsUtils.getHost(), SettingsUtils.getPort(), 100);
String info = jedis.info();
String versionString = (String) JedisConverters.stringToProps().convert(info).get("redis_version");
version = RedisVersionUtils.parseVersion(versionString);
} finally {
if (jedis != null) {
try {
// force socket to be closed
jedis.getClient().quit();
jedis.getClient().getSocket().close();
try {
// need to wait a bit
Thread.sleep(5);
} catch (InterruptedException e) {
// just ignore it
Thread.interrupted();
}
} catch (IOException e1) {
// ignore as well
}
jedis.close();
}
}
return version;
}
public RedisTestProfileValueSource() {
INSTANCE = this;
}
public String get(String key) {
if (!REDIS_VERSION_KEY.equals(key)) {
return System.getProperty(key);
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_606)) >= 0) {
return REDIS_606;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_60)) >= 0) {
return REDIS_60;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_50)) >= 0) {
return REDIS_50;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_32)) >= 0) {
return REDIS_32;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_30)) >= 0) {
return REDIS_30;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_28)) >= 0) {
return REDIS_28;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_26)) >= 0) {
return REDIS_26;
}
if (redisVersion.compareTo(RedisVersionUtils.parseVersion(REDIS_24)) >= 0) {
return REDIS_24;
}
throw new UnsupportedOperationException("Only Redis 2.4 and higher are supported");
}
public static boolean matches(String key, String value) {
if (INSTANCE == null) {
INSTANCE = new RedisTestProfileValueSource();
}
return INSTANCE.get(key) != null ? INSTANCE.get(key).equals(value) : value == null;
}
public static boolean atLeast(String key, String value) {
if (INSTANCE == null) {
INSTANCE = new RedisTestProfileValueSource();
}
String current = INSTANCE.get(key);
if(current == null) {
return value == null;
}
return org.springframework.data.util.Version.parse(current).isGreaterThanOrEqualTo(org.springframework.data.util.Version.parse(value));
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2011-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis;
import org.springframework.data.redis.connection.RedisConnection;
/**
* Utilities for examining the Redis version
*
* @author Jennifer Hickey
* @author Christoph Strobl
*/
public abstract class RedisVersionUtils {
public static Version getRedisVersion(RedisConnection connection) {
return parseVersion((String) connection.info().get("redis_version"));
}
public static boolean atLeast(String version, RedisConnection connection) {
return getRedisVersion(connection).compareTo(parseVersion(version)) >= 0;
}
public static boolean atMost(String version, RedisConnection connection) {
return getRedisVersion(connection).compareTo(parseVersion(version)) <= 0;
}
public static Version parseVersion(String version) {
Version resolvedVersion = VersionParser.parseVersion(version);
if (Version.UNKNOWN.equals(resolvedVersion)) {
throw new IllegalArgumentException("Specified version cannot be parsed");
}
return resolvedVersion;
}
}

View File

@@ -17,40 +17,40 @@ package org.springframework.data.redis;
import static org.assertj.core.api.Assertions.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Christoph Strobl
*/
public class VersionParserUnitTests {
class VersionParserUnitTests {
@Test
public void shouldParseNullToUnknown() {
void shouldParseNullToUnknown() {
assertThat(VersionParser.parseVersion(null)).isEqualTo(Version.UNKNOWN);
}
@Test
public void shouldParseEmptyVersionStringToUnknown() {
void shouldParseEmptyVersionStringToUnknown() {
assertThat(VersionParser.parseVersion("")).isEqualTo(Version.UNKNOWN);
}
@Test
public void shouldParseInvalidVersionStringToUnknown() {
void shouldParseInvalidVersionStringToUnknown() {
assertThat(VersionParser.parseVersion("ThisIsNoValidVersion")).isEqualTo(Version.UNKNOWN);
}
@Test
public void shouldParseMajorMinorWithoutPatchCorrectly() {
void shouldParseMajorMinorWithoutPatchCorrectly() {
assertThat(VersionParser.parseVersion("1.2")).isEqualTo(new Version(1, 2, 0));
}
@Test
public void shouldParseMajorMinorPatchCorrectly() {
void shouldParseMajorMinorPatchCorrectly() {
assertThat(VersionParser.parseVersion("1.2.3")).isEqualTo(new Version(1, 2, 3));
}
@Test
public void shouldParseMajorWithoutMinorPatchCorrectly() {
void shouldParseMajorWithoutMinorPatchCorrectly() {
assertThat(VersionParser.parseVersion("1.2.3.a")).isEqualTo(new Version(1, 2, 3));
}
}

View File

@@ -15,17 +15,12 @@
*/
package org.springframework.data.redis.cache;
import lombok.RequiredArgsConstructor;
import lombok.experimental.Delegate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.runners.model.Statement;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
@@ -37,14 +32,16 @@ import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSeriali
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.OxmSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.SerializationException;
import org.springframework.data.redis.test.XstreamOxmSerializerSingleton;
import org.springframework.data.redis.test.condition.RedisDetector;
import org.springframework.data.redis.test.extension.RedisCluster;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.util.StringUtils;
import org.springframework.lang.Nullable;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
class CacheTestParams {
@@ -59,27 +56,26 @@ class CacheTestParams {
// Jedis Standalone
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
.getConnectionFactory(RedisStanalone.class);
factoryList.add(new FixDamnedJunitParameterizedNameForConnectionFactory(jedisConnectionFactory, ""));
factoryList.add(jedisConnectionFactory);
// Lettuce Standalone
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisStanalone.class);
factoryList.add(new FixDamnedJunitParameterizedNameForConnectionFactory(lettuceConnectionFactory, ""));
factoryList.add(lettuceConnectionFactory);
if (clusterAvailable()) {
// Jedis Cluster
JedisConnectionFactory jedisClusterConnectionFactory = JedisConnectionFactoryExtension
.getConnectionFactory(RedisCluster.class);
factoryList
.add(new FixDamnedJunitParameterizedNameForConnectionFactory(jedisClusterConnectionFactory, "cluster"));
.add(jedisClusterConnectionFactory);
// Lettuce Cluster
LettuceConnectionFactory lettuceClusterConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisCluster.class);
factoryList
.add(new FixDamnedJunitParameterizedNameForConnectionFactory(lettuceClusterConnectionFactory, "cluster"));
.add(lettuceClusterConnectionFactory);
}
return factoryList;
@@ -91,11 +87,7 @@ class CacheTestParams {
static Collection<Object[]> connectionFactoriesAndSerializers() {
// XStream serializer
XStreamMarshaller xstream = new XStreamMarshaller();
xstream.afterPropertiesSet();
OxmSerializer oxmSerializer = new OxmSerializer(xstream, xstream);
OxmSerializer oxmSerializer = XstreamOxmSerializerSingleton.getInstance();
GenericJackson2JsonRedisSerializer jackson2Serializer = new GenericJackson2JsonRedisSerializer();
JdkSerializationRedisSerializer jdkSerializer = new JdkSerializationRedisSerializer();
@@ -106,22 +98,55 @@ class CacheTestParams {
.collect(Collectors.toList());
}
@RequiredArgsConstructor
static class FixDamnedJunitParameterizedNameForConnectionFactory/* ¯\_(ツ)_/¯ */ implements RedisConnectionFactory {
final @Delegate RedisConnectionFactory connectionFactory;
final String addon;
@Override // Why Junit? Why?
public String toString() {
return connectionFactory.getClass().getSimpleName() + (StringUtils.hasText(addon) ? " - [" + addon + "]" : "");
}
}
@RequiredArgsConstructor
static class FixDamnedJunitParameterizedNameForRedisSerializer/* ¯\_(ツ)_/¯ */ implements RedisSerializer {
final @Delegate RedisSerializer serializer;
final RedisSerializer serializer;
FixDamnedJunitParameterizedNameForRedisSerializer(RedisSerializer serializer) {
this.serializer = serializer;
}
@Override
@Nullable
public byte[] serialize(@Nullable Object o) throws SerializationException {
return serializer.serialize(o);
}
@Override
@Nullable
public Object deserialize(@Nullable byte[] bytes) throws SerializationException {
return serializer.deserialize(bytes);
}
public static RedisSerializer<Object> java() {
return RedisSerializer.java();
}
public static RedisSerializer<Object> java(@Nullable ClassLoader classLoader) {
return RedisSerializer.java(classLoader);
}
public static RedisSerializer<Object> json() {
return RedisSerializer.json();
}
public static RedisSerializer<String> string() {
return RedisSerializer.string();
}
public static RedisSerializer<byte[]> byteArray() {
return RedisSerializer.byteArray();
}
@Override
public boolean canSerialize(Class type) {
return serializer.canSerialize(type);
}
@Override
public Class<?> getTargetType() {
return serializer.getTargetType();
}
@Override // Why Junit? Why?
public String toString() {
@@ -130,17 +155,6 @@ class CacheTestParams {
}
private static boolean clusterAvailable() {
try {
new RedisClusterRule().apply(new Statement() {
@Override
public void evaluate() throws Throwable {
}
}, null).evaluate();
} catch (Throwable throwable) {
return false;
}
return true;
return RedisDetector.isClusterAvailable();
}
}

View File

@@ -27,11 +27,7 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.function.Consumer;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
@@ -40,6 +36,8 @@ import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultRedisCacheWriter}.
@@ -47,30 +45,29 @@ import org.springframework.data.redis.test.extension.RedisStanalone;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
public class DefaultRedisCacheWriterTests {
static final String CACHE_NAME = "default-redis-cache-writer-tests";
private static final String CACHE_NAME = "default-redis-cache-writer-tests";
String key = "key-1";
String cacheKey = CACHE_NAME + "::" + key;
private String key = "key-1";
private String cacheKey = CACHE_NAME + "::" + key;
byte[] binaryCacheKey = cacheKey.getBytes(StandardCharsets.UTF_8);
byte[] binaryCacheValue = "value".getBytes(StandardCharsets.UTF_8);
private byte[] binaryCacheKey = cacheKey.getBytes(StandardCharsets.UTF_8);
private byte[] binaryCacheValue = "value".getBytes(StandardCharsets.UTF_8);
RedisConnectionFactory connectionFactory;
private RedisConnectionFactory connectionFactory;
public DefaultRedisCacheWriterTests(RedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Parameters(name = "{index}: {0}")
public static Collection<Object[]> testParams() {
return CacheTestParams.justConnectionFactories();
}
@Before
public void setUp() {
@BeforeEach
void setUp() {
JedisConnectionFactory cf = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
@@ -79,8 +76,8 @@ public class DefaultRedisCacheWriterTests {
doWithConnection(RedisConnection::flushAll);
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void putShouldAddEternalEntry() {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void putShouldAddEternalEntry() {
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
.withStatisticsCollector(CacheStatisticsCollector.create());
@@ -95,8 +92,8 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getLockWaitDuration(TimeUnit.NANOSECONDS)).isZero();
}
@Test // DATAREDIS-481
public void putShouldAddExpiringEntry() {
@ParameterizedRedisTest // DATAREDIS-481
void putShouldAddExpiringEntry() {
nonLockingRedisCacheWriter(connectionFactory).put(CACHE_NAME, binaryCacheKey, binaryCacheValue,
Duration.ofSeconds(1));
@@ -107,8 +104,8 @@ public class DefaultRedisCacheWriterTests {
});
}
@Test // DATAREDIS-481
public void putShouldOverwriteExistingEternalEntry() {
@ParameterizedRedisTest // DATAREDIS-481
void putShouldOverwriteExistingEternalEntry() {
doWithConnection(connection -> connection.set(binaryCacheKey, "foo".getBytes()));
@@ -120,8 +117,8 @@ public class DefaultRedisCacheWriterTests {
});
}
@Test // DATAREDIS-481
public void putShouldOverwriteExistingExpiringEntryAndResetTtl() {
@ParameterizedRedisTest // DATAREDIS-481
void putShouldOverwriteExistingExpiringEntryAndResetTtl() {
doWithConnection(connection -> connection.set(binaryCacheKey, "foo".getBytes(),
Expiration.from(1, TimeUnit.MINUTES), SetOption.upsert()));
@@ -135,8 +132,8 @@ public class DefaultRedisCacheWriterTests {
});
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void getShouldReturnValue() {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void getShouldReturnValue() {
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
@@ -150,13 +147,13 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getMisses()).isZero();
}
@Test // DATAREDIS-481
public void getShouldReturnNullWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-481
void getShouldReturnNullWhenKeyDoesNotExist() {
assertThat(nonLockingRedisCacheWriter(connectionFactory).get(CACHE_NAME, binaryCacheKey)).isNull();
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void putIfAbsentShouldAddEternalEntryWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void putIfAbsentShouldAddEternalEntryWhenKeyDoesNotExist() {
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
.withStatisticsCollector(CacheStatisticsCollector.create());
@@ -170,8 +167,8 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isOne();
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void putIfAbsentShouldNotAddEternalEntryWhenKeyAlreadyExist() {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void putIfAbsentShouldNotAddEternalEntryWhenKeyAlreadyExist() {
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
@@ -187,8 +184,8 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isZero();
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void putIfAbsentShouldAddExpiringEntryWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void putIfAbsentShouldAddExpiringEntryWhenKeyDoesNotExist() {
RedisCacheWriter writer = nonLockingRedisCacheWriter(connectionFactory)
.withStatisticsCollector(CacheStatisticsCollector.create());
@@ -200,8 +197,8 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getPuts()).isOne();
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void removeShouldDeleteEntry() {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void removeShouldDeleteEntry() {
doWithConnection(connection -> connection.set(binaryCacheKey, binaryCacheValue));
@@ -213,8 +210,8 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getDeletes()).isOne();
}
@Test // DATAREDIS-418, DATAREDIS-1082
public void cleanShouldRemoveAllKeysByPattern() {
@ParameterizedRedisTest // DATAREDIS-418, DATAREDIS-1082
void cleanShouldRemoveAllKeysByPattern() {
doWithConnection(connection -> {
connection.set(binaryCacheKey, binaryCacheValue);
@@ -232,8 +229,8 @@ public class DefaultRedisCacheWriterTests {
assertThat(writer.getCacheStatistics(CACHE_NAME).getDeletes()).isOne();
}
@Test // DATAREDIS-481
public void nonLockingCacheWriterShouldIgnoreExistingLock() {
@ParameterizedRedisTest // DATAREDIS-481
void nonLockingCacheWriterShouldIgnoreExistingLock() {
((DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory)).lock(CACHE_NAME);
@@ -244,8 +241,8 @@ public class DefaultRedisCacheWriterTests {
});
}
@Test // DATAREDIS-481
public void lockingCacheWriterShouldIgnoreExistingLockOnDifferenceCache() {
@ParameterizedRedisTest // DATAREDIS-481
void lockingCacheWriterShouldIgnoreExistingLockOnDifferenceCache() {
((DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory)).lock(CACHE_NAME);
@@ -257,8 +254,8 @@ public class DefaultRedisCacheWriterTests {
});
}
@Test // DATAREDIS-481, DATAREDIS-1082
public void lockingCacheWriterShouldWaitForLockRelease() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-481, DATAREDIS-1082
void lockingCacheWriterShouldWaitForLockRelease() throws InterruptedException {
DefaultRedisCacheWriter writer = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory)
.withStatisticsCollector(CacheStatisticsCollector.create());
@@ -297,8 +294,8 @@ public class DefaultRedisCacheWriterTests {
}
}
@Test // DATAREDIS-481
public void lockingCacheWriterShouldExitWhenInterruptedWaitForLockRelease() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-481
void lockingCacheWriterShouldExitWhenInterruptedWaitForLockRelease() throws InterruptedException {
DefaultRedisCacheWriter cw = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory);
cw.lock(CACHE_NAME);
@@ -338,8 +335,8 @@ public class DefaultRedisCacheWriterTests {
.hasCauseInstanceOf(InterruptedException.class);
}
@Test // DATAREDIS-1082
public void noOpSatisticsCollectorReturnsEmptyStatsInstance() {
@ParameterizedRedisTest // DATAREDIS-1082
void noOpSatisticsCollectorReturnsEmptyStatsInstance() {
DefaultRedisCacheWriter cw = (DefaultRedisCacheWriter) lockingRedisCacheWriter(connectionFactory);
CacheStatistics stats = cw.getCacheStatistics(CACHE_NAME);

View File

@@ -29,24 +29,21 @@ import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.Disabled;
import org.springframework.cache.Cache;
import org.springframework.cache.Cache.ValueRetrievalException;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.AbstractOperationsTestParams;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Tests moved over from 1.x line RedisCache implementation. Just removed somme of the limitations/assumtions previously
* required.
* Tests moved over from 1.x line RedisCache implementation. Just removed somme of the limitations/assumptions
* previously required.
*
* @author Costin Leau
* @author Jennifer Hickey
@@ -54,16 +51,16 @@ import org.springframework.data.redis.core.RedisTemplate;
* @author Mark Paluch
*/
@SuppressWarnings("rawtypes")
@RunWith(Parameterized.class)
@MethodSource("testParams")
public class LegacyRedisCacheTests {
final static String CACHE_NAME = "testCache";
ObjectFactory<Object> keyFactory;
ObjectFactory<Object> valueFactory;
RedisConnectionFactory connectionFactory;
final boolean allowCacheNullValues;
private final static String CACHE_NAME = "testCache";
private ObjectFactory<Object> keyFactory;
private ObjectFactory<Object> valueFactory;
private RedisConnectionFactory connectionFactory;
private final boolean allowCacheNullValues;
RedisCache cache;
private RedisCache cache;
public LegacyRedisCacheTests(RedisTemplate template, ObjectFactory<Object> keyFactory,
ObjectFactory<Object> valueFactory, boolean allowCacheNullValues) {
@@ -76,7 +73,6 @@ public class LegacyRedisCacheTests {
cache = createCache();
}
@Parameters
public static Collection<Object[]> testParams() {
Collection<Object[]> params = AbstractOperationsTestParams.testParams();
@@ -117,8 +113,8 @@ public class LegacyRedisCacheTests {
return keyFactory.instance();
}
@Test
public void testCachePut() throws Exception {
@ParameterizedRedisTest
void testCachePut() {
Object key = getKey();
Object value = getValue();
@@ -131,8 +127,8 @@ public class LegacyRedisCacheTests {
}
}
@Test
public void testCacheClear() throws Exception {
@ParameterizedRedisTest
void testCacheClear() {
Object key1 = getKey();
Object value1 = getValue();
@@ -148,8 +144,8 @@ public class LegacyRedisCacheTests {
assertThat(cache.get(key1)).isNull();
}
@Test
public void testConcurrentRead() throws Exception {
@ParameterizedRedisTest
void testConcurrentRead() throws Exception {
final Object key1 = getKey();
final Object value1 = getValue();
@@ -194,8 +190,8 @@ public class LegacyRedisCacheTests {
assertThat(valueWrapper.get()).isEqualTo(v1);
}
@Test
public void testGetWhileClear() throws InterruptedException {
@ParameterizedRedisTest
void testGetWhileClear() throws InterruptedException {
final Object key1 = getKey();
final Object value1 = getValue();
@@ -220,8 +216,8 @@ public class LegacyRedisCacheTests {
assertThat(monitorStateException.get()).isFalse();
}
@Test // DATAREDIS-243
public void testCacheGetShouldReturnCachedInstance() {
@ParameterizedRedisTest // DATAREDIS-243
void testCacheGetShouldReturnCachedInstance() {
Object key = getKey();
Object value = getValue();
@@ -230,8 +226,8 @@ public class LegacyRedisCacheTests {
assertThat(value).isEqualTo(cache.get(key, Object.class));
}
@Test // DATAREDIS-243
public void testCacheGetShouldRetunInstanceOfCorrectType() {
@ParameterizedRedisTest // DATAREDIS-243
void testCacheGetShouldRetunInstanceOfCorrectType() {
Object key = getKey();
Object value = getValue();
@@ -240,19 +236,18 @@ public class LegacyRedisCacheTests {
assertThat(cache.get(key, value.getClass())).isInstanceOf(value.getClass());
}
@Test(expected = IllegalStateException.class) // DATAREDIS-243
public void testCacheGetShouldThrowExceptionOnInvalidType() {
@ParameterizedRedisTest // DATAREDIS-243
void testCacheGetShouldThrowExceptionOnInvalidType() {
Object key = getKey();
Object value = getValue();
cache.put(key, value);
@SuppressWarnings("unused")
Cache retrievedObject = cache.get(key, Cache.class);
assertThatIllegalStateException().isThrownBy(() -> cache.get(key, Cache.class));
}
@Test // DATAREDIS-243
public void testCacheGetShouldReturnNullIfNoCachedValueFound() {
@ParameterizedRedisTest // DATAREDIS-243
void testCacheGetShouldReturnNullIfNoCachedValueFound() {
Object key = getKey();
Object value = getValue();
@@ -262,8 +257,8 @@ public class LegacyRedisCacheTests {
assertThat(cache.get(invalidKey, value.getClass())).isNull();
}
@Test // DATAREDIS-344, DATAREDIS-416
public void putIfAbsentShouldSetValueOnlyIfNotPresent() {
@ParameterizedRedisTest // DATAREDIS-344, DATAREDIS-416
void putIfAbsentShouldSetValueOnlyIfNotPresent() {
Object key = getKey();
@@ -280,18 +275,18 @@ public class LegacyRedisCacheTests {
assertThat(wrapper.get()).isEqualTo(value);
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-510, DATAREDIS-606
public void cachePutWithNullShouldNotAddStuffToRedis() {
@ParameterizedRedisTest // DATAREDIS-510, DATAREDIS-606
void cachePutWithNullShouldNotAddStuffToRedis() {
assumeThat(allowCacheNullValues).as("Only suitable when cache does NOT allow null values.").isFalse();
Object key = getKey();
cache.put(key, null);
assertThatIllegalArgumentException().isThrownBy(() -> cache.put(key, null));
}
@Test // DATAREDIS-510, DATAREDIS-606
public void cachePutWithNullShouldErrorAndLeaveExistingKeyUntouched() {
@ParameterizedRedisTest // DATAREDIS-510, DATAREDIS-606
void cachePutWithNullShouldErrorAndLeaveExistingKeyUntouched() {
assumeThat(allowCacheNullValues).as("Only suitable when cache does NOT allow null values.").isFalse();
@@ -311,13 +306,14 @@ public class LegacyRedisCacheTests {
assertThat(cache.get(key).get()).isEqualTo(value);
}
@Test // DATAREDIS-443, DATAREDIS-452
public void testCacheGetSynchronized() throws Throwable {
@ParameterizedRedisTest // DATAREDIS-443, DATAREDIS-452
@Disabled("junit.framework.AssertionFailedError: expected:<2> but was:<1>")
void testCacheGetSynchronized() throws Throwable {
runOnce(new CacheGetWithValueLoaderIsThreadSafe(cache));
}
@Test // DATAREDIS-553
public void cachePutWithNullShouldAddStuffToRedisWhenCachingNullIsEnabled() {
@ParameterizedRedisTest // DATAREDIS-553
void cachePutWithNullShouldAddStuffToRedisWhenCachingNullIsEnabled() {
assumeThat(allowCacheNullValues).as("Only suitable when cache does allow null values.").isTrue();
@@ -329,8 +325,8 @@ public class LegacyRedisCacheTests {
assertThat(cache.get(key, String.class)).isNull();
}
@Test // DATAREDIS-553
public void testCacheGetSynchronizedNullAllowingNull() {
@ParameterizedRedisTest // DATAREDIS-553
void testCacheGetSynchronizedNullAllowingNull() {
assumeThat(allowCacheNullValues).as("Only suitable when cache does allow null values.").isTrue();
@@ -341,26 +337,29 @@ public class LegacyRedisCacheTests {
assertThat(cache.get(key).get()).isNull();
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-553, DATAREDIS-606
public void testCacheGetSynchronizedNullNotAllowingNull() {
@ParameterizedRedisTest // DATAREDIS-553, DATAREDIS-606
void testCacheGetSynchronizedNullNotAllowingNull() {
assumeThat(allowCacheNullValues).as("Only suitable when cache does NOT allow null values.").isFalse();
Object key = getKey();
Object value = cache.get(key, () -> null);
assertThatIllegalArgumentException().isThrownBy(() -> cache.get(key, () -> null));
}
@Test(expected = ValueRetrievalException.class)
public void testCacheGetSynchronizedThrowsExceptionInValueLoader() {
@ParameterizedRedisTest
void testCacheGetSynchronizedThrowsExceptionInValueLoader() {
Object key = getKey();
Object value = cache.get(key, () -> {
throw new RuntimeException("doh!");
assertThatExceptionOfType(ValueRetrievalException.class).isThrownBy(() -> {
cache.get(key, () -> {
throw new RuntimeException("doh!");
});
});
}
@Test // DATAREDIS-553
public void testCacheGetSynchronizedNullWithStoredNull() {
@ParameterizedRedisTest // DATAREDIS-553
void testCacheGetSynchronizedNullWithStoredNull() {
assumeThat(allowCacheNullValues).as("Only suitable when cache does allow null values.").isTrue();
@@ -378,14 +377,14 @@ public class LegacyRedisCacheTests {
Cache redisCache;
TestCacheLoader<String> cacheLoader;
public CacheGetWithValueLoaderIsThreadSafe(Cache redisCache) {
CacheGetWithValueLoaderIsThreadSafe(Cache redisCache) {
this.redisCache = redisCache;
cacheLoader = new TestCacheLoader<String>("test") {
@Override
public String call() throws Exception {
public String call() {
waitForTick(2);
return super.call();
@@ -411,12 +410,12 @@ public class LegacyRedisCacheTests {
private final T value;
public TestCacheLoader(T value) {
TestCacheLoader(T value) {
this.value = value;
}
@Override
public T call() throws Exception {
public T call() {
return value;
}
}

View File

@@ -23,28 +23,24 @@ import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import java.io.Serializable;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;
import java.util.Date;
import java.util.function.Consumer;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.cache.interceptor.SimpleKey;
import org.springframework.cache.interceptor.SimpleKeyGenerator;
import org.springframework.cache.support.NullValue;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Tests for {@link RedisCache} with {@link DefaultRedisCacheWriter} using different {@link RedisSerializer} and
@@ -53,38 +49,35 @@ import org.springframework.data.redis.serializer.RedisSerializer;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
public class RedisCacheTests {
String key = "key-1";
String cacheKey = "cache::" + key;
byte[] binaryCacheKey = cacheKey.getBytes(StandardCharsets.UTF_8);
private String key = "key-1";
private String cacheKey = "cache::" + key;
private byte[] binaryCacheKey = cacheKey.getBytes(StandardCharsets.UTF_8);
Person sample = new Person("calmity", new Date());
byte[] binarySample;
private Person sample = new Person("calmity", new Date());
private byte[] binarySample;
byte[] binaryNullValue = RedisSerializer.java().serialize(NullValue.INSTANCE);
private byte[] binaryNullValue = RedisSerializer.java().serialize(NullValue.INSTANCE);
RedisConnectionFactory connectionFactory;
RedisSerializer serializer;
RedisCache cache;
private RedisConnectionFactory connectionFactory;
private RedisSerializer serializer;
private RedisCache cache;
public RedisCacheTests(RedisConnectionFactory connectionFactory, RedisSerializer serializer) {
this.connectionFactory = connectionFactory;
this.serializer = serializer;
this.binarySample = serializer.serialize(sample);
ConnectionFactoryTracker.add(connectionFactory);
}
@Parameters(name = "{index}: {0} & {1}")
public static Collection<Object[]> testParams() {
return CacheTestParams.connectionFactoriesAndSerializers();
}
@Before
public void setUp() {
@BeforeEach
void setUp() {
doWithConnection(RedisConnection::flushAll);
@@ -92,8 +85,8 @@ public class RedisCacheTests {
RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(SerializationPair.fromSerializer(serializer)));
}
@Test // DATAREDIS-481
public void putShouldAddEntry() {
@ParameterizedRedisTest // DATAREDIS-481
void putShouldAddEntry() {
cache.put("key-1", sample);
@@ -102,8 +95,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void putNullShouldAddEntryForNullValue() {
@ParameterizedRedisTest // DATAREDIS-481
void putNullShouldAddEntryForNullValue() {
cache.put("key-1", null);
@@ -113,8 +106,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void putIfAbsentShouldAddEntryIfNotExists() {
@ParameterizedRedisTest // DATAREDIS-481
void putIfAbsentShouldAddEntryIfNotExists() {
cache.putIfAbsent("key-1", sample);
@@ -124,8 +117,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void putIfAbsentWithNullShouldAddNullValueEntryIfNotExists() {
@ParameterizedRedisTest // DATAREDIS-481
void putIfAbsentWithNullShouldAddNullValueEntryIfNotExists() {
assertThat(cache.putIfAbsent("key-1", null)).isNull();
@@ -135,8 +128,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void putIfAbsentShouldReturnExistingIfExists() {
@ParameterizedRedisTest // DATAREDIS-481
void putIfAbsentShouldReturnExistingIfExists() {
doWithConnection(connection -> connection.set(binaryCacheKey, binarySample));
@@ -150,8 +143,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void putIfAbsentShouldReturnExistingNullValueIfExists() {
@ParameterizedRedisTest // DATAREDIS-481
void putIfAbsentShouldReturnExistingNullValueIfExists() {
doWithConnection(connection -> connection.set(binaryCacheKey, binaryNullValue));
@@ -165,8 +158,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void getShouldRetrieveEntry() {
@ParameterizedRedisTest // DATAREDIS-481
void getShouldRetrieveEntry() {
doWithConnection(connection -> {
connection.set(binaryCacheKey, binarySample);
@@ -177,8 +170,8 @@ public class RedisCacheTests {
assertThat(result.get()).isEqualTo(sample);
}
@Test // DATAREDIS-481
public void shouldReadAndWriteSimpleCacheKey() {
@ParameterizedRedisTest // DATAREDIS-481
void shouldReadAndWriteSimpleCacheKey() {
SimpleKey key = new SimpleKey("param-1", "param-2");
@@ -189,16 +182,16 @@ public class RedisCacheTests {
assertThat(result.get()).isEqualTo(sample);
}
@Test(expected = IllegalStateException.class) // DATAREDIS-481
public void shouldRejectNonInvalidKey() {
@ParameterizedRedisTest // DATAREDIS-481
void shouldRejectNonInvalidKey() {
InvalidKey key = new InvalidKey(sample.getFirstame(), sample.getBirthdate());
cache.put(key, sample);
assertThatIllegalStateException().isThrownBy(() -> cache.put(key, sample));
}
@Test // DATAREDIS-481
public void shouldAllowComplexKeyWithToStringMethod() {
@ParameterizedRedisTest // DATAREDIS-481
void shouldAllowComplexKeyWithToStringMethod() {
ComplexKey key = new ComplexKey(sample.getFirstame(), sample.getBirthdate());
@@ -209,13 +202,13 @@ public class RedisCacheTests {
assertThat(result.get()).isEqualTo(sample);
}
@Test // DATAREDIS-481
public void getShouldReturnNullWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-481
void getShouldReturnNullWhenKeyDoesNotExist() {
assertThat(cache.get(key)).isNull();
}
@Test // DATAREDIS-481
public void getShouldReturnValueWrapperHoldingNullIfNullValueStored() {
@ParameterizedRedisTest // DATAREDIS-481
void getShouldReturnValueWrapperHoldingNullIfNullValueStored() {
doWithConnection(connection -> {
connection.set(binaryCacheKey, binaryNullValue);
@@ -226,8 +219,8 @@ public class RedisCacheTests {
assertThat(result.get()).isEqualTo(null);
}
@Test // DATAREDIS-481
public void evictShouldRemoveKey() {
@ParameterizedRedisTest // DATAREDIS-481
void evictShouldRemoveKey() {
doWithConnection(connection -> {
connection.set(binaryCacheKey, binaryNullValue);
@@ -240,8 +233,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void getWithCallableShouldResolveValueIfNotPresent() {
@ParameterizedRedisTest // DATAREDIS-481
void getWithCallableShouldResolveValueIfNotPresent() {
assertThat(cache.get(key, () -> sample)).isEqualTo(sample);
@@ -251,8 +244,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-481
public void getWithCallableShouldNotResolveValueIfPresent() {
@ParameterizedRedisTest // DATAREDIS-481
void getWithCallableShouldNotResolveValueIfPresent() {
doWithConnection(connection -> connection.set(binaryCacheKey, binaryNullValue));
@@ -266,8 +259,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-715
public void computePrefixCreatesCacheKeyCorrectly() {
@ParameterizedRedisTest // DATAREDIS-715
void computePrefixCreatesCacheKeyCorrectly() {
RedisCache cacheWithCustomPrefix = new RedisCache("cache", new DefaultRedisCacheWriter(connectionFactory),
RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(SerializationPair.fromSerializer(serializer))
@@ -282,8 +275,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-1041
public void prefixCacheNameCreatesCacheKeyCorrectly() {
@ParameterizedRedisTest // DATAREDIS-1041
void prefixCacheNameCreatesCacheKeyCorrectly() {
RedisCache cacheWithCustomPrefix = new RedisCache("cache", new DefaultRedisCacheWriter(connectionFactory),
RedisCacheConfiguration.defaultCacheConfig().serializeValuesWith(SerializationPair.fromSerializer(serializer))
@@ -298,8 +291,8 @@ public class RedisCacheTests {
});
}
@Test // DATAREDIS-715
public void fetchKeyWithComputedPrefixReturnsExpectedResult() {
@ParameterizedRedisTest // DATAREDIS-715
void fetchKeyWithComputedPrefixReturnsExpectedResult() {
doWithConnection(connection -> connection.set("_cache_key-1".getBytes(StandardCharsets.UTF_8), binarySample));
@@ -313,8 +306,8 @@ public class RedisCacheTests {
assertThat(result.get()).isEqualTo(sample);
}
@Test // DATAREDIS-1032
public void cacheShouldAllowListKeyCacheKeysOfSimpleTypes() {
@ParameterizedRedisTest // DATAREDIS-1032
void cacheShouldAllowListKeyCacheKeysOfSimpleTypes() {
Object key = SimpleKeyGenerator.generateKey(Collections.singletonList("my-cache-key-in-a-list"));
cache.put(key, sample);
@@ -324,8 +317,8 @@ public class RedisCacheTests {
assertThat(target.get()).isEqualTo(sample);
}
@Test // DATAREDIS-1032
public void cacheShouldAllowArrayKeyCacheKeysOfSimpleTypes() {
@ParameterizedRedisTest // DATAREDIS-1032
void cacheShouldAllowArrayKeyCacheKeysOfSimpleTypes() {
Object key = SimpleKeyGenerator.generateKey("my-cache-key-in-an-array");
cache.put(key, sample);
@@ -334,8 +327,8 @@ public class RedisCacheTests {
assertThat(target.get()).isEqualTo(sample);
}
@Test // DATAREDIS-1032
public void cacheShouldAllowListCacheKeysOfComplexTypes() {
@ParameterizedRedisTest // DATAREDIS-1032
void cacheShouldAllowListCacheKeysOfComplexTypes() {
Object key = SimpleKeyGenerator
.generateKey(Collections.singletonList(new ComplexKey(sample.getFirstame(), sample.getBirthdate())));
@@ -346,8 +339,8 @@ public class RedisCacheTests {
assertThat(target.get()).isEqualTo(sample);
}
@Test // DATAREDIS-1032
public void cacheShouldAllowMapCacheKeys() {
@ParameterizedRedisTest // DATAREDIS-1032
void cacheShouldAllowMapCacheKeys() {
Object key = SimpleKeyGenerator
.generateKey(Collections.singletonMap("map-key", new ComplexKey(sample.getFirstame(), sample.getBirthdate())));
@@ -358,8 +351,8 @@ public class RedisCacheTests {
assertThat(target.get()).isEqualTo(sample);
}
@Test // DATAREDIS-1032
public void cacheShouldFailOnNonConvertibleCacheKey() {
@ParameterizedRedisTest // DATAREDIS-1032
void cacheShouldFailOnNonConvertibleCacheKey() {
Object key = SimpleKeyGenerator
.generateKey(Collections.singletonList(new InvalidKey(sample.getFirstame(), sample.getBirthdate())));

View File

@@ -21,10 +21,8 @@ import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.test.annotation.IfProfileValue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Base test class for integration tests that execute each operation of a Connection while a pipeline is open, verifying
@@ -38,71 +36,100 @@ import org.springframework.test.annotation.IfProfileValue;
*/
abstract public class AbstractConnectionPipelineIntegrationTests extends AbstractConnectionIntegrationTests {
@Ignore
public void testNullKey() throws Exception {}
@Override
@Disabled
public void testNullKey() {}
@Ignore
public void testNullValue() throws Exception {}
@Override
@Disabled
public void testNullValue() {}
@Ignore
public void testHashNullKey() throws Exception {}
@Override
@Disabled
public void testHashNullKey() {}
@Ignore
public void testHashNullValue() throws Exception {}
@Override
@Disabled
public void testHashNullValue() {}
@Ignore("Pub/Sub not supported while pipelining")
@Override
@Disabled("Pub/Sub not supported while pipelining")
public void testPubSubWithNamedChannels() throws Exception {}
@Ignore("Pub/Sub not supported while pipelining")
@Override
@Disabled("Pub/Sub not supported while pipelining")
public void testPubSubWithPatterns() throws Exception {}
@Override
@Test
public void testExecWithoutMulti() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testExecWithoutMulti);
connection.exec();
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Override
@Test
public void testErrorInTx() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testErrorInTx);
connection.multi();
connection.set("foo", "bar");
// Try to do a list op on a value
connection.lPop("foo");
connection.exec();
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Override
@Test
public void exceptionExecuteNative() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::exceptionExecuteNative);
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> {
connection.execute("set", "foo");
getResults();
});
}
@Override
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaNotFound() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testEvalShaNotFound);
connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2");
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Override
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleError() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testEvalReturnSingleError);
connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0);
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Override
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreBadData() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testRestoreBadData);
connection.restore("testing".getBytes(), 0, "foo".getBytes());
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Override
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreExistingKey() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testRestoreExistingKey);
actual.add(connection.set("testing", "12"));
actual.add(connection.dump("testing".getBytes()));
List<Object> results = getResults();
initConnection();
connection.restore("testing".getBytes(), 0, (byte[]) results.get(1));
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Override
@Test
@Ignore
@Disabled
public void testEvalArrayScriptError() {}
@Override
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(super::testEvalShaArrayError);
connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1");
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(this::getResults);
}
@Test
@@ -120,22 +147,25 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends Abstrac
}
@Test // DATAREDIS-417
@Ignore
@Disabled
@Override
public void scanShouldReadEntireValueRangeWhenIdividualScanIterationsReturnEmptyCollection() {
super.scanShouldReadEntireValueRangeWhenIdividualScanIterationsReturnEmptyCollection();
}
@Override
@Test
@Ignore
@Disabled
public void xClaim() throws InterruptedException {
super.xClaim();
}
@Override
protected void initConnection() {
connection.openPipeline();
}
@Override
protected void verifyResults(List<Object> expected) {
List<Object> expectedPipeline = new ArrayList<>();
for (int i = 0; i < actual.size(); i++) {
@@ -146,6 +176,7 @@ abstract public class AbstractConnectionPipelineIntegrationTests extends Abstrac
assertThat(results).isEqualTo(expected);
}
@Override
protected List<Object> getResults() {
try {

View File

@@ -20,10 +20,8 @@ import static org.assertj.core.api.Assertions.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.test.annotation.IfProfileValue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* @author Jennifer Hickey
@@ -32,23 +30,33 @@ import org.springframework.test.annotation.IfProfileValue;
*/
abstract public class AbstractConnectionTransactionIntegrationTests extends AbstractConnectionIntegrationTests {
@Ignore
@Test
@Override
@Disabled
public void testMultiDiscard() {}
@Ignore
@Test
@Override
@Disabled
public void testMultiExec() {}
@Ignore
@Test
@Override
@Disabled
public void testUnwatch() {}
@Ignore
@Test
@Override
@Disabled
public void testWatch() {}
@Ignore
@Override
@Disabled
@Test
public void testExecWithoutMulti() {}
@Ignore
@Override
@Disabled
@Test
public void testErrorInTx() {}
@@ -58,76 +66,103 @@ abstract public class AbstractConnectionTransactionIntegrationTests extends Abst
* clients to perform a push operation. *
*/
@Ignore
@Test
@Override
@Disabled
public void testBLPop() {}
@Ignore
@Test
@Override
@Disabled
public void testBRPop() {}
@Ignore
@Test
@Override
@Disabled
public void testBRPopLPush() {}
@Ignore
@Test
@Override
@Disabled
public void testBLPopTimeout() {}
@Ignore
@Test
@Override
@Disabled
public void testBRPopTimeout() {}
@Ignore
@Test
@Override
@Disabled
public void testBRPopLPushTimeout() {}
@Ignore("Pub/Sub not supported with transactions")
@Test
@Override
@Disabled("Pub/Sub not supported with transactions")
public void testPubSubWithNamedChannels() throws Exception {}
@Ignore("Pub/Sub not supported with transactions")
@Test
@Override
@Disabled("Pub/Sub not supported with transactions")
public void testPubSubWithPatterns() throws Exception {}
@Ignore
public void testNullKey() throws Exception {}
@Test
@Override
@Disabled
public void testNullKey() {}
@Ignore
public void testNullValue() throws Exception {}
@Test
@Override
@Disabled
public void testNullValue() {}
@Ignore
public void testHashNullKey() throws Exception {}
@Test
@Override
@Disabled
public void testHashNullKey() {}
@Ignore
public void testHashNullValue() throws Exception {}
@Test
@Override
@Disabled
public void testHashNullValue() {}
@Test
public void testWatchWhileInTx() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> connection.watch("foo".getBytes()));
}
@Test(expected = UnsupportedOperationException.class)
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Test
public void testScriptKill() {
// Impossible to call script kill in a tx because you can't issue the
// exec command while Redis is running a script
connection.scriptKill();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> connection.scriptKill());
}
@Test // DATAREDIS-417
@Ignore
@Disabled
@Override
public void scanShouldReadEntireValueRangeWhenIdividualScanIterationsReturnEmptyCollection() {
super.scanShouldReadEntireValueRangeWhenIdividualScanIterationsReturnEmptyCollection();
}
@Override
@Test
@Ignore
@Disabled
public void xClaim() throws InterruptedException {
super.xClaim();
}
@Override
protected void initConnection() {
connection.multi();
}
@Override
protected List<Object> getResults() {
return connection.exec();
}
@Override
protected void verifyResults(List<Object> expected) {
List<Object> expectedTx = new ArrayList<>();
for (int i = 0; i < actual.size(); i++) {

View File

@@ -24,18 +24,18 @@ import java.util.List;
import javax.sql.DataSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.context.transaction.AfterTransaction;
import org.springframework.transaction.PlatformTransactionManager;
import org.springframework.transaction.annotation.Transactional;
@@ -47,7 +47,7 @@ import org.springframework.transaction.annotation.Transactional;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@Transactional(transactionManager = "transactionManager")
public abstract class AbstractTransactionalTestBase {
@@ -88,7 +88,7 @@ public abstract class AbstractTransactionalTestBase {
private List<String> KEYS = Arrays.asList("spring", "data", "redis");
private boolean valuesShouldHaveBeenPersisted = false;
@Before
@BeforeEach
public void setUp() {
valuesShouldHaveBeenPersisted = false;
cleanDataStore();

View File

@@ -289,10 +289,10 @@ public interface ClusterConnectionTests {
void lPopShouldReturnElementCorrectly();
// DATAREDIS-315
void lPushNXShoultNotAddValuesWhenKeyDoesNotExist();
void lPushNXShouldNotAddValuesWhenKeyDoesNotExist();
// DATAREDIS-315
void lPushShoultAddValuesCorrectly();
void lPushShouldAddValuesCorrectly();
// DATAREDIS-315
void lRangeShouldGetValuesCorrectly();
@@ -399,10 +399,10 @@ public interface ClusterConnectionTests {
void rPopShouldReturnElementCorrectly();
// DATAREDIS-315
void rPushNXShoultNotAddValuesWhenKeyDoesNotExist();
void rPushNXShouldNotAddValuesWhenKeyDoesNotExist();
// DATAREDIS-315
void rPushShoultAddValuesCorrectly();
void rPushShouldAddValuesCorrectly();
// DATAREDIS-315
void randomKeyShouldReturnCorrectlyWhenKeysAvailable();

View File

@@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.env.PropertySource;
import org.springframework.mock.env.MockPropertySource;
@@ -31,15 +31,15 @@ import org.springframework.util.StringUtils;
* @author Christoph Strobl
* @author Mark Paluch
*/
public class RedisClusterConfigurationUnitTests {
class RedisClusterConfigurationUnitTests {
static final String HOST_AND_PORT_1 = "127.0.0.1:123";
static final String HOST_AND_PORT_2 = "localhost:456";
static final String HOST_AND_PORT_3 = "localhost:789";
static final String HOST_AND_NO_PORT = "localhost";
private static final String HOST_AND_PORT_1 = "127.0.0.1:123";
private static final String HOST_AND_PORT_2 = "localhost:456";
private static final String HOST_AND_PORT_3 = "localhost:789";
private static final String HOST_AND_NO_PORT = "localhost";
@Test // DATAREDIS-315
public void shouldCreateRedisClusterConfigurationCorrectly() {
void shouldCreateRedisClusterConfigurationCorrectly() {
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.singleton(HOST_AND_PORT_1));
@@ -49,7 +49,7 @@ public class RedisClusterConfigurationUnitTests {
}
@Test // DATAREDIS-315
public void shouldCreateRedisClusterConfigurationCorrectlyGivenMultipleHostAndPortStrings() {
void shouldCreateRedisClusterConfigurationCorrectlyGivenMultipleHostAndPortStrings() {
RedisClusterConfiguration config = new RedisClusterConfiguration(
new HashSet<>(Arrays.asList(HOST_AND_PORT_1,
@@ -61,19 +61,19 @@ public class RedisClusterConfigurationUnitTests {
}
@Test // DATAREDIS-315
public void shouldThrowExecptionOnInvalidHostAndPortString() {
void shouldThrowExecptionOnInvalidHostAndPortString() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new RedisClusterConfiguration(Collections.singleton(HOST_AND_NO_PORT)));
}
@Test // DATAREDIS-315
public void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
void shouldThrowExceptionWhenListOfHostAndPortIsNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> new RedisClusterConfiguration(Collections.<String> singleton(null)));
}
@Test // DATAREDIS-315
public void shouldNotFailWhenListOfHostAndPortIsEmpty() {
void shouldNotFailWhenListOfHostAndPortIsEmpty() {
RedisClusterConfiguration config = new RedisClusterConfiguration(Collections.<String> emptySet());
@@ -81,12 +81,12 @@ public class RedisClusterConfigurationUnitTests {
}
@Test // DATAREDIS-315
public void shouldThrowExceptionGivenNullPropertySource() {
void shouldThrowExceptionGivenNullPropertySource() {
assertThatIllegalArgumentException().isThrownBy(() -> new RedisClusterConfiguration((PropertySource<?>) null));
}
@Test // DATAREDIS-315
public void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
void shouldNotFailWhenGivenPropertySourceNotContainingRelevantProperties() {
RedisClusterConfiguration config = new RedisClusterConfiguration(new MockPropertySource());
@@ -95,7 +95,7 @@ public class RedisClusterConfigurationUnitTests {
}
@Test // DATAREDIS-315
public void shouldBeCreatedCorrecltyGivenValidPropertySourceWithSingleHostPort() {
void shouldBeCreatedCorrecltyGivenValidPropertySourceWithSingleHostPort() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.cluster.nodes", HOST_AND_PORT_1);
@@ -108,7 +108,7 @@ public class RedisClusterConfigurationUnitTests {
}
@Test // DATAREDIS-315
public void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMultipleHostPort() {
void shouldBeCreatedCorrecltyGivenValidPropertySourceWithMultipleHostPort() {
MockPropertySource propertySource = new MockPropertySource();
propertySource.setProperty("spring.redis.cluster.nodes",

View File

@@ -25,7 +25,6 @@ import static org.springframework.data.redis.connection.RedisGeoCommands.Distanc
import static org.springframework.data.redis.connection.RedisGeoCommands.GeoRadiusCommandArgs.*;
import static org.springframework.data.redis.core.ScanOptions.*;
import org.junit.jupiter.api.TestInstance;
import redis.clients.jedis.HostAndPort;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisCluster;
@@ -39,6 +38,7 @@ import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.dao.DataAccessException;
@@ -72,7 +72,6 @@ import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
import org.springframework.data.redis.test.extension.JedisExtension;
import org.springframework.data.redis.test.util.HexStringUtils;
import org.springframework.test.annotation.IfProfileValue;
/**
* @author Christoph Strobl
@@ -468,19 +467,16 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddMultipleGeoLocations() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO))).isEqualTo(3L);
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddSingleGeoLocation() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO)).isEqualTo(1L);
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDist() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -493,7 +489,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDistWithMetric() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -507,7 +502,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoHash() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -518,7 +512,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoHashNonExisting() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -530,7 +523,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPosition() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -546,7 +538,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPositionNonExisting() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -565,7 +556,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldApplyLimit() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -579,7 +569,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -595,7 +584,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -610,7 +598,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldApplyLimit() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -624,7 +611,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -640,7 +626,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -653,7 +638,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRemoveDeletesMembers() {
nativeConnection.geoadd(KEY_1_BYTES, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -1043,7 +1027,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void lPushNXShoultNotAddValuesWhenKeyDoesNotExist() {
public void lPushNXShouldNotAddValuesWhenKeyDoesNotExist() {
clusterConnection.lPushX(KEY_1_BYTES, VALUE_1_BYTES);
@@ -1051,7 +1035,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void lPushShoultAddValuesCorrectly() {
public void lPushShouldAddValuesCorrectly() {
clusterConnection.lPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES);
@@ -1373,7 +1357,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void rPushNXShoultNotAddValuesWhenKeyDoesNotExist() {
public void rPushNXShouldNotAddValuesWhenKeyDoesNotExist() {
clusterConnection.rPushX(KEY_1_BYTES, VALUE_1_BYTES);
@@ -1381,7 +1365,7 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void rPushShoultAddValuesCorrectly() {
public void rPushShouldAddValuesCorrectly() {
clusterConnection.rPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES);
@@ -2313,7 +2297,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-697
@IfProfileValue(name = "redisVersion", value = "2.8.7+")
void bitPosShouldReturnPositionCorrectly() {
nativeConnection.set(KEY_1_BYTES, HexStringUtils.hexToBytes("fff000"));
@@ -2322,7 +2305,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-697
@IfProfileValue(name = "redisVersion", value = "2.8.7+")
void bitPosShouldReturnPositionInRangeCorrectly() {
nativeConnection.set(KEY_1_BYTES, HexStringUtils.hexToBytes("fff0f0"));
@@ -2372,7 +2354,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldSetShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2382,7 +2363,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldGetShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2390,7 +2370,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldIncrByShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2398,7 +2377,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2417,7 +2395,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitfieldShouldAllowMultipleSubcommands() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2426,7 +2403,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitfieldShouldWorkUsingNonZeroBasedOffset() {
assertThat(
@@ -2443,7 +2419,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-1005
@IfProfileValue(name = "redisVersion", value = "2.6+")
void evalShouldRunScript() {
byte[] keyAndArgs = JedisConverters.toBytes("FOO");
@@ -2456,7 +2431,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-1005
@IfProfileValue(name = "redisVersion", value = "2.6+")
void scriptLoadShouldLoadScript() {
String luaScript = "return redis.call(\"INCR\", KEYS[1])";
@@ -2469,7 +2443,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-1005
@IfProfileValue(name = "redisVersion", value = "2.6+")
void scriptFlushShouldRemoveScripts() {
byte[] keyAndArgs = JedisConverters.toBytes("FOO");
@@ -2488,7 +2461,6 @@ public class JedisClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-1005
@IfProfileValue(name = "redisVersion", value = "2.6+")
void evelShaShouldRunScript() {
byte[] keyAndArgs = JedisConverters.toBytes("FOO");

View File

@@ -42,8 +42,6 @@ import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisPassword;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.test.util.ReflectionTestUtils;
/**
@@ -108,6 +106,8 @@ class JedisConnectionFactoryUnitTests {
JedisConnectionFactory factory = new JedisConnectionFactory();
ReflectionTestUtils.setField(factory, "cluster", clusterMock);
factory.destroy();
verify(clusterMock, times(1)).close();
}

View File

@@ -27,10 +27,10 @@ import java.util.concurrent.BlockingDeque;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.RedisConnectionFailureException;
@@ -44,12 +44,9 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.StringRedisConnection.StringTuple;
import org.springframework.data.redis.test.util.RedisSentinelRule;
import org.springframework.data.redis.test.util.RedisSentinelRule.SentinelsAvailable;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.data.redis.test.util.RequiresRedisSentinel;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link JedisConnection}
@@ -61,13 +58,11 @@ import org.springframework.test.context.ContextConfiguration;
* @author David Liu
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration
public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.withDefaultConfig().dynamicModeSelection();
@After
@AfterEach
public void tearDown() {
try {
connection.flushAll();
@@ -89,7 +84,6 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
@@ -102,7 +96,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test
public void testCreateConnectionWithDb() {
void testCreateConnectionWithDb() {
JedisConnectionFactory factory2 = new JedisConnectionFactory();
factory2.setDatabase(1);
factory2.afterPropertiesSet();
@@ -111,22 +105,22 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
factory2.destroy();
}
@Test(expected = RedisConnectionFailureException.class) // DATAREDIS-714
public void testCreateConnectionWithDbFailure() {
@Test // DATAREDIS-714
void testCreateConnectionWithDbFailure() {
JedisConnectionFactory factory2 = new JedisConnectionFactory();
factory2.setDatabase(77);
factory2.afterPropertiesSet();
try {
factory2.getConnection();
assertThatExceptionOfType(RedisConnectionFailureException.class).isThrownBy(factory2::getConnection);
} finally {
factory2.destroy();
}
}
@Test
public void testClosePool() {
void testClosePool() {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(1);
@@ -144,7 +138,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test
public void testZAddSameScores() {
void testZAddSameScores() {
Set<StringTuple> strTuples = new HashSet<>();
strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0));
strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 2.0));
@@ -153,53 +147,55 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleError() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalArrayScriptError() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> super.testEvalArrayScriptError());
.isThrownBy(() -> connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar"));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaNotFound() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2"));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testEvalShaArrayError());
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreBadData() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testRestoreBadData());
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testRestoreExistingKey() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> super.testRestoreExistingKey());
.isThrownBy(() -> connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1"));
}
@Test
public void testRestoreBadData() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> connection.restore("testing".getBytes(), 0, "foo".getBytes()));
}
@Test
@Disabled
public void testRestoreExistingKey() {
}
@Test
public void testExecWithoutMulti() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testExecWithoutMulti());
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> connection.exec());
}
@Test
public void testErrorInTx() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testErrorInTx());
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> {
connection.multi();
connection.set("foo", "bar");
// Try to do a list op on a value
connection.lPop("foo");
connection.exec();
getResults();
});
}
/**
@@ -323,7 +319,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test
public void testPoolNPE() {
void testPoolNPE() {
JedisPoolConfig config = new JedisPoolConfig();
config.setMaxTotal(1);
@@ -346,7 +342,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
@SuppressWarnings("unchecked")
@Test // DATAREDIS-285
public void testExecuteShouldConvertArrayReplyCorrectly() {
void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
connection.set("redis", "supercalifragilisticexpialidocious");
@@ -358,7 +354,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-286, DATAREDIS-564
public void expireShouldSupportExiprationForValuesLargerThanInteger() {
void expireShouldSupportExiprationForValuesLargerThanInteger() {
connection.set("expireKey", "foo");
@@ -370,7 +366,7 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-286
public void pExpireShouldSupportExiprationForValuesLargerThanInteger() {
void pExpireShouldSupportExiprationForValuesLargerThanInteger() {
connection.set("pexpireKey", "foo");
@@ -385,8 +381,8 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-330
@RequiresRedisSentinel(SentinelsAvailable.ONE_ACTIVE)
public void shouldReturnSentinelCommandsWhenWhenActiveSentinelFound() {
@EnabledOnRedisSentinelAvailable
void shouldReturnSentinelCommandsWhenWhenActiveSentinelFound() {
((JedisConnection) byteConnection).setSentinelConfiguration(
new RedisSentinelConfiguration().master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));
@@ -394,12 +390,12 @@ public class JedisConnectionIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-552
public void shouldSetClientName() {
void shouldSetClientName() {
assertThat(connection.getClientName()).isEqualTo("jedis-client");
}
@Test // DATAREDIS-106
public void zRangeByScoreTest() {
void zRangeByScoreTest() {
connection.zAdd("myzset", 1, "one");
connection.zAdd("myzset", 2, "two");

View File

@@ -22,18 +22,17 @@ import redis.clients.jedis.JedisPoolConfig;
import java.util.Arrays;
import java.util.List;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link JedisConnection} pipeline functionality
@@ -43,11 +42,11 @@ import org.springframework.test.context.ContextConfiguration;
* @author Thomas Darimont
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests {
@After
@AfterEach
public void tearDown() {
try {
connection.flushAll();
@@ -61,7 +60,7 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
connection = null;
}
@Ignore("Jedis issue: Pipeline tries to return String instead of List<String>")
@Disabled("Jedis issue: Pipeline tries to return String instead of List<String>")
public void testGetConfig() {}
@Test
@@ -126,114 +125,98 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
// Unsupported Ops
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptLoadEvalSha() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testScriptLoadEvalSha);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayStrings() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalShaArrayStrings);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalShaArrayBytes);
}
@Test
@Ignore
@Disabled
public void testEvalShaNotFound() {}
@Test
@Ignore
@Disabled
public void testEvalShaArrayError() {}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnString() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnString);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnNumber() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnNumber);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnSingleOK() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnSingleOK);
}
@Test
@Ignore
@Disabled
public void testEvalReturnSingleError() {
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnFalse() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnFalse);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnTrue() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnTrue);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayStrings() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayStrings);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayNumbers() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayNumbers);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayOKs() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayOKs);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayFalses() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayFalses);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalReturnArrayTrues() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayTrues);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptExists() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testScriptExists);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testScriptKill() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> connection.scriptKill());
}
@Test
@Ignore
@Disabled
public void testScriptFlush() {}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testInfoBySection() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testInfoBySection);
}
@@ -252,6 +235,6 @@ public class JedisConnectionPipelineIntegrationTests extends AbstractConnectionP
}
@Test // DATAREDIS-296
@Ignore
@Disabled
public void testExecWithoutMulti() {}
}

View File

@@ -19,10 +19,8 @@ import static org.assertj.core.api.Assertions.*;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* @author Jennifer Hickey
@@ -30,23 +28,16 @@ import org.springframework.data.redis.connection.RedisPipelineException;
*/
public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTransactionIntegrationTests {
@Ignore("Jedis issue: Pipeline tries to return String instead of List<String>")
@Disabled("Jedis issue: Pipeline tries to return String instead of List<String>")
@Test
public void testGetConfig() {}
@Test(expected = RedisPipelineException.class)
public void exceptionExecuteNative() throws Exception {
connection.execute("set", "foo");
connection.execute("ZadD", getClass() + "#foo\t0.90\titem");
getResults();
}
@Test
@Ignore
@Disabled
public void testRestoreBadData() {}
@Test
@Ignore
@Disabled
public void testRestoreExistingKey() {}
protected void initConnection() {
@@ -66,6 +57,6 @@ public class JedisConnectionPipelineTxIntegrationTests extends JedisConnectionTr
}
@Test
@Ignore
@Disabled
public void testListClientsContainsAtLeastOneElement() {}
}

View File

@@ -17,16 +17,15 @@ package org.springframework.data.redis.connection.jedis;
import static org.assertj.core.api.Assertions.*;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link JedisConnection} transaction functionality.
@@ -37,11 +36,11 @@ import org.springframework.test.context.ContextConfiguration;
* @author Jennifer Hickey
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
public class JedisConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@After
@AfterEach
public void tearDown() {
try {
connection.flushAll();
@@ -55,151 +54,130 @@ public class JedisConnectionTransactionIntegrationTests extends AbstractConnecti
connection = null;
}
@Ignore("Jedis issue: Transaction tries to return String instead of List<String>")
@Disabled("Jedis issue: Transaction tries to return String instead of List<String>")
public void testGetConfig() {}
// Unsupported Ops
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testScriptLoadEvalSha() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testScriptLoadEvalSha);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalShaArrayStrings() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalShaArrayStrings);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalShaArrayBytes() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalShaArrayBytes);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalShaNotFound() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalShaNotFound);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayError() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalShaArrayError);
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1"));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalArrayScriptError() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalArrayScriptError);
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar"));
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnString() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnString);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnNumber() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnNumber);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnSingleOK() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnSingleOK);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnSingleError() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnSingleError);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnFalse() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnFalse);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnTrue() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnTrue);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnArrayStrings() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayStrings);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnArrayNumbers() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayNumbers);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnArrayOKs() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayOKs);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnArrayFalses() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayFalses);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testEvalReturnArrayTrues() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testEvalReturnArrayTrues);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testScriptExists() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testScriptExists);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testScriptKill() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> connection.scriptKill());
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testScriptFlush() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> connection.scriptFlush());
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testInfoBySection() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testInfoBySection);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testRestoreBadData() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testRestoreBadData);
}
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
@Disabled
public void testRestoreExistingKey() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(super::testRestoreExistingKey);
}
@Test // DATAREDIS-269
@Disabled
public void clientSetNameWorksCorrectly() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::clientSetNameWorksCorrectly);
}
@Test

View File

@@ -17,26 +17,24 @@ package org.springframework.data.redis.connection.jedis;
import static org.assertj.core.api.Assertions.*;
import org.junit.jupiter.api.extension.ExtendWith;
import redis.clients.jedis.Jedis;
import java.util.Collection;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.data.redis.test.extension.RedisSentinel;
import org.springframework.test.util.ReflectionTestUtils;
/**
@@ -44,110 +42,47 @@ import org.springframework.test.util.ReflectionTestUtils;
* @author Thomas Darimont
* @author Mark Paluch
*/
@ExtendWith(SpringExtension.class)
@ContextConfiguration("JedisConnectionIntegrationTests-context.xml")
@ExtendWith(JedisConnectionFactoryExtension.class)
@EnabledOnRedisSentinelAvailable
public class JedisSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
private static final String MASTER_NAME = "mymaster";
private static final RedisServer SENTINEL_0 = new RedisServer("127.0.0.1", 26379);
private static final RedisServer SENTINEL_1 = new RedisServer("127.0.0.1", 26380);
private static final RedisServer SLAVE_0 = new RedisServer("127.0.0.1", 6380);
private static final RedisServer SLAVE_1 = new RedisServer("127.0.0.1", 6381);
private static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration() //
.master(MASTER_NAME).sentinel(SENTINEL_0).sentinel(SENTINEL_1);
@Before
public void setUp() {
JedisConnectionFactory jedisConnectionFactory = new JedisConnectionFactory(SENTINEL_CONFIG);
jedisConnectionFactory.setClientName("jedis-client");
jedisConnectionFactory.afterPropertiesSet();
connectionFactory = jedisConnectionFactory;
super.setUp();
}
@After
public void tearDown() {
super.tearDown();
((JedisConnectionFactory) connectionFactory).destroy();
}
@Test
@Ignore
public void testScriptKill() throws Exception {
super.testScriptKill();
}
@Test
public void testEvalReturnSingleError() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0));
public JedisSentinelIntegrationTests(@RedisSentinel JedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Test
public void testEvalArrayScriptError() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> super.testEvalArrayScriptError());
}
@Test
public void testEvalShaNotFound() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2"));
}
@Test
public void testEvalShaArrayError() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testEvalShaArrayError());
}
@Test
public void testRestoreBadData() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testRestoreBadData());
}
@Test
public void testRestoreExistingKey() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> super.testRestoreExistingKey());
}
@Test
public void testExecWithoutMulti() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testExecWithoutMulti());
}
@Test
public void testErrorInTx() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> super.testErrorInTx());
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> {
// Syntax error
connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar");
});
}
@Test // DATAREDIS-330
public void shouldReadMastersCorrectly() {
void shouldReadMastersCorrectly() {
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
assertThat(servers.size()).isEqualTo(1);
assertThat(servers.get(0).getName()).isEqualTo(MASTER_NAME);
assertThat(servers).hasSize(1);
assertThat(servers.get(0).getName()).isEqualTo(SettingsUtils.getSentinelMaster());
}
@Test // DATAREDIS-330
public void shouldReadSlavesOfMastersCorrectly() {
void shouldReadSlavesOfMastersCorrectly() {
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
List<RedisServer> servers = (List<RedisServer>) sentinelConnection.masters();
assertThat(servers.size()).isEqualTo(1);
assertThat(servers).hasSize(1);
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
assertThat(slaves.size()).isEqualTo(2);
assertThat(slaves).contains(SLAVE_0, SLAVE_1);
assertThat(slaves).hasSize(2).contains(SLAVE_0, SLAVE_1);
}
@Test // DATAREDIS-552
public void shouldSetClientName() {
void shouldSetClientName() {
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
Jedis jedis = (Jedis) ReflectionTestUtils.getField(sentinelConnection, "jedis");
@@ -155,4 +90,38 @@ public class JedisSentinelIntegrationTests extends AbstractConnectionIntegration
assertThat(jedis.clientGetname()).isEqualTo("jedis-client");
}
@Test
@Disabled
@Override
public void testRestoreExistingKey() {}
@Test
@Disabled
@Override
public void testRestoreBadData() {}
@Test
@Disabled
@Override
public void testEvalShaArrayError() {}
@Test
@Disabled
@Override
public void testEvalReturnSingleError() {}
@Test
@Disabled
@Override
public void testEvalShaNotFound() {}
@Test
@Disabled
@Override
public void testErrorInTx() {}
@Test
@Disabled
@Override
public void testExecWithoutMulti() {}
}

View File

@@ -15,7 +15,10 @@
*/
package org.springframework.data.redis.connection.jedis;
import org.junit.Test;
import redis.clients.jedis.JedisPoolConfig;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@@ -28,8 +31,6 @@ import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.transaction.annotation.Transactional;
import redis.clients.jedis.JedisPoolConfig;
/**
* @author Thomas Darimont
* @author Christoph Strobl
@@ -37,11 +38,11 @@ import redis.clients.jedis.JedisPoolConfig;
@ContextConfiguration(classes = { PooledJedisContextConfiguration.class })
public class JedisTransactionalConnectionStarvationTest extends AbstractTransactionalTestBase {
protected static final int MAX_CONNECTIONS = 5;
private static final int MAX_CONNECTIONS = 5;
@Autowired StringRedisTemplate template;
protected void tryOperations(int numOperationsToTry) {
void tryOperations(int numOperationsToTry) {
ValueOperations<String, String> ops = template.opsForValue();
@@ -52,19 +53,19 @@ public class JedisTransactionalConnectionStarvationTest extends AbstractTransact
@Test // DATAREDIS-332
@Rollback
public void testNumberOfOperationsIsOne() {
void testNumberOfOperationsIsOne() {
tryOperations(1);
}
@Test // DATAREDIS-332
@Rollback
public void testNumberOfOperationsEqualToNumberOfConnections() {
void testNumberOfOperationsEqualToNumberOfConnections() {
tryOperations(MAX_CONNECTIONS);
}
@Test // DATAREDIS-332
@Rollback
public void testNumberOfOperationsGreaterThanNumberOfConnections() {
void testNumberOfOperationsGreaterThanNumberOfConnections() {
tryOperations(MAX_CONNECTIONS + 1);
}

View File

@@ -25,14 +25,8 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
@@ -43,25 +37,26 @@ import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("params")
public class ScanTests {
RedisConnectionFactory factory;
RedisTemplate<String, String> redisOperations;
private RedisConnectionFactory factory;
private RedisTemplate<String, String> redisOperations;
ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 1, TimeUnit.MINUTES,
private ThreadPoolExecutor executor = new ThreadPoolExecutor(10, 10, 1, TimeUnit.MINUTES,
new LinkedBlockingDeque<>());
public ScanTests(RedisConnectionFactory factory) {
this.factory = factory;
}
@Parameters
public static List<RedisConnectionFactory> params() {
JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension
@@ -70,18 +65,18 @@ public class ScanTests {
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisStanalone.class);
return Arrays.<RedisConnectionFactory> asList(jedisConnectionFactory, lettuceConnectionFactory);
return Arrays.asList(jedisConnectionFactory, lettuceConnectionFactory);
}
@Before
public void setUp() {
@BeforeEach
void setUp() {
redisOperations = new StringRedisTemplate(factory);
redisOperations.afterPropertiesSet();
}
@Test
public void contextLoads() throws InterruptedException {
@ParameterizedRedisTest
void contextLoads() throws InterruptedException {
BoundHashOperations<String, String, String> hash = redisOperations.boundHashOps("hash");
final AtomicReference<Exception> exception = new AtomicReference<>();

View File

@@ -15,9 +15,7 @@
*/
package org.springframework.data.redis.connection.jedis.extension;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.JedisShardInfo;
import java.io.Closeable;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
@@ -56,38 +54,38 @@ public class JedisConnectionFactoryExtension implements ParameterResolver {
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace
.create(JedisConnectionFactoryExtension.class);
private static final JedisClientConfiguration CLIENT_CONFIGURATION = JedisClientConfiguration.builder()
.clientName("jedis-client").usePooling().build();
private static final Lazy<JedisConnectionFactory> STANDALONE = Lazy.of(() -> {
JedisClientConfiguration configuration = JedisClientConfiguration.builder().usePooling().build();
ManagedJedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.standaloneConfiguration(),
CLIENT_CONFIGURATION);
JedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.standaloneConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
private static final Lazy<JedisConnectionFactory> SENTINEL = Lazy.of(() -> {
JedisClientConfiguration configuration = JedisClientConfiguration.builder().usePooling().build();
ManagedJedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.sentinelConfiguration(),
CLIENT_CONFIGURATION);
JedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.sentinelConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
private static final Lazy<JedisConnectionFactory> CLUSTER = Lazy.of(() -> {
JedisClientConfiguration configuration = JedisClientConfiguration.builder().usePooling().build();
ManagedJedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.clusterConfiguration(),
CLIENT_CONFIGURATION);
JedisConnectionFactory factory = new ManagedJedisConnectionFactory(SettingsUtils.clusterConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -146,53 +144,34 @@ public class JedisConnectionFactoryExtension implements ParameterResolver {
static class ManagedJedisConnectionFactory extends JedisConnectionFactory
implements ConnectionFactoryTracker.Managed {
public ManagedJedisConnectionFactory() {
super();
}
private volatile boolean mayClose;
public ManagedJedisConnectionFactory(JedisShardInfo shardInfo) {
super(shardInfo);
}
public ManagedJedisConnectionFactory(JedisPoolConfig poolConfig) {
super(poolConfig);
}
public ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig) {
super(sentinelConfig);
}
public ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig, JedisPoolConfig poolConfig) {
super(sentinelConfig, poolConfig);
}
public ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig) {
super(clusterConfig);
}
public ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig, JedisPoolConfig poolConfig) {
super(clusterConfig, poolConfig);
}
public ManagedJedisConnectionFactory(RedisStandaloneConfiguration standaloneConfig) {
super(standaloneConfig);
}
public ManagedJedisConnectionFactory(RedisStandaloneConfiguration standaloneConfig,
ManagedJedisConnectionFactory(RedisStandaloneConfiguration standaloneConfig,
JedisClientConfiguration clientConfig) {
super(standaloneConfig, clientConfig);
}
public ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig,
ManagedJedisConnectionFactory(RedisSentinelConfiguration sentinelConfig,
JedisClientConfiguration clientConfig) {
super(sentinelConfig, clientConfig);
}
public ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig,
ManagedJedisConnectionFactory(RedisClusterConfiguration clusterConfig,
JedisClientConfiguration clientConfig) {
super(clusterConfig, clientConfig);
}
@Override
public void destroy() {
if (!mayClose) {
throw new IllegalStateException(
"Prematurely attempted to close ManagedJedisConnectionFactory. Shutdown hook didn't run yet which means that the test run isn't finished yet. Please fix the tests so that they don't close this connection factory.");
}
super.destroy();
}
@Override
public String toString() {
@@ -212,5 +191,16 @@ public class JedisConnectionFactoryExtension implements ParameterResolver {
return builder.toString();
}
Closeable toCloseable() {
return () -> {
try {
mayClose = true;
destroy();
} catch (Exception e) {
e.printStackTrace();
}
};
}
}
}

View File

@@ -20,11 +20,14 @@ import io.lettuce.core.RedisException;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.pubsub.StatefulRedisPubSubConnection;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.springframework.data.redis.test.util.ServerAvailable;
import java.util.concurrent.TimeUnit;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.test.condition.EnabledOnRedisAvailable;
/**
* Integration test of {@link AuthenticatingRedisClient}.
@@ -33,72 +36,72 @@ import org.springframework.data.redis.test.util.ServerAvailable;
* @author Thomas Darimont
* @author Christoph Strobl
*/
public class AuthenticatingRedisClientTests {
@EnabledOnRedisAvailable(6382)
class AuthenticatingRedisClientTests {
private RedisClient client;
@ClassRule public static ServerAvailable serverAvailable = ServerAvailable.runningAtLocalhost(6382);
@Before
public void setUp() {
@BeforeEach
void setUp() {
client = new AuthenticatingRedisClient("localhost", 6382, "foobared");
}
@After
public void tearDown() {
@AfterEach
void tearDown() {
if (client != null) {
client.shutdown();
}
}
@Test
public void connect() {
void connect() {
StatefulRedisConnection<String, String> conn = client.connect();
conn.sync().ping();
conn.close();
}
@Test(expected = RedisException.class)
public void connectWithInvalidPassword() {
@Test
void connectWithInvalidPassword() {
if (client != null) {
client.shutdown();
}
RedisClient badClient = new AuthenticatingRedisClient("localhost", 6382, "notthepassword");
badClient.connect();
Assertions.assertThatExceptionOfType(RedisException.class).isThrownBy(badClient::connect);
badClient.shutdown(0, 0, TimeUnit.MILLISECONDS);
}
@Test
public void codecConnect() {
void codecConnect() {
StatefulRedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
conn.sync().ping();
conn.close();
}
@Test
public void connectAsync() {
void connectAsync() {
StatefulRedisConnection<String, String> conn = client.connect();
conn.sync().ping();
conn.close();
}
@Test
public void codecConnectAsync() {
void codecConnectAsync() {
StatefulRedisConnection<byte[], byte[]> conn = client.connect(LettuceConnection.CODEC);
conn.sync().ping();
conn.close();
}
@Test
public void connectPubSub() {
void connectPubSub() {
StatefulRedisPubSubConnection<String, String> conn = client.connectPubSub();
conn.sync().ping();
conn.close();
}
@Test
public void codecConnectPubSub() {
void codecConnectPubSub() {
StatefulRedisPubSubConnection<byte[], byte[]> conn = client.connectPubSub(LettuceConnection.CODEC);
conn.sync().ping();
conn.close();

View File

@@ -26,9 +26,8 @@ import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.After;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.PoolException;
@@ -43,12 +42,12 @@ import org.springframework.data.redis.test.extension.LettuceTestClientResources;
* @author Christoph Strobl
* @author Mark Paluch
*/
public class DefaultLettucePoolTests {
class DefaultLettucePoolTests {
private DefaultLettucePool pool;
@After
public void tearDown() {
@AfterEach
void tearDown() {
if (pool != null) {
@@ -61,7 +60,7 @@ public class DefaultLettucePoolTests {
}
@Test
public void testGetResource() {
void testGetResource() {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -73,7 +72,7 @@ public class DefaultLettucePoolTests {
}
@Test
public void testGetResourcePoolExhausted() {
void testGetResourcePoolExhausted() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
@@ -92,7 +91,7 @@ public class DefaultLettucePoolTests {
}
@Test
public void testGetResourceValidate() {
void testGetResourceValidate() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setTestOnBorrow(true);
@@ -104,17 +103,17 @@ public class DefaultLettucePoolTests {
client.close();
}
@Test(expected = PoolException.class)
public void testGetResourceCreationUnsuccessful() throws Exception {
@Test
void testGetResourceCreationUnsuccessful() throws Exception {
pool = new DefaultLettucePool(SettingsUtils.getHost(), 3333);
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
pool.getResource();
assertThatExceptionOfType(PoolException.class).isThrownBy(() -> pool.getResource());
}
@Test
public void testReturnResource() {
void testReturnResource() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
@@ -130,7 +129,7 @@ public class DefaultLettucePoolTests {
}
@Test
public void testReturnBrokenResource() {
void testReturnBrokenResource() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
poolConfig.setMaxTotal(1);
@@ -153,7 +152,7 @@ public class DefaultLettucePoolTests {
}
@Test
public void testCreateWithDbIndex() {
void testCreateWithDbIndex() {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -162,42 +161,18 @@ public class DefaultLettucePoolTests {
assertThat(pool.getResource()).isNotNull();
}
@Test(expected = PoolException.class)
public void testCreateWithDbIndexInvalid() {
@Test
void testCreateWithDbIndexInvalid() {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.setDatabase(17);
pool.afterPropertiesSet();
pool.getResource();
}
@Ignore("Redis must have requirepass set to run this test")
@Test
public void testCreatePassword() {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.setPassword("foo");
pool.afterPropertiesSet();
StatefulRedisConnection<byte[], byte[]> client = (StatefulRedisConnection<byte[], byte[]>) pool.getResource();
client.sync().ping();
client.sync().getStatefulConnection().close();
}
@Ignore("Redis must have requirepass set to run this test")
@Test(expected = PoolException.class)
public void testCreateInvalidPassword() {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.setPassword("bad");
pool.afterPropertiesSet();
pool.getResource();
assertThatExceptionOfType(PoolException.class).isThrownBy(() -> pool.getResource());
}
@Test // DATAREDIS-524
public void testCreateSentinelWithPassword() {
void testCreateSentinelWithPassword() {
pool = new DefaultLettucePool(new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234")));
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -210,7 +185,7 @@ public class DefaultLettucePoolTests {
}
@Test // DATAREDIS-462
public void poolWorksWithoutClientResources() {
void poolWorksWithoutClientResources() {
pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setDatabase(1);

View File

@@ -23,19 +23,17 @@ import io.lettuce.core.protocol.ProtocolVersion;
import java.io.IOException;
import java.util.Collections;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.rules.RuleChain;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.condition.EnabledOnRedisAvailable;
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.ServerAvailable;
/**
* Integration tests for Redis 6 ACL.
@@ -43,13 +41,12 @@ import org.springframework.data.redis.test.util.ServerAvailable;
* @author Mark Paluch
* @author Christoph Strobl
*/
public class LettuceAclIntegrationTests {
@ClassRule public static RuleChain requirements = RuleChain.outerRule(ServerAvailable.runningAtLocalhost(6382))
.around(new MinimumRedisVersionRule());
@EnabledOnRedisAvailable(6382)
@EnabledOnCommand("HELLO")
class LettuceAclIntegrationTests {
@Test // DATAREDIS-1046
public void shouldConnectWithDefaultAuthentication() {
void shouldConnectWithDefaultAuthentication() {
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
standaloneConfiguration.setPassword("foobared");
@@ -67,7 +64,7 @@ public class LettuceAclIntegrationTests {
}
@Test // DATAREDIS-1046
public void shouldConnectStandaloneWithAclAuthentication() {
void shouldConnectStandaloneWithAclAuthentication() {
RedisStandaloneConfiguration standaloneConfiguration = new RedisStandaloneConfiguration("localhost", 6382);
standaloneConfiguration.setUsername("spring");
@@ -86,10 +83,8 @@ public class LettuceAclIntegrationTests {
}
@Test // DATAREDIS-1145
public void shouldConnectSentinelWithAuthentication() throws IOException {
Assume.assumeTrue("Redis Sentinel at localhost:26382 did not answer.",
ServerAvailable.runningAtLocalhost(26382).isAvailable());
@EnabledOnRedisSentinelAvailable(26382)
void shouldConnectSentinelWithAuthentication() throws IOException {
// Note: As per https://github.com/redis/redis/issues/7708, Sentinel does not support ACL authentication yet.
@@ -113,8 +108,7 @@ public class LettuceAclIntegrationTests {
}
@Test // DATAREDIS-1046
@Ignore("https://github.com/lettuce-io/lettuce-core/issues/1406")
public void shouldConnectMasterReplicaWithAclAuthentication() {
void shouldConnectMasterReplicaWithAclAuthentication() {
RedisStaticMasterReplicaConfiguration masterReplicaConfiguration = new RedisStaticMasterReplicaConfiguration(
"localhost", 6382);

View File

@@ -20,10 +20,10 @@ import static org.assertj.core.api.Assertions.*;
import io.lettuce.core.ClientOptions;
import io.lettuce.core.TimeoutOptions;
import io.lettuce.core.resource.ClientResources;
import org.junit.jupiter.api.Test;
import java.time.Duration;
import org.junit.Test;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
@@ -34,10 +34,10 @@ import org.springframework.data.redis.test.extension.LettuceTestClientResources;
* @author Christoph Strobl
* @author Yanming Zhou
*/
public class LettuceClientConfigurationUnitTests {
class LettuceClientConfigurationUnitTests {
@Test // DATAREDIS-574, DATAREDIS-576, DATAREDIS-667, DATAREDIS-918
public void shouldCreateEmptyConfiguration() {
void shouldCreateEmptyConfiguration() {
LettuceClientConfiguration configuration = LettuceClientConfiguration.defaultConfiguration();
@@ -58,7 +58,7 @@ public class LettuceClientConfigurationUnitTests {
}
@Test // DATAREDIS-574, DATAREDIS-576, DATAREDIS-667
public void shouldConfigureAllProperties() {
void shouldConfigureAllProperties() {
ClientOptions clientOptions = ClientOptions.create();
ClientResources sharedClientResources = LettuceTestClientResources.getSharedClientResources();
@@ -87,7 +87,7 @@ public class LettuceClientConfigurationUnitTests {
}
@Test // DATAREDIS-881
public void shutdownQuietPeriodShouldDefaultToTimeout() {
void shutdownQuietPeriodShouldDefaultToTimeout() {
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
.shutdownTimeout(Duration.ofSeconds(42)).build();
@@ -97,12 +97,12 @@ public class LettuceClientConfigurationUnitTests {
}
@Test // DATAREDIS-576
public void clientConfigurationThrowsExceptionForNullClientName() {
void clientConfigurationThrowsExceptionForNullClientName() {
assertThatIllegalArgumentException().isThrownBy(() -> LettuceClientConfiguration.builder().clientName(null));
}
@Test // DATAREDIS-576
public void clientConfigurationThrowsExceptionForEmptyClientName() {
void clientConfigurationThrowsExceptionForEmptyClientName() {
assertThatIllegalArgumentException().isThrownBy(() -> LettuceClientConfiguration.builder().clientName(" "));
}
}

View File

@@ -29,7 +29,7 @@ import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import io.lettuce.core.codec.ByteArrayCodec;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.TimeUnit;
@@ -57,15 +57,13 @@ import org.springframework.data.redis.connection.RedisZSetCommands.Range;
import org.springframework.data.redis.connection.RedisZSetCommands.Tuple;
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
import org.springframework.data.redis.connection.jedis.JedisConverters;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.core.Cursor;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
import org.springframework.data.redis.test.extension.LettuceExtension;
import org.springframework.data.redis.test.extension.RedisCluster;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.util.HexStringUtils;
import org.springframework.test.annotation.IfProfileValue;
/**
* @author Christoph Strobl
@@ -94,13 +92,13 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
private static final GeoLocation<String> PALERMO = new GeoLocation<>("palermo", POINT_PALERMO);
private static final GeoLocation<byte[]> ARIGENTO_BYTES = new GeoLocation<>(
"arigento".getBytes(Charset.forName("UTF-8")),
"arigento".getBytes(StandardCharsets.UTF_8),
POINT_ARIGENTO);
private static final GeoLocation<byte[]> CATANIA_BYTES = new GeoLocation<>(
"catania".getBytes(Charset.forName("UTF-8")),
"catania".getBytes(StandardCharsets.UTF_8),
POINT_CATANIA);
private static final GeoLocation<byte[]> PALERMO_BYTES = new GeoLocation<>(
"palermo".getBytes(Charset.forName("UTF-8")),
"palermo".getBytes(StandardCharsets.UTF_8),
POINT_PALERMO);
private final RedisClusterClient client;
@@ -118,7 +116,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
@BeforeEach
void setUp() {
nativeConnection.getStatefulConnection().async().flushallAsync();
nativeConnection.getStatefulConnection().sync().flushallAsync();
}
@AfterAll
@@ -140,6 +138,18 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
}
private static LettuceConnectionFactory createConnectionFactory() {
LettucePoolingClientConfiguration clientConfiguration = LettucePoolingClientConfiguration.builder() //
.clientResources(LettuceTestClientResources.getSharedClientResources()) //
.shutdownTimeout(Duration.ZERO) //
.build();
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.addClusterNode(ClusterTestVariables.CLUSTER_NODE_1);
return new LettuceConnectionFactory(clusterConfiguration, clientConfiguration);
}
@Test // DATAREDIS-775
void shouldCreateConnectionWithPooling() {
@@ -168,9 +178,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
factory.destroy();
}
private static LettuceConnectionFactory createConnectionFactory() {
return LettuceConnectionFactoryExtension.getConnectionFactory(RedisCluster.class);
}
@Test // DATAREDIS-315
public void appendShouldAddValueCorrectly() {
@@ -492,20 +499,17 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddMultipleGeoLocations() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES,
Arrays.asList(PALERMO_BYTES, ARIGENTO_BYTES, CATANIA_BYTES, PALERMO_BYTES))).isEqualTo(3L);
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoAddSingleGeoLocation() {
assertThat(clusterConnection.geoAdd(KEY_1_BYTES, PALERMO_BYTES)).isEqualTo(1L);
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDist() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -518,7 +522,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoDistWithMetric() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -533,7 +536,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoHash() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -544,7 +546,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoHashNonExisting() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -556,7 +557,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPosition() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -572,7 +572,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoPositionNonExisting() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -591,7 +590,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldApplyLimit() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -605,7 +603,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -621,7 +618,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -636,7 +632,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldApplyLimit() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -650,7 +645,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnDistanceCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -666,7 +660,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRadiusShouldReturnMembersCorrectly() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -679,7 +672,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-438
@IfProfileValue(name = "redisVersion", value = "3.2+")
public void geoRemoveDeletesMembers() {
nativeConnection.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO.getName());
@@ -1073,7 +1065,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void lPushNXShoultNotAddValuesWhenKeyDoesNotExist() {
public void lPushNXShouldNotAddValuesWhenKeyDoesNotExist() {
clusterConnection.lPushX(KEY_1_BYTES, VALUE_1_BYTES);
@@ -1081,7 +1073,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void lPushShoultAddValuesCorrectly() {
public void lPushShouldAddValuesCorrectly() {
clusterConnection.lPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES);
@@ -1402,7 +1394,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void rPushNXShoultNotAddValuesWhenKeyDoesNotExist() {
public void rPushNXShouldNotAddValuesWhenKeyDoesNotExist() {
clusterConnection.rPushX(KEY_1_BYTES, VALUE_1_BYTES);
@@ -1410,7 +1402,7 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-315
public void rPushShoultAddValuesCorrectly() {
public void rPushShouldAddValuesCorrectly() {
clusterConnection.rPush(KEY_1_BYTES, VALUE_1_BYTES, VALUE_2_BYTES);
@@ -2404,7 +2396,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldSetShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2414,7 +2405,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldGetShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2422,7 +2412,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldIncrByShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2430,7 +2419,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2447,7 +2435,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitfieldShouldAllowMultipleSubcommands() {
assertThat(clusterConnection.stringCommands().bitField(JedisConverters.toBytes(KEY_1),
@@ -2456,7 +2443,6 @@ public class LettuceClusterConnectionTests implements ClusterConnectionTests {
}
@Test // DATAREDIS-562
@IfProfileValue(name = "redisVersion", value = "3.2+")
void bitfieldShouldWorkUsingNonZeroBasedOffset() {
assertThat(

View File

@@ -38,11 +38,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.redis.connection.ClusterCommandExecutor;
import org.springframework.data.redis.connection.ClusterNodeResourceProvider;
@@ -54,16 +56,17 @@ import org.springframework.data.redis.connection.RedisClusterNode;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.Silent.class)
public class LettuceClusterConnectionUnitTests {
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class LettuceClusterConnectionUnitTests {
static final byte[] KEY_1_BYTES = KEY_1.getBytes();
private static final byte[] KEY_1_BYTES = KEY_1.getBytes();
static final byte[] VALUE_1_BYTES = VALUE_1.getBytes();
static final byte[] KEY_2_BYTES = KEY_2.getBytes();
private static final byte[] KEY_2_BYTES = KEY_2.getBytes();
static final byte[] KEY_3_BYTES = KEY_3.getBytes();
private static final byte[] KEY_3_BYTES = KEY_3.getBytes();
@Mock RedisClusterClient clusterMock;
@Mock ClusterTopologyProvider topologyProviderMock;
@@ -77,10 +80,10 @@ public class LettuceClusterConnectionUnitTests {
@Mock RedisClusterCommands<byte[], byte[]> clusterConnection2Mock;
@Mock RedisClusterCommands<byte[], byte[]> clusterConnection3Mock;
LettuceClusterConnection connection;
private LettuceClusterConnection connection;
@Before
public void setUp() {
@BeforeEach
void setUp() {
Partitions partitions = new Partitions();
@@ -131,12 +134,12 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void thowsExceptionWhenClusterCommandExecturorIsNull() {
void thowsExceptionWhenClusterCommandExecturorIsNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new LettuceClusterConnection(clusterMock, null));
}
@Test // DATAREDIS-315
public void clusterMeetShouldSendCommandsToExistingNodesCorrectly() {
void clusterMeetShouldSendCommandsToExistingNodesCorrectly() {
connection.clusterMeet(UNKNOWN_CLUSTER_NODE);
@@ -149,12 +152,12 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterMeetShouldThrowExceptionWhenNodeIsNull() {
void clusterMeetShouldThrowExceptionWhenNodeIsNull() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.clusterMeet(null));
}
@Test // DATAREDIS-315
public void clusterForgetShouldSendCommandsToRemainingNodesCorrectly() {
void clusterForgetShouldSendCommandsToRemainingNodesCorrectly() {
connection.clusterForget(CLUSTER_NODE_2);
@@ -164,7 +167,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterReplicateShouldSendCommandsCorrectly() {
void clusterReplicateShouldSendCommandsCorrectly() {
connection.clusterReplicate(CLUSTER_NODE_1, CLUSTER_NODE_2);
@@ -173,7 +176,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void closeShouldNotCloseUnderlyingClusterPool() throws IOException {
void closeShouldNotCloseUnderlyingClusterPool() throws IOException {
connection.close();
@@ -181,7 +184,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void isClosedShouldReturnConnectionStateCorrectly() {
void isClosedShouldReturnConnectionStateCorrectly() {
assertThat(connection.isClosed()).isFalse();
@@ -191,7 +194,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void keysShouldBeRunOnAllClusterNodes() {
void keysShouldBeRunOnAllClusterNodes() {
when(clusterConnection1Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
@@ -207,7 +210,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void keysShouldOnlyBeRunOnDedicatedNodeWhenPinned() {
void keysShouldOnlyBeRunOnDedicatedNodeWhenPinned() {
when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections.<byte[]> emptyList());
@@ -221,7 +224,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void randomKeyShouldReturnAnyKeyFromRandomNode() {
void randomKeyShouldReturnAnyKeyFromRandomNode() {
when(clusterConnection1Mock.randomkey()).thenReturn(KEY_1_BYTES);
when(clusterConnection2Mock.randomkey()).thenReturn(KEY_2_BYTES);
@@ -233,7 +236,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void randomKeyShouldReturnKeyWhenAvailableOnAnyNode() {
void randomKeyShouldReturnKeyWhenAvailableOnAnyNode() {
when(clusterConnection3Mock.randomkey()).thenReturn(KEY_3_BYTES);
@@ -243,7 +246,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void randomKeyShouldReturnNullWhenNoKeysPresentOnAllNodes() {
void randomKeyShouldReturnNullWhenNoKeysPresentOnAllNodes() {
when(clusterConnection1Mock.randomkey()).thenReturn(null);
when(clusterConnection2Mock.randomkey()).thenReturn(null);
@@ -253,7 +256,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterSetSlotImportingShouldBeExecutedCorrectly() {
void clusterSetSlotImportingShouldBeExecutedCorrectly() {
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.IMPORTING);
@@ -261,7 +264,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterSetSlotMigratingShouldBeExecutedCorrectly() {
void clusterSetSlotMigratingShouldBeExecutedCorrectly() {
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.MIGRATING);
@@ -269,7 +272,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterSetSlotStableShouldBeExecutedCorrectly() {
void clusterSetSlotStableShouldBeExecutedCorrectly() {
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.STABLE);
@@ -277,7 +280,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterSetSlotNodeShouldBeExecutedCorrectly() {
void clusterSetSlotNodeShouldBeExecutedCorrectly() {
connection.clusterSetSlot(CLUSTER_NODE_1, 100, AddSlots.NODE);
@@ -285,7 +288,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterSetSlotShouldBeExecutedOnTargetNodeWhenNodeIdNotSet() {
void clusterSetSlotShouldBeExecutedOnTargetNodeWhenNodeIdNotSet() {
connection.clusterSetSlot(new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT), 100, AddSlots.IMPORTING);
@@ -293,12 +296,12 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterSetSlotShouldThrowExceptionWhenModeIsNull() {
void clusterSetSlotShouldThrowExceptionWhenModeIsNull() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.clusterSetSlot(CLUSTER_NODE_1, 100, null));
}
@Test // DATAREDIS-315
public void clusterDeleteSlotsShouldBeExecutedCorrectly() {
void clusterDeleteSlotsShouldBeExecutedCorrectly() {
int[] slots = new int[] { 9000, 10000 };
connection.clusterDeleteSlots(CLUSTER_NODE_2, slots);
@@ -307,12 +310,12 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void clusterDeleteSlotShouldThrowExceptionWhenNodeIsNull() {
void clusterDeleteSlotShouldThrowExceptionWhenNodeIsNull() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.clusterDeleteSlots(null, new int[] { 1 }));
}
@Test // DATAREDIS-315
public void timeShouldBeExecutedOnArbitraryNode() {
void timeShouldBeExecutedOnArbitraryNode() {
List<byte[]> values = Arrays.asList("1449655759".getBytes(), "92217".getBytes());
when(clusterConnection1Mock.time()).thenReturn(values);
@@ -325,7 +328,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void timeShouldBeExecutedOnSingleNode() {
void timeShouldBeExecutedOnSingleNode() {
when(clusterConnection2Mock.time()).thenReturn(Arrays.asList("1449655759".getBytes(), "92217".getBytes()));
@@ -336,7 +339,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void resetConfigStatsShouldBeExecutedOnAllNodes() {
void resetConfigStatsShouldBeExecutedOnAllNodes() {
connection.resetConfigStats();
@@ -346,7 +349,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-315
public void resetConfigStatsShouldBeExecutedOnSingleNodeCorrectly() {
void resetConfigStatsShouldBeExecutedOnSingleNodeCorrectly() {
connection.resetConfigStats(CLUSTER_NODE_2);
@@ -356,7 +359,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-731, DATAREDIS-545
public void shouldExecuteOnSharedConnection() {
void shouldExecuteOnSharedConnection() {
RedisAdvancedClusterCommands<byte[], byte[]> sync = mock(RedisAdvancedClusterCommands.class);
@@ -372,7 +375,7 @@ public class LettuceClusterConnectionUnitTests {
}
@Test // DATAREDIS-731, DATAREDIS-545
public void shouldExecuteOnDedicatedConnection() {
void shouldExecuteOnDedicatedConnection() {
RedisCommands<byte[], byte[]> sync = mock(RedisCommands.class);
StatefulRedisConnection<byte[], byte[]> dedicatedConnection = mock(StatefulRedisConnection.class);

View File

@@ -32,19 +32,20 @@ import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.ClusterCommandExecutor;
import org.springframework.data.redis.connection.ClusterTopologyProvider;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisClusterConnection;
import org.springframework.data.redis.connection.RedisConfiguration;
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.lang.Nullable;
/**
@@ -52,23 +53,25 @@ import org.springframework.lang.Nullable;
*
* @author Mark Paluch
*/
public class LettuceClusterKeyspaceNotificationsTests {
@EnabledOnRedisClusterAvailable
class LettuceClusterKeyspaceNotificationsTests {
@ClassRule public static RedisClusterRule clusterRule = new RedisClusterRule();
CustomLettuceConnectionFactory factory;
String keyspaceConfig;
private static CustomLettuceConnectionFactory factory;
private String keyspaceConfig;
// maps to 127.0.0.1:7381/slot hash 13477
String key = "10923";
private String key = "10923";
@Before
public void before() {
@BeforeAll
static void beforeAll() throws Exception {
factory = new CustomLettuceConnectionFactory(clusterRule.getConfiguration());
factory = new CustomLettuceConnectionFactory(SettingsUtils.clusterConfiguration());
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
ConnectionFactoryTracker.add(factory);
factory.afterPropertiesSet();
}
@BeforeEach
void before() {
// enable keyspace events on a specific node.
withConnection("127.0.0.1", 7381, commands -> {
@@ -80,8 +83,8 @@ public class LettuceClusterKeyspaceNotificationsTests {
assertThat(SlotHash.getSlot(key)).isEqualTo(13477);
}
@After
public void tearDown() {
@AfterEach
void tearDown() {
// Restore previous settings.
withConnection("127.0.0.1", 7381, commands -> {
@@ -89,8 +92,13 @@ public class LettuceClusterKeyspaceNotificationsTests {
});
}
@AfterAll
static void afterAll() {
factory.destroy();
}
@Test // DATAREDIS-976
public void shouldListenForKeyspaceNotifications() throws Exception {
void shouldListenForKeyspaceNotifications() throws Exception {
CompletableFuture<String> expiry = new CompletableFuture<>();

View File

@@ -33,11 +33,10 @@ import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisConnectionFailureException;
@@ -48,6 +47,7 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.RedisStaticMasterReplicaConfiguration;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
/**
@@ -58,39 +58,37 @@ import org.springframework.data.redis.test.extension.LettuceTestClientResources;
* @author Christoph Strobl
* @author Mark Paluch
*/
public class LettuceConnectionFactoryTests {
@ExtendWith(LettuceConnectionFactoryExtension.class)
class LettuceConnectionFactoryTests {
private LettuceConnectionFactory factory;
private StringRedisConnection connection;
@Before
public void setUp() {
@BeforeEach
void setUp() {
factory = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory = new LettuceConnectionFactory(SettingsUtils.standaloneConfiguration());
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory.afterPropertiesSet();
factory.setShutdownTimeout(0);
connection = new DefaultStringRedisConnection(factory.getConnection());
}
@After
public void tearDown() {
factory.destroy();
@AfterEach
void tearDown() {
if (connection != null) {
connection.close();
}
factory.destroy();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@SuppressWarnings("rawtypes")
@Test
public void testGetNewConnectionOnError() throws Exception {
void testGetNewConnectionOnError() throws Exception {
factory.setValidateConnection(true);
connection.lPush("alist", "baz");
RedisAsyncCommands nativeConn = (RedisAsyncCommands) connection.getNativeConnection();
@@ -113,7 +111,7 @@ public class LettuceConnectionFactoryTests {
@SuppressWarnings("rawtypes")
@Test
public void testConnectionErrorNoValidate() throws Exception {
void testConnectionErrorNoValidate() throws Exception {
connection.lPush("ablist", "baz");
((RedisAsyncCommands) connection.getNativeConnection()).getStatefulConnection().close();
// Give some time for async channel close
@@ -130,14 +128,14 @@ public class LettuceConnectionFactoryTests {
}
@Test
public void testValidateNoError() {
void testValidateNoError() {
factory.setValidateConnection(true);
RedisConnection conn2 = factory.getConnection();
assertThat(conn2.getNativeConnection()).isSameAs(connection.getNativeConnection());
}
@Test // DATAREDIS-973
public void testSelectDb() {
void testSelectDb() {
// put an item in database 0
connection.set("sometestkey", "sometestvalue");
@@ -153,7 +151,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-973
public void testSelectDbReactive() {
void testSelectDbReactive() {
LettuceConnectionFactory sharingConnectionFactory = newConnectionFactory(cf -> cf.setDatabase(1));
runSelectDbReactiveTest(sharingConnectionFactory);
@@ -223,7 +221,7 @@ public class LettuceConnectionFactoryTests {
@SuppressWarnings("unchecked")
@Test
public void testDisableSharedConnection() throws Exception {
void testDisableSharedConnection() throws Exception {
factory.setShareNativeConnection(false);
RedisConnection conn2 = factory.getConnection();
assertThat(conn2.getNativeConnection()).isNotSameAs(connection.getNativeConnection());
@@ -244,7 +242,7 @@ public class LettuceConnectionFactoryTests {
@SuppressWarnings("unchecked")
@Test
public void testResetConnection() {
void testResetConnection() {
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
.getNativeConnection();
factory.resetConnection();
@@ -254,7 +252,7 @@ public class LettuceConnectionFactoryTests {
@SuppressWarnings("unchecked")
@Test
public void testInitConnection() {
void testInitConnection() {
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
.getNativeConnection();
factory.initConnection();
@@ -265,7 +263,7 @@ public class LettuceConnectionFactoryTests {
@SuppressWarnings("unchecked")
@Test
public void testResetAndInitConnection() {
void testResetAndInitConnection() {
RedisAsyncCommands<byte[], byte[]> nativeConn = (RedisAsyncCommands<byte[], byte[]>) connection
.getNativeConnection();
factory.resetConnection();
@@ -276,7 +274,7 @@ public class LettuceConnectionFactoryTests {
}
@Test
public void testGetConnectionException() {
void testGetConnectionException() {
factory.resetConnection();
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
@@ -287,7 +285,7 @@ public class LettuceConnectionFactoryTests {
}
@Test
public void testGetConnectionNotSharedBadHostname() {
void testGetConnectionNotSharedBadHostname() {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
@@ -295,7 +293,7 @@ public class LettuceConnectionFactoryTests {
}
@Test
public void testGetSharedConnectionNotShared() {
void testGetSharedConnectionNotShared() {
factory.setShareNativeConnection(false);
factory.setHostName("fakeHost");
factory.afterPropertiesSet();
@@ -303,7 +301,7 @@ public class LettuceConnectionFactoryTests {
}
@Test
public void testCreateFactoryWithPool() {
void testCreateFactoryWithPool() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
@@ -319,20 +317,8 @@ public class LettuceConnectionFactoryTests {
pool.destroy();
}
@Ignore("Redis must have requirepass set to run this test")
@Test
public void testConnectWithPassword() {
factory.setPassword("foo");
factory.afterPropertiesSet();
RedisConnection conn = factory.getConnection();
// Test shared and dedicated conns
conn.ping();
conn.bLPop(1, "key".getBytes());
conn.close();
}
@Test // DATAREDIS-431
public void dbIndexShouldBePropagatedCorrectly() {
void dbIndexShouldBePropagatedCorrectly() {
LettuceConnectionFactory factory = new LettuceConnectionFactory();
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -356,7 +342,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-462
public void factoryWorksWithoutClientResources() {
void factoryWorksWithoutClientResources() {
LettuceConnectionFactory factory = new LettuceConnectionFactory();
factory.setShutdownTimeout(0);
@@ -374,7 +360,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-525
public void factoryShouldReturnReactiveConnectionWhenCorrectly() {
void factoryShouldReturnReactiveConnectionWhenCorrectly() {
LettuceConnectionFactory factory = new LettuceConnectionFactory();
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -386,7 +372,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-667
public void factoryCreatesPooledConnections() {
void factoryCreatesPooledConnections() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
@@ -415,7 +401,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-687
public void connectsThroughRedisSocket() {
void connectsThroughRedisSocket() {
assumeTrue(EpollProvider.isAvailable() || KqueueProvider.isAvailable());
assumeTrue(new File(SettingsUtils.getSocket()).exists());
@@ -435,7 +421,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterReplicaConnections() {
void factoryUsesElastiCacheMasterReplicaConnections() {
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
@@ -462,7 +448,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-1093
public void pubSubDoesNotSupportMasterReplicaConnections() {
void pubSubDoesNotSupportMasterReplicaConnections() {
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
@@ -485,7 +471,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterWithoutMaster() {
void factoryUsesElastiCacheMasterWithoutMaster() {
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
@@ -516,7 +502,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-580, DATAREDIS-869
public void factoryUsesMasterReplicaConnections() {
void factoryUsesMasterReplicaConnections() {
assumeTrue(String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0);
@@ -541,7 +527,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-576
public void connectionAppliesClientName() {
void connectionAppliesClientName() {
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).clientName("clientName").build();
@@ -559,7 +545,7 @@ public class LettuceConnectionFactoryTests {
}
@Test // DATAREDIS-576
public void getClientNameShouldEqualWithFactorySetting() {
void getClientNameShouldEqualWithFactorySetting() {
LettuceConnectionFactory factory = new LettuceConnectionFactory(new RedisStandaloneConfiguration());
factory.setClientResources(LettuceTestClientResources.getSharedClientResources());

View File

@@ -42,10 +42,11 @@ import java.time.Duration;
import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentMatchers;
import org.springframework.beans.DirectFieldAccessor;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.data.redis.ConnectionFactoryTracker;
@@ -72,22 +73,22 @@ import org.springframework.test.util.ReflectionTestUtils;
* @author Luis De Bello
* @author Andrea Como
*/
public class LettuceConnectionFactoryUnitTests {
class LettuceConnectionFactoryUnitTests {
RedisClusterConfiguration clusterConfig;
private RedisClusterConfiguration clusterConfig;
@Before
public void setUp() {
@BeforeEach
void setUp() {
clusterConfig = new RedisClusterConfiguration().clusterNode("127.0.0.1", 6379).clusterNode("127.0.0.1", 6380);
}
@After
public void tearDown() {
@AfterEach
void tearDown() {
ConnectionFactoryTracker.cleanUp();
}
@Test // DATAREDIS-315
public void shouldInitClientCorrectlyWhenClusterConfigPresent() {
void shouldInitClientCorrectlyWhenClusterConfigPresent() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setClientResources(getSharedClientResources());
@@ -99,7 +100,7 @@ public class LettuceConnectionFactoryUnitTests {
@Test // DATAREDIS-315
@SuppressWarnings("unchecked")
public void timeoutShouldBeSetCorrectlyOnClusterClient() {
void timeoutShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setClientResources(getSharedClientResources());
@@ -118,7 +119,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-930
public void portShouldBeReturnedProperlyBasedOnConfiguration() {
void portShouldBeReturnedProperlyBasedOnConfiguration() {
RedisConfiguration redisConfiguration = new RedisStandaloneConfiguration("localhost", 16379);
@@ -129,7 +130,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-930
public void portShouldBeReturnedProperlyBasedOnCustomRedisConfiguration() {
void portShouldBeReturnedProperlyBasedOnCustomRedisConfiguration() {
RedisConfiguration redisConfiguration = new CustomRedisConfiguration("localhost", 16379);
@@ -141,7 +142,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-930
public void hostNameShouldBeReturnedProperlyBasedOnConfiguration() {
void hostNameShouldBeReturnedProperlyBasedOnConfiguration() {
RedisConfiguration redisConfiguration = new RedisStandaloneConfiguration("external");
@@ -152,7 +153,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-930
public void hostNameShouldBeReturnedProperlyBasedOnCustomRedisConfiguration() {
void hostNameShouldBeReturnedProperlyBasedOnCustomRedisConfiguration() {
RedisConfiguration redisConfiguration = new CustomRedisConfiguration("external");
@@ -165,7 +166,7 @@ public class LettuceConnectionFactoryUnitTests {
@Test // DATAREDIS-315
@SuppressWarnings("unchecked")
public void passwordShouldBeSetCorrectlyOnClusterClient() {
void passwordShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setClientResources(getSharedClientResources());
@@ -184,7 +185,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-524, DATAREDIS-1045, DATAREDIS-1060
public void passwordShouldNotBeSetOnSentinelClient() {
void passwordShouldNotBeSetOnSentinelClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(
new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234")));
@@ -206,7 +207,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-1060
public void sentinelPasswordShouldBeSetOnSentinelClient() {
void sentinelPasswordShouldBeSetOnSentinelClient() {
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234"));
config.setSentinelPassword("sentinel-pwd");
@@ -230,7 +231,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-1060
public void sentinelPasswordShouldNotLeakIntoDataNodeClient() {
void sentinelPasswordShouldNotLeakIntoDataNodeClient() {
RedisSentinelConfiguration config = new RedisSentinelConfiguration("mymaster", Collections.singleton("host:1234"));
config.setSentinelPassword("sentinel-pwd");
@@ -253,7 +254,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-462
public void clusterClientShouldInitializeWithoutClientResources() {
void clusterClientShouldInitializeWithoutClientResources() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setShutdownTimeout(0);
@@ -265,7 +266,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-480
public void sslOptionsShouldBeDisabledByDefaultOnClient() {
void sslOptionsShouldBeDisabledByDefaultOnClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setClientResources(getSharedClientResources());
@@ -286,7 +287,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-476
public void sslShouldBeSetCorrectlyOnClient() {
void sslShouldBeSetCorrectlyOnClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setClientResources(getSharedClientResources());
@@ -306,7 +307,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-480
public void verifyPeerOptionShouldBeSetCorrectlyOnClient() {
void verifyPeerOptionShouldBeSetCorrectlyOnClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setClientResources(getSharedClientResources());
@@ -324,7 +325,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-480
public void startTLSOptionShouldBeSetCorrectlyOnClient() {
void startTLSOptionShouldBeSetCorrectlyOnClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setClientResources(getSharedClientResources());
@@ -342,7 +343,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-990
public void sslShouldBeSetCorrectlyOnSentinelClient() {
void sslShouldBeSetCorrectlyOnSentinelClient() {
RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration("myMaster",
Collections.singleton("localhost:1234"));
@@ -364,7 +365,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-990
public void verifyPeerOptionShouldBeSetCorrectlyOnSentinelClient() {
void verifyPeerOptionShouldBeSetCorrectlyOnSentinelClient() {
RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration("myMaster",
Collections.singleton("localhost:1234"));
@@ -384,7 +385,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-990
public void startTLSOptionShouldBeSetCorrectlyOnSentinelClient() {
void startTLSOptionShouldBeSetCorrectlyOnSentinelClient() {
RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration("myMaster",
Collections.singleton("localhost:1234"));
@@ -404,7 +405,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-537
public void sslShouldBeSetCorrectlyOnClusterClient() {
void sslShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(
new RedisClusterConfiguration().clusterNode(CLUSTER_NODE_1));
@@ -424,7 +425,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-537
public void startTLSOptionShouldBeSetCorrectlyOnClusterClient() {
void startTLSOptionShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(
new RedisClusterConfiguration().clusterNode(CLUSTER_NODE_1));
@@ -444,7 +445,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-537
public void verifyPeerTLSOptionShouldBeSetCorrectlyOnClusterClient() {
void verifyPeerTLSOptionShouldBeSetCorrectlyOnClusterClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(
new RedisClusterConfiguration().clusterNode(CLUSTER_NODE_1));
@@ -464,7 +465,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-682
public void socketShouldBeSetOnStandaloneClient() {
void socketShouldBeSetOnStandaloneClient() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(new RedisSocketConfiguration());
connectionFactory.afterPropertiesSet();
@@ -479,7 +480,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReadStandalonePassword() {
void shouldReadStandalonePassword() {
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -491,7 +492,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldWriteStandalonePassword() {
void shouldWriteStandalonePassword() {
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -505,7 +506,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReadSentinelPassword() {
void shouldReadSentinelPassword() {
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -517,7 +518,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldWriteSentinelPassword() {
void shouldWriteSentinelPassword() {
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -531,7 +532,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-682
public void shouldWriteSocketPassword() {
void shouldWriteSocketPassword() {
RedisSocketConfiguration envConfig = new RedisSocketConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -545,7 +546,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReadClusterPassword() {
void shouldReadClusterPassword() {
RedisClusterConfiguration envConfig = new RedisClusterConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -557,7 +558,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldWriteClusterPassword() {
void shouldWriteClusterPassword() {
RedisClusterConfiguration envConfig = new RedisClusterConfiguration();
envConfig.setPassword(RedisPassword.of("foo"));
@@ -571,7 +572,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReadStandaloneDatabaseIndex() {
void shouldReadStandaloneDatabaseIndex() {
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
envConfig.setDatabase(2);
@@ -583,7 +584,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldWriteStandaloneDatabaseIndex() {
void shouldWriteStandaloneDatabaseIndex() {
RedisStandaloneConfiguration envConfig = new RedisStandaloneConfiguration();
envConfig.setDatabase(2);
@@ -597,7 +598,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReadSentinelDatabaseIndex() {
void shouldReadSentinelDatabaseIndex() {
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
envConfig.setDatabase(2);
@@ -609,7 +610,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldWriteSentinelDatabaseIndex() {
void shouldWriteSentinelDatabaseIndex() {
RedisSentinelConfiguration envConfig = new RedisSentinelConfiguration();
envConfig.setDatabase(2);
@@ -623,7 +624,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-682
public void shouldWriteSocketDatabaseIndex() {
void shouldWriteSocketDatabaseIndex() {
RedisSocketConfiguration envConfig = new RedisSocketConfiguration();
envConfig.setDatabase(2);
@@ -637,7 +638,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldApplyClientConfiguration() {
void shouldApplyClientConfiguration() {
ClientOptions clientOptions = ClientOptions.create();
ClientResources sharedClientResources = LettuceTestClientResources.getSharedClientResources();
@@ -666,7 +667,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReturnStandaloneConfiguration() {
void shouldReturnStandaloneConfiguration() {
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration();
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration,
@@ -678,7 +679,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-682
public void shouldReturnSocketConfiguration() {
void shouldReturnSocketConfiguration() {
RedisSocketConfiguration configuration = new RedisSocketConfiguration("/var/redis/socket");
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration,
@@ -691,7 +692,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReturnSentinelConfiguration() {
void shouldReturnSentinelConfiguration() {
RedisSentinelConfiguration configuration = new RedisSentinelConfiguration();
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration,
@@ -703,7 +704,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldReturnClusterConfiguration() {
void shouldReturnClusterConfiguration() {
RedisClusterConfiguration configuration = new RedisClusterConfiguration();
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(configuration,
@@ -715,7 +716,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-574
public void shouldDenyChangesToImmutableClientConfiguration() {
void shouldDenyChangesToImmutableClientConfiguration() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(new RedisStandaloneConfiguration(),
LettuceClientConfiguration.defaultConfiguration());
@@ -724,7 +725,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-676
public void timeoutShouldBePassedOnToClusterConnection() {
void timeoutShouldBePassedOnToClusterConnection() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig);
connectionFactory.setShutdownTimeout(0);
@@ -740,7 +741,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-676
public void timeoutSetOnClientConfigShouldBePassedOnToClusterConnection() {
void timeoutSetOnClientConfigShouldBePassedOnToClusterConnection() {
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory(clusterConfig, LettuceClientConfiguration
.builder().commandTimeout(Duration.ofSeconds(2)).shutdownTimeout(Duration.ZERO).build());
@@ -756,7 +757,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-731
public void shouldShareNativeConnectionWithCluster() {
void shouldShareNativeConnectionWithCluster() {
RedisClusterClient clientMock = mock(RedisClusterClient.class);
StatefulRedisClusterConnection<byte[], byte[]> connectionMock = mock(StatefulRedisClusterConnection.class);
@@ -783,7 +784,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-950
public void shouldValidateSharedClusterConnection() {
void shouldValidateSharedClusterConnection() {
RedisClusterClient clientMock = mock(RedisClusterClient.class);
StatefulRedisClusterConnection<byte[], byte[]> connectionMock = mock(StatefulRedisClusterConnection.class);
@@ -813,7 +814,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-953
public void shouldReleaseSharedConnectionOnlyOnce() {
void shouldReleaseSharedConnectionOnlyOnce() {
RedisClusterClient clientMock = mock(RedisClusterClient.class);
StatefulRedisClusterConnection<byte[], byte[]> connectionMock = mock(StatefulRedisClusterConnection.class);
@@ -841,7 +842,7 @@ public class LettuceConnectionFactoryUnitTests {
@Test // DATAREDIS-721
@SuppressWarnings("unchecked")
public void shouldEagerlyInitializeSharedConnection() {
void shouldEagerlyInitializeSharedConnection() {
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class);
StatefulRedisConnection connectionMock = mock(StatefulRedisConnection.class);
@@ -865,7 +866,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-1189
public void shouldTranslateConnectionException() {
void shouldTranslateConnectionException() {
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class);
@@ -886,7 +887,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-1027
public void shouldDisposeConnectionProviders() throws Exception {
void shouldDisposeConnectionProviders() throws Exception {
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class,
withSettings().extraInterfaces(DisposableBean.class));
@@ -905,7 +906,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-842
public void databaseShouldBeSetCorrectlyOnSentinelClient() {
void databaseShouldBeSetCorrectlyOnSentinelClient() {
RedisSentinelConfiguration redisSentinelConfiguration = new RedisSentinelConfiguration("mymaster",
Collections.singleton("host:1234"));
@@ -925,7 +926,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-949
public void maxRedirectsShouldBeSetOnClientOptions() {
void maxRedirectsShouldBeSetOnClientOptions() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.clusterNode("localhost", 1234).setMaxRedirects(42);
@@ -945,7 +946,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-949
public void maxRedirectsShouldBeSetOnClusterClientOptions() {
void maxRedirectsShouldBeSetOnClusterClientOptions() {
RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration();
clusterConfiguration.clusterNode("localhost", 1234).setMaxRedirects(42);
@@ -968,7 +969,7 @@ public class LettuceConnectionFactoryUnitTests {
}
@Test // DATAREDIS-1142
public void shouldFallbackToReactiveRedisClusterConnectionWhenGetReactiveConnectionWithClusterConfig() {
void shouldFallbackToReactiveRedisClusterConnectionWhenGetReactiveConnectionWithClusterConfig() {
LettuceConnectionProvider connectionProviderMock = mock(LettuceConnectionProvider.class);
StatefulConnection<?, ?> statefulConnection = mock(StatefulConnection.class);

View File

@@ -16,24 +16,18 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import io.lettuce.core.api.async.RedisAsyncCommands;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.awaitility.Awaitility;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
@@ -41,12 +35,11 @@ import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
import org.springframework.data.redis.test.condition.LongRunningTest;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.util.RedisSentinelRule;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.data.redis.test.util.RequiresRedisSentinel;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link LettuceConnection}
@@ -58,15 +51,12 @@ import org.springframework.test.context.ContextConfiguration;
* @author David Liu
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration
public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegrationTests {
public @Rule RedisSentinelRule sentinelRule = RedisSentinelRule.withDefaultConfig().dynamicModeSelection();
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testMultiThreadsOneBlocking() throws Exception {
@LongRunningTest
void testMultiThreadsOneBlocking() throws Exception {
Thread th = new Thread(() -> {
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection());
conn2.openPipeline();
@@ -82,7 +72,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test
public void testMultiConnectionsOneInTx() throws Exception {
void testMultiConnectionsOneInTx() throws Exception {
connection.set("txs1", "rightnow");
connection.multi();
connection.set("txs1", "delay");
@@ -104,7 +94,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test
public void testCloseInTransaction() {
void testCloseInTransaction() {
connection.multi();
connection.close();
try {
@@ -116,7 +106,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test
public void testCloseBlockingOps() {
void testCloseBlockingOps() {
connection.lPush("what", "baz");
connection.bLPop(1, "what".getBytes());
connection.close();
@@ -132,7 +122,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test
public void testClosePooledConnectionWithShared() {
void testClosePooledConnectionWithShared() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
@@ -154,7 +144,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test
public void testClosePooledConnectionNotShared() {
void testClosePooledConnectionNotShared() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
@@ -174,7 +164,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test
public void testCloseNonPooledConnectionNotShared() {
void testCloseNonPooledConnectionNotShared() {
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.setShutdownTimeout(0);
@@ -194,7 +184,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@SuppressWarnings("rawtypes")
@Test
public void testCloseReturnBrokenResourceToPool() {
void testCloseReturnBrokenResourceToPool() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
pool.setClientResources(LettuceTestClientResources.getSharedClientResources());
pool.afterPropertiesSet();
@@ -216,7 +206,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test // DATAREDIS-1062
public void testSelectNotShared() {
void testSelectNotShared() {
DefaultLettucePool pool = new DefaultLettucePool(SettingsUtils.getHost(), SettingsUtils.getPort());
GenericObjectPoolConfig config = new GenericObjectPoolConfig();
config.setMaxTotal(1);
@@ -251,35 +241,6 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> super.testSelect());
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testScriptKill() throws Exception {
getResults();
assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection));
final AtomicBoolean scriptDead = new AtomicBoolean(false);
Thread th = new Thread(() -> {
// Use a different factory to get a non-shared native conn for blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.setShutdownTimeout(0);
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
});
th.start();
Thread.sleep(1000);
connection.scriptKill();
Awaitility.await().untilTrue(scriptDead);
}
@Test
public void testMove() {
connection.set("foo", "bar");
@@ -305,7 +266,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@SuppressWarnings("unchecked")
@Test // DATAREDIS-285
public void testExecuteShouldConvertArrayReplyCorrectly() {
void testExecuteShouldConvertArrayReplyCorrectly() {
connection.set("spring", "awesome");
connection.set("data", "cool");
@@ -319,7 +280,6 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
@SuppressWarnings("unchecked")
@Test
@IfProfileValue(name = "redisVersion", value = "2.6+")
public void testEvalShaArrayBytes() {
getResults();
byte[] sha1 = connection.scriptLoad("return {KEYS[1],ARGV[1]}").getBytes();
@@ -332,7 +292,7 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test // DATAREDIS-106
public void zRangeByScoreTest() {
void zRangeByScoreTest() {
connection.zAdd("myzset", 1, "one");
connection.zAdd("myzset", 2, "two");
@@ -344,8 +304,8 @@ public class LettuceConnectionIntegrationTests extends AbstractConnectionIntegra
}
@Test // DATAREDIS-348
@RequiresRedisSentinel(RedisSentinelRule.SentinelsAvailable.ONE_ACTIVE)
public void shouldReturnSentinelCommandsWhenWhenActiveSentinelFound() {
@EnabledOnRedisSentinelAvailable
void shouldReturnSentinelCommandsWhenWhenActiveSentinelFound() {
((LettuceConnection) byteConnection).setSentinelConfiguration(
new RedisSentinelConfiguration().master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380));

View File

@@ -15,12 +15,12 @@
*/
package org.springframework.data.redis.connection.lettuce;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link LettuceConnection} pipeline functionality with
@@ -28,12 +28,13 @@ import org.springframework.test.context.ContextConfiguration;
*
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration("LettuceConnectionPipelineFlushOnEndIntegrationTests-context.xml")
public class LettuceConnectionPipelineFlushOnEndIntegrationTests extends LettuceConnectionPipelineIntegrationTests {
@Test
@Ignore("WATCH command is flushed during EXEC therefore we're not run commands between WATCH and EXEC")
@Disabled("WATCH command is flushed during EXEC therefore we're not run commands between WATCH and EXEC")
@Override
public void testWatch() throws Exception {
}

View File

@@ -16,26 +16,18 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.util.Arrays;
import java.util.concurrent.atomic.AtomicBoolean;
import org.awaitility.Awaitility;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.dao.DataAccessException;
import org.springframework.data.redis.RedisVersionUtils;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.AbstractConnectionPipelineIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link LettuceConnection} pipeline functionality
@@ -45,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectionPipelineIntegrationTests {
@@ -54,36 +46,6 @@ public class LettuceConnectionPipelineIntegrationTests extends AbstractConnectio
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> super.testSelect());
}
@Test
@IfProfileValue(name = "runLongTests", value = "true")
public void testScriptKill() throws Exception {
getResults();
assumeTrue(RedisVersionUtils.atLeast("2.6", byteConnection));
initConnection();
final AtomicBoolean scriptDead = new AtomicBoolean(false);
Thread th = new Thread(() -> {
// Use separate conn factory to avoid using the underlying shared native conn on blocking script
final LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(),
SettingsUtils.getPort());
factory2.setClientResources(LettuceTestClientResources.getSharedClientResources());
factory2.afterPropertiesSet();
DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(factory2.getConnection());
try {
conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0);
} catch (DataAccessException e) {
scriptDead.set(true);
}
conn2.close();
factory2.destroy();
});
th.start();
Thread.sleep(1000);
connection.scriptKill();
getResults();
Awaitility.await().untilTrue(scriptDead);
}
@Test
public void testMove() {

View File

@@ -19,10 +19,8 @@ import static org.assertj.core.api.Assertions.*;
import java.util.List;
import org.junit.Test;
import org.springframework.data.redis.connection.RedisPipelineException;
import org.springframework.test.annotation.IfProfileValue;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Integration test of {@link LettuceConnection} transactions within a pipeline
@@ -33,33 +31,33 @@ import org.springframework.test.annotation.IfProfileValue;
public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnectionTransactionIntegrationTests {
@Test
@Disabled("Different exception")
public void testEvalShaNotFound() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalShaNotFound());
}
@Test
@Disabled("Different exception")
public void testEvalReturnSingleError() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalReturnSingleError());
}
@Test
@Disabled("Different exception")
public void testRestoreBadData() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testRestoreBadData());
}
@Test
@Disabled("Different exception")
public void testRestoreExistingKey() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testRestoreExistingKey());
}
@Test
@Disabled("Different exception")
public void testEvalArrayScriptError() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalArrayScriptError());
}
@Test
@Disabled("Different exception")
public void testEvalShaArrayError() {
assertThatExceptionOfType(RedisPipelineException.class).isThrownBy(() -> super.testEvalShaArrayError());
}
protected void initConnection() {
@@ -83,7 +81,7 @@ public class LettuceConnectionPipelineTxIntegrationTests extends LettuceConnecti
// DATAREDIS-268
public void testListClientsContainsAtLeastOneElement() {
assertThatExceptionOfType(UnsupportedOperationException.class)
.isThrownBy(() -> super.testListClientsContainsAtLeastOneElement());
.isThrownBy(super::testListClientsContainsAtLeastOneElement);
}
}

View File

@@ -19,15 +19,15 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.redis.connection.AbstractConnectionTransactionIntegrationTests;
import org.springframework.data.redis.connection.DefaultStringRedisConnection;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.util.RelaxedJUnit4ClassRunner;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.SpringExtension;
/**
* Integration test of {@link LettuceConnection} functionality within a transaction
@@ -37,7 +37,7 @@ import org.springframework.test.context.ContextConfiguration;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(RelaxedJUnit4ClassRunner.class)
@ExtendWith(SpringExtension.class)
@ContextConfiguration("LettuceConnectionIntegrationTests-context.xml")
public class LettuceConnectionTransactionIntegrationTests extends AbstractConnectionTransactionIntegrationTests {
@@ -68,6 +68,6 @@ public class LettuceConnectionTransactionIntegrationTests extends AbstractConnec
@Test
public void testSelect() {
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> super.testSelect());
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(super::testSelect);
}
}

View File

@@ -30,7 +30,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.RedisClusterNode;
import org.springframework.data.redis.connection.RedisClusterNode.Flag;
@@ -43,24 +43,24 @@ import org.springframework.data.redis.core.types.RedisClientInfo;
/**
* @author Christoph Strobl
*/
public class LettuceConvertersUnitTests {
class LettuceConvertersUnitTests {
private static final String CLIENT_ALL_SINGLE_LINE_RESPONSE = "addr=127.0.0.1:60311 fd=6 name= age=4059 idle=0 flags=N db=0 sub=0 psub=0 multi=-1 qbuf=0 qbuf-free=32768 obl=0 oll=0 omem=0 events=r cmd=client";
@Test // DATAREDIS-268
public void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
void convertingEmptyStringToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(LettuceConverters.toListOfRedisClientInformation(""))
.isEqualTo(Collections.<RedisClientInfo> emptyList());
}
@Test // DATAREDIS-268
public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() {
assertThat(LettuceConverters.toListOfRedisClientInformation(null))
.isEqualTo(Collections.<RedisClientInfo> emptyList());
}
@Test // DATAREDIS-268
public void convertingMultipleLiesToListOfRedisClientInfoReturnsListCorrectly() {
void convertingMultipleLiesToListOfRedisClientInfoReturnsListCorrectly() {
StringBuilder sb = new StringBuilder();
sb.append(CLIENT_ALL_SINGLE_LINE_RESPONSE);
@@ -71,12 +71,12 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-315
public void partitionsToClusterNodesShouldReturnEmptyCollectionWhenPartionsDoesNotContainElements() {
void partitionsToClusterNodesShouldReturnEmptyCollectionWhenPartionsDoesNotContainElements() {
assertThat(LettuceConverters.partitionsToClusterNodes(new Partitions())).isNotNull();
}
@Test // DATAREDIS-315
public void partitionsToClusterNodesShouldConvertPartitionCorrctly() {
void partitionsToClusterNodesShouldConvertPartitionCorrctly() {
Partitions partitions = new Partitions();
@@ -102,7 +102,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldReturnEmptyArgsForNullValues() {
void toSetArgsShouldReturnEmptyArgsForNullValues() {
SetArgs args = LettuceConverters.toSetArgs(null, null);
@@ -113,7 +113,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldNotSetExOrPxForPersistent() {
void toSetArgsShouldNotSetExOrPxForPersistent() {
SetArgs args = LettuceConverters.toSetArgs(Expiration.persistent(), null);
@@ -124,7 +124,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldSetExForSeconds() {
void toSetArgsShouldSetExForSeconds() {
SetArgs args = LettuceConverters.toSetArgs(Expiration.seconds(10), null);
@@ -135,7 +135,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldSetPxForMilliseconds() {
void toSetArgsShouldSetPxForMilliseconds() {
SetArgs args = LettuceConverters.toSetArgs(Expiration.milliseconds(100), null);
@@ -146,7 +146,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldSetNxForAbsent() {
void toSetArgsShouldSetNxForAbsent() {
SetArgs args = LettuceConverters.toSetArgs(null, SetOption.ifAbsent());
@@ -157,7 +157,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldSetXxForPresent() {
void toSetArgsShouldSetXxForPresent() {
SetArgs args = LettuceConverters.toSetArgs(null, SetOption.ifPresent());
@@ -168,7 +168,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-316
public void toSetArgsShouldNotSetNxOrXxForUpsert() {
void toSetArgsShouldNotSetNxOrXxForUpsert() {
SetArgs args = LettuceConverters.toSetArgs(null, SetOption.upsert());
@@ -179,7 +179,7 @@ public class LettuceConvertersUnitTests {
}
@Test // DATAREDIS-981
public void toLimit() {
void toLimit() {
Limit limit = LettuceConverters.toLimit(RedisZSetCommands.Limit.unlimited());
assertThat(limit.isLimited()).isFalse();

View File

@@ -25,7 +25,7 @@ import io.lettuce.core.resource.ClientResources;
import java.time.Duration;
import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
@@ -36,10 +36,10 @@ import org.springframework.data.redis.test.extension.LettuceTestClientResources;
* @author Christoph Strobl
* @author Longlong Zhao
*/
public class LettucePoolingClientConfigurationUnitTests {
class LettucePoolingClientConfigurationUnitTests {
@Test // DATAREDIS-667, DATAREDIS-918
public void shouldCreateEmptyConfiguration() {
void shouldCreateEmptyConfiguration() {
LettucePoolingClientConfiguration configuration = LettucePoolingClientConfiguration.defaultConfiguration();
@@ -59,7 +59,7 @@ public class LettucePoolingClientConfigurationUnitTests {
}
@Test // DATAREDIS-667
public void shouldConfigureAllProperties() {
void shouldConfigureAllProperties() {
ClientOptions clientOptions = ClientOptions.create();
ClientResources sharedClientResources = LettuceTestClientResources.getSharedClientResources();
@@ -89,7 +89,7 @@ public class LettucePoolingClientConfigurationUnitTests {
}
@Test // DATAREDIS-956
public void shouldConfigureReadFrom() {
void shouldConfigureReadFrom() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
@@ -103,7 +103,7 @@ public class LettucePoolingClientConfigurationUnitTests {
}
@Test // DATAREDIS-956
public void shouldConfigureClientName() {
void shouldConfigureClientName() {
GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();

View File

@@ -20,35 +20,38 @@ import static org.mockito.Mockito.*;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.async.RedisAsyncCommands;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
/**
* Unit tests for {@link LettucePoolingConnectionProvider}.
*
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class LettucePoolingConnectionProviderUnitTests {
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class LettucePoolingConnectionProviderUnitTests {
@Mock LettuceConnectionProvider connectionProviderMock;
@Mock StatefulRedisConnection<byte[], byte[]> connectionMock;
@Mock RedisAsyncCommands<byte[], byte[]> commandsMock;
LettucePoolingClientConfiguration config = LettucePoolingClientConfiguration.defaultConfiguration();
private LettucePoolingClientConfiguration config = LettucePoolingClientConfiguration.defaultConfiguration();
@Before
public void before() {
@BeforeEach
void before() {
when(connectionMock.async()).thenReturn(commandsMock);
when(connectionProviderMock.getConnection(any())).thenReturn(connectionMock);
}
@Test // DATAREDIS-988
public void shouldReturnConnectionOnRelease() {
void shouldReturnConnectionOnRelease() {
LettucePoolingConnectionProvider provider = new LettucePoolingConnectionProvider(connectionProviderMock, config);
@@ -58,7 +61,7 @@ public class LettucePoolingConnectionProviderUnitTests {
}
@Test // DATAREDIS-988
public void shouldDiscardTransactionOnReleaseOnActiveTransaction() {
void shouldDiscardTransactionOnReleaseOnActiveTransaction() {
LettucePoolingConnectionProvider provider = new LettucePoolingConnectionProvider(connectionProviderMock, config);
when(connectionMock.isMulti()).thenReturn(true);

View File

@@ -21,7 +21,8 @@ import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.ReactiveClusterCommands;
import org.springframework.data.redis.connection.RedisClusterNode;
@@ -34,21 +35,21 @@ import org.springframework.data.redis.connection.RedisClusterNode;
* @author Mark Paluch
* @author Christoph Strobl
*/
public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
@Test // DATAREDIS-1150
public void pingShouldReturnPong() {
void pingShouldReturnPong() {
connection.ping().as(StepVerifier::create).expectNext("PONG").verifyComplete();
}
@Test // DATAREDIS-1150
public void pingShouldReturnPongForServers() {
void pingShouldReturnPongForServers() {
connection.clusterGetNodes().flatMap(connection::ping).as(StepVerifier::create)
.expectNext("PONG", "PONG", "PONG", "PONG").verifyComplete();
}
@Test // DATAREDIS-1150
public void clusterGetNodesShouldReturnNodes() {
void clusterGetNodesShouldReturnNodes() {
connection.clusterGetNodes().collectList() //
.as(StepVerifier::create) //
@@ -59,7 +60,7 @@ public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterC
}
@Test // DATAREDIS-1150
public void clusterGetSlavesShouldReturnNodes() {
void clusterGetSlavesShouldReturnNodes() {
connection.clusterGetNodes().filter(RedisClusterNode::isMaster)
.filter(node -> (node.getPort() == 7379 || node.getPort() == 7382))
@@ -73,7 +74,7 @@ public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterC
}
@Test // DATAREDIS-1150
public void clusterGetMasterSlaveMapShouldReportTopology() {
void clusterGetMasterSlaveMapShouldReportTopology() {
connection.clusterGetMasterSlaveMap() //
.as(StepVerifier::create) //
@@ -84,7 +85,7 @@ public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterC
}
@Test // DATAREDIS-1150
public void clusterGetSlotForKeyShouldResolveSlot() {
void clusterGetSlotForKeyShouldResolveSlot() {
connection.clusterGetSlotForKey(ByteBuffer.wrap("hello".getBytes())) //
.as(StepVerifier::create) //
@@ -93,7 +94,7 @@ public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterC
}
@Test // DATAREDIS-1150
public void clusterGetNodeForSlotShouldReportNode() {
void clusterGetNodeForSlotShouldReportNode() {
connection.clusterGetNodeForSlot(866) //
.as(StepVerifier::create) //
@@ -104,7 +105,7 @@ public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterC
}
@Test // DATAREDIS-1150
public void clusterGetNodeForKeyShouldReportNode() {
void clusterGetNodeForKeyShouldReportNode() {
connection.clusterGetNodeForKey(ByteBuffer.wrap("hello".getBytes())) //
.as(StepVerifier::create) //
@@ -115,7 +116,7 @@ public class LettuceReactiveClusterCommandsTests extends LettuceReactiveClusterC
}
@Test // DATAREDIS-1150
public void clusterGetClusterInfoShouldReportState() {
void clusterGetClusterInfoShouldReportState() {
connection.clusterGetClusterInfo() //
.as(StepVerifier::create) //

View File

@@ -16,19 +16,19 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestSupport.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Christoph Strobl
*/
public class LettuceReactiveClusterHyperLogLogCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterHyperLogLogCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
@Test // DATAREDIS-525
public void pfCountWithMultipleKeysShouldReturnCorrectlyWhenKeysMapToSameSlot() {
void pfCountWithMultipleKeysShouldReturnCorrectlyWhenKeysMapToSameSlot() {
nativeCommands.pfadd(SAME_SLOT_KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(SAME_SLOT_KEY_2, new String[] { VALUE_2, VALUE_3 });
@@ -38,7 +38,7 @@ public class LettuceReactiveClusterHyperLogLogCommandsTests extends LettuceReact
}
@Test // DATAREDIS-525
public void pfMergeShouldWorkCorrectlyWhenKeysMapToSameSlot() {
void pfMergeShouldWorkCorrectlyWhenKeysMapToSameSlot() {
nativeCommands.pfadd(SAME_SLOT_KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(SAME_SLOT_KEY_2, new String[] { VALUE_2, VALUE_3 });

View File

@@ -17,26 +17,26 @@ package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.RedisClusterNode.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestSupport.*;
import reactor.core.publisher.Mono;
import java.nio.ByteBuffer;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.RedisClusterNode;
/**
* @author Christoph Strobl
*/
public class LettuceReactiveClusterKeyCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterKeyCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
static final RedisClusterNode NODE_1 = newRedisClusterNode().listeningAt("127.0.0.1", 7379).build();
private static final RedisClusterNode NODE_1 = newRedisClusterNode().listeningAt("127.0.0.1", 7379).build();
@Test // DATAREDIS-525
public void keysShouldReturnOnlyKeysFromSelectedNode() {
void keysShouldReturnOnlyKeysFromSelectedNode() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -47,7 +47,7 @@ public class LettuceReactiveClusterKeyCommandsTests extends LettuceReactiveClust
}
@Test // DATAREDIS-525
public void randomkeyShouldReturnOnlyKeysFromSelectedNode() {
void randomkeyShouldReturnOnlyKeysFromSelectedNode() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);

View File

@@ -16,23 +16,23 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestSupport.*;
import java.nio.ByteBuffer;
import java.time.Duration;
import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.ReactiveListCommands;
/**
* @author Christoph Strobl
*/
public class LettuceReactiveClusterListCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterListCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
@Test // DATAREDIS-525
public void bRPopLPushShouldWorkCorrectlyWhenAllKeysMapToSameSlot() {
void bRPopLPushShouldWorkCorrectlyWhenAllKeysMapToSameSlot() {
nativeCommands.rpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.rpush(SAME_SLOT_KEY_2, VALUE_1);
@@ -46,7 +46,7 @@ public class LettuceReactiveClusterListCommandsTests extends LettuceReactiveClus
}
@Test // DATAREDIS-525
public void blPopShouldReturnFirstAvailableWhenAllKeysMapToTheSameSlot() {
void blPopShouldReturnFirstAvailableWhenAllKeysMapToTheSameSlot() {
nativeCommands.rpush(SAME_SLOT_KEY_1, VALUE_1, VALUE_2, VALUE_3);

View File

@@ -17,45 +17,45 @@ package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestSupport.*;
import reactor.test.StepVerifier;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.RedisClusterNode;
/**
* @author Mark Paluch
* @author Christoph Strobl
*/
public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterServerCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
static final RedisClusterNode NODE1 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT);
static final RedisClusterNode NODE2 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT);
static final RedisClusterNode NODE3 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT);
private static final RedisClusterNode NODE1 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT);
private static final RedisClusterNode NODE2 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT);
private static final RedisClusterNode NODE3 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT);
@Test // DATAREDIS-659
public void pingShouldRespondCorrectly() {
void pingShouldRespondCorrectly() {
connection.ping(NODE1).as(StepVerifier::create).expectNext("PONG").verifyComplete();
}
@Test // DATAREDIS-659
public void lastSaveShouldRespondCorrectly() {
void lastSaveShouldRespondCorrectly() {
connection.serverCommands().lastSave(NODE1).as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-659
public void saveShouldRespondCorrectly() {
void saveShouldRespondCorrectly() {
connection.serverCommands().save(NODE1).as(StepVerifier::create).expectNext("OK").verifyComplete();
}
@Test // DATAREDIS-659
public void dbSizeShouldRespondCorrectly() {
void dbSizeShouldRespondCorrectly() {
connection.serverCommands().dbSize(NODE1).as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-659
public void flushDbShouldRespondCorrectly() {
void flushDbShouldRespondCorrectly() {
connection.serverCommands().flushDb() //
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
@@ -73,7 +73,7 @@ public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-659
public void flushAllShouldRespondCorrectly() {
void flushAllShouldRespondCorrectly() {
connection.serverCommands().flushAll() //
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
@@ -91,7 +91,7 @@ public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-659
public void infoShouldRespondCorrectly() {
void infoShouldRespondCorrectly() {
connection.serverCommands().info(NODE1).as(StepVerifier::create) //
.consumeNextWith(properties -> assertThat(properties).containsKey("tcp_port")) //
@@ -99,7 +99,7 @@ public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-659
public void standaloneInfoWithSectionShouldRespondCorrectly() {
void standaloneInfoWithSectionShouldRespondCorrectly() {
connection.serverCommands().info(NODE1, "server").as(StepVerifier::create) //
.consumeNextWith(properties -> {
@@ -109,7 +109,7 @@ public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-659
public void getConfigShouldRespondCorrectly() {
void getConfigShouldRespondCorrectly() {
connection.serverCommands().getConfig(NODE1, "*").as(StepVerifier::create) //
.consumeNextWith(properties -> {
@@ -119,7 +119,7 @@ public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-659
public void setConfigShouldApplyConfiguration() throws InterruptedException {
void setConfigShouldApplyConfiguration() throws InterruptedException {
final String slowLogKey = "slowlog-max-len";
@@ -156,17 +156,17 @@ public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-659
public void configResetstatShouldRespondCorrectly() {
void configResetstatShouldRespondCorrectly() {
connection.serverCommands().resetConfigStats(NODE1).as(StepVerifier::create).expectNext("OK").verifyComplete();
}
@Test // DATAREDIS-659
public void timeShouldRespondCorrectly() {
void timeShouldRespondCorrectly() {
connection.serverCommands().time(NODE1).as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-659
public void getClientListShouldReportClient() {
void getClientListShouldReportClient() {
connection.serverCommands().getClientList(NODE1).as(StepVerifier::create).expectNextCount(1).thenCancel().verify();
}
}

View File

@@ -16,14 +16,14 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestSupport.*;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.RedisStringCommands;
@@ -31,10 +31,10 @@ import org.springframework.data.redis.connection.RedisStringCommands;
* @author Christoph Strobl
* @since 2.0
*/
public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterStringCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
@Test // DATAREDIS-525
public void mSetNXShouldAddMultipleKeyValueParisWhenMappedToSameSlot() {
void mSetNXShouldAddMultipleKeyValueParisWhenMappedToSameSlot() {
Map<ByteBuffer, ByteBuffer> map = new LinkedHashMap<>();
map.put(SAME_SLOT_KEY_1_BBUFFER, VALUE_1_BBUFFER);
@@ -47,7 +47,7 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-525
public void mSetNXShouldNotAddMultipleKeyValueParisWhenAlreadyExitAndMapToSameSlot() {
void mSetNXShouldNotAddMultipleKeyValueParisWhenAlreadyExitAndMapToSameSlot() {
nativeCommands.set(SAME_SLOT_KEY_2, VALUE_2);
@@ -62,7 +62,7 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-525
public void bitOpAndShouldWorkAsExpectedWhenKeysMapToSameSlot() {
void bitOpAndShouldWorkAsExpectedWhenKeysMapToSameSlot() {
nativeCommands.set(SAME_SLOT_KEY_1, VALUE_1);
nativeCommands.set(SAME_SLOT_KEY_2, VALUE_2);
@@ -73,7 +73,7 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-525
public void bitOpOrShouldWorkAsExpectedWhenKeysMapToSameSlot() {
void bitOpOrShouldWorkAsExpectedWhenKeysMapToSameSlot() {
nativeCommands.set(SAME_SLOT_KEY_1, VALUE_1);
nativeCommands.set(SAME_SLOT_KEY_2, VALUE_2);
@@ -84,7 +84,7 @@ public class LettuceReactiveClusterStringCommandsTests extends LettuceReactiveCl
}
@Test // DATAREDIS-525
public void bitNotShouldThrowExceptionWhenMoreThanOnSourceKeyAndKeysMapToSameSlot() {
void bitNotShouldThrowExceptionWhenMoreThanOnSourceKeyAndKeysMapToSameSlot() {
assertThatIllegalArgumentException().isThrownBy(
() -> connection.stringCommands().bitOp(Arrays.asList(SAME_SLOT_KEY_1_BBUFFER, SAME_SLOT_KEY_2_BBUFFER),
RedisStringCommands.BitOperation.NOT, SAME_SLOT_KEY_3_BBUFFER).block());

View File

@@ -15,41 +15,38 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assumptions.*;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.redis.test.util.LettuceRedisClusterClientProvider;
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
import org.springframework.data.redis.test.extension.LettuceExtension;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
public abstract class LettuceReactiveClusterCommandsTestsBase {
public static @ClassRule LettuceRedisClusterClientProvider clientProvider = LettuceRedisClusterClientProvider.local();
@EnabledOnRedisClusterAvailable
@ExtendWith(LettuceExtension.class)
public abstract class LettuceReactiveClusterTestSupport {
RedisClusterCommands<String, String> nativeCommands;
LettuceReactiveRedisClusterConnection connection;
@Before
public void before() {
@BeforeEach
public void before(RedisClusterClient clusterClient) {
assumeThat(clientProvider.test()).isTrue();
nativeCommands = clientProvider.getClient().connect().sync();
nativeCommands = clusterClient.connect().sync();
connection = new LettuceReactiveRedisClusterConnection(
new ClusterConnectionProvider(clientProvider.getClient(), LettuceReactiveRedisConnection.CODEC),
clientProvider.getClient());
new ClusterConnectionProvider(clusterClient, LettuceReactiveRedisConnection.CODEC), clusterClient);
}
@After
@AfterEach
public void tearDown() {
if (nativeCommands != null) {

View File

@@ -16,19 +16,19 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestSupport.*;
import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
/**
* @author Christoph Strobl
*/
public class LettuceReactiveClusterZSetCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
class LettuceReactiveClusterZSetCommandsIntegrationTests extends LettuceReactiveClusterTestSupport {
@Test // DATAREDIS-525
public void zUnionStoreShouldWorkWhenAllKeysMapToSameSlot() {
void zUnionStoreShouldWorkWhenAllKeysMapToSameSlot() {
nativeCommands.zadd(SAME_SLOT_KEY_1, 1D, VALUE_1);
nativeCommands.zadd(SAME_SLOT_KEY_1, 2D, VALUE_2);
@@ -42,7 +42,7 @@ public class LettuceReactiveClusterZSetCommandsTests extends LettuceReactiveClus
}
@Test // DATAREDIS-525
public void zInterStoreShouldWorkCorrectlyWhenKeysMapToSameSlot() {
void zInterStoreShouldWorkCorrectlyWhenKeysMapToSameSlot() {
nativeCommands.zadd(SAME_SLOT_KEY_1, 1D, VALUE_1);
nativeCommands.zadd(SAME_SLOT_KEY_1, 2D, VALUE_2);

View File

@@ -15,32 +15,33 @@
*/
package org.springframework.data.redis.connection.lettuce;
import io.lettuce.core.RedisClient;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.sync.RedisCommands;
import io.lettuce.core.cluster.RedisClusterClient;
import io.lettuce.core.cluster.api.StatefulRedisClusterConnection;
import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands;
import io.lettuce.core.cluster.api.sync.RedisClusterCommands;
import io.lettuce.core.codec.StringCodec;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.connection.lettuce.LettuceReactiveRedisConnection.ByteBufferCodec;
import org.springframework.data.redis.test.util.LettuceRedisClientProvider;
import org.springframework.data.redis.test.util.LettuceRedisClusterClientProvider;
import org.springframework.data.redis.test.extension.LettuceExtension;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
public abstract class LettuceReactiveCommandsTestsBase {
@MethodSource("parameters")
public abstract class LettuceReactiveCommandsTestSupport {
static final String KEY_1 = "key-1";
static final String KEY_2 = "key-2";
@@ -52,15 +53,15 @@ public abstract class LettuceReactiveCommandsTestsBase {
static final String VALUE_2 = "value-2";
static final String VALUE_3 = "value-3";
static final byte[] SAME_SLOT_KEY_1_BYTES = SAME_SLOT_KEY_1.getBytes(Charset.forName("UTF-8"));
static final byte[] SAME_SLOT_KEY_2_BYTES = SAME_SLOT_KEY_2.getBytes(Charset.forName("UTF-8"));
static final byte[] SAME_SLOT_KEY_3_BYTES = SAME_SLOT_KEY_3.getBytes(Charset.forName("UTF-8"));
static final byte[] KEY_1_BYTES = KEY_1.getBytes(Charset.forName("UTF-8"));
static final byte[] KEY_2_BYTES = KEY_2.getBytes(Charset.forName("UTF-8"));
static final byte[] KEY_3_BYTES = KEY_3.getBytes(Charset.forName("UTF-8"));
static final byte[] VALUE_1_BYTES = VALUE_1.getBytes(Charset.forName("UTF-8"));
static final byte[] VALUE_2_BYTES = VALUE_2.getBytes(Charset.forName("UTF-8"));
static final byte[] VALUE_3_BYTES = VALUE_3.getBytes(Charset.forName("UTF-8"));
static final byte[] SAME_SLOT_KEY_1_BYTES = SAME_SLOT_KEY_1.getBytes(StandardCharsets.UTF_8);
static final byte[] SAME_SLOT_KEY_2_BYTES = SAME_SLOT_KEY_2.getBytes(StandardCharsets.UTF_8);
static final byte[] SAME_SLOT_KEY_3_BYTES = SAME_SLOT_KEY_3.getBytes(StandardCharsets.UTF_8);
static final byte[] KEY_1_BYTES = KEY_1.getBytes(StandardCharsets.UTF_8);
static final byte[] KEY_2_BYTES = KEY_2.getBytes(StandardCharsets.UTF_8);
static final byte[] KEY_3_BYTES = KEY_3.getBytes(StandardCharsets.UTF_8);
static final byte[] VALUE_1_BYTES = VALUE_1.getBytes(StandardCharsets.UTF_8);
static final byte[] VALUE_2_BYTES = VALUE_2.getBytes(StandardCharsets.UTF_8);
static final byte[] VALUE_3_BYTES = VALUE_3.getBytes(StandardCharsets.UTF_8);
static final ByteBuffer KEY_1_BBUFFER = ByteBuffer.wrap(KEY_1_BYTES);
static final ByteBuffer SAME_SLOT_KEY_1_BBUFFER = ByteBuffer.wrap(SAME_SLOT_KEY_1_BYTES);
@@ -74,53 +75,79 @@ public abstract class LettuceReactiveCommandsTestsBase {
static final ByteBuffer SAME_SLOT_KEY_3_BBUFFER = ByteBuffer.wrap(SAME_SLOT_KEY_3_BYTES);
static final ByteBuffer VALUE_3_BBUFFER = ByteBuffer.wrap(VALUE_3_BYTES);
@Parameterized.Parameter(value = 0) public LettuceConnectionProvider connectionProvider;
@Parameterized.Parameter(value = 1) public LettuceConnectionProvider nativeConnectionProvider;
@Parameterized.Parameter(value = 2) public LettuceConnectionProvider nativeBinaryConnectionProvider;
@Parameterized.Parameter(value = 3) public Object displayName;
public final LettuceConnectionProvider connectionProvider;
public final LettuceConnectionProvider nativeConnectionProvider;
public final LettuceConnectionProvider nativeBinaryConnectionProvider;
LettuceReactiveRedisConnection connection;
RedisClusterCommands<String, String> nativeCommands;
RedisClusterCommands<ByteBuffer, ByteBuffer> nativeBinaryCommands;
@Parameterized.Parameters(name = "{3}")
public static List<Object[]> parameters() {
public LettuceReactiveCommandsTestSupport(Fixture fixture) {
this.connectionProvider = fixture.connectionProvider;
this.nativeConnectionProvider = fixture.nativeConnectionProvider;
this.nativeBinaryConnectionProvider = fixture.nativeBinaryConnectionProvider;
}
LettuceRedisClientProvider standalone = LettuceRedisClientProvider.local();
LettuceRedisClusterClientProvider cluster = LettuceRedisClusterClientProvider.local();
public static List<Fixture> parameters() {
List<Object[]> parameters = new ArrayList<>();
LettuceExtension extension = new LettuceExtension();
StandaloneConnectionProvider standaloneProvider = new StandaloneConnectionProvider(standalone.getClient(),
List<Fixture> parameters = new ArrayList<>();
StandaloneConnectionProvider standaloneProvider = new StandaloneConnectionProvider(
extension.getInstance(RedisClient.class),
LettuceReactiveRedisConnection.CODEC);
StandaloneConnectionProvider nativeConnectionProvider = new StandaloneConnectionProvider(standalone.getClient(),
StandaloneConnectionProvider nativeConnectionProvider = new StandaloneConnectionProvider(
extension.getInstance(RedisClient.class),
StringCodec.UTF8);
StandaloneConnectionProvider nativeBinaryConnectionProvider = new StandaloneConnectionProvider(
standalone.getClient(), ByteBufferCodec.INSTANCE);
extension.getInstance(RedisClient.class), ByteBufferCodec.INSTANCE);
parameters.add(
new Object[] { standaloneProvider, nativeConnectionProvider, nativeBinaryConnectionProvider, "Standalone" });
parameters.add(new Object[] {
new Fixture(standaloneProvider, nativeConnectionProvider, nativeBinaryConnectionProvider, "Standalone"));
parameters.add(new Fixture(
new LettucePoolingConnectionProvider(standaloneProvider, LettucePoolingClientConfiguration.builder().build()),
nativeConnectionProvider, nativeBinaryConnectionProvider, "Standalone/Pooled" });
nativeConnectionProvider, nativeBinaryConnectionProvider, "Pooling"));
if (cluster.test()) {
ClusterConnectionProvider clusterProvider = new ClusterConnectionProvider(cluster.getClient(),
ClusterConnectionProvider clusterProvider = new ClusterConnectionProvider(
extension.getInstance(RedisClusterClient.class),
LettuceReactiveRedisConnection.CODEC);
ClusterConnectionProvider nativeClusterConnectionProvider = new ClusterConnectionProvider(cluster.getClient(),
ClusterConnectionProvider nativeClusterConnectionProvider = new ClusterConnectionProvider(
extension.getInstance(RedisClusterClient.class),
StringCodec.UTF8);
ClusterConnectionProvider nativeBinaryClusterConnectionProvider = new ClusterConnectionProvider(
cluster.getClient(), ByteBufferCodec.INSTANCE);
extension.getInstance(RedisClusterClient.class), ByteBufferCodec.INSTANCE);
parameters.add(new Object[] { clusterProvider, nativeClusterConnectionProvider,
nativeBinaryClusterConnectionProvider, "Cluster" });
}
parameters.add(new Fixture(clusterProvider, nativeClusterConnectionProvider,
nativeBinaryClusterConnectionProvider, "Cluster"));
return parameters;
}
@Before
static class Fixture {
final LettuceConnectionProvider connectionProvider;
final LettuceConnectionProvider nativeConnectionProvider;
final LettuceConnectionProvider nativeBinaryConnectionProvider;
final String label;
Fixture(LettuceConnectionProvider connectionProvider, LettuceConnectionProvider nativeConnectionProvider,
LettuceConnectionProvider nativeBinaryConnectionProvider, String label) {
this.connectionProvider = connectionProvider;
this.nativeConnectionProvider = nativeConnectionProvider;
this.nativeBinaryConnectionProvider = nativeBinaryConnectionProvider;
this.label = label;
}
@Override
public String toString() {
return label;
}
}
@BeforeEach
public void setUp() {
if (nativeConnectionProvider instanceof StandaloneConnectionProvider) {
@@ -137,7 +164,7 @@ public abstract class LettuceReactiveCommandsTestsBase {
}
}
@After
@AfterEach
public void tearDown() {
if (nativeCommands != null) {

View File

@@ -27,18 +27,17 @@ import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Christoph Strobl
*/
public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveGeoCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
private static final String ARIGENTO_MEMBER_NAME = "arigento";
private static final String CATANIA_MEMBER_NAME = "catania";
@@ -55,19 +54,23 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
private static final GeoLocation<ByteBuffer> PALERMO = new GeoLocation<>(
ByteBuffer.wrap(PALERMO_MEMBER_NAME.getBytes(Charset.forName("UTF-8"))), POINT_PALERMO);
@Test // DATAREDIS-525
public void geoAddShouldAddSingleGeoLocationCorrectly() {
public LettuceReactiveGeoCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void geoAddShouldAddSingleGeoLocationCorrectly() {
assertThat(connection.geoCommands().geoAdd(KEY_1_BBUFFER, ARIGENTO).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void geoAddShouldAddMultipleGeoLocationsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void geoAddShouldAddMultipleGeoLocationsCorrectly() {
assertThat(connection.geoCommands().geoAdd(KEY_1_BBUFFER, Arrays.asList(ARIGENTO, CATANIA, PALERMO)).block())
.isEqualTo(3L);
}
@Test // DATAREDIS-525
public void geoDistShouldReturnDistanceInMetersByDefault() {
@ParameterizedRedisTest // DATAREDIS-525
void geoDistShouldReturnDistanceInMetersByDefault() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -76,8 +79,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.isCloseTo(166274.15156960033D, offset(0.005));
}
@Test // DATAREDIS-525
public void geoDistShouldReturnDistanceInDesiredMetric() {
@ParameterizedRedisTest // DATAREDIS-525
void geoDistShouldReturnDistanceInDesiredMetric() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -86,8 +89,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.block().getValue()).isCloseTo(166.27415156960033D, offset(0.005));
}
@Test // DATAREDIS-525
public void geoHash() {
@ParameterizedRedisTest // DATAREDIS-525
void geoHash() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -97,8 +100,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.containsExactly("sqc8b49rny0", "sqdtr74hyu0");
}
@Test // DATAREDIS-525
public void geoHashNotExisting() {
@ParameterizedRedisTest // DATAREDIS-525
void geoHashNotExisting() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -108,8 +111,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.containsExactly("sqc8b49rny0", null, "sqdtr74hyu0");
}
@Test // DATAREDIS-525
public void geoPos() {
@ParameterizedRedisTest // DATAREDIS-525
void geoPos() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -123,8 +126,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
assertThat(result.get(1).getY()).isCloseTo(POINT_CATANIA.getY(), offset(0.005));
}
@Test // DATAREDIS-525
public void geoPosNonExisting() {
@ParameterizedRedisTest // DATAREDIS-525
void geoPosNonExisting() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -140,8 +143,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
assertThat(result.get(2).getY()).isCloseTo(POINT_CATANIA.getY(), offset(0.005));
}
@Test // DATAREDIS-525
public void geoRadiusShouldReturnMembersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void geoRadiusShouldReturnMembersCorrectly() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -158,8 +161,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.expectComplete();
}
@Test // DATAREDIS-525
public void geoRadiusShouldReturnDistanceCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void geoRadiusShouldReturnDistanceCorrectly() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -177,8 +180,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.expectComplete();
}
@Test // DATAREDIS-525
public void geoRadiusShouldApplyLimit() {
@ParameterizedRedisTest // DATAREDIS-525
void geoRadiusShouldApplyLimit() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -192,8 +195,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.expectComplete();
}
@Test // DATAREDIS-525
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void geoRadiusByMemberShouldReturnMembersCorrectly() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -210,8 +213,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
.expectComplete();
}
@Test // DATAREDIS-525
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void geoRadiusByMemberShouldReturnDistanceCorrectly() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);
@@ -231,8 +234,8 @@ public class LettuceReactiveGeoCommandsTests extends LettuceReactiveCommandsTest
}
@Test // DATAREDIS-525
public void geoRadiusByMemberShouldApplyLimit() {
@ParameterizedRedisTest // DATAREDIS-525
void geoRadiusByMemberShouldApplyLimit() {
nativeCommands.geoadd(KEY_1, PALERMO.getPoint().getX(), PALERMO.getPoint().getY(), PALERMO_MEMBER_NAME);
nativeCommands.geoadd(KEY_1, CATANIA.getPoint().getX(), CATANIA.getPoint().getY(), CATANIA_MEMBER_NAME);

View File

@@ -26,9 +26,8 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Test;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link LettuceReactiveHashCommands}.
@@ -36,35 +35,39 @@ import org.springframework.data.redis.core.ScanOptions;
* @author Christoph Strobl
* @author Mark Paluch
*/
public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveHashCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
static final String FIELD_1 = "field-1";
static final String FIELD_2 = "field-2";
static final String FIELD_3 = "field-3";
private static final String FIELD_1 = "field-1";
private static final String FIELD_2 = "field-2";
private static final String FIELD_3 = "field-3";
static final byte[] FIELD_1_BYTES = FIELD_1.getBytes(StandardCharsets.UTF_8);
static final byte[] FIELD_2_BYTES = FIELD_2.getBytes(StandardCharsets.UTF_8);
static final byte[] FIELD_3_BYTES = FIELD_3.getBytes(StandardCharsets.UTF_8);
private static final byte[] FIELD_1_BYTES = FIELD_1.getBytes(StandardCharsets.UTF_8);
private static final byte[] FIELD_2_BYTES = FIELD_2.getBytes(StandardCharsets.UTF_8);
private static final byte[] FIELD_3_BYTES = FIELD_3.getBytes(StandardCharsets.UTF_8);
static final ByteBuffer FIELD_1_BBUFFER = ByteBuffer.wrap(FIELD_1_BYTES);
static final ByteBuffer FIELD_2_BBUFFER = ByteBuffer.wrap(FIELD_2_BYTES);
static final ByteBuffer FIELD_3_BBUFFER = ByteBuffer.wrap(FIELD_3_BYTES);
private static final ByteBuffer FIELD_1_BBUFFER = ByteBuffer.wrap(FIELD_1_BYTES);
private static final ByteBuffer FIELD_2_BBUFFER = ByteBuffer.wrap(FIELD_2_BYTES);
private static final ByteBuffer FIELD_3_BBUFFER = ByteBuffer.wrap(FIELD_3_BYTES);
@Test // DATAREDIS-525
public void hSetShouldOperateCorrectly() {
public LettuceReactiveHashCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void hSetShouldOperateCorrectly() {
connection.hashCommands().hSet(KEY_1_BBUFFER, FIELD_1_BBUFFER, VALUE_1_BBUFFER).as(StepVerifier::create)
.expectNext(true).verifyComplete();
}
@Test // DATAREDIS-525
public void hSetNxShouldOperateCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hSetNxShouldOperateCorrectly() {
connection.hashCommands().hSetNX(KEY_1_BBUFFER, FIELD_1_BBUFFER, VALUE_1_BBUFFER).as(StepVerifier::create)
.expectNext(true).verifyComplete();
}
@Test // DATAREDIS-525
public void hSetNxShouldReturnFalseIfFieldAlreadyExists() {
@ParameterizedRedisTest // DATAREDIS-525
void hSetNxShouldReturnFalseIfFieldAlreadyExists() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
@@ -72,8 +75,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.expectNext(false).verifyComplete();
}
@Test // DATAREDIS-525
public void hGetShouldReturnValueForExistingField() {
@ParameterizedRedisTest // DATAREDIS-525
void hGetShouldReturnValueForExistingField() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -83,16 +86,16 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void hGetShouldReturnNullForNotExistingField() {
@ParameterizedRedisTest // DATAREDIS-525
void hGetShouldReturnNullForNotExistingField() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
connection.hashCommands().hGet(KEY_1_BBUFFER, FIELD_2_BBUFFER).as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-525
public void hMGetShouldReturnValueForFields() {
@ParameterizedRedisTest // DATAREDIS-525
void hMGetShouldReturnValueForFields() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -107,8 +110,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
}).verifyComplete();
}
@Test // DATAREDIS-525
public void hMGetShouldReturnNullValueForFieldsThatHaveNoValue() {
@ParameterizedRedisTest // DATAREDIS-525
void hMGetShouldReturnNullValueForFieldsThatHaveNoValue() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_3, VALUE_3);
@@ -118,8 +121,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.expectNext(Arrays.asList(VALUE_1_BBUFFER, null, VALUE_3_BBUFFER)).verifyComplete();
}
@Test // DATAREDIS-525
public void hMSetSouldSetValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hMSetSouldSetValuesCorrectly() {
Map<ByteBuffer, ByteBuffer> fieldValues = new LinkedHashMap<>();
fieldValues.put(FIELD_1_BBUFFER, VALUE_1_BBUFFER);
@@ -131,8 +134,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
assertThat(nativeCommands.hget(KEY_1, FIELD_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-791
public void hMSetShouldOverwriteValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-791
void hMSetShouldOverwriteValuesCorrectly() {
Map<ByteBuffer, ByteBuffer> fieldValues = new LinkedHashMap<>();
fieldValues.put(FIELD_1_BBUFFER, VALUE_1_BBUFFER);
@@ -148,8 +151,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
assertThat(nativeCommands.hget(KEY_1, FIELD_1)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void hExistsShouldReturnTrueForExistingField() {
@ParameterizedRedisTest // DATAREDIS-525
void hExistsShouldReturnTrueForExistingField() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
@@ -157,14 +160,14 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void hExistsShouldReturnFalseForNonExistingField() {
@ParameterizedRedisTest // DATAREDIS-525
void hExistsShouldReturnFalseForNonExistingField() {
connection.hashCommands().hExists(KEY_1_BBUFFER, FIELD_1_BBUFFER).as(StepVerifier::create).expectNext(false)
.verifyComplete();
}
@Test // DATAREDIS-525
public void hDelShouldRemoveSingleFieldsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hDelShouldRemoveSingleFieldsCorrectly() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -174,8 +177,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void hDelShouldRemoveMultipleFieldsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hDelShouldRemoveMultipleFieldsCorrectly() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -186,8 +189,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-525
public void hLenShouldReturnSizeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hLenShouldReturnSizeCorrectly() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -196,8 +199,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
connection.hashCommands().hLen(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(3L).verifyComplete();
}
@Test // DATAREDIS-525
public void hKeysShouldReturnFieldsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hKeysShouldReturnFieldsCorrectly() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -208,8 +211,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void hValsShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hValsShouldReturnValuesCorrectly() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -220,8 +223,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void hGetAllShouldReturnEntriesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hGetAllShouldReturnEntriesCorrectly() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -239,8 +242,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-743
public void hScanShouldIterateOverHash() {
@ParameterizedRedisTest // DATAREDIS-743
void hScanShouldIterateOverHash() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -251,8 +254,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-698
public void hStrLenReturnsFieldLength() {
@ParameterizedRedisTest // DATAREDIS-698
void hStrLenReturnsFieldLength() {
nativeCommands.hset(KEY_1, FIELD_1, VALUE_1);
nativeCommands.hset(KEY_1, FIELD_2, VALUE_2);
@@ -262,8 +265,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-698
public void hStrLenReturnsZeroWhenFieldDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-698
void hStrLenReturnsZeroWhenFieldDoesNotExist() {
nativeCommands.hset(KEY_1, FIELD_2, VALUE_3);
@@ -271,8 +274,8 @@ public class LettuceReactiveHashCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-698
public void hStrLenReturnsZeroWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-698
void hStrLenReturnsZeroWhenKeyDoesNotExist() {
connection.hashCommands().hStrLen(KEY_1_BBUFFER, FIELD_1_BBUFFER).as(StepVerifier::create).expectNext(0L) //
.verifyComplete();

View File

@@ -16,67 +16,73 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import java.util.Arrays;
import java.util.Collections;
import org.junit.Test;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
public class LettuceReactiveHyperLogLogCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveHyperLogLogCommandsTests extends LettuceReactiveCommandsTestSupport {
@Test // DATAREDIS-525
public void pfAddShouldAddToNonExistingKeyCorrectly() {
public LettuceReactiveHyperLogLogCommandsTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void pfAddShouldAddToNonExistingKeyCorrectly() {
assertThat(connection.hyperLogLogCommands()
.pfAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER, VALUE_3_BBUFFER)).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void pfAddShouldReturnZeroWhenValueAlreadyExists() {
@ParameterizedRedisTest // DATAREDIS-525
void pfAddShouldReturnZeroWhenValueAlreadyExists() {
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_1, new String[] { VALUE_3 });
nativeCommands.pfadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.pfadd(KEY_1, VALUE_3);
assertThat(connection.hyperLogLogCommands().pfAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER)).block())
assertThat(
connection.hyperLogLogCommands().pfAdd(KEY_1_BBUFFER, Collections.singletonList(VALUE_1_BBUFFER)).block())
.isEqualTo(0L);
}
@Test // DATAREDIS-525
public void pfCountShouldReturnCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void pfCountShouldReturnCorrectly() {
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.hyperLogLogCommands().pfCount(KEY_1_BBUFFER).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void pfCountWithMultipleKeysShouldReturnCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void pfCountWithMultipleKeysShouldReturnCorrectly() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_2, new String[] { VALUE_2, VALUE_3 });
nativeCommands.pfadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.pfadd(KEY_2, VALUE_2, VALUE_3);
assertThat(connection.hyperLogLogCommands().pfCount(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isEqualTo(3L);
}
@Test // DATAREDIS-525
public void pfMergeShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void pfMergeShouldWorkCorrectly() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.pfadd(KEY_1, new String[] { VALUE_1, VALUE_2 });
nativeCommands.pfadd(KEY_2, new String[] { VALUE_2, VALUE_3 });
nativeCommands.pfadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.pfadd(KEY_2, VALUE_2, VALUE_3);
assertThat(
connection.hyperLogLogCommands().pfMerge(KEY_3_BBUFFER, Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).block())
.isTrue();
assertThat(nativeCommands.pfcount(new String[] { KEY_3 })).isEqualTo(3L);
assertThat(nativeCommands.pfcount(KEY_3)).isEqualTo(3L);
}
}

View File

@@ -30,17 +30,14 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.ReactiveRedisConnection.KeyCommand;
import org.springframework.data.redis.connection.ReactiveRedisConnection.NumericResponse;
import org.springframework.data.redis.connection.ValueEncoding.RedisValueEncoding;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link LettuceReactiveKeyCommands}.
@@ -48,25 +45,27 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Christoph Strobl
* @author Mark Paluch
*/
public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveKeyCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
public LettuceReactiveKeyCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@Test // DATAREDIS-525
public void existsShouldReturnTrueForExistingKeys() {
@ParameterizedRedisTest // DATAREDIS-525
void existsShouldReturnTrueForExistingKeys() {
nativeCommands.set(KEY_1, VALUE_1);
connection.keyCommands().exists(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-525
public void existsShouldReturnFalseForNonExistingKeys() {
@ParameterizedRedisTest // DATAREDIS-525
void existsShouldReturnFalseForNonExistingKeys() {
connection.keyCommands().exists(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-525
public void typeShouldReturnTypeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void typeShouldReturnTypeCorrectly() {
nativeCommands.set(KEY_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2);
@@ -77,8 +76,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
connection.keyCommands().type(KEY_3_BBUFFER).as(StepVerifier::create).expectNext(DataType.HASH).verifyComplete();
}
@Test // DATAREDIS-525
public void keysShouldReturnCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void keysShouldReturnCorrectly() {
nativeCommands.set(KEY_1, VALUE_2);
nativeCommands.set(KEY_2, VALUE_2);
@@ -96,8 +95,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.expectNextCount(3).verifyComplete();
}
@Test // DATAREDIS-743
public void scanShouldShouldIterateOverKeyspace() {
@ParameterizedRedisTest // DATAREDIS-743
void scanShouldShouldIterateOverKeyspace() {
nativeCommands.set(KEY_1, VALUE_2);
nativeCommands.set(KEY_2, VALUE_2);
@@ -116,8 +115,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-525
public void randomKeyShouldReturnAnyKey() {
@ParameterizedRedisTest // DATAREDIS-525
void randomKeyShouldReturnAnyKey() {
nativeCommands.set(KEY_1, VALUE_2);
nativeCommands.set(KEY_2, VALUE_2);
@@ -126,13 +125,13 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
connection.keyCommands().randomKey().as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-525
public void randomKeyShouldReturnNullWhenNoKeyExists() {
@ParameterizedRedisTest // DATAREDIS-525
void randomKeyShouldReturnNullWhenNoKeyExists() {
connection.keyCommands().randomKey().as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-525
public void renameShouldAlterKeyNameCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void renameShouldAlterKeyNameCorrectly() {
nativeCommands.set(KEY_1, VALUE_2);
@@ -142,15 +141,15 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
}
@Test // DATAREDIS-525
public void renameShouldThrowErrorWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-525
void renameShouldThrowErrorWhenKeyDoesNotExist() {
connection.keyCommands().rename(KEY_1_BBUFFER, KEY_2_BBUFFER).as(StepVerifier::create)
.expectError(RedisSystemException.class).verify();
}
@Test // DATAREDIS-525
public void renameNXShouldAlterKeyNameCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void renameNXShouldAlterKeyNameCorrectly() {
nativeCommands.set(KEY_1, VALUE_2);
@@ -161,8 +160,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
}
@Test // DATAREDIS-525
public void renameNXShouldNotAlterExistingKeyName() {
@ParameterizedRedisTest // DATAREDIS-525
void renameNXShouldNotAlterExistingKeyName() {
nativeCommands.set(KEY_1, VALUE_2);
nativeCommands.set(KEY_2, VALUE_2);
@@ -171,16 +170,16 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-525
public void shouldDeleteKeyCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void shouldDeleteKeyCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
connection.keyCommands().del(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-525
public void shouldDeleteKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void shouldDeleteKeysCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -191,8 +190,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
result.as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
@Test // DATAREDIS-525
public void shouldDeleteKeysInBatchCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void shouldDeleteKeysInBatchCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -202,8 +201,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
result.as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-525
public void shouldDeleteKeysInMultipleBatchesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void shouldDeleteKeysInMultipleBatchesCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -216,18 +215,18 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
result.as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
@Test // DATAREDIS-693
@IfProfileValue(name = "redisVersion", value = "4.0.0+")
public void shouldUnlinkKeyCorrectly() {
@ParameterizedRedisTest // DATAREDIS-693
@EnabledOnCommand("UNLINK")
void shouldUnlinkKeyCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
connection.keyCommands().unlink(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-693
@IfProfileValue(name = "redisVersion", value = "4.0.0+")
public void shouldUnlinkKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-693
@EnabledOnCommand("UNLINK")
void shouldUnlinkKeysCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -238,9 +237,9 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
result.as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
@Test // DATAREDIS-693
@IfProfileValue(name = "redisVersion", value = "4.0.0+")
public void shouldUnlinkKeysInBatchCorrectly() {
@ParameterizedRedisTest // DATAREDIS-693
@EnabledOnCommand("UNLINK")
void shouldUnlinkKeysInBatchCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -250,9 +249,9 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
result.as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-693
@IfProfileValue(name = "redisVersion", value = "4.0.0+")
public void shouldUnlinkKeysInMultipleBatchesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-693
@EnabledOnCommand("UNLINK")
void shouldUnlinkKeysInMultipleBatchesCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -265,8 +264,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
result.as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
@Test // DATAREDIS-602
public void shouldExpireKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldExpireKeysCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -278,8 +277,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
}
@Test // DATAREDIS-602, DATAREDIS-1031
public void shouldPreciseExpireKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-1031
void shouldPreciseExpireKeysCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -291,8 +290,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8).isLessThan(11);
}
@Test // DATAREDIS-602, DATAREDIS-1031
public void shouldExpireAtKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-1031
void shouldExpireAtKeysCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
Instant expireAt = Instant.now().plus(Duration.ofSeconds(10));
@@ -305,8 +304,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8).isLessThan(11);
}
@Test // DATAREDIS-602, DATAREDIS-1031
public void shouldPreciseExpireAtKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-1031
void shouldPreciseExpireAtKeysCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
Instant expireAt = Instant.now().plus(Duration.ofSeconds(10));
@@ -319,22 +318,21 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8).isLessThan(11);
}
@Test // DATAREDIS-602
public void shouldReportTimeToLiveCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldReportTimeToLiveCorrectly() {
nativeCommands.set(KEY_1, VALUE_1, SetArgs.Builder.ex(10));
connection.keyCommands().ttl(KEY_1_BBUFFER).as(StepVerifier::create) //
.expectNextMatches(actual -> {
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
return true;
}) //
.expectNextCount(1) //
.expectComplete() //
.verify();
assertThat(nativeCommands.ttl(KEY_1)).isGreaterThan(8L);
}
@Test // DATAREDIS-602
public void shouldReportPreciseTimeToLiveCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldReportPreciseTimeToLiveCorrectly() {
nativeCommands.set(KEY_1, VALUE_1, SetArgs.Builder.ex(10));
@@ -347,8 +345,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.verify();
}
@Test // DATAREDIS-602
public void shouldPersist() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldPersist() {
nativeCommands.set(KEY_1, VALUE_1, SetArgs.Builder.ex(10));
@@ -360,8 +358,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.ttl(KEY_1)).isEqualTo(-1L);
}
@Test // DATAREDIS-602
public void shouldMoveToDatabase() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldMoveToDatabase() {
assumeThat(connection).isNotInstanceOf(LettuceReactiveRedisClusterConnection.class);
@@ -374,8 +372,8 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.exists(KEY_1)).isEqualTo(0L);
}
@Test // DATAREDIS-694
public void touchReturnsNrOfKeysTouched() {
@ParameterizedRedisTest // DATAREDIS-694
void touchReturnsNrOfKeysTouched() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -385,16 +383,16 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-694
public void touchReturnsZeroIfNoKeysTouched() {
@ParameterizedRedisTest // DATAREDIS-694
void touchReturnsZeroIfNoKeysTouched() {
connection.keyCommands().touch(Collections.singletonList(KEY_1_BBUFFER)).as(StepVerifier::create) //
.expectNext(0L) //
.verifyComplete();
}
@Test // DATAREDIS-716
public void encodingReturnsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-716
void encodingReturnsCorrectly() {
nativeCommands.set(KEY_1, "1000");
@@ -402,15 +400,15 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-716
public void encodingReturnsVacantWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-716
void encodingReturnsVacantWhenKeyDoesNotExist() {
connection.keyCommands().encodingOf(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(RedisValueEncoding.VACANT)
.verifyComplete();
}
@Test // DATAREDIS-716
public void idletimeReturnsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-716
void idletimeReturnsCorrectly() {
nativeCommands.set(KEY_1, "1000");
nativeCommands.get(KEY_1);
@@ -420,21 +418,21 @@ public class LettuceReactiveKeyCommandsTests extends LettuceReactiveCommandsTest
}).verifyComplete();
}
@Test // DATAREDIS-716
public void idldetimeReturnsNullWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-716
void idldetimeReturnsNullWhenKeyDoesNotExist() {
connection.keyCommands().idletime(KEY_1_BBUFFER).as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-716
public void refcountReturnsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-716
void refcountReturnsCorrectly() {
nativeCommands.lpush(KEY_1, "1000");
connection.keyCommands().refcount(KEY_1_BBUFFER).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-716
public void refcountReturnsNullWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-716
void refcountReturnsNullWhenKeyDoesNotExist() {
connection.keyCommands().refcount(KEY_1_BBUFFER).as(StepVerifier::create).verifyComplete();
}
}

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.domain.Range.Bound.*;
import reactor.core.publisher.Mono;
@@ -27,8 +27,6 @@ import java.nio.charset.StandardCharsets;
import java.time.Duration;
import java.util.Arrays;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.ReactiveListCommands.LPosCommand;
@@ -38,20 +36,22 @@ import org.springframework.data.redis.connection.ReactiveRedisConnection;
import org.springframework.data.redis.connection.ReactiveRedisConnection.CommandResponse;
import org.springframework.data.redis.connection.ReactiveRedisConnection.RangeCommand;
import org.springframework.data.redis.connection.RedisListCommands.Position;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Christoph Strobl
* @author Mark Paluch
* @author Michele Mancioppi
*/
public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveListCommandIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Rule public MinimumRedisVersionRule redisVersion = new MinimumRedisVersionRule();
public LettuceReactiveListCommandIntegrationTests(Fixture fixture) {
super(fixture);
}
@Test // DATAREDIS-525
public void rPushShouldAppendValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void rPushShouldAppendValuesCorrectly() {
nativeCommands.lpush(KEY_1, VALUE_1);
@@ -60,8 +60,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
public void lPushShouldPrependValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lPushShouldPrependValuesCorrectly() {
nativeCommands.lpush(KEY_1, VALUE_1);
@@ -70,8 +70,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_3, VALUE_2, VALUE_1);
}
@Test // DATAREDIS-525
public void rPushXShouldAppendValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void rPushXShouldAppendValuesCorrectly() {
nativeCommands.lpush(KEY_1, VALUE_1);
@@ -79,8 +79,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2);
}
@Test // DATAREDIS-525
public void lPushXShouldPrependValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lPushXShouldPrependValuesCorrectly() {
nativeCommands.lpush(KEY_1, VALUE_1);
@@ -88,24 +88,24 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_1);
}
@Test // DATAREDIS-525
public void pushShouldThrowErrorForMoreThanOneValueWhenUsingExistsOption() {
@ParameterizedRedisTest // DATAREDIS-525
void pushShouldThrowErrorForMoreThanOneValueWhenUsingExistsOption() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class).isThrownBy(() -> connection.listCommands()
.push(Mono.just(
PushCommand.right().values(Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER)).to(KEY_1_BBUFFER).ifExists()))
.blockFirst());
}
@Test // DATAREDIS-525
public void lLenShouldReturnSizeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lLenShouldReturnSizeCorrectly() {
nativeCommands.lpush(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.listCommands().lLen(KEY_1_BBUFFER).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void lRangeShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lRangeShouldReturnValuesCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -113,8 +113,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
VALUE_3_BBUFFER);
}
@Test // DATAREDIS-852
public void lRangeShouldReturnValuesCorrectlyWithMinUnbounded() {
@ParameterizedRedisTest // DATAREDIS-852
void lRangeShouldReturnValuesCorrectlyWithMinUnbounded() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -125,8 +125,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.expectNext(VALUE_1_BBUFFER).expectNext(VALUE_2_BBUFFER).verifyComplete();
}
@Test // DATAREDIS-852
public void lRangeShouldReturnValuesCorrectlyWithMaxUnbounded() {
@ParameterizedRedisTest // DATAREDIS-852
void lRangeShouldReturnValuesCorrectlyWithMaxUnbounded() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -137,8 +137,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.expectNext(VALUE_2_BBUFFER).expectNext(VALUE_3_BBUFFER).verifyComplete();
}
@Test // DATAREDIS-525
public void lTrimShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lTrimShouldReturnValuesCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -146,8 +146,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).doesNotContain(VALUE_1);
}
@Test // DATAREDIS-852
public void lTrimShouldReturnValuesCorrectlyWithMinUnbounded() {
@ParameterizedRedisTest // DATAREDIS-852
void lTrimShouldReturnValuesCorrectlyWithMinUnbounded() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -158,8 +158,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-852
public void lTrimShouldReturnValuesCorrectlyWithMaxUnbounded() {
@ParameterizedRedisTest // DATAREDIS-852
void lTrimShouldReturnValuesCorrectlyWithMaxUnbounded() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -170,16 +170,16 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-525
public void lIndexShouldReturnValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lIndexShouldReturnValueCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.listCommands().lIndex(KEY_1_BBUFFER, 1).block()).isEqualTo(VALUE_2_BBUFFER);
}
@Test // DATAREDIS-525
public void lInsertShouldAddValueCorrectlyBeforeExisting() {
@ParameterizedRedisTest // DATAREDIS-525
void lInsertShouldAddValueCorrectlyBeforeExisting() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2);
@@ -189,8 +189,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_3, VALUE_2);
}
@Test // DATAREDIS-525
public void lInsertShouldAddValueCorrectlyAfterExisting() {
@ParameterizedRedisTest // DATAREDIS-525
void lInsertShouldAddValueCorrectlyAfterExisting() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2);
@@ -200,8 +200,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
public void lSetSouldSetValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lSetSouldSetValueCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2);
@@ -210,8 +210,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).doesNotContain(VALUE_2);
}
@Test // DATAREDIS-525
public void lRemSouldRemoveAllValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lRemSouldRemoveAllValuesCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_1, VALUE_3);
@@ -220,8 +220,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).doesNotContain(VALUE_1);
}
@Test // DATAREDIS-525
public void lRemSouldRemoveFirstValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lRemSouldRemoveFirstValuesCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_1, VALUE_3);
@@ -229,8 +229,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_1, VALUE_3);
}
@Test // DATAREDIS-525
public void lRemSouldRemoveLastValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lRemSouldRemoveLastValuesCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_1, VALUE_3);
@@ -238,8 +238,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
public void lPopSouldRemoveFirstValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void lPopSouldRemoveFirstValueCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -247,8 +247,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_2, VALUE_3);
}
@Test // DATAREDIS-525
public void rPopSouldRemoveFirstValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void rPopSouldRemoveFirstValueCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -256,10 +256,10 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lrange(KEY_1, 0, -1)).containsExactly(VALUE_1, VALUE_2);
}
@Test // DATAREDIS-525
public void blPopShouldReturnFirstAvailable() {
@ParameterizedRedisTest // DATAREDIS-525
void blPopShouldReturnFirstAvailable() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -269,10 +269,10 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(result.getValue()).isEqualTo(VALUE_1_BBUFFER);
}
@Test // DATAREDIS-525
public void brPopShouldReturnLastAvailable() {
@ParameterizedRedisTest // DATAREDIS-525
void brPopShouldReturnLastAvailable() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -282,8 +282,8 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(result.getValue()).isEqualTo(VALUE_3_BBUFFER);
}
@Test // DATAREDIS-525
public void rPopLPushShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void rPopLPushShouldWorkCorrectly() {
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.rpush(KEY_2, VALUE_1);
@@ -295,10 +295,10 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lindex(KEY_2, 0)).isEqualTo(VALUE_3);
}
@Test // DATAREDIS-525
public void brPopLPushShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void brPopLPushShouldWorkCorrectly() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.rpush(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.rpush(KEY_2, VALUE_1);
@@ -311,9 +311,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.lindex(KEY_2, 0)).isEqualTo(VALUE_3);
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lPos() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lPos() {
nativeCommands.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");
@@ -324,9 +324,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lPosRank() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lPosRank() {
nativeCommands.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");
@@ -337,9 +337,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lPosNegativeRank() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lPosNegativeRank() {
nativeCommands.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");
@@ -350,9 +350,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lPosCount() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lPosCount() {
nativeCommands.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");
@@ -364,9 +364,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lPosRankCount() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lPosRankCount() {
nativeCommands.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");
@@ -379,9 +379,9 @@ public class LettuceReactiveListCommandTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lPosCountZero() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lPosCountZero() {
nativeCommands.rpush(KEY_1, "a", "b", "c", "1", "2", "3", "c", "c");

View File

@@ -18,35 +18,39 @@ package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import org.junit.Test;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Christoph Strobl
*/
public class LettuceReactiveNumberCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveNumberCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Test // DATAREDIS-525
public void incrByDoubleShouldIncreaseValueCorrectly() {
public LettuceReactiveNumberCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void incrByDoubleShouldIncreaseValueCorrectly() {
assertThat(connection.numberCommands().incrBy(KEY_1_BBUFFER, 1.5D).block()).isCloseTo(1.5D, offset(0D));
}
@Test // DATAREDIS-525
public void incrByIntegerShouldIncreaseValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void incrByIntegerShouldIncreaseValueCorrectly() {
assertThat(connection.numberCommands().incrBy(KEY_1_BBUFFER, 3).block()).isEqualTo(3);
}
@Test // DATAREDIS-525
public void decrByDoubleShouldDecreaseValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void decrByDoubleShouldDecreaseValueCorrectly() {
assertThat(connection.numberCommands().decrBy(KEY_1_BBUFFER, 1.5D).block()).isCloseTo(-1.5D, offset(0D));
}
@Test // DATAREDIS-525
public void decrByIntegerShouldDecreaseValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void decrByIntegerShouldDecreaseValueCorrectly() {
assertThat(connection.numberCommands().decrBy(KEY_1_BBUFFER, 3).block()).isEqualTo(-3);
}
@Test // DATAREDIS-525
public void hIncrByDoubleShouldIncreaseValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hIncrByDoubleShouldIncreaseValueCorrectly() {
nativeCommands.hset(KEY_1, KEY_1, "2");
@@ -54,8 +58,8 @@ public class LettuceReactiveNumberCommandsTests extends LettuceReactiveCommandsT
offset(0D));
}
@Test // DATAREDIS-525
public void hIncrByIntegerShouldIncreaseValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void hIncrByIntegerShouldIncreaseValueCorrectly() {
nativeCommands.hset(KEY_1, KEY_1, "2");

View File

@@ -32,8 +32,8 @@ import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import java.util.concurrent.CompletableFuture;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

View File

@@ -31,13 +31,15 @@ import java.util.Collections;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Answers;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.redis.RedisConnectionFailureException;
import org.springframework.data.redis.connection.ReactiveStreamCommands.AddStreamRecord;
@@ -49,23 +51,24 @@ import org.springframework.data.redis.connection.stream.MapRecord;
*
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class LettuceReactiveRedisConnectionUnitTests {
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class LettuceReactiveRedisConnectionUnitTests {
@Mock(answer = Answers.RETURNS_MOCKS) StatefulRedisConnection<ByteBuffer, ByteBuffer> sharedConnection;
@Mock RedisReactiveCommands<ByteBuffer, ByteBuffer> reactiveCommands;
@Mock LettuceConnectionProvider connectionProvider;
@Before
public void before() {
@BeforeEach
void before() {
when(connectionProvider.getConnectionAsync(any())).thenReturn(CompletableFuture.completedFuture(sharedConnection));
when(connectionProvider.releaseAsync(any())).thenReturn(CompletableFuture.completedFuture(null));
when(sharedConnection.reactive()).thenReturn(reactiveCommands);
}
@Test // DATAREDIS-720
public void shouldLazilyInitializeConnection() {
void shouldLazilyInitializeConnection() {
new LettuceReactiveRedisConnection(connectionProvider);
@@ -73,7 +76,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldExecuteUsingConnectionProvider() {
void shouldExecuteUsingConnectionProvider() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
@@ -83,7 +86,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldExecuteDedicatedUsingConnectionProvider() {
void shouldExecuteDedicatedUsingConnectionProvider() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
@@ -93,7 +96,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720
public void shouldExecuteOnSharedConnection() {
void shouldExecuteOnSharedConnection() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(sharedConnection,
connectionProvider);
@@ -104,7 +107,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldExecuteDedicatedWithSharedConnection() {
void shouldExecuteDedicatedWithSharedConnection() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(sharedConnection,
connectionProvider);
@@ -115,7 +118,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldOperateOnDedicatedConnection() {
void shouldOperateOnDedicatedConnection() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
@@ -125,7 +128,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldCloseOnlyDedicatedConnection() {
void shouldCloseOnlyDedicatedConnection() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(sharedConnection,
connectionProvider);
@@ -140,7 +143,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldCloseConnectionOnlyOnce() {
void shouldCloseConnectionOnlyOnce() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
@@ -154,7 +157,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
@Test // DATAREDIS-720, DATAREDIS-721
@SuppressWarnings("unchecked")
public void multipleCallsInProgressShouldConnectOnlyOnce() throws Exception {
void multipleCallsInProgressShouldConnectOnlyOnce() throws Exception {
CompletableFuture<StatefulConnection<?, ?>> connectionFuture = new CompletableFuture<>();
reset(connectionProvider);
@@ -182,7 +185,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldPropagateConnectionFailures() {
void shouldPropagateConnectionFailures() {
reset(connectionProvider);
when(connectionProvider.getConnectionAsync(any()))
@@ -194,7 +197,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-720, DATAREDIS-721
public void shouldRejectCommandsAfterClose() {
void shouldRejectCommandsAfterClose() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
connection.close();
@@ -203,7 +206,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-659, DATAREDIS-708
public void bgReWriteAofShouldRespondCorrectly() {
void bgReWriteAofShouldRespondCorrectly() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
@@ -213,7 +216,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-659, DATAREDIS-667, DATAREDIS-708
public void bgSaveShouldRespondCorrectly() {
void bgSaveShouldRespondCorrectly() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);
@@ -223,7 +226,7 @@ public class LettuceReactiveRedisConnectionUnitTests {
}
@Test // DATAREDIS-1122
public void xaddShouldHonorMaxlen() {
void xaddShouldHonorMaxlen() {
LettuceReactiveRedisConnection connection = new LettuceReactiveRedisConnection(connectionProvider);

View File

@@ -15,34 +15,31 @@
*/
package org.springframework.data.redis.connection.lettuce;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import io.lettuce.core.ScriptOutputType;
import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import java.util.Arrays;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.awaitility.Awaitility;
import org.junit.Test;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.ReactiveRedisClusterConnection;
import org.springframework.data.redis.connection.ReturnType;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Mark Paluch
* @author Christoph Strobl
*/
public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveScriptingCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Test // DATAREDIS-683
public void scriptExistsShouldReturnState() {
public LettuceReactiveScriptingCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
assumeFalse(connection instanceof ReactiveRedisClusterConnection);
@ParameterizedRedisTest // DATAREDIS-683
void scriptExistsShouldReturnState() {
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
String sha1 = nativeCommands.scriptLoad("return KEYS[1]");
@@ -52,10 +49,10 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683
public void scriptFlushShouldRemoveScripts() {
@ParameterizedRedisTest // DATAREDIS-683
void scriptFlushShouldRemoveScripts() {
assumeFalse(connection instanceof ReactiveRedisClusterConnection);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
String sha1 = nativeCommands.scriptLoad("return KEYS[1]");
@@ -72,10 +69,10 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683
public void evalShaShouldReturnKey() {
@ParameterizedRedisTest // DATAREDIS-683
void evalShaShouldReturnKey() {
assumeFalse(connection instanceof ReactiveRedisClusterConnection);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
String sha1 = nativeCommands.scriptLoad("return KEYS[1]");
@@ -86,10 +83,10 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683, DATAREDIS-711
public void evalShaShouldReturnMulti() {
@ParameterizedRedisTest // DATAREDIS-683, DATAREDIS-711
void evalShaShouldReturnMulti() {
assumeFalse(connection instanceof ReactiveRedisClusterConnection);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
String sha1 = nativeCommands.scriptLoad("return {KEYS[1],ARGV[1]}");
@@ -100,10 +97,10 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683
public void evalShaShouldFail() {
@ParameterizedRedisTest // DATAREDIS-683
void evalShaShouldFail() {
assumeFalse(connection instanceof ReactiveRedisClusterConnection);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
connection.scriptingCommands().evalSha("foo", ReturnType.VALUE, 1, SAME_SLOT_KEY_1_BBUFFER.duplicate())
.as(StepVerifier::create) //
@@ -111,8 +108,8 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verify();
}
@Test // DATAREDIS-683
public void evalShouldReturnStatus() {
@ParameterizedRedisTest // DATAREDIS-683
void evalShouldReturnStatus() {
ByteBuffer script = wrap(String.format("return redis.call('set','%s','ghk')", SAME_SLOT_KEY_1));
@@ -122,8 +119,8 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683
public void evalShouldReturnBooleanFalse() {
@ParameterizedRedisTest // DATAREDIS-683
void evalShouldReturnBooleanFalse() {
ByteBuffer script = wrap("return false");
@@ -132,8 +129,8 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683, DATAREDIS-711
public void evalShouldReturnMultiNumbers() {
@ParameterizedRedisTest // DATAREDIS-683, DATAREDIS-711
void evalShouldReturnMultiNumbers() {
ByteBuffer script = wrap("return {1,2}");
@@ -142,8 +139,8 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verifyComplete();
}
@Test // DATAREDIS-683
public void evalShouldFailWithScriptError() {
@ParameterizedRedisTest // DATAREDIS-683
void evalShouldFailWithScriptError() {
ByteBuffer script = wrap("return {1,2");
@@ -152,30 +149,6 @@ public class LettuceReactiveScriptingCommandsTests extends LettuceReactiveComman
.verify();
}
@Test // DATAREDIS-683
public void scriptKillShouldKillScripts() throws Exception {
assumeFalse(connection instanceof ReactiveRedisClusterConnection);
AtomicBoolean scriptDead = new AtomicBoolean(false);
CountDownLatch sync = new CountDownLatch(1);
Thread th = new Thread(() -> {
try {
sync.countDown();
nativeCommands.eval("local time=1 while time < 10000000000 do time=time+1 end", ScriptOutputType.BOOLEAN);
} catch (Exception e) {
scriptDead.set(true);
}
});
th.start();
sync.await(2, TimeUnit.SECONDS);
Thread.sleep(200);
connection.scriptingCommands().scriptKill().as(StepVerifier::create).expectNext("OK").verifyComplete();
Awaitility.await().untilTrue(scriptDead);
}
private static ByteBuffer wrap(String content) {
return ByteBuffer.wrap(content.getBytes());
}

View File

@@ -16,43 +16,47 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import reactor.test.StepVerifier;
import org.junit.Test;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Mark Paluch
* @author Christoph Strobl
*/
public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveServerCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Test // DATAREDIS-659
public void pingShouldRespondCorrectly() {
public LettuceReactiveServerCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-659
void pingShouldRespondCorrectly() {
connection.ping().as(StepVerifier::create).expectNext("PONG").verifyComplete();
}
@Test // DATAREDIS-659
public void lastSaveShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void lastSaveShouldRespondCorrectly() {
connection.serverCommands().lastSave().as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-659, DATAREDIS-667
public void saveShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659, DATAREDIS-667
void saveShouldRespondCorrectly() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
connection.serverCommands().save().as(StepVerifier::create).expectNext("OK").verifyComplete();
}
@Test // DATAREDIS-659
public void dbSizeShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void dbSizeShouldRespondCorrectly() {
connection.serverCommands().dbSize().as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-659
public void flushDbShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void flushDbShouldRespondCorrectly() {
connection.serverCommands().flushDb() //
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)).as(StepVerifier::create) //
@@ -66,8 +70,8 @@ public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsT
connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-659
public void flushAllShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void flushAllShouldRespondCorrectly() {
connection.serverCommands().flushAll() //
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)).as(StepVerifier::create) //
@@ -81,8 +85,8 @@ public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsT
connection.serverCommands().dbSize().as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-659
public void infoShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void infoShouldRespondCorrectly() {
if (connection instanceof LettuceReactiveRedisClusterConnection) {
@@ -102,8 +106,8 @@ public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsT
}
}
@Test // DATAREDIS-659
public void standaloneInfoWithSectionShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void standaloneInfoWithSectionShouldRespondCorrectly() {
if (connection instanceof LettuceReactiveRedisClusterConnection) {
@@ -124,8 +128,8 @@ public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsT
}
}
@Test // DATAREDIS-659
public void getConfigShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void getConfigShouldRespondCorrectly() {
if (connection instanceof LettuceReactiveRedisClusterConnection) {
@@ -145,8 +149,8 @@ public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsT
}
}
@Test // DATAREDIS-659
public void setConfigShouldApplyConfiguration() {
@ParameterizedRedisTest // DATAREDIS-659
void setConfigShouldApplyConfiguration() {
final String slowLogKey = "slowlog-max-len";
@@ -180,28 +184,28 @@ public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsT
}
}
@Test // DATAREDIS-659
public void configResetstatShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void configResetstatShouldRespondCorrectly() {
connection.serverCommands().resetConfigStats().as(StepVerifier::create).expectNext("OK").verifyComplete();
}
@Test // DATAREDIS-659
public void timeShouldRespondCorrectly() {
@ParameterizedRedisTest // DATAREDIS-659
void timeShouldRespondCorrectly() {
connection.serverCommands().time().as(StepVerifier::create).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-659
public void setClientNameShouldSetName() {
@ParameterizedRedisTest // DATAREDIS-659
void setClientNameShouldSetName() {
// see lettuce-io/lettuce-core#563
assumeFalse(connection instanceof LettuceReactiveRedisClusterConnection);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
connection.serverCommands().setClientName("foo").as(StepVerifier::create).expectNextCount(1).verifyComplete();
connection.serverCommands().getClientName().as(StepVerifier::create).expectNext("foo").verifyComplete();
}
@Test // DATAREDIS-659
public void getClientListShouldReportClient() {
@ParameterizedRedisTest // DATAREDIS-659
void getClientListShouldReportClient() {
connection.serverCommands().getClientList().as(StepVerifier::create).expectNextCount(1).thenCancel().verify();
}
}

View File

@@ -21,9 +21,8 @@ import reactor.test.StepVerifier;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link LettuceReactiveSetCommands}.
@@ -31,21 +30,25 @@ import org.springframework.data.redis.core.ScanOptions;
* @author Christoph Strobl
* @author Mark Paluch
*/
public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveSetCommandsIntegrationIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Test // DATAREDIS-525
public void sAddShouldAddSingleValue() {
public LettuceReactiveSetCommandsIntegrationIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void sAddShouldAddSingleValue() {
assertThat(connection.setCommands().sAdd(KEY_1_BBUFFER, VALUE_1_BBUFFER).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void sAddShouldAddValues() {
@ParameterizedRedisTest // DATAREDIS-525
void sAddShouldAddValues() {
assertThat(connection.setCommands().sAdd(KEY_1_BBUFFER, Arrays.asList(VALUE_1_BBUFFER, VALUE_2_BBUFFER)).block())
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void sRemShouldRemoveSingleValue() {
@ParameterizedRedisTest // DATAREDIS-525
void sRemShouldRemoveSingleValue() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -53,8 +56,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.sismember(KEY_1, VALUE_1)).isFalse();
}
@Test // DATAREDIS-525
public void sRemShouldRemoveValues() {
@ParameterizedRedisTest // DATAREDIS-525
void sRemShouldRemoveValues() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -64,29 +67,29 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.sismember(KEY_1, VALUE_2)).isFalse();
}
@Test // DATAREDIS-525
public void sPopShouldRetrieveRandomValue() {
@ParameterizedRedisTest // DATAREDIS-525
void sPopShouldRetrieveRandomValue() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sPop(KEY_1_BBUFFER).block()).isNotNull();
}
@Test // DATAREDIS-668
public void sPopCountShouldRetrieveValues() {
@ParameterizedRedisTest // DATAREDIS-668
void sPopCountShouldRetrieveValues() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
connection.setCommands().sPop(KEY_1_BBUFFER, 2).as(StepVerifier::create).expectNextCount(2).verifyComplete();
}
@Test // DATAREDIS-525
public void sPopShouldReturnNullWhenNotPresent() {
@ParameterizedRedisTest // DATAREDIS-525
void sPopShouldReturnNullWhenNotPresent() {
assertThat(connection.setCommands().sPop(KEY_1_BBUFFER).block()).isNull();
}
@Test // DATAREDIS-525
public void sMoveShouldMoveValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sMoveShouldMoveValueCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.sadd(KEY_2, VALUE_1);
@@ -95,8 +98,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.sismember(KEY_2, VALUE_3)).isTrue();
}
@Test // DATAREDIS-525
public void sMoveShouldReturnFalseIfValueIsNotAMember() {
@ParameterizedRedisTest // DATAREDIS-525
void sMoveShouldReturnFalseIfValueIsNotAMember() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_1);
@@ -105,8 +108,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.sismember(KEY_2, VALUE_3)).isFalse();
}
@Test // DATAREDIS-525
public void sMoveShouldReturnOperateCorrectlyWhenValueAlreadyPresentInTarget() {
@ParameterizedRedisTest // DATAREDIS-525
void sMoveShouldReturnOperateCorrectlyWhenValueAlreadyPresentInTarget() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
nativeCommands.sadd(KEY_2, VALUE_1, VALUE_3);
@@ -116,32 +119,32 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.sismember(KEY_2, VALUE_3)).isTrue();
}
@Test // DATAREDIS-525
public void sCardShouldCountValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sCardShouldCountValuesCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
assertThat(connection.setCommands().sCard(KEY_1_BBUFFER).block()).isEqualTo(3L);
}
@Test // DATAREDIS-525
public void sIsMemberShouldReturnTrueWhenValueContainedInKey() {
@ParameterizedRedisTest // DATAREDIS-525
void sIsMemberShouldReturnTrueWhenValueContainedInKey() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_1_BBUFFER).block()).isTrue();
}
@Test // DATAREDIS-525
public void sIsMemberShouldReturnFalseWhenValueNotContainedInKey() {
@ParameterizedRedisTest // DATAREDIS-525
void sIsMemberShouldReturnFalseWhenValueNotContainedInKey() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
assertThat(connection.setCommands().sIsMember(KEY_1_BBUFFER, VALUE_3_BBUFFER).block()).isFalse();
}
@Test // DATAREDIS-525, DATAREDIS-647
public void sInterShouldIntersectSetsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525, DATAREDIS-647
void sInterShouldIntersectSetsCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
@@ -155,8 +158,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-525
public void sInterStoreShouldReturnSizeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sInterStoreShouldReturnSizeCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
@@ -166,19 +169,19 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
assertThat(nativeCommands.sismember(KEY_3, VALUE_2)).isTrue();
}
@Test // DATAREDIS-525
public void sUnionShouldCombineSetsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sUnionShouldCombineSetsCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
connection.setCommands().sUnion(Arrays.asList(KEY_1_BBUFFER, KEY_2_BBUFFER)).as(StepVerifier::create) //
.expectNextCount(3) //
.expectComplete();
.verifyComplete();
}
@Test // DATAREDIS-525
public void sUnionStoreShouldReturnSizeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sUnionStoreShouldReturnSizeCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
@@ -187,8 +190,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
.isEqualTo(3L);
}
@Test // DATAREDIS-525, DATAREDIS-647
public void sDiffShouldBeExcecutedCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525, DATAREDIS-647
void sDiffShouldBeExcecutedCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
@@ -202,8 +205,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-525
public void sDiffStoreShouldBeExcecutedCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sDiffStoreShouldBeExcecutedCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2);
nativeCommands.sadd(KEY_2, VALUE_2, VALUE_3);
@@ -212,8 +215,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
.isEqualTo(1L);
}
@Test // DATAREDIS-525
public void sMembersReadsValuesFromSetCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void sMembersReadsValuesFromSetCorrectly() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -222,8 +225,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-743
public void sScanShouldIterateOverSet() {
@ParameterizedRedisTest // DATAREDIS-743
void sScanShouldIterateOverSet() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -237,8 +240,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
.verifyComplete();
}
@Test // DATAREDIS-525
public void sRandMemberReturnsRandomMember() {
@ParameterizedRedisTest // DATAREDIS-525
void sRandMemberReturnsRandomMember() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);
@@ -246,8 +249,8 @@ public class LettuceReactiveSetCommandsTests extends LettuceReactiveCommandsTest
VALUE_3_BBUFFER);
}
@Test // DATAREDIS-525
public void sRandMemberReturnsRandomMembers() {
@ParameterizedRedisTest // DATAREDIS-525
void sRandMemberReturnsRandomMembers() {
nativeCommands.sadd(KEY_1, VALUE_1, VALUE_2, VALUE_3);

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import io.lettuce.core.XReadArgs;
import reactor.test.StepVerifier;
@@ -25,19 +24,18 @@ import java.time.Duration;
import java.util.Collections;
import org.assertj.core.data.Offset;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisStreamCommands.XClaimOptions;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.stream.Consumer;
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.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link LettuceReactiveStreamCommands}.
@@ -47,15 +45,15 @@ import org.springframework.data.redis.connection.stream.StreamOffset;
* @author Tugdual Grall
* @author Dengliming
*/
public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsTestsBase {
@EnabledOnCommand("XADD")
public class LettuceReactiveStreamCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Before
public void before() {
assumeTrue(RedisTestProfileValueSource.atLeast("redisVersion", "5.0"));
public LettuceReactiveStreamCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@Test // DATAREDIS-864
public void xAddShouldAddMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void xAddShouldAddMessage() {
connection.streamCommands().xAdd(KEY_1_BBUFFER, Collections.singletonMap(KEY_2_BBUFFER, VALUE_2_BBUFFER)) //
.as(StepVerifier::create) //
@@ -68,8 +66,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xDelShouldRemoveMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void xDelShouldRemoveMessage() {
RecordId messageId = connection.streamCommands()
.xAdd(KEY_1_BBUFFER, Collections.singletonMap(KEY_2_BBUFFER, VALUE_2_BBUFFER)).block();
@@ -85,8 +83,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xRangeShouldReportMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void xRangeShouldReportMessages() {
connection.streamCommands().xAdd(KEY_1_BBUFFER, Collections.singletonMap(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
.as(StepVerifier::create) //
@@ -118,8 +116,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xReadShouldReadMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void xReadShouldReadMessage() {
connection.streamCommands().xAdd(KEY_1_BBUFFER, Collections.singletonMap(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
.as(StepVerifier::create) //
@@ -136,8 +134,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xReadGroupShouldReadMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void xReadGroupShouldReadMessage() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -156,8 +154,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xRevRangeShouldReportMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void xRevRangeShouldReportMessages() {
connection.streamCommands().xAdd(KEY_1_BBUFFER, Collections.singletonMap(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
.as(StepVerifier::create) //
@@ -179,8 +177,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xGroupCreateShouldCreateGroup() {
@ParameterizedRedisTest // DATAREDIS-864
void xGroupCreateShouldCreateGroup() {
nativeCommands.xadd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2));
@@ -190,8 +188,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xGroupCreateShouldCreateGroupBeforeStream() {
@ParameterizedRedisTest // DATAREDIS-864
void xGroupCreateShouldCreateGroupBeforeStream() {
connection.streamCommands().xGroupCreate(KEY_1_BBUFFER, "group-1", ReadOffset.latest(), false)
.as(StepVerifier::create) //
.expectError(RedisSystemException.class) //
@@ -203,9 +201,9 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
@ParameterizedRedisTest // DATAREDIS-864
@Ignore("commands sent correctly - however lettuce returns false")
public void xGroupDelConsumerShouldRemoveConsumer() {
void xGroupDelConsumerShouldRemoveConsumer() {
String id = nativeCommands.xadd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2));
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, id), "group-1");
@@ -218,8 +216,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-864
public void xGroupDestroyShouldDestroyGroup() {
@ParameterizedRedisTest // DATAREDIS-864
void xGroupDestroyShouldDestroyGroup() {
String id = nativeCommands.xadd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2));
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, id), "group-1");
@@ -229,8 +227,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-1084
public void xPendingShouldLoadOverviewCorrectly() {
@ParameterizedRedisTest // DATAREDIS-1084
void xPendingShouldLoadOverviewCorrectly() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -254,8 +252,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void xPendingShouldLoadEmptyOverviewCorrectly() {
@ParameterizedRedisTest // DATAREDIS-1084
void xPendingShouldLoadEmptyOverviewCorrectly() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -271,8 +269,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void xPendingShouldLoadPendingMessages() {
@ParameterizedRedisTest // DATAREDIS-1084
void xPendingShouldLoadPendingMessages() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -296,8 +294,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void xPendingShouldLoadPendingMessagesForConsumer() {
@ParameterizedRedisTest // DATAREDIS-1084
void xPendingShouldLoadPendingMessagesForConsumer() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -321,8 +319,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void xPendingShouldLoadPendingMessagesForNonExistingConsumer() {
@ParameterizedRedisTest // DATAREDIS-1084
void xPendingShouldLoadPendingMessagesForNonExistingConsumer() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -342,8 +340,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void xPendingShouldLoadEmptyPendingMessages() {
@ParameterizedRedisTest // DATAREDIS-1084
void xPendingShouldLoadEmptyPendingMessages() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -356,8 +354,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void xClaim() {
@ParameterizedRedisTest // DATAREDIS-1084
void xClaim() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");
@@ -378,8 +376,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfo() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfo() {
String firstRecord = nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
String lastRecord = nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -399,8 +397,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfoNoGroup() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfoNoGroup() {
String firstRecord = nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
String lastRecord = nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -417,8 +415,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfoGroups() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfoGroups() {
nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
String lastRecord = nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -435,8 +433,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfoGroupsNoGroup() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfoGroupsNoGroup() {
nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
String lastRecord = nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -445,8 +443,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfoGroupsNoConsumer() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfoGroupsNoConsumer() {
nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
String lastRecord = nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -461,8 +459,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfoConsumers() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfoConsumers() {
nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -479,8 +477,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
}).verifyComplete();
}
@Test // DATAREDIS-1119
public void xinfoConsumersNoConsumer() {
@ParameterizedRedisTest // DATAREDIS-1119
void xinfoConsumersNoConsumer() {
nativeCommands.xadd(KEY_1, KEY_2, VALUE_2);
nativeCommands.xadd(KEY_1, KEY_3, VALUE_3);
@@ -489,8 +487,8 @@ public class LettuceReactiveStreamCommandsTests extends LettuceReactiveCommandsT
connection.streamCommands().xInfoConsumers(KEY_1_BBUFFER, "my-group").as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-1226
public void xClaimJustId() {
@ParameterizedRedisTest // DATAREDIS-1226
void xClaimJustId() {
String initialMessage = nativeCommands.xadd(KEY_1, KEY_1, VALUE_1);
nativeCommands.xgroupCreate(XReadArgs.StreamOffset.from(KEY_1, initialMessage), "my-group");

View File

@@ -38,7 +38,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.assertj.core.data.Offset;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.redis.connection.ReactiveRedisConnection;
@@ -51,6 +51,7 @@ import org.springframework.data.redis.connection.ReactiveStringCommands.SetComma
import org.springframework.data.redis.connection.RedisStringCommands.BitOperation;
import org.springframework.data.redis.connection.RedisStringCommands.SetOption;
import org.springframework.data.redis.core.types.Expiration;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
import org.springframework.data.redis.test.util.HexStringUtils;
import org.springframework.data.redis.util.ByteUtils;
@@ -59,10 +60,14 @@ import org.springframework.data.redis.util.ByteUtils;
* @author Mark Paluch
* @author Michele Mancioppi
*/
public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveStringCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
@Test // DATAREDIS-525
public void getSetShouldReturnPreviousValueCorrectly() {
public LettuceReactiveStringCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void getSetShouldReturnPreviousValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -73,16 +78,16 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525, DATAREDIS-645
public void getSetShouldNotEmitPreviousValueCorrectlyWhenNotExists() {
@ParameterizedRedisTest // DATAREDIS-525, DATAREDIS-645
void getSetShouldNotEmitPreviousValueCorrectlyWhenNotExists() {
connection.stringCommands().getSet(KEY_1_BBUFFER, VALUE_2_BBUFFER).as(StepVerifier::create).verifyComplete();
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void setShouldAddValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void setShouldAddValueCorrectly() {
connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER).as(StepVerifier::create) //
.expectNext(true) //
@@ -91,8 +96,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_1)).isEqualTo(VALUE_1);
}
@Test // DATAREDIS-525
public void setShouldAddValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void setShouldAddValuesCorrectly() {
List<SetCommand> setCommands = Arrays.asList(SetCommand.set(KEY_1_BBUFFER).value(VALUE_1_BBUFFER),
SetCommand.set(KEY_2_BBUFFER).value(VALUE_2_BBUFFER));
@@ -105,8 +110,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void getShouldRetrieveValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void getShouldRetrieveValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -114,13 +119,13 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525, DATAREDIS-645
public void getShouldNotEmitValueValueIfAbsent() {
@ParameterizedRedisTest // DATAREDIS-525, DATAREDIS-645
void getShouldNotEmitValueValueIfAbsent() {
connection.stringCommands().get(KEY_1_BBUFFER).as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-525
public void getShouldRetrieveValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void getShouldRetrieveValuesCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -133,8 +138,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void getShouldRetrieveValuesWithNullCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void getShouldRetrieveValuesWithNullCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_3, VALUE_3);
@@ -149,8 +154,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
}
@Test // DATAREDIS-525
public void mGetShouldRetrieveValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void mGetShouldRetrieveValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -161,8 +166,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
}
@Test // DATAREDIS-525
public void mGetShouldRetrieveNullValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void mGetShouldRetrieveNullValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_3, VALUE_3);
@@ -173,8 +178,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(result.block()).containsExactly(VALUE_1_BBUFFER, ByteBuffer.allocate(0), VALUE_3_BBUFFER);
}
@Test // DATAREDIS-525
public void mGetShouldRetrieveValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void mGetShouldRetrieveValuesCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
nativeCommands.set(KEY_2, VALUE_2);
@@ -193,16 +198,16 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void setNXshouldOnlySetValueWhenNotPresent() {
@ParameterizedRedisTest // DATAREDIS-525
void setNXshouldOnlySetValueWhenNotPresent() {
connection.stringCommands().setNX(KEY_1_BBUFFER, VALUE_1_BBUFFER).as(StepVerifier::create) //
.expectNext(true) //
.verifyComplete();
}
@Test // DATAREDIS-525
public void setNXshouldNotSetValueWhenAlreadyPresent() {
@ParameterizedRedisTest // DATAREDIS-525
void setNXshouldNotSetValueWhenAlreadyPresent() {
nativeCommands.setnx(KEY_1, VALUE_1);
@@ -211,8 +216,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void setEXshouldSetKeyAndExpirationTime() {
@ParameterizedRedisTest // DATAREDIS-525
void setEXshouldSetKeyAndExpirationTime() {
connection.stringCommands().setEX(KEY_1_BBUFFER, VALUE_1_BBUFFER, Expiration.seconds(3)).as(StepVerifier::create) //
.expectNext(true) //
@@ -221,8 +226,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.ttl(KEY_1) > 1).isTrue();
}
@Test // DATAREDIS-525
public void pSetEXshouldSetKeyAndExpirationTime() {
@ParameterizedRedisTest // DATAREDIS-525
void pSetEXshouldSetKeyAndExpirationTime() {
connection.stringCommands().pSetEX(KEY_1_BBUFFER, VALUE_1_BBUFFER, Expiration.milliseconds(600))
.as(StepVerifier::create) //
@@ -232,8 +237,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.pttl(KEY_1) > 1).isTrue();
}
@Test // DATAREDIS-525
public void mSetShouldAddMultipleKeyValuePairs() {
@ParameterizedRedisTest // DATAREDIS-525
void mSetShouldAddMultipleKeyValuePairs() {
Map<ByteBuffer, ByteBuffer> map = new LinkedHashMap<>();
map.put(KEY_1_BBUFFER, VALUE_1_BBUFFER);
@@ -245,8 +250,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void mSetNXShouldAddMultipleKeyValuePairs() {
@ParameterizedRedisTest // DATAREDIS-525
void mSetNXShouldAddMultipleKeyValuePairs() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
@@ -260,8 +265,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void mSetNXShouldNotAddMultipleKeyValuePairsWhenAlreadyExit() {
@ParameterizedRedisTest // DATAREDIS-525
void mSetNXShouldNotAddMultipleKeyValuePairsWhenAlreadyExit() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
@@ -277,8 +282,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_2)).isEqualTo(VALUE_2);
}
@Test // DATAREDIS-525
public void appendShouldDoItsThing() {
@ParameterizedRedisTest // DATAREDIS-525
void appendShouldDoItsThing() {
connection.stringCommands().append(KEY_1_BBUFFER, VALUE_1_BBUFFER).as(StepVerifier::create) //
.expectNext(7L) //
@@ -289,8 +294,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void getRangeShouldReturnSubstringCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void getRangeShouldReturnSubstringCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -299,8 +304,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void getRangeShouldReturnSubstringCorrectlyWithMinUnbound() {
@ParameterizedRedisTest // DATAREDIS-525
void getRangeShouldReturnSubstringCorrectlyWithMinUnbound() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -312,8 +317,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void getRangeShouldReturnSubstringCorrectlyWithMaxUnbound() {
@ParameterizedRedisTest // DATAREDIS-525
void getRangeShouldReturnSubstringCorrectlyWithMaxUnbound() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -325,8 +330,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void setRangeShouldReturnNewStringLengthCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void setRangeShouldReturnNewStringLengthCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -335,8 +340,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void getBitShouldReturnValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void getBitShouldReturnValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -349,8 +354,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void setBitShouldReturnValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void setBitShouldReturnValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -361,8 +366,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.getbit(KEY_1, 1)).isEqualTo(0L);
}
@Test // DATAREDIS-525
public void bitCountShouldReturnValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void bitCountShouldReturnValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -371,8 +376,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-525
public void bitCountShouldCountInRangeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void bitCountShouldCountInRangeCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -381,8 +386,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-562
public void bitFieldSetShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-562
void bitFieldSetShouldWorkCorrectly() {
connection.stringCommands().bitField(KEY_1_BBUFFER, create().set(INT_8).valueAt(offset(0L)).to(10L))
.as(StepVerifier::create)
@@ -393,24 +398,24 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(Collections.singletonList(10L)).verifyComplete();
}
@Test // DATAREDIS-562
public void bitFieldGetShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-562
void bitFieldGetShouldWorkCorrectly() {
connection.stringCommands().bitField(KEY_1_BBUFFER, create().get(INT_8).valueAt(offset(0L)))
.as(StepVerifier::create)
.expectNext(Collections.singletonList(0L)).verifyComplete();
}
@Test // DATAREDIS-562
public void bitFieldIncrByShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-562
void bitFieldIncrByShouldWorkCorrectly() {
connection.stringCommands().bitField(KEY_1_BBUFFER, create().incr(INT_8).valueAt(offset(100L)).by(1L))
.as(StepVerifier::create)
.expectNext(Collections.singletonList(1L)).verifyComplete();
}
@Test // DATAREDIS-562
public void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-562
void bitFieldIncrByWithOverflowShouldWorkCorrectly() {
connection.stringCommands()
.bitField(KEY_1_BBUFFER, create().incr(unsigned(2)).valueAt(offset(102L)).overflow(FAIL).by(1L))
@@ -430,8 +435,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(Collections.singletonList(null)).verifyComplete();
}
@Test // DATAREDIS-562
public void bitfieldShouldAllowMultipleSubcommands() {
@ParameterizedRedisTest // DATAREDIS-562
void bitfieldShouldAllowMultipleSubcommands() {
connection.stringCommands()
.bitField(KEY_1_BBUFFER, create().incr(signed(5)).valueAt(offset(100L)).by(1L).get(unsigned(4)).valueAt(0L))
@@ -439,8 +444,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(Arrays.asList(1L, 0L)).verifyComplete();
}
@Test // DATAREDIS-525
public void bitOpAndShouldWorkAsExpected() {
@ParameterizedRedisTest // DATAREDIS-525
void bitOpAndShouldWorkAsExpected() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
@@ -455,8 +460,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_3)).isEqualTo("value-0");
}
@Test // DATAREDIS-525
public void bitOpOrShouldWorkAsExpected() {
@ParameterizedRedisTest // DATAREDIS-525
void bitOpOrShouldWorkAsExpected() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
@@ -471,8 +476,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
assertThat(nativeCommands.get(KEY_3)).isEqualTo(VALUE_3);
}
@Test // DATAREDIS-525
public void bitNotShouldThrowExceptionWhenMoreThanOnSourceKey() {
@ParameterizedRedisTest // DATAREDIS-525
void bitNotShouldThrowExceptionWhenMoreThanOnSourceKey() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
@@ -482,8 +487,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verify();
}
@Test // DATAREDIS-525
public void strLenShouldReturnValueCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void strLenShouldReturnValueCorrectly() {
nativeCommands.set(KEY_1, VALUE_1);
@@ -492,16 +497,16 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.verifyComplete();
}
@Test // DATAREDIS-697
public void bitPosShouldReturnPositionCorrectly() {
@ParameterizedRedisTest // DATAREDIS-697
void bitPosShouldReturnPositionCorrectly() {
nativeBinaryCommands.set(KEY_1_BBUFFER, ByteBuffer.wrap(HexStringUtils.hexToBytes("fff000")));
connection.stringCommands().bitPos(KEY_1_BBUFFER, false).as(StepVerifier::create).expectNext(12L).verifyComplete();
}
@Test // DATAREDIS-697
public void bitPosShouldReturnPositionInRangeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-697
void bitPosShouldReturnPositionInRangeCorrectly() {
nativeBinaryCommands.set(KEY_1_BBUFFER, ByteBuffer.wrap(HexStringUtils.hexToBytes("fff0f0")));
@@ -510,8 +515,8 @@ public class LettuceReactiveStringCommandsTests extends LettuceReactiveCommandsT
.expectNext(16L).verifyComplete();
}
@Test // DATAREDIS-1103
public void setKeepTTL() {
@ParameterizedRedisTest // DATAREDIS-1103
void setKeepTTL() {
long expireSeconds = 10;
nativeCommands.setex(KEY_1, expireSeconds, VALUE_1);

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.springframework.data.redis.util.ByteUtils.*;
@@ -31,11 +31,12 @@ import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import java.util.concurrent.CancellationException;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.redis.RedisSystemException;
import org.springframework.data.redis.connection.ReactiveSubscription.Message;
import org.springframework.data.redis.connection.ReactiveSubscription.PatternMessage;
@@ -46,20 +47,20 @@ import org.springframework.data.redis.connection.ReactiveSubscription.PatternMes
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(MockitoJUnitRunner.class)
public class LettuceReactiveSubscriptionUnitTests {
@ExtendWith(MockitoExtension.class)
class LettuceReactiveSubscriptionUnitTests {
LettuceReactiveSubscription subscription;
private LettuceReactiveSubscription subscription;
@Mock RedisPubSubReactiveCommands<ByteBuffer, ByteBuffer> commandsMock;
@Before
public void before() {
@BeforeEach
void before() {
subscription = new LettuceReactiveSubscription(commandsMock, e -> new RedisSystemException(e.getMessage(), e));
}
@Test // DATAREDIS-612
public void shouldSubscribeChannels() {
void shouldSubscribeChannels() {
when(commandsMock.subscribe(any())).thenReturn(Mono.empty());
@@ -74,7 +75,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldSubscribeChannelsShouldFail() {
void shouldSubscribeChannelsShouldFail() {
when(commandsMock.subscribe(any())).thenReturn(Mono.error(new RedisConnectionException("Foo")));
@@ -84,7 +85,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldSubscribePatterns() {
void shouldSubscribePatterns() {
when(commandsMock.psubscribe(any())).thenReturn(Mono.empty());
@@ -99,7 +100,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldUnsubscribeChannels() {
void shouldUnsubscribeChannels() {
when(commandsMock.subscribe(any())).thenReturn(Mono.empty());
when(commandsMock.unsubscribe(any())).thenReturn(Mono.empty());
@@ -112,7 +113,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldUnsubscribePatterns() {
void shouldUnsubscribePatterns() {
when(commandsMock.psubscribe(any())).thenReturn(Mono.empty());
when(commandsMock.punsubscribe(any())).thenReturn(Mono.empty());
@@ -125,7 +126,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldEmitChannelMessage() {
void shouldEmitChannelMessage() {
when(commandsMock.subscribe(any())).thenReturn(Mono.empty());
subscription.subscribe(getByteBuffer("foo"), getByteBuffer("bar")).as(StepVerifier::create).verifyComplete();
@@ -145,7 +146,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldEmitPatternMessage() {
void shouldEmitPatternMessage() {
when(commandsMock.psubscribe(any())).thenReturn(Mono.empty());
subscription.pSubscribe(getByteBuffer("foo*"), getByteBuffer("bar*")).as(StepVerifier::create).verifyComplete();
@@ -167,7 +168,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldEmitError() {
void shouldEmitError() {
when(commandsMock.subscribe(any())).thenReturn(Mono.empty());
subscription.subscribe(getByteBuffer("foo"), getByteBuffer("bar")).as(StepVerifier::create).verifyComplete();
@@ -184,7 +185,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void shouldTerminateActiveSubscriptions() {
void shouldTerminateActiveSubscriptions() {
when(commandsMock.psubscribe(any())).thenReturn(Mono.empty());
when(commandsMock.punsubscribe(any())).thenReturn(Mono.empty());
@@ -201,7 +202,7 @@ public class LettuceReactiveSubscriptionUnitTests {
}
@Test // DATAREDIS-612
public void cancelledSubscriptionShouldUnregisterDownstream() {
void cancelledSubscriptionShouldUnregisterDownstream() {
DirectProcessor<io.lettuce.core.pubsub.api.reactive.PatternMessage<ByteBuffer, ByteBuffer>> emitter = DirectProcessor
.create();

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.connection.lettuce;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.domain.Range.Bound.*;
import reactor.test.StepVerifier;
@@ -24,11 +24,10 @@ import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import java.util.Arrays;
import org.junit.Test;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.connection.DefaultTuple;
import org.springframework.data.redis.core.ScanOptions;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link LettuceReactiveZSetCommands}.
@@ -37,7 +36,7 @@ import org.springframework.data.redis.core.ScanOptions;
* @author Mark Paluch
* @author Michele Mancioppi
*/
public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTestsBase {
public class LettuceReactiveZSetCommandsIntegrationTests extends LettuceReactiveCommandsTestSupport {
private static final Range<Long> ONE_TO_TWO = Range.closed(1L, 2L);
@@ -45,13 +44,17 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
private static final Range<Double> TWO_INCLUSIVE_TO_THREE_EXCLUSIVE = Range.rightOpen(2D, 3D);
private static final Range<Double> TWO_EXCLUSIVE_TO_THREE_INCLUSIVE = Range.leftOpen(2D, 3D);
@Test // DATAREDIS-525
public void zAddShouldAddValuesWithScores() {
public LettuceReactiveZSetCommandsIntegrationTests(Fixture fixture) {
super(fixture);
}
@ParameterizedRedisTest // DATAREDIS-525
void zAddShouldAddValuesWithScores() {
assertThat(connection.zSetCommands().zAdd(KEY_1_BBUFFER, 3.5D, VALUE_1_BBUFFER).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void zRemShouldRemoveValuesFromSet() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemShouldRemoveValuesFromSet() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -61,16 +64,16 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zIncrByShouldInreaseAndReturnScore() {
@ParameterizedRedisTest // DATAREDIS-525
void zIncrByShouldInreaseAndReturnScore() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
assertThat(connection.zSetCommands().zIncrBy(KEY_1_BBUFFER, 3.5D, VALUE_1_BBUFFER).block()).isEqualTo(4.5D);
}
@Test // DATAREDIS-525
public void zRankShouldReturnIndexCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRankShouldReturnIndexCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -79,8 +82,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zRank(KEY_1_BBUFFER, VALUE_3_BBUFFER).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zRevRankShouldReturnIndexCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRankShouldReturnIndexCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -89,8 +92,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zRevRank(KEY_1_BBUFFER, VALUE_3_BBUFFER).block()).isEqualTo(0L);
}
@Test // DATAREDIS-525
public void zRangeShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeShouldReturnValuesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -101,8 +104,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeWithScoreShouldReturnTuplesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeWithScoreShouldReturnTuplesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -113,8 +116,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeShouldReturnValuesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -125,8 +128,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeWithScoreShouldReturnTuplesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeWithScoreShouldReturnTuplesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -137,8 +140,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeByScoreShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByScoreShouldReturnValuesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -149,8 +152,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-852
public void zRangeByScoreShouldReturnValuesCorrectlyWithMinUnbounded() {
@ParameterizedRedisTest // DATAREDIS-852
void zRangeByScoreShouldReturnValuesCorrectlyWithMinUnbounded() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -162,8 +165,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-852
public void zRangeByScoreShouldReturnValuesCorrectlyWithMaxUnbounded() {
@ParameterizedRedisTest // DATAREDIS-852
void zRangeByScoreShouldReturnValuesCorrectlyWithMaxUnbounded() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -175,8 +178,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeByScoreShouldReturnValuesCorrectlyWithMinExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByScoreShouldReturnValuesCorrectlyWithMinExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -187,8 +190,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeByScoreShouldReturnValuesCorrectlyWithMaxExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByScoreShouldReturnValuesCorrectlyWithMaxExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -199,8 +202,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeByScoreWithScoreShouldReturnTuplesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByScoreWithScoreShouldReturnTuplesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -212,8 +215,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMinExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMinExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -225,8 +228,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMaxExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMaxExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -238,8 +241,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeByScoreShouldReturnValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByScoreShouldReturnValuesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -250,8 +253,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeByScoreShouldReturnValuesCorrectlyWithMinExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByScoreShouldReturnValuesCorrectlyWithMinExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -262,8 +265,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeByScoreShouldReturnValuesCorrectlyWithMaxExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByScoreShouldReturnValuesCorrectlyWithMaxExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -274,8 +277,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeByScoreWithScoreShouldReturnTuplesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByScoreWithScoreShouldReturnTuplesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -287,8 +290,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMinExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMinExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -300,8 +303,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zRevRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMaxExclusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByScoreWithScoreShouldReturnTuplesCorrectlyWithMaxExclusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -313,8 +316,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-743
public void zScanShouldIterateOverSortedSet() {
@ParameterizedRedisTest // DATAREDIS-743
void zScanShouldIterateOverSortedSet() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -329,8 +332,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.verifyComplete();
}
@Test // DATAREDIS-525
public void zCountShouldCountValuesInRange() {
@ParameterizedRedisTest // DATAREDIS-525
void zCountShouldCountValuesInRange() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -339,8 +342,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_TO_THREE_ALL_INCLUSIVE).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zCountShouldCountValuesInRangeWithMinExlusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zCountShouldCountValuesInRangeWithMinExlusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -349,8 +352,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_EXCLUSIVE_TO_THREE_INCLUSIVE).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void zCountShouldCountValuesInRangeWithMaxExlusion() {
@ParameterizedRedisTest // DATAREDIS-525
void zCountShouldCountValuesInRangeWithMaxExlusion() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -359,8 +362,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zCount(KEY_1_BBUFFER, TWO_INCLUSIVE_TO_THREE_EXCLUSIVE).block()).isEqualTo(1L);
}
@Test // DATAREDIS-525
public void zCountShouldCountValuesInRangeWithNegativeInfinity() {
@ParameterizedRedisTest // DATAREDIS-525
void zCountShouldCountValuesInRangeWithNegativeInfinity() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -370,8 +373,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zCountShouldCountValuesInRangeWithPositiveInfinity() {
@ParameterizedRedisTest // DATAREDIS-525
void zCountShouldCountValuesInRangeWithPositiveInfinity() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -381,8 +384,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zCardShouldReturnSizeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zCardShouldReturnSizeCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -391,16 +394,16 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zCard(KEY_1_BBUFFER).block()).isEqualTo(3L);
}
@Test // DATAREDIS-525
public void zScoreShouldReturnScoreCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zScoreShouldReturnScoreCorrectly() {
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
assertThat(connection.zSetCommands().zScore(KEY_1_BBUFFER, VALUE_2_BBUFFER).block()).isEqualTo(2D);
}
@Test // DATAREDIS-525
public void zRemRangeByRankShouldRemoveValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemRangeByRankShouldRemoveValuesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -409,8 +412,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zRemRangeByRank(KEY_1_BBUFFER, ONE_TO_TWO).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zRemRangeByScoreShouldRemoveValuesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemRangeByScoreShouldRemoveValuesCorrectly() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -419,8 +422,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
assertThat(connection.zSetCommands().zRemRangeByScore(KEY_1_BBUFFER, Range.closed(1D, 2D)).block()).isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zRemRangeByScoreShouldRemoveValuesCorrectlyWithNegativeInfinity() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemRangeByScoreShouldRemoveValuesCorrectlyWithNegativeInfinity() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -430,8 +433,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zRemRangeByScoreShouldRemoveValuesCorrectlyWithPositiveInfinity() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemRangeByScoreShouldRemoveValuesCorrectlyWithPositiveInfinity() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -441,8 +444,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zRemRangeByScoreShouldRemoveValuesCorrectlyWithExcludingMinRange() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemRangeByScoreShouldRemoveValuesCorrectlyWithExcludingMinRange() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -452,8 +455,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(1L);
}
@Test // DATAREDIS-525
public void zRemRangeByScoreShouldRemoveValuesCorrectlyWithExcludingMaxRange() {
@ParameterizedRedisTest // DATAREDIS-525
void zRemRangeByScoreShouldRemoveValuesCorrectlyWithExcludingMaxRange() {
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -463,10 +466,10 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(1L);
}
@Test // DATAREDIS-525
public void zUnionStoreShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zUnionStoreShouldWorkCorrectly() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -479,10 +482,10 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(3L);
}
@Test // DATAREDIS-525
public void zInterStoreShouldWorkCorrectly() {
@ParameterizedRedisTest // DATAREDIS-525
void zInterStoreShouldWorkCorrectly() {
assumeTrue(connectionProvider instanceof StandaloneConnectionProvider);
assumeThat(connectionProvider).isInstanceOf(StandaloneConnectionProvider.class);
nativeCommands.zadd(KEY_1, 1D, VALUE_1);
nativeCommands.zadd(KEY_1, 2D, VALUE_2);
@@ -495,8 +498,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
.isEqualTo(2L);
}
@Test // DATAREDIS-525
public void zRangeByLex() {
@ParameterizedRedisTest // DATAREDIS-525
void zRangeByLex() {
nativeCommands.zadd(KEY_1, 0D, "a");
nativeCommands.zadd(KEY_1, 0D, "b");
@@ -519,8 +522,8 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes
ByteBuffer.wrap("d".getBytes()), ByteBuffer.wrap("e".getBytes()), ByteBuffer.wrap("f".getBytes()));
}
@Test // DATAREDIS-525
public void zRevRangeByLex() {
@ParameterizedRedisTest // DATAREDIS-525
void zRevRangeByLex() {
nativeCommands.zadd(KEY_1, 0D, "a");
nativeCommands.zadd(KEY_1, 0D, "b");

View File

@@ -27,11 +27,14 @@ import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.data.redis.connection.RedisNode;
import org.springframework.data.redis.connection.RedisNode.RedisNodeBuilder;
import org.springframework.data.redis.connection.RedisServer;
@@ -40,10 +43,11 @@ import org.springframework.data.redis.connection.RedisServer;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(MockitoJUnitRunner.class)
public class LettuceSentinelConnectionUnitTests {
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
class LettuceSentinelConnectionUnitTests {
public static final String MASTER_ID = "mymaster";
private static final String MASTER_ID = "mymaster";
private @Mock RedisClient redisClientMock;
@@ -54,8 +58,8 @@ public class LettuceSentinelConnectionUnitTests {
private LettuceSentinelConnection connection;
@Before
public void setUp() {
@BeforeEach
void setUp() {
when(redisClientMock.connectSentinel()).thenReturn(connectionMock);
when(connectionMock.sync()).thenReturn(sentinelCommandsMock);
@@ -63,29 +67,29 @@ public class LettuceSentinelConnectionUnitTests {
}
@Test // DATAREDIS-348
public void shouldConnectAfterCreation() {
void shouldConnectAfterCreation() {
verify(redisClientMock, times(1)).connectSentinel();
}
@Test // DATAREDIS-348
public void failoverShouldBeSentCorrectly() {
void failoverShouldBeSentCorrectly() {
connection.failover(new RedisNodeBuilder().withName(MASTER_ID).build());
verify(sentinelCommandsMock, times(1)).failover(eq(MASTER_ID));
}
@Test // DATAREDIS-348
public void failoverShouldThrowExceptionIfMasterNodeIsNull() {
void failoverShouldThrowExceptionIfMasterNodeIsNull() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.failover(null));
}
@Test // DATAREDIS-348
public void failoverShouldThrowExceptionIfMasterNodeNameIsEmpty() {
void failoverShouldThrowExceptionIfMasterNodeNameIsEmpty() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.failover(new RedisNodeBuilder().build()));
}
@Test // DATAREDIS-348
public void mastersShouldReadMastersCorrectly() {
void mastersShouldReadMastersCorrectly() {
when(sentinelCommandsMock.masters()).thenReturn(Collections.<Map<String, String>> emptyList());
connection.masters();
@@ -93,7 +97,7 @@ public class LettuceSentinelConnectionUnitTests {
}
@Test // DATAREDIS-348
public void shouldReadSlavesCorrectly() {
void shouldReadSlavesCorrectly() {
when(sentinelCommandsMock.slaves(MASTER_ID)).thenReturn(Collections.<Map<String, String>> emptyList());
connection.slaves(MASTER_ID);
@@ -101,7 +105,7 @@ public class LettuceSentinelConnectionUnitTests {
}
@Test // DATAREDIS-348
public void shouldReadSlavesCorrectlyWhenGivenNamedNode() {
void shouldReadSlavesCorrectlyWhenGivenNamedNode() {
when(sentinelCommandsMock.slaves(MASTER_ID)).thenReturn(Collections.<Map<String, String>> emptyList());
connection.slaves(new RedisNodeBuilder().withName(MASTER_ID).build());
@@ -109,44 +113,44 @@ public class LettuceSentinelConnectionUnitTests {
}
@Test // DATAREDIS-348
public void readSlavesShouldThrowExceptionWhenGivenEmptyMasterName() {
void readSlavesShouldThrowExceptionWhenGivenEmptyMasterName() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaves(""));
}
@Test // DATAREDIS-348
public void readSlavesShouldThrowExceptionWhenGivenNull() {
void readSlavesShouldThrowExceptionWhenGivenNull() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaves((RedisNode) null));
}
@Test // DATAREDIS-348
public void readSlavesShouldThrowExceptionWhenNodeWithoutName() {
void readSlavesShouldThrowExceptionWhenNodeWithoutName() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.slaves(new RedisNodeBuilder().build()));
}
@Test // DATAREDIS-348
public void shouldRemoveMasterCorrectlyWhenGivenNamedNode() {
void shouldRemoveMasterCorrectlyWhenGivenNamedNode() {
connection.remove(new RedisNodeBuilder().withName(MASTER_ID).build());
verify(sentinelCommandsMock, times(1)).remove(eq(MASTER_ID));
}
@Test // DATAREDIS-348
public void removeShouldThrowExceptionWhenGivenEmptyMasterName() {
void removeShouldThrowExceptionWhenGivenEmptyMasterName() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.remove(""));
}
@Test // DATAREDIS-348
public void removeShouldThrowExceptionWhenGivenNull() {
void removeShouldThrowExceptionWhenGivenNull() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.remove((RedisNode) null));
}
@Test // DATAREDIS-348
public void removeShouldThrowExceptionWhenNodeWithoutName() {
void removeShouldThrowExceptionWhenNodeWithoutName() {
assertThatIllegalArgumentException().isThrownBy(() -> connection.remove(new RedisNodeBuilder().build()));
}
@Test // DATAREDIS-348
public void monitorShouldBeSentCorrectly() {
void monitorShouldBeSentCorrectly() {
RedisServer server = new RedisServer("127.0.0.1", 6382);
server.setName("anothermaster");

View File

@@ -21,18 +21,13 @@ import io.lettuce.core.ReadFrom;
import reactor.test.StepVerifier;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.AbstractConnectionIntegrationTests;
@@ -43,10 +38,9 @@ import org.springframework.data.redis.connection.RedisSentinelConnection;
import org.springframework.data.redis.connection.RedisServer;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.test.condition.EnabledOnRedisSentinelAvailable;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.extension.RedisSentinel;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.data.redis.test.util.RedisSentinelRule;
/**
* Integration tests for Lettuce and Redis Sentinel interaction.
@@ -54,7 +48,8 @@ import org.springframework.data.redis.test.util.RedisSentinelRule;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@ExtendWith(LettuceConnectionFactoryExtension.class)
@EnabledOnRedisSentinelAvailable
public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrationTests {
private static final String MASTER_NAME = "mymaster";
@@ -73,31 +68,11 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
SENTINEL_CONFIG.setDatabase(5);
}
public static @ClassRule RedisSentinelRule sentinelRule = RedisSentinelRule.forConfig(SENTINEL_CONFIG).oneActive();
public @Rule MinimumRedisVersionRule minimumVersionRule = new MinimumRedisVersionRule();
public LettuceSentinelIntegrationTests(LettuceConnectionFactory connectionFactory, String displayName) {
public LettuceSentinelIntegrationTests(@RedisSentinel LettuceConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Parameters(name = "{1}")
public static List<Object[]> parameters() {
List<Object[]> parameters = new ArrayList<>();
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisSentinel.class, false);
LettuceConnectionFactory pooledConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisSentinel.class, true);
parameters.add(new Object[] { lettuceConnectionFactory, "Sentinel" });
parameters.add(new Object[] { pooledConnectionFactory, "Sentinel/Pooled" });
return parameters;
}
@After
@AfterEach
public void tearDown() {
try {
@@ -111,8 +86,20 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
connection.close();
}
@Test
@Disabled("SELECT not allowed on shared connections")
@Override
public void testMove() {}
@Test
@Disabled("SELECT not allowed on shared connections")
@Override
public void testSelect() {
super.testSelect();
}
@Test // DATAREDIS-348
public void shouldReadMastersCorrectly() {
void shouldReadMastersCorrectly() {
List<RedisServer> servers = (List<RedisServer>) connectionFactory.getSentinelConnection().masters();
assertThat(servers.size()).isEqualTo(1);
@@ -120,7 +107,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-842, DATAREDIS-973
public void shouldUseSpecifiedDatabase() {
void shouldUseSpecifiedDatabase() {
RedisConnection connection = connectionFactory.getConnection();
@@ -136,22 +123,21 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
connectionFactory.afterPropertiesSet();
RedisConnection directConnection = connectionFactory.getConnection();
assertThat(directConnection.exists("foo".getBytes())).isTrue();
assertThat(directConnection.exists("foo".getBytes())).isFalse();
directConnection.select(0);
assertThat(directConnection.exists("foo".getBytes())).isFalse();
assertThat(directConnection.exists("foo".getBytes())).isTrue();
directConnection.close();
connectionFactory.destroy();
}
@Test // DATAREDIS-973
public void reactiveShouldUseSpecifiedDatabase() {
void reactiveShouldUseSpecifiedDatabase() {
RedisConnection connection = connectionFactory.getConnection();
connection.flushAll();
connection.set("foo".getBytes(), "bar".getBytes());
connection.close();
LettuceConnectionFactory connectionFactory = new LettuceConnectionFactory();
connectionFactory.setClientResources(LettuceTestClientResources.getSharedClientResources());
@@ -164,15 +150,16 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
reactiveConnection.keyCommands().exists(ByteBuffer.wrap("foo".getBytes())) //
.as(StepVerifier::create) //
.expectNext(true) //
.expectNext(false) //
.verifyComplete();
reactiveConnection.close();
connectionFactory.destroy();
}
@Test // DATAREDIS-348
public void shouldReadSlavesOfMastersCorrectly() {
@Test
// DATAREDIS-348
void shouldReadSlavesOfMastersCorrectly() {
RedisSentinelConnection sentinelConnection = connectionFactory.getSentinelConnection();
@@ -180,12 +167,11 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
assertThat(servers.size()).isEqualTo(1);
Collection<RedisServer> slaves = sentinelConnection.slaves(servers.get(0));
assertThat(slaves.size()).isEqualTo(2);
assertThat(slaves).contains(SLAVE_0, SLAVE_1);
assertThat(slaves).containsAnyOf(SLAVE_0, SLAVE_1);
}
@Test // DATAREDIS-462
public void factoryWorksWithoutClientResources() {
void factoryWorksWithoutClientResources() {
LettuceConnectionFactory factory = new LettuceConnectionFactory(SENTINEL_CONFIG);
factory.setShutdownTimeout(0);
@@ -203,7 +189,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-576
public void connectionAppliesClientName() {
void connectionAppliesClientName() {
LettuceClientConfiguration clientName = LettuceClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).clientName("clientName").build();
@@ -223,7 +209,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-580
public void factoryWithReadFromMasterSettings() {
void factoryWithReadFromMasterSettings() {
LettuceConnectionFactory factory = new LettuceConnectionFactory(SENTINEL_CONFIG,
LettuceTestClientConfiguration.builder().readFrom(ReadFrom.MASTER).build());
@@ -242,7 +228,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-580
public void factoryWithReadFromSlaveSettings() {
void factoryWithReadFromSlaveSettings() {
LettuceConnectionFactory factory = new LettuceConnectionFactory(SENTINEL_CONFIG,
LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE).build());
@@ -261,7 +247,7 @@ public class LettuceSentinelIntegrationTests extends AbstractConnectionIntegrati
}
@Test // DATAREDIS-580
public void factoryUsesMasterSlaveConnections() {
void factoryUsesMasterSlaveConnections() {
LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder().readFrom(ReadFrom.SLAVE)
.build();

View File

@@ -23,8 +23,8 @@ import io.lettuce.core.pubsub.api.sync.RedisPubSubCommands;
import java.util.Collection;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.data.redis.connection.RedisInvalidSubscriptionException;
@@ -36,7 +36,7 @@ import org.springframework.data.redis.connection.RedisInvalidSubscriptionExcepti
* @author Christoph Strobl
* @author Mark Paluch
*/
public class LettuceSubscriptionTests {
class LettuceSubscriptionUnitTests {
private LettuceSubscription subscription;
@@ -47,8 +47,8 @@ public class LettuceSubscriptionTests {
private LettuceConnectionProvider connectionProvider;
@SuppressWarnings("unchecked")
@Before
public void setUp() {
@BeforeEach
void setUp() {
pubsub = mock(StatefulRedisPubSubConnection.class);
asyncCommands = mock(RedisPubSubCommands.class);
@@ -59,7 +59,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeAllAndClose() {
void testUnsubscribeAllAndClose() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
@@ -75,7 +75,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeAllChannelsWithPatterns() {
void testUnsubscribeAllChannelsWithPatterns() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
@@ -93,7 +93,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeChannelAndClose() {
void testUnsubscribeChannelAndClose() {
byte[][] channel = new byte[][] { "a".getBytes() };
@@ -112,7 +112,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeChannelSomeLeft() {
void testUnsubscribeChannelSomeLeft() {
byte[][] channels = new byte[][] { "a".getBytes(), "b".getBytes() };
@@ -132,7 +132,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeChannelWithPatterns() {
void testUnsubscribeChannelWithPatterns() {
byte[][] channel = new byte[][] { "a".getBytes() };
@@ -153,7 +153,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeChannelWithPatternsSomeLeft() {
void testUnsubscribeChannelWithPatternsSomeLeft() {
byte[][] channel = new byte[][] { "a".getBytes() };
@@ -176,7 +176,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeAllNoChannels() {
void testUnsubscribeAllNoChannels() {
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
subscription.unsubscribe();
@@ -193,7 +193,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribeNotAlive() {
void testUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
@@ -208,18 +208,20 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).punsubscribe();
}
@Test(expected = RedisInvalidSubscriptionException.class)
public void testSubscribeNotAlive() {
@Test
void testSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertThat(subscription.isAlive()).isFalse();
subscription.subscribe(new byte[][] { "s".getBytes() });
assertThatExceptionOfType(RedisInvalidSubscriptionException.class)
.isThrownBy(() -> subscription.subscribe(new byte[][] { "s".getBytes() }));
}
@Test
public void testPUnsubscribeAllAndClose() {
void testPUnsubscribeAllAndClose() {
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
subscription.pUnsubscribe();
@@ -235,7 +237,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testPUnsubscribeAllPatternsWithChannels() {
void testPUnsubscribeAllPatternsWithChannels() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
@@ -253,7 +255,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testPUnsubscribeAndClose() {
void testPUnsubscribeAndClose() {
byte[][] pattern = new byte[][] { "a*".getBytes() };
@@ -272,7 +274,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testPUnsubscribePatternSomeLeft() {
void testPUnsubscribePatternSomeLeft() {
byte[][] patterns = new byte[][] { "a*".getBytes(), "b*".getBytes() };
subscription.pSubscribe(patterns);
@@ -291,7 +293,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testPUnsubscribePatternWithChannels() {
void testPUnsubscribePatternWithChannels() {
byte[][] pattern = new byte[][] { "s*".getBytes() };
@@ -312,7 +314,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testUnsubscribePatternWithChannelsSomeLeft() {
void testUnsubscribePatternWithChannelsSomeLeft() {
byte[][] pattern = new byte[][] { "a*".getBytes() };
@@ -336,7 +338,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testPUnsubscribeAllNoPatterns() {
void testPUnsubscribeAllNoPatterns() {
subscription.subscribe(new byte[][] { "s".getBytes() });
subscription.pUnsubscribe();
@@ -352,7 +354,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testPUnsubscribeNotAlive() {
void testPUnsubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
@@ -367,19 +369,20 @@ public class LettuceSubscriptionTests {
verify(asyncCommands, never()).punsubscribe();
}
@Test(expected = RedisInvalidSubscriptionException.class)
public void testPSubscribeNotAlive() {
@Test
void testPSubscribeNotAlive() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.unsubscribe();
assertThat(subscription.isAlive()).isFalse();
subscription.pSubscribe(new byte[][] { "s*".getBytes() });
assertThatExceptionOfType(RedisInvalidSubscriptionException.class)
.isThrownBy(() -> subscription.pSubscribe(new byte[][] { "s*".getBytes() }));
}
@Test
public void testDoCloseNotSubscribed() {
void testDoCloseNotSubscribed() {
subscription.doClose();
@@ -388,7 +391,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testDoCloseSubscribedChannels() {
void testDoCloseSubscribedChannels() {
subscription.subscribe(new byte[][] { "a".getBytes() });
subscription.doClose();
@@ -398,7 +401,7 @@ public class LettuceSubscriptionTests {
}
@Test
public void testDoCloseSubscribedPatterns() {
void testDoCloseSubscribedPatterns() {
subscription.pSubscribe(new byte[][] { "a*".getBytes() });
subscription.doClose();

View File

@@ -20,21 +20,21 @@ import static org.springframework.data.redis.connection.lettuce.LettuceConnectio
import io.lettuce.core.api.StatefulRedisConnection;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
/**
* Unit tests for {@link PipeliningFlushPolicy}.
*/
@RunWith(MockitoJUnitRunner.class)
public class PipeliningFlushPolicyUnitTests {
@ExtendWith(MockitoExtension.class)
class PipeliningFlushPolicyUnitTests {
@Mock StatefulRedisConnection<?, ?> connection;
@Test // DATAREDIS-1011
public void shouldFlushEachCommand() {
void shouldFlushEachCommand() {
PipeliningFlushPolicy policy = PipeliningFlushPolicy.flushEachCommand();
@@ -48,7 +48,7 @@ public class PipeliningFlushPolicyUnitTests {
}
@Test // DATAREDIS-1011
public void shouldFlushOnClose() {
void shouldFlushOnClose() {
PipeliningFlushPolicy policy = PipeliningFlushPolicy.flushOnClose();
@@ -69,7 +69,7 @@ public class PipeliningFlushPolicyUnitTests {
}
@Test // DATAREDIS-1011
public void shouldFlushOnBuffer() {
void shouldFlushOnBuffer() {
PipeliningFlushPolicy policy = PipeliningFlushPolicy.buffered(2);

View File

@@ -1,16 +0,0 @@
/*
* Copyright 2016-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.redis.connection.lettuce;

View File

@@ -15,6 +15,7 @@
*/
package org.springframework.data.redis.connection.lettuce.extension;
import java.io.Closeable;
import java.lang.annotation.Annotation;
import java.util.HashMap;
import java.util.Map;
@@ -28,13 +29,11 @@ import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.ReactiveRedisConnectionFactory;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceClientConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePool;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.extension.RedisCluster;
@@ -63,10 +62,11 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
ManagedLettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(
SettingsUtils.standaloneConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -76,10 +76,10 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.sentinelConfiguration(),
ManagedLettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.sentinelConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -89,10 +89,10 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
LettuceClientConfiguration configuration = LettucePoolingClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.clusterConfiguration(),
ManagedLettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.clusterConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -102,10 +102,11 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.standaloneConfiguration(),
ManagedLettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(
SettingsUtils.standaloneConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -115,10 +116,10 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.sentinelConfiguration(),
ManagedLettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.sentinelConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -128,10 +129,10 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
LettuceClientConfiguration configuration = LettuceClientConfiguration.builder()
.clientResources(LettuceTestClientResources.getSharedClientResources()).build();
LettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.clusterConfiguration(),
ManagedLettuceConnectionFactory factory = new ManagedLettuceConnectionFactory(SettingsUtils.clusterConfiguration(),
configuration);
factory.afterPropertiesSet();
ShutdownQueue.register(ShutdownQueue.toCloseable(factory));
ShutdownQueue.register(factory.toCloseable());
return factory;
});
@@ -208,54 +209,34 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
static class ManagedLettuceConnectionFactory extends LettuceConnectionFactory
implements ConnectionFactoryTracker.Managed {
public ManagedLettuceConnectionFactory() {
super();
}
private volatile boolean mayClose;
public ManagedLettuceConnectionFactory(RedisStandaloneConfiguration configuration) {
super(configuration);
}
public ManagedLettuceConnectionFactory(String host, int port) {
super(host, port);
}
public ManagedLettuceConnectionFactory(RedisConfiguration redisConfiguration) {
super(redisConfiguration);
}
public ManagedLettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration) {
super(sentinelConfiguration);
}
public ManagedLettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration) {
super(clusterConfiguration);
}
public ManagedLettuceConnectionFactory(LettucePool pool) {
super(pool);
}
public ManagedLettuceConnectionFactory(RedisStandaloneConfiguration standaloneConfig,
ManagedLettuceConnectionFactory(RedisStandaloneConfiguration standaloneConfig,
LettuceClientConfiguration clientConfig) {
super(standaloneConfig, clientConfig);
}
public ManagedLettuceConnectionFactory(RedisConfiguration redisConfiguration,
LettuceClientConfiguration clientConfig) {
super(redisConfiguration, clientConfig);
}
public ManagedLettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration,
ManagedLettuceConnectionFactory(RedisSentinelConfiguration sentinelConfiguration,
LettuceClientConfiguration clientConfig) {
super(sentinelConfiguration, clientConfig);
}
public ManagedLettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration,
ManagedLettuceConnectionFactory(RedisClusterConfiguration clusterConfiguration,
LettuceClientConfiguration clientConfig) {
super(clusterConfiguration, clientConfig);
}
@Override
public void destroy() {
if (!mayClose) {
throw new IllegalStateException(
"Prematurely attempted to close ManagedLettuceConnectionFactory. Shutdown hook didn't run yet which means that the test run isn't finished yet. Please fix the tests so that they don't close this connection factory.");
}
super.destroy();
}
@Override
public String toString() {
@@ -275,5 +256,16 @@ public class LettuceConnectionFactoryExtension implements ParameterResolver {
return builder.toString();
}
Closeable toCloseable() {
return () -> {
try {
mayClose = true;
destroy();
} catch (Exception e) {
e.printStackTrace();
}
};
}
}
}

View File

@@ -24,19 +24,16 @@ import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.PersonObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.OxmSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.XstreamOxmSerializerSingleton;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.oxm.xstream.XStreamMarshaller;
/**
* Parameters for testing implementations of {@link AbstractOperations}
@@ -57,14 +54,6 @@ abstract public class AbstractOperationsTestParams {
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
ObjectFactory<Person> personFactory = new PersonObjectFactory();
// XStream serializer
XStreamMarshaller xstream = new XStreamMarshaller();
try {
xstream.afterPropertiesSet();
} catch (Exception ex) {
throw new RuntimeException("Cannot init XStream", ex);
}
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisStanalone.class);
@@ -93,7 +82,7 @@ abstract public class AbstractOperationsTestParams {
personTemplate.setConnectionFactory(lettuceConnectionFactory);
personTemplate.afterPropertiesSet();
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
OxmSerializer serializer = XstreamOxmSerializerSingleton.getInstance();
RedisTemplate<String, String> xstreamStringTemplate = new RedisTemplate<>();
xstreamStringTemplate.setConnectionFactory(lettuceConnectionFactory);
xstreamStringTemplate.setDefaultSerializer(serializer);

View File

@@ -25,25 +25,18 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.GeoResults;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link org.springframework.data.redis.core.DefaultGeoOperations}
@@ -52,11 +45,9 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@IfProfileValue(name = "redisVersion", value = "3.2.0+")
public class DefaultGeoOperationsTests<K, M> {
public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
@MethodSource("testParams")
@EnabledOnCommand("GEOADD")
public class DefaultGeoOperationsIntegrationTests<K, M> {
private static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
private static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
@@ -67,48 +58,42 @@ public class DefaultGeoOperationsTests<K, M> {
private static final double DISTANCE_PALERMO_CATANIA_MILES = 103.31822459492733;
private static final double DISTANCE_PALERMO_CATANIA_FEET = 545518.8699790037;
private RedisTemplate<K, M> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<M> valueFactory;
private GeoOperations<K, M> geoOperations;
private final RedisTemplate<K, M> redisTemplate;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<M> valueFactory;
private final GeoOperations<K, M> geoOperations;
public DefaultGeoOperationsTests(RedisTemplate<K, M> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultGeoOperationsIntegrationTests(RedisTemplate<K, M> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<M> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.geoOperations = redisTemplate.opsForGeo();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
geoOperations = redisTemplate.opsForGeo();
}
@After
public void tearDown() {
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@Test // DATAREDIS-438, DATAREDIS-614
public void testGeoAdd() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void testGeoAdd() {
Long numAdded = geoOperations.add(keyFactory.instance(), POINT_PALERMO, valueFactory.instance());
assertThat(numAdded).isEqualTo(1L);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void testGeoAddWithLocationMap() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void testGeoAddWithLocationMap() {
Map<M, Point> memberCoordinateMap = new HashMap<>();
memberCoordinateMap.put(valueFactory.instance(), POINT_PALERMO);
@@ -119,8 +104,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(numAdded).isEqualTo(2L);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoDistShouldReturnDistanceInMetersByDefault() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoDistShouldReturnDistanceInMetersByDefault() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -134,8 +119,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(dist.getUnit()).isEqualTo("m");
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoDistShouldReturnDistanceInKilometersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoDistShouldReturnDistanceInKilometersCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -149,8 +134,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(dist.getUnit()).isEqualTo("km");
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoDistShouldReturnDistanceInMilesCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoDistShouldReturnDistanceInMilesCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -164,8 +149,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(dist.getUnit()).isEqualTo("mi");
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoDistShouldReturnDistanceInFeeCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoDistShouldReturnDistanceInFeeCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -179,8 +164,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(dist.getUnit()).isEqualTo("ft");
}
@Test // DATAREDIS-1214
public void geoDistShouldReturnNullIfNoDistanceCalculable() {
@ParameterizedRedisTest // DATAREDIS-1214
void geoDistShouldReturnNullIfNoDistanceCalculable() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -195,8 +180,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(dist).isNull();
}
@Test // DATAREDIS-438, DATAREDIS-614
public void testGeoHash() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void testGeoHash() {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
@@ -212,8 +197,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.get(1)).isEqualTo("sqdtr74hyu0");
}
@Test // DATAREDIS-438, DATAREDIS-614
public void testGeoPos() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void testGeoPos() {
K key = keyFactory.instance();
M v1 = valueFactory.instance();
@@ -235,8 +220,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.get(2)).isNull();
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusShouldReturnMembersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusShouldReturnMembersCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -251,8 +236,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent()).hasSize(2);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusShouldReturnLocationsWithDistance() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusShouldReturnLocationsWithDistance() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -275,8 +260,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member2);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusShouldReturnLocationsWithCoordinates() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusShouldReturnLocationsWithCoordinates() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -303,8 +288,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member1);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusShouldReturnLocationsWithCoordinatesAndDistance() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusShouldReturnLocationsWithCoordinatesAndDistance() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -335,8 +320,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member1);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusByMemberShouldReturnMembersCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -351,8 +336,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent()).hasSize(3);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusByMemberShouldReturnDistanceCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusByMemberShouldReturnDistanceCorrectly() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -373,8 +358,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member3);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusByMemberShouldReturnCoordinates() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusByMemberShouldReturnCoordinates() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -402,8 +387,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member1);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusByMemberShouldReturnCoordinatesAndDistance() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusByMemberShouldReturnCoordinatesAndDistance() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();
@@ -434,8 +419,8 @@ public class DefaultGeoOperationsTests<K, M> {
assertThat(result.getContent().get(1).getContent().getName()).isEqualTo(member3);
}
@Test // DATAREDIS-438, DATAREDIS-614
public void testGeoRemove() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void testGeoRemove() {
K key = keyFactory.instance();
M member1 = valueFactory.instance();

View File

@@ -16,32 +16,23 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link DefaultHashOperations}
@@ -52,31 +43,25 @@ import org.springframework.test.annotation.IfProfileValue;
* @param <HK> Hash key type
* @param <HV> Hash value type
*/
@RunWith(Parameterized.class)
public class DefaultHashOperationsTests<K, HK, HV> {
@MethodSource("testParams")
public class DefaultHashOperationsIntegrationTests<K, HK, HV> {
public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
private final RedisTemplate<K, ?> redisTemplate;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<HK> hashKeyFactory;
private final ObjectFactory<HV> hashValueFactory;
private final HashOperations<K, HK, HV> hashOps;
private RedisTemplate<K, ?> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<HK> hashKeyFactory;
private ObjectFactory<HV> hashValueFactory;
private HashOperations<K, HK, HV> hashOps;
public DefaultHashOperationsTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultHashOperationsIntegrationTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.hashKeyFactory = hashKeyFactory;
this.hashValueFactory = hashValueFactory;
this.hashOps = redisTemplate.opsForHash();
}
@Parameters
public static Collection<Object[]> testParams() {
ObjectFactory<String> stringFactory = new StringObjectFactory();
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
@@ -97,21 +82,16 @@ public class DefaultHashOperationsTests<K, HK, HV> {
{ rawTemplate, rawFactory, rawFactory, rawFactory } });
}
@Before
public void setUp() {
hashOps = redisTemplate.opsForHash();
}
@After
public void tearDown() {
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@Test
public void testEntries() {
@ParameterizedRedisTest
void testEntries() {
K key = keyFactory.instance();
HK key1 = hashKeyFactory.instance();
HV val1 = hashValueFactory.instance();
@@ -126,8 +106,8 @@ public class DefaultHashOperationsTests<K, HK, HV> {
}
}
@Test
public void testDelete() {
@ParameterizedRedisTest
void testDelete() {
K key = keyFactory.instance();
HK key1 = hashKeyFactory.instance();
HV val1 = hashValueFactory.instance();
@@ -140,9 +120,8 @@ public class DefaultHashOperationsTests<K, HK, HV> {
assertThat(numDeleted.longValue()).isEqualTo(2L);
}
@Test // DATAREDIS-305
@IfProfileValue(name = "redisVersion", value = "2.8+")
public void testHScanReadsValuesFully() throws IOException {
@ParameterizedRedisTest // DATAREDIS-305
void testHScanReadsValuesFully() throws IOException {
K key = keyFactory.instance();
HK key1 = hashKeyFactory.instance();
@@ -166,11 +145,10 @@ public class DefaultHashOperationsTests<K, HK, HV> {
assertThat(count).isEqualTo(hashOps.size(key));
}
@Test // DATAREDIS-698
@IfProfileValue(name = "redisVersion", value = "3.0.3+")
public void lengthOfValue() throws IOException {
@ParameterizedRedisTest // DATAREDIS-698
void lengthOfValue() throws IOException {
assumeTrue(hashValueFactory instanceof StringObjectFactory);
assumeThat(hashValueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
HK key1 = hashKeyFactory.instance();

View File

@@ -19,72 +19,48 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Collection;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@IfProfileValue(name = "redisVersion", value = "2.8.9+")
public class DefaultHyperLogLogOperationsTests<K, V> {
@MethodSource("testParams")
public class DefaultHyperLogLogOperationsIntegrationTests<K, V> {
private RedisTemplate<K, V> redisTemplate;
private final RedisTemplate<K, V> redisTemplate;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final HyperLogLogOperations<K, V> hyperLogLogOps;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
private HyperLogLogOperations<K, V> hyperLogLogOps;
public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
public DefaultHyperLogLogOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultHyperLogLogOperationsIntegrationTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.hyperLogLogOps = redisTemplate.opsForHyperLogLog();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Before
public void setUp() {
hyperLogLogOps = redisTemplate.opsForHyperLogLog();
}
@After
public void tearDown() {
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@Test // DATAREDIS-308
@ParameterizedRedisTest // DATAREDIS-308
@SuppressWarnings("unchecked")
public void addShouldAddDistinctValuesCorrectly() {
void addShouldAddDistinctValuesCorrectly() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -94,9 +70,9 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
assertThat(hyperLogLogOps.add(key, v1, v2, v3)).isEqualTo(1L);
}
@Test // DATAREDIS-308
@ParameterizedRedisTest // DATAREDIS-308
@SuppressWarnings("unchecked")
public void addShouldNotAddExistingValuesCorrectly() {
void addShouldNotAddExistingValuesCorrectly() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -107,9 +83,9 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
assertThat(hyperLogLogOps.add(key, v2)).isEqualTo(0L);
}
@Test // DATAREDIS-308
@ParameterizedRedisTest // DATAREDIS-308
@SuppressWarnings("unchecked")
public void sizeShouldCountValuesCorrectly() {
void sizeShouldCountValuesCorrectly() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -120,9 +96,9 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
assertThat(hyperLogLogOps.size(key)).isEqualTo(3L);
}
@Test // DATAREDIS-308
@ParameterizedRedisTest // DATAREDIS-308
@SuppressWarnings("unchecked")
public void sizeShouldCountValuesOfMultipleKeysCorrectly() {
void sizeShouldCountValuesOfMultipleKeysCorrectly() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -138,9 +114,9 @@ public class DefaultHyperLogLogOperationsTests<K, V> {
assertThat(hyperLogLogOps.size(key, key2)).isGreaterThan(3L);
}
@Test // DATAREDIS-308
@ParameterizedRedisTest // DATAREDIS-308
@SuppressWarnings("unchecked")
public void unionShouldMergeValuesOfMultipleKeysCorrectly() throws InterruptedException {
void unionShouldMergeValuesOfMultipleKeysCorrectly() throws InterruptedException {
K sourceKey_1 = keyFactory.instance();
V v1 = valueFactory.instance();

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import java.time.Duration;
import java.util.Arrays;
@@ -24,21 +24,15 @@ import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link DefaultListOperations}
@@ -49,52 +43,42 @@ import org.springframework.test.annotation.IfProfileValue;
* @param <K> Key test
* @param <V> Value test
*/
@RunWith(Parameterized.class)
public class DefaultListOperationsTests<K, V> {
@MethodSource("testParams")
public class DefaultListOperationsIntegrationIntegrationTests<K, V> {
@Rule public MinimumRedisVersionRule redisVersion = new MinimumRedisVersionRule();
private final RedisTemplate<K, V> redisTemplate;
private RedisTemplate<K, V> redisTemplate;
private final ObjectFactory<K> keyFactory;
private ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private ObjectFactory<V> valueFactory;
private final ListOperations<K, V> listOps;
private ListOperations<K, V> listOps;
public DefaultListOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultListOperationsIntegrationIntegrationTests(RedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.listOps = redisTemplate.opsForList();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@BeforeEach
void setUp() {
@Before
public void setUp() {
listOps = redisTemplate.opsForList();
}
@After
public void tearDown() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@Test
public void testLeftPushWithPivot() {
@ParameterizedRedisTest
void testLeftPushWithPivot() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -107,8 +91,8 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.range(key, 0, -1)).containsSequence(v2, v3, v1);
}
@Test
public void testLeftPushIfPresent() {
@ParameterizedRedisTest
void testLeftPushIfPresent() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -121,8 +105,8 @@ public class DefaultListOperationsTests<K, V> {
}
@SuppressWarnings("unchecked")
@Test
public void testLeftPushAll() {
@ParameterizedRedisTest
void testLeftPushAll() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -134,12 +118,12 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.range(key, 0, -1)).contains(v3, v2, v1);
}
@Test // DATAREDIS-611
public void testLeftPopDuration() {
@ParameterizedRedisTest // DATAREDIS-611
@EnabledIfLongRunningTest
void testLeftPopDuration() {
// 1 ms timeout gets upgraded to 1 sec timeout at the moment
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(valueFactory instanceof StringObjectFactory);
assumeThat(valueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -150,12 +134,12 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.leftPop(key, Duration.ofSeconds(1))).isEqualTo(v1);
}
@Test // DATAREDIS-611
public void testRightPopDuration() {
@ParameterizedRedisTest // DATAREDIS-611
@EnabledIfLongRunningTest
void testRightPopDuration() {
// 1 ms timeout gets upgraded to 1 sec timeout at the moment
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(valueFactory instanceof StringObjectFactory);
assumeThat(valueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -166,11 +150,11 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.rightPop(key, Duration.ofSeconds(1))).isEqualTo(v2);
}
@Test
public void testRightPopAndLeftPushTimeout() {
@ParameterizedRedisTest
@EnabledIfLongRunningTest
void testRightPopAndLeftPushTimeout() {
// 1 ms timeout gets upgraded to 1 sec timeout at the moment
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(valueFactory instanceof StringObjectFactory);
assumeThat(valueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -181,11 +165,11 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.rightPopAndLeftPush(key, key2, 1, TimeUnit.MILLISECONDS)).isEqualTo(v1);
}
@Test // DATAREDIS-611
public void testRightPopAndLeftPushDuration() {
@ParameterizedRedisTest // DATAREDIS-611
@EnabledIfLongRunningTest
void testRightPopAndLeftPushDuration() {
// 1 ms timeout gets upgraded to 1 sec timeout at the moment
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(valueFactory instanceof StringObjectFactory);
assumeThat(valueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -196,8 +180,8 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.rightPopAndLeftPush(key, key2, Duration.ofMillis(1))).isEqualTo(v1);
}
@Test
public void testRightPopAndLeftPush() {
@ParameterizedRedisTest
void testRightPopAndLeftPush() {
K key = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -208,8 +192,8 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.rightPopAndLeftPush(key, key2)).isEqualTo(v1);
}
@Test
public void testRightPushWithPivot() {
@ParameterizedRedisTest
void testRightPushWithPivot() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -222,8 +206,8 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v3, v2);
}
@Test
public void testRightPushIfPresent() {
@ParameterizedRedisTest
void testRightPushIfPresent() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -236,8 +220,8 @@ public class DefaultListOperationsTests<K, V> {
}
@SuppressWarnings("unchecked")
@Test
public void testRightPushAll() {
@ParameterizedRedisTest
void testRightPushAll() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -249,9 +233,9 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v2, v3);
}
@Test // DATAREDIS-288
@SuppressWarnings("unchecked")
public void testRightPushAllCollection() {
@ParameterizedRedisTest // DATAREDIS-288
void testRightPushAllCollection() {
K key = keyFactory.instance();
@@ -263,31 +247,30 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.range(key, 0, -1)).containsSequence(v1, v2, v3);
}
@Test // DATAREDIS-288
public void rightPushAllShouldThrowExceptionWhenCalledWithEmptyCollection() {
@ParameterizedRedisTest // DATAREDIS-288
void rightPushAllShouldThrowExceptionWhenCalledWithEmptyCollection() {
assertThatIllegalArgumentException()
.isThrownBy(() -> listOps.rightPushAll(keyFactory.instance(), Collections.<V> emptyList()));
}
@Test
@SuppressWarnings("unchecked")
@ParameterizedRedisTest
// DATAREDIS-288
public void rightPushAllShouldThrowExceptionWhenCollectionContainsNullValue() {
void rightPushAllShouldThrowExceptionWhenCollectionContainsNullValue() {
assertThatIllegalArgumentException()
.isThrownBy(() -> listOps.rightPushAll(keyFactory.instance(), Arrays.asList(valueFactory.instance(), null)));
}
@Test // DATAREDIS-288
public void rightPushAllShouldThrowExceptionWhenCalledWithNull() {
@ParameterizedRedisTest // DATAREDIS-288
void rightPushAllShouldThrowExceptionWhenCalledWithNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> listOps.rightPushAll(keyFactory.instance(), (Collection<V>) null));
}
@Test // DATAREDIS-288
@SuppressWarnings("unchecked")
public void testLeftPushAllCollection() {
@ParameterizedRedisTest // DATAREDIS-288
assumeTrue(redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
void testLeftPushAllCollection() {
assumeThat(redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory).isTrue();
K key = keyFactory.instance();
@@ -299,27 +282,27 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.range(key, 0, -1)).containsSequence(v3, v2, v1);
}
@Test // DATAREDIS-288
public void leftPushAllShouldThrowExceptionWhenCalledWithEmptyCollection() {
@ParameterizedRedisTest // DATAREDIS-288
void leftPushAllShouldThrowExceptionWhenCalledWithEmptyCollection() {
assertThatIllegalArgumentException()
.isThrownBy(() -> listOps.leftPushAll(keyFactory.instance(), Collections.<V> emptyList()));
}
@Test // DATAREDIS-288
public void leftPushAllShouldThrowExceptionWhenCollectionContainsNullValue() {
@ParameterizedRedisTest // DATAREDIS-288
void leftPushAllShouldThrowExceptionWhenCollectionContainsNullValue() {
assertThatIllegalArgumentException()
.isThrownBy(() -> listOps.leftPushAll(keyFactory.instance(), Arrays.asList(valueFactory.instance(), null)));
}
@Test // DATAREDIS-288
public void leftPushAllShouldThrowExceptionWhenCalledWithNull() {
@ParameterizedRedisTest // DATAREDIS-288
void leftPushAllShouldThrowExceptionWhenCalledWithNull() {
assertThatIllegalArgumentException()
.isThrownBy(() -> listOps.leftPushAll(keyFactory.instance(), (Collection<V>) null));
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void indexOf() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void indexOf() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -332,9 +315,9 @@ public class DefaultListOperationsTests<K, V> {
assertThat(listOps.indexOf(key, v1)).isEqualTo(0);
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lastIndexOf() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lastIndexOf() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();

View File

@@ -28,25 +28,20 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.geo.Circle;
import org.springframework.data.geo.Distance;
import org.springframework.data.geo.Metrics;
import org.springframework.data.geo.Point;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveGeoOperations}.
@@ -54,12 +49,10 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@IfProfileValue(name = "redisVersion", value = "3.2.0+")
@MethodSource("testParams")
@EnabledOnCommand("GEOADD")
public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
private static final Point POINT_ARIGENTO = new Point(13.583333, 37.316667);
private static final Point POINT_CATANIA = new Point(15.087269, 37.502669);
private static final Point POINT_PALERMO = new Point(13.361389, 38.115556);
@@ -73,28 +66,20 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveGeoOperationsIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveGeoOperationsIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = redisTemplate;
this.redisTemplate = fixture.getTemplate();
this.geoOperations = redisTemplate.opsForGeo();
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -102,8 +87,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoAdd() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoAdd() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -112,8 +97,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoAddLocation() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoAddLocation() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -125,8 +110,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verify();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoAddMapOfLocations() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoAddMapOfLocations() {
K key = keyFactory.instance();
@@ -140,8 +125,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoAddIterableOfLocations() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoAddIterableOfLocations() {
K key = keyFactory.instance();
@@ -154,8 +139,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoAddPublisherOfLocations() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoAddPublisherOfLocations() {
K key = keyFactory.instance();
@@ -172,8 +157,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoDistShouldReturnDistanceInMetersByDefault() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoDistShouldReturnDistanceInMetersByDefault() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -192,8 +177,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoDistShouldReturnDistanceInKilometersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoDistShouldReturnDistanceInKilometersCorrectly() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -212,8 +197,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoHash() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoHash() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -226,8 +211,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoHashShouldReturnMultipleElements() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoHashShouldReturnMultipleElements() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -243,8 +228,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoPos() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoPos() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -261,8 +246,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoPosShouldReturnMultipleElements() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoPosShouldReturnMultipleElements() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -285,8 +270,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadius() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadius() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -300,8 +285,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoRadiusShouldReturnLocationsWithDistance() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoRadiusShouldReturnLocationsWithDistance() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -327,8 +312,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-438, DATAREDIS-614
public void geoRadiusByMemberShouldReturnMembersCorrectly() {
@ParameterizedRedisTest // DATAREDIS-438, DATAREDIS-614
void geoRadiusByMemberShouldReturnMembersCorrectly() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -342,8 +327,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoRadiusByMemberWithin100_000MetersShouldReturnLocations() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoRadiusByMemberWithin100_000MetersShouldReturnLocations() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -364,8 +349,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoRadiusByMemberWithin100KMShouldReturnLocations() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoRadiusByMemberWithin100KMShouldReturnLocations() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -386,8 +371,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoRadiusByMemberShouldReturnLocationsWithDistance() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoRadiusByMemberShouldReturnLocationsWithDistance() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -414,8 +399,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void geoRemove() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void geoRemove() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();
@@ -433,8 +418,8 @@ public class DefaultReactiveGeoOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-614
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614
void delete() {
K key = keyFactory.instance();
V member1 = valueFactory.instance();

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import reactor.test.StepVerifier;
@@ -27,13 +27,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.SettingsUtils;
@@ -41,9 +36,11 @@ import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveHashOperations}.
@@ -51,7 +48,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
@@ -62,7 +59,16 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
private final ObjectFactory<HK> hashKeyFactory;
private final ObjectFactory<HV> hashValueFactory;
@Parameters(name = "{4}")
public DefaultReactiveHashOperationsIntegrationTests(ReactiveRedisTemplate<K, ?> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory) {
this.redisTemplate = redisTemplate;
this.hashOperations = redisTemplate.opsForHash();
this.keyFactory = keyFactory;
this.hashKeyFactory = hashKeyFactory;
this.hashValueFactory = hashValueFactory;
}
public static Collection<Object[]> testParams() {
ObjectFactory<String> stringFactory = new StringObjectFactory();
@@ -86,26 +92,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
{ rawTemplate, rawFactory, rawFactory, rawFactory, "raw" } });
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
public DefaultReactiveHashOperationsIntegrationTests(ReactiveRedisTemplate<K, ?> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<HK> hashKeyFactory, ObjectFactory<HV> hashValueFactory,
String testName) {
this.redisTemplate = redisTemplate;
this.hashOperations = redisTemplate.opsForHash();
this.keyFactory = keyFactory;
this.hashKeyFactory = hashKeyFactory;
this.hashValueFactory = hashValueFactory;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -113,8 +101,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
connection.close();
}
@Test // DATAREDIS-602
public void remove() {
@ParameterizedRedisTest // DATAREDIS-602
void remove() {
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -131,8 +119,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void hasKey() {
@ParameterizedRedisTest // DATAREDIS-602
void hasKey() {
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();
@@ -154,8 +142,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void get() {
@ParameterizedRedisTest // DATAREDIS-602
void get() {
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();
@@ -172,17 +160,18 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-824
public void getAbsentKey() {
@ParameterizedRedisTest // DATAREDIS-824
void getAbsentKey() {
hashOperations.get(keyFactory.instance(), hashKeyFactory.instance()).as(StepVerifier::create) //
.verifyComplete();
}
@Test // DATAREDIS-602
public void multiGet() {
@ParameterizedRedisTest // DATAREDIS-602
void multiGet() {
assumeTrue(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory);
assumeThat(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory)
.isTrue();
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -200,10 +189,11 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-824
public void multiGetAbsentKeys() {
@ParameterizedRedisTest // DATAREDIS-824
void multiGetAbsentKeys() {
assumeTrue(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory);
assumeThat(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory)
.isTrue();
hashOperations.multiGet(keyFactory.instance(), Arrays.asList(hashKeyFactory.instance(), hashKeyFactory.instance()))
.as(StepVerifier::create) //
@@ -213,10 +203,10 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void increment() {
@ParameterizedRedisTest // DATAREDIS-602
void increment() {
assumeTrue(hashValueFactory instanceof StringObjectFactory);
assumeThat(hashValueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();
@@ -238,11 +228,11 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
@ParameterizedRedisTest // DATAREDIS-602
@SuppressWarnings("unchecked")
public void incrementDouble() {
void incrementDouble() {
assumeTrue(hashValueFactory instanceof StringObjectFactory);
assumeThat(hashValueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();
@@ -264,10 +254,10 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void keys() {
@ParameterizedRedisTest // DATAREDIS-602
void keys() {
assumeTrue(hashKeyFactory instanceof StringObjectFactory);
assumeThat(hashKeyFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -284,8 +274,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void size() {
@ParameterizedRedisTest // DATAREDIS-602
void size() {
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -302,8 +292,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void putAll() {
@ParameterizedRedisTest // DATAREDIS-602
void putAll() {
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -325,8 +315,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void put() {
@ParameterizedRedisTest // DATAREDIS-602
void put() {
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();
@@ -338,8 +328,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void putIfAbsent() {
@ParameterizedRedisTest // DATAREDIS-602
void putIfAbsent() {
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();
@@ -357,10 +347,10 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void values() {
@ParameterizedRedisTest // DATAREDIS-602
void values() {
assumeTrue(hashValueFactory instanceof StringObjectFactory);
assumeThat(hashValueFactory instanceof StringObjectFactory).isTrue();
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -377,10 +367,11 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void entries() {
@ParameterizedRedisTest // DATAREDIS-602
void entries() {
assumeTrue(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory);
assumeThat(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory)
.isTrue();
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -403,10 +394,11 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-743
public void scan() {
@ParameterizedRedisTest // DATAREDIS-743
void scan() {
assumeTrue(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory);
assumeThat(hashKeyFactory instanceof StringObjectFactory && hashValueFactory instanceof StringObjectFactory)
.isTrue();
K key = keyFactory.instance();
HK hashkey1 = hashKeyFactory.instance();
@@ -429,8 +421,8 @@ public class DefaultReactiveHashOperationsIntegrationTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602
void delete() {
K key = keyFactory.instance();
HK hashkey = hashKeyFactory.instance();

View File

@@ -21,18 +21,14 @@ import reactor.test.StepVerifier;
import java.util.Collection;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveHyperLogLogOperations}.
@@ -40,7 +36,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
@@ -50,28 +46,20 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveHyperLogLogOperationsIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveHyperLogLogOperationsIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = redisTemplate;
this.redisTemplate = fixture.getTemplate();
this.hyperLogLogOperations = redisTemplate.opsForHyperLogLog();
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -79,8 +67,8 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602
public void add() {
@ParameterizedRedisTest // DATAREDIS-602
void add() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -91,8 +79,8 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
hyperLogLogOperations.size(key).as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-602
public void union() {
@ParameterizedRedisTest // DATAREDIS-602
void union() {
K mergedKey = keyFactory.instance();
V sharedValue = valueFactory.instance();
@@ -113,8 +101,8 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests<K, V> {
}).verifyComplete();
}
@Test // DATAREDIS-602
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602
void delete() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();

View File

@@ -15,28 +15,25 @@
*/
package org.springframework.data.redis.core;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.*;
import reactor.test.StepVerifier;
import java.time.Duration;
import java.util.Collection;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ByteBufferObjectFactory;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveListOperations}.
@@ -44,11 +41,10 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveListOperationsIntegrationTests<K, V> {
@Rule public MinimumRedisVersionRule redisVersion = new MinimumRedisVersionRule();
private final ReactiveRedisTemplate<K, V> redisTemplate;
private final ReactiveListOperations<K, V> listOperations;
@@ -56,28 +52,20 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveListOperationsIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveListOperationsIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = redisTemplate;
this.redisTemplate = fixture.getTemplate();
this.listOperations = redisTemplate.opsForList();
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -85,8 +73,8 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602
public void trim() {
@ParameterizedRedisTest // DATAREDIS-602
void trim() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -108,8 +96,8 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void size() {
@ParameterizedRedisTest // DATAREDIS-602
void size() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -130,10 +118,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void leftPush() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPush() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -156,10 +144,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void leftPushAll() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPushAll() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -177,8 +165,8 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void leftPushIfPresent() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPushIfPresent() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -200,10 +188,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void leftPushWithPivot() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPushWithPivot() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -228,10 +216,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rightPush() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPush() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -253,10 +241,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rightPushAll() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPushAll() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -271,8 +259,8 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rightPushIfPresent() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPushIfPresent() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -283,10 +271,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.rightPushIfPresent(key, value2).as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-602
public void rightPushWithPivot() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPushWithPivot() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -308,10 +296,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void set() {
@ParameterizedRedisTest // DATAREDIS-602
void set() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -328,10 +316,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void remove() {
@ParameterizedRedisTest // DATAREDIS-602
void remove() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -350,10 +338,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void index() {
@ParameterizedRedisTest // DATAREDIS-602
void index() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -364,9 +352,9 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.index(key, 1).as(StepVerifier::create).expectNext(value2).verifyComplete();
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void indexOf() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void indexOf() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -378,9 +366,9 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.indexOf(key, v1).as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-1196
@IfProfileValue(name = "redisVersion", value = "6.0.6+")
public void lastIndexOf() {
@ParameterizedRedisTest // DATAREDIS-1196
@EnabledOnCommand("LPOS")
void lastIndexOf() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -392,10 +380,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.lastIndexOf(key, v1).as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-602
public void leftPop() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPop() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -406,10 +394,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.leftPop(key).as(StepVerifier::create).expectNext(value2).verifyComplete();
}
@Test // DATAREDIS-602
public void rightPop() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPop() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -420,10 +408,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.rightPop(key).as(StepVerifier::create).expectNext(value2).verifyComplete();
}
@Test // DATAREDIS-602
public void leftPopWithTimeout() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPopWithTimeout() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -434,18 +422,18 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.leftPop(key, Duration.ZERO).as(StepVerifier::create).expectNext(value2).verifyComplete();
}
@Test(expected = IllegalArgumentException.class) // DATAREDIS-602
public void leftPopWithMillisecondTimeoutShouldFail() {
@ParameterizedRedisTest // DATAREDIS-602
void leftPopWithMillisecondTimeoutShouldFail() {
K key = keyFactory.instance();
listOperations.leftPop(key, Duration.ofMillis(1001));
assertThatIllegalArgumentException().isThrownBy(() -> listOperations.leftPop(key, Duration.ofMillis(1001)));
}
@Test // DATAREDIS-602
public void rightPopWithTimeout() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPopWithTimeout() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -456,10 +444,10 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.rightPop(key, Duration.ZERO).as(StepVerifier::create).expectNext(value2).verifyComplete();
}
@Test // DATAREDIS-602
public void rightPopAndLeftPush() {
@ParameterizedRedisTest // DATAREDIS-602
void rightPopAndLeftPush() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K source = keyFactory.instance();
K target = keyFactory.instance();
@@ -473,10 +461,11 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.size(target).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void rightPopAndLeftPushWithTimeout() {
@ParameterizedRedisTest // DATAREDIS-602
@EnabledIfLongRunningTest
void rightPopAndLeftPushWithTimeout() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K source = keyFactory.instance();
K target = keyFactory.instance();
@@ -494,8 +483,8 @@ public class DefaultReactiveListOperationsIntegrationTests<K, V> {
listOperations.size(target).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602
void delete() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();

View File

@@ -16,25 +16,22 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import reactor.test.StepVerifier;
import java.util.Arrays;
import java.util.Collection;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ByteBufferObjectFactory;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveSetOperations}.
@@ -42,7 +39,7 @@ import org.springframework.data.redis.serializer.RedisSerializer;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
@@ -52,28 +49,20 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveSetOperationsIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveSetOperationsIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = redisTemplate;
this.redisTemplate = fixture.getTemplate();
this.setOperations = redisTemplate.opsForSet();
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -81,8 +70,8 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602
public void add() {
@ParameterizedRedisTest // DATAREDIS-602
void add() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -92,10 +81,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.add(key, value1, value2).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void remove() {
@ParameterizedRedisTest // DATAREDIS-602
void remove() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -108,10 +97,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.remove(key, value1, value2).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void pop() {
@ParameterizedRedisTest // DATAREDIS-602
void pop() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -123,10 +112,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
}).verifyComplete();
}
@Test // DATAREDIS-668
public void popWithCount() {
@ParameterizedRedisTest // DATAREDIS-668
void popWithCount() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -138,8 +127,8 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.size(key).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void move() {
@ParameterizedRedisTest // DATAREDIS-602
void move() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -152,10 +141,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.size(otherKey).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void isMember() {
@ParameterizedRedisTest // DATAREDIS-602
void isMember() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -165,10 +154,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.isMember(key, value1).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-873
public void intersect() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-873
void intersect() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -193,8 +182,8 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-873
public void intersectAndStore() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-873
void intersectAndStore() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -220,10 +209,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.isMember(destKey, shared).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-873
public void difference() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-873
void difference() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -248,8 +237,8 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-873
public void differenceAndStore() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-873
void differenceAndStore() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -271,10 +260,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.isMember(destKey, onlyInKey).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-873
public void union() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-873
void union() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -297,8 +286,8 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-873
public void unionAndStore() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-873
void unionAndStore() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -323,10 +312,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.isMember(destKey, onlyInOtherKey).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-602
public void members() {
@ParameterizedRedisTest // DATAREDIS-602
void members() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -337,10 +326,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
.consumeNextWith(actual -> assertThat(actual).isIn(value1, value2)).expectNextCount(1).verifyComplete();
}
@Test // DATAREDIS-743
public void scan() {
@ParameterizedRedisTest // DATAREDIS-743
void scan() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -356,10 +345,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void randomMember() {
@ParameterizedRedisTest // DATAREDIS-602
void randomMember() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -372,10 +361,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
}).verifyComplete();
}
@Test // DATAREDIS-602
public void randomMembers() {
@ParameterizedRedisTest // DATAREDIS-602
void randomMembers() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -386,10 +375,10 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
setOperations.randomMembers(key, 3).as(StepVerifier::create).expectNextCount(3).verifyComplete();
}
@Test // DATAREDIS-602
public void distinctRandomMembers() {
@ParameterizedRedisTest // DATAREDIS-602
void distinctRandomMembers() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -402,8 +391,8 @@ public class DefaultReactiveSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602
void delete() {
K key = keyFactory.instance();
V value = valueFactory.instance();

View File

@@ -23,23 +23,16 @@ import reactor.test.StepVerifier;
import java.util.Collection;
import java.util.Collections;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.PersonObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ReadOffset;
@@ -47,6 +40,7 @@ import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.StreamOffset;
import org.springframework.data.redis.connection.stream.StreamReadOptions;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
@@ -55,6 +49,9 @@ import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveStreamOperations}.
@@ -62,9 +59,10 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Mark Paluch
* @auhtor Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
@EnabledOnCommand("XADD")
public class DefaultReactiveStreamOperationsIntegrationTests<K, HK, HV> {
private final ReactiveRedisTemplate<K, ?> redisTemplate;
private final ReactiveStreamOperations<K, HK, HV> streamOperations;
@@ -73,53 +71,41 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
private final ObjectFactory<HK> hashKeyFactory;
private final ObjectFactory<HV> valueFactory;
RedisSerializer<?> serializer;
private final RedisSerializer<?> serializer;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveStreamOperationsTests(ReactiveRedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<HV> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveStreamOperationsIntegrationTests(Fixture<K, HV> fixture) {
// Currently, only Lettuce supports Redis Streams.
// See https://github.com/xetorthio/jedis/issues/1820
assumeTrue(redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "5.0"));
this.serializer = fixture.getSerializer();
this.keyFactory = fixture.getKeyFactory();
this.hashKeyFactory = (ObjectFactory<HK>) keyFactory;
this.valueFactory = fixture.getValueFactory();
RedisSerializationContext<K, ?> context = null;
if (serializer != null) {
context = RedisSerializationContext.newSerializationContext().value(SerializationPair.fromSerializer(serializer))
if (fixture.getSerializer() != null) {
context = RedisSerializationContext.newSerializationContext()
.value(SerializationPair.fromSerializer(fixture.getSerializer()))
.hashKey(keyFactory instanceof PersonObjectFactory ? RedisSerializer.java() : RedisSerializer.string())
.hashValue(serializer)
.key(keyFactory instanceof PersonObjectFactory ? RedisSerializer.java() : RedisSerializer.string()).build();
}
this.redisTemplate = redisTemplate;
this.streamOperations = serializer != null ? redisTemplate.opsForStream(context) : redisTemplate.opsForStream();
this.keyFactory = keyFactory;
this.hashKeyFactory = (ObjectFactory<HK>) keyFactory;
this.valueFactory = valueFactory;
this.serializer = serializer;
ConnectionFactoryTracker.add(redisTemplate.getConnectionFactory());
this.redisTemplate = fixture.getTemplate();
this.streamOperations = fixture.getSerializer() != null ? redisTemplate.opsForStream(context)
: redisTemplate.opsForStream();
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -127,8 +113,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
connection.close();
}
@Test // DATAREDIS-864
public void addShouldAddMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void addShouldAddMessage() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -150,8 +136,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-864
public void addShouldAddReadSimpleMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void addShouldAddReadSimpleMessage() {
assumeTrue(!(serializer instanceof Jackson2JsonRedisSerializer)
&& !(serializer instanceof GenericJackson2JsonRedisSerializer)
@@ -173,8 +159,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-864
public void addShouldAddReadSimpleMessageWithRawSerializer() {
@ParameterizedRedisTest // DATAREDIS-864
void addShouldAddReadSimpleMessageWithRawSerializer() {
assumeTrue(!(serializer instanceof Jackson2JsonRedisSerializer)
&& !(serializer instanceof GenericJackson2JsonRedisSerializer));
@@ -203,8 +189,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-864
public void rangeShouldReportMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void rangeShouldReportMessages() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -224,8 +210,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-864
public void reverseRangeShouldReportMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void reverseRangeShouldReportMessages() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -240,8 +226,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-864
public void reverseRangeShouldConvertSimpleMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void reverseRangeShouldConvertSimpleMessages() {
assumeTrue(!(serializer instanceof Jackson2JsonRedisSerializer)
&& !(serializer instanceof GenericJackson2JsonRedisSerializer));
@@ -258,8 +244,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.consumeNextWith(it -> assertThat(it.getId()).isEqualTo(messageId1)).verifyComplete();
}
@Test // DATAREDIS-864
public void readShouldReadMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void readShouldReadMessage() {
// assumeFalse(valueFactory instanceof PersonObjectFactory);
// assumeFalse(keyFactory instanceof LongObjectFactory);
@@ -284,8 +270,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
}).verifyComplete();
}
@Test // DATAREDIS-864
public void readShouldReadMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void readShouldReadMessages() {
assumeFalse(valueFactory instanceof PersonObjectFactory);
@@ -302,8 +288,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-864
public void sizeShouldReportStreamSize() {
@ParameterizedRedisTest // DATAREDIS-864
void sizeShouldReportStreamSize() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -324,8 +310,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
.verifyComplete();
}
@Test // DATAREDIS-1084
public void pendingShouldReadMessageSummary() {
@ParameterizedRedisTest // DATAREDIS-1084
void pendingShouldReadMessageSummary() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -347,8 +333,8 @@ public class DefaultReactiveStreamOperationsTests<K, HK, HV> {
}).verifyComplete();
}
@Test // DATAREDIS-1084
public void pendingShouldReadMessageDetails() {
@ParameterizedRedisTest // DATAREDIS-1084
void pendingShouldReadMessageDetails() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();

View File

@@ -32,18 +32,16 @@ import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveValueOperations}.
@@ -52,7 +50,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Christoph Strobl
* @author Jiahe Cai
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
@@ -62,31 +60,23 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final RedisSerializer serializer;
private final RedisSerializer<?> serializer;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveValueOperationsIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveValueOperationsIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = redisTemplate;
this.redisTemplate = fixture.getTemplate();
this.valueOperations = redisTemplate.opsForValue();
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.serializer = serializer;
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
this.serializer = fixture.getSerializer();
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -94,8 +84,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602
public void set() {
@ParameterizedRedisTest // DATAREDIS-602
void set() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -105,8 +95,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key).as(StepVerifier::create).expectNext(value).verifyComplete();
}
@Test // DATAREDIS-602
public void setWithExpiry() {
@ParameterizedRedisTest // DATAREDIS-602
void setWithExpiry() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -122,8 +112,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
.verify();
}
@Test // DATAREDIS-602, DATAREDIS-779
public void setIfAbsent() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-779
void setIfAbsent() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -133,8 +123,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.setIfAbsent(key, value).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-782
public void setIfAbsentWithExpiry() {
@ParameterizedRedisTest // DATAREDIS-782
void setIfAbsentWithExpiry() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -153,8 +143,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
}).verifyComplete();
}
@Test // DATAREDIS-602, DATAREDIS-779
public void setIfPresent() {
@ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-779
void setIfPresent() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -169,8 +159,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key).as(StepVerifier::create).expectNext(laterValue).verifyComplete();
}
@Test // DATAREDIS-782
public void setIfPresentWithExpiry() {
@ParameterizedRedisTest // DATAREDIS-782
void setIfPresentWithExpiry() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -193,8 +183,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
}).verifyComplete();
}
@Test // DATAREDIS-602
public void multiSet() {
@ParameterizedRedisTest // DATAREDIS-602
void multiSet() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -211,8 +201,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key2).as(StepVerifier::create).expectNext(value2).verifyComplete();
}
@Test // DATAREDIS-602
public void multiSetIfAbsent() {
@ParameterizedRedisTest // DATAREDIS-602
void multiSetIfAbsent() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -232,8 +222,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key2).as(StepVerifier::create).expectNextCount(0).verifyComplete();
}
@Test // DATAREDIS-602
public void get() {
@ParameterizedRedisTest // DATAREDIS-602
void get() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -245,8 +235,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key).as(StepVerifier::create).expectNext(value).verifyComplete();
}
@Test // DATAREDIS-602
public void getAndSet() {
@ParameterizedRedisTest // DATAREDIS-602
void getAndSet() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -261,8 +251,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key).as(StepVerifier::create).expectNext(nextValue).verifyComplete();
}
@Test // DATAREDIS-602
public void multiGet() {
@ParameterizedRedisTest // DATAREDIS-602
void multiGet() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -288,8 +278,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
.expectNext(Arrays.asList(value2, value1, absentValue)).verifyComplete();
}
@Test // DATAREDIS-602
public void append() {
@ParameterizedRedisTest // DATAREDIS-602
void append() {
assumeTrue(serializer instanceof StringRedisSerializer);
@@ -303,8 +293,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key).as(StepVerifier::create).expectNext((V) (value + "foo")).verifyComplete();
}
@Test // DATAREDIS-602
public void getRange() {
@ParameterizedRedisTest // DATAREDIS-602
void getRange() {
assumeTrue(serializer instanceof StringRedisSerializer);
@@ -318,8 +308,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.get(key, 1, 4).as(StepVerifier::create).expectNext(substring).verifyComplete();
}
@Test // DATAREDIS-602
public void setRange() {
@ParameterizedRedisTest // DATAREDIS-602
void setRange() {
assumeTrue(serializer instanceof StringRedisSerializer);
@@ -338,8 +328,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
}).verifyComplete();
}
@Test // DATAREDIS-602
public void size() {
@ParameterizedRedisTest // DATAREDIS-602
void size() {
assumeTrue(serializer instanceof StringRedisSerializer);
@@ -351,8 +341,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
.verify();
}
@Test // DATAREDIS-602
public void setBit() {
@ParameterizedRedisTest // DATAREDIS-602
void setBit() {
K key = keyFactory.instance();
@@ -360,8 +350,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.setBit(key, 2, true).as(StepVerifier::create).expectNext(false).expectComplete();
}
@Test // DATAREDIS-602
public void getBit() {
@ParameterizedRedisTest // DATAREDIS-602
void getBit() {
K key = keyFactory.instance();
@@ -370,8 +360,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.getBit(key, 1).as(StepVerifier::create).expectNext(false).expectComplete();
}
@Test // DATAREDIS-562
public void bitField() {
@ParameterizedRedisTest // DATAREDIS-562
void bitField() {
K key = keyFactory.instance();
@@ -389,8 +379,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
.expectNext(Collections.singletonList(null)).verifyComplete();
}
@Test // DATAREDIS-602
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602
void delete() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -402,8 +392,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.size(key).as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-784
public void increment() {
@ParameterizedRedisTest // DATAREDIS-784
void increment() {
K key = keyFactory.instance();
@@ -412,8 +402,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.increment(key).as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-784
public void incrementByLongDelta() {
@ParameterizedRedisTest // DATAREDIS-784
void incrementByLongDelta() {
K key = keyFactory.instance();
@@ -424,8 +414,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.increment(key, 1L).as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-784
public void incrementByFloatDelta() {
@ParameterizedRedisTest // DATAREDIS-784
void incrementByFloatDelta() {
K key = keyFactory.instance();
@@ -436,8 +426,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.increment(key, 0.2).as(StepVerifier::create).expectNext(0.0).verifyComplete();
}
@Test // DATAREDIS-784
public void decrement() {
@ParameterizedRedisTest // DATAREDIS-784
void decrement() {
K key = keyFactory.instance();
@@ -446,8 +436,8 @@ public class DefaultReactiveValueOperationsIntegrationTests<K, V> {
valueOperations.decrement(key).as(StepVerifier::create).expectNext(-2L).verifyComplete();
}
@Test // DATAREDIS-784
public void decrementByLongDelta() {
@ParameterizedRedisTest // DATAREDIS-784
void decrementByLongDelta() {
K key = keyFactory.instance();

View File

@@ -16,7 +16,7 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import reactor.test.StepVerifier;
@@ -25,23 +25,21 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.domain.Range;
import org.springframework.data.redis.ByteBufferObjectFactory;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisZSetCommands.Aggregate;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link DefaultReactiveZSetOperations}.
@@ -50,7 +48,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Christoph Strobl
* @author Andrey Shlykov
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
@@ -66,30 +64,22 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final RedisSerializer serializer;
private final RedisSerializer<?> serializer;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public DefaultReactiveZSetOperationsIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate,
ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
public DefaultReactiveZSetOperationsIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = redisTemplate;
this.redisTemplate = fixture.getTemplate();
this.zSetOperations = redisTemplate.opsForZSet();
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.serializer = serializer;
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
this.serializer = fixture.getSerializer();
}
@Before
@BeforeEach
public void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
@@ -98,8 +88,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602
public void add() {
@ParameterizedRedisTest // DATAREDIS-602
void add() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -107,8 +97,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.add(key, value, 42.1).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-602
public void addAll() {
@ParameterizedRedisTest // DATAREDIS-602
void addAll() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -126,8 +116,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.score(key, value1).as(StepVerifier::create).expectNext(52.1d).verifyComplete();
}
@Test // DATAREDIS-602
public void remove() {
@ParameterizedRedisTest // DATAREDIS-602
void remove() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -139,8 +129,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.remove(key, value).as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-602
public void incrementScore() {
@ParameterizedRedisTest // DATAREDIS-602
void incrementScore() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -150,8 +140,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.incrementScore(key, value, 1.1).as(StepVerifier::create).expectNext(43.2).verifyComplete();
}
@Test // DATAREDIS-602
public void rank() {
@ParameterizedRedisTest // DATAREDIS-602
void rank() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -163,8 +153,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.rank(key, value1).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRank() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRank() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -176,10 +166,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.reverseRank(key, value1).as(StepVerifier::create).expectNext(0L).verifyComplete();
}
@Test // DATAREDIS-602
public void range() {
@ParameterizedRedisTest // DATAREDIS-602
void range() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -194,10 +184,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
}
@Test // DATAREDIS-602
public void rangeWithScores() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeWithScores() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -211,10 +201,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rangeByScore() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeByScore() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -228,10 +218,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rangeByScoreWithScores() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeByScoreWithScores() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -245,10 +235,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rangeByScoreWithLimit() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeByScoreWithLimit() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -263,10 +253,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rangeByScoreWithScoresWithLimit() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeByScoreWithScoresWithLimit() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -281,10 +271,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRange() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRange() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -299,10 +289,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
}
@Test // DATAREDIS-602
public void reverseRangeWithScores() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeWithScores() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -316,10 +306,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRangeByScore() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeByScore() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -333,10 +323,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRangeByScoreWithScores() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeByScoreWithScores() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -350,10 +340,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRangeByScoreWithLimit() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeByScoreWithLimit() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -368,10 +358,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRangeByScoreWithScoresWithLimit() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeByScoreWithScoresWithLimit() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -386,10 +376,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-743
public void scan() {
@ParameterizedRedisTest // DATAREDIS-743
void scan() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -409,8 +399,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void count() {
@ParameterizedRedisTest // DATAREDIS-602
void count() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -423,10 +413,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.count(key, Range.closed(0d, 10d)).as(StepVerifier::create).expectNext(1L).verifyComplete();
}
@Test // DATAREDIS-729
public void lexCount() {
@ParameterizedRedisTest // DATAREDIS-729
void lexCount() {
assumeTrue(serializer instanceof StringRedisSerializer);
assumeThat(serializer instanceof StringRedisSerializer).isTrue();
K key = keyFactory.instance();
@@ -443,8 +433,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.lexCount(key, Range.rightOpen("b", "f")).as(StepVerifier::create).expectNext(4L).verifyComplete();
}
@Test // DATAREDIS-602
public void size() {
@ParameterizedRedisTest // DATAREDIS-602
void size() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -456,8 +446,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.size(key).as(StepVerifier::create).expectNext(2L).verifyComplete();
}
@Test // DATAREDIS-602
public void score() {
@ParameterizedRedisTest // DATAREDIS-602
void score() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -470,10 +460,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.score(key, value2).as(StepVerifier::create).expectNext(10d).verifyComplete();
}
@Test // DATAREDIS-602
public void removeRange() {
@ParameterizedRedisTest // DATAREDIS-602
void removeRange() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -486,10 +476,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.range(key, ZERO_TO_FIVE).as(StepVerifier::create).expectNext(value1).verifyComplete();
}
@Test // DATAREDIS-602
public void removeRangeByScore() {
@ParameterizedRedisTest // DATAREDIS-602
void removeRangeByScore() {
assumeFalse(valueFactory instanceof ByteBufferObjectFactory);
assumeThat(valueFactory instanceof ByteBufferObjectFactory).isFalse();
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -506,8 +496,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void unionAndStore() {
@ParameterizedRedisTest // DATAREDIS-602
void unionAndStore() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -527,8 +517,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.range(destKey, Range.closed(0L, 100L)).as(StepVerifier::create).expectNextCount(3).verifyComplete();
}
@Test // DATAREDIS-746
public void unionAndStoreWithAggregation() {
@ParameterizedRedisTest // DATAREDIS-746
void unionAndStoreWithAggregation() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -554,8 +544,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
zSetOperations.score(destKey, shared).as(StepVerifier::create).expectNext(33d).verifyComplete();
}
@Test // DATAREDIS-602
public void intersectAndStore() {
@ParameterizedRedisTest // DATAREDIS-602
void intersectAndStore() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -579,8 +569,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-746
public void intersectAndStoreWithAggregation() {
@ParameterizedRedisTest // DATAREDIS-746
void intersectAndStoreWithAggregation() {
K key = keyFactory.instance();
K otherKey = keyFactory.instance();
@@ -612,10 +602,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void rangeByLex() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeByLex() {
assumeTrue(serializer instanceof StringRedisSerializer);
assumeThat(serializer instanceof StringRedisSerializer).isTrue();
K key = keyFactory.instance();
V a = (V) "a";
@@ -630,10 +620,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
}
@Test // DATAREDIS-602
public void rangeByLexWithLimit() {
@ParameterizedRedisTest // DATAREDIS-602
void rangeByLexWithLimit() {
assumeTrue(serializer instanceof StringRedisSerializer);
assumeThat(serializer instanceof StringRedisSerializer).isTrue();
K key = keyFactory.instance();
V a = (V) "a";
@@ -653,10 +643,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRangeByLex() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeByLex() {
assumeTrue(serializer instanceof StringRedisSerializer);
assumeThat(serializer instanceof StringRedisSerializer).isTrue();
K key = keyFactory.instance();
V a = (V) "a";
@@ -670,10 +660,10 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void reverseRangeByLexLimit() {
@ParameterizedRedisTest // DATAREDIS-602
void reverseRangeByLexLimit() {
assumeTrue(serializer instanceof StringRedisSerializer);
assumeThat(serializer instanceof StringRedisSerializer).isTrue();
K key = keyFactory.instance();
V a = (V) "a";
@@ -693,8 +683,8 @@ public class DefaultReactiveZSetOperationsIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void delete() {
@ParameterizedRedisTest // DATAREDIS-602
void delete() {
K key = keyFactory.instance();
V value = valueFactory.instance();

View File

@@ -16,7 +16,6 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import java.io.IOException;
import java.util.Arrays;
@@ -24,20 +23,11 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link DefaultSetOperations}
@@ -47,40 +37,30 @@ import org.springframework.test.annotation.IfProfileValue;
* @author Thomas Darimont
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
@SuppressWarnings("unchecked")
public class DefaultSetOperationsTests<K, V> {
public class DefaultSetOperationsIntegrationTests<K, V> {
private RedisTemplate<K, V> redisTemplate;
private final RedisTemplate<K, V> redisTemplate;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final SetOperations<K, V> setOps;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
private SetOperations<K, V> setOps;
public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
public DefaultSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultSetOperationsIntegrationTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.setOps = redisTemplate.opsForSet();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
setOps = redisTemplate.opsForSet();
}
@After
public void tearDown() {
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
@@ -88,10 +68,8 @@ public class DefaultSetOperationsTests<K, V> {
}
@SuppressWarnings("unchecked")
@Test
public void testDistinctRandomMembers() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest
void testDistinctRandomMembers() {
K setKey = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -100,32 +78,26 @@ public class DefaultSetOperationsTests<K, V> {
setOps.add(setKey, v1);
setOps.add(setKey, v2);
setOps.add(setKey, v3);
Set<V> members = setOps.distinctRandomMembers(setKey, 2);
assertThat(members).hasSize(2).contains(v1, v2, v3);
assertThat(members).contains(v1, v2);
}
@Test
public void testRandomMembersWithDuplicates() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest
void testRandomMembersWithDuplicates() {
K setKey = keyFactory.instance();
V v1 = valueFactory.instance();
V v2 = valueFactory.instance();
setOps.add(setKey, v1);
setOps.add(setKey, v2);
List<V> members = setOps.randomMembers(setKey, 2);
assertThat(members).hasSize(2).contains(v1, v2);
assertThat(members).hasSize(2).contains(v1);
}
@Test
public void testRandomMembersNegative() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest
void testRandomMembersNegative() {
try {
setOps.randomMembers(keyFactory.instance(), -1);
@@ -133,10 +105,8 @@ public class DefaultSetOperationsTests<K, V> {
} catch (IllegalArgumentException e) {}
}
@Test
public void testDistinctRandomMembersNegative() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest
void testDistinctRandomMembersNegative() {
try {
setOps.distinctRandomMembers(keyFactory.instance(), -2);
@@ -145,8 +115,8 @@ public class DefaultSetOperationsTests<K, V> {
}
@SuppressWarnings("unchecked")
@Test
public void testMove() {
@ParameterizedRedisTest
void testMove() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -162,8 +132,8 @@ public class DefaultSetOperationsTests<K, V> {
}
@SuppressWarnings("unchecked")
@Test
public void testPop() {
@ParameterizedRedisTest
void testPop() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -174,8 +144,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.members(key)).isEmpty();
}
@Test // DATAREDIS-668
public void testPopWithCount() {
@ParameterizedRedisTest // DATAREDIS-668
void testPopWithCount() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -189,8 +159,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(result.get(0)).isInstanceOf(v1.getClass());
}
@Test
public void testRandomMember() {
@ParameterizedRedisTest
void testRandomMember() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -200,8 +170,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.randomMember(key)).isEqualTo(v1);
}
@Test
public void testAdd() {
@ParameterizedRedisTest
void testAdd() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -212,8 +182,8 @@ public class DefaultSetOperationsTests<K, V> {
}
@SuppressWarnings("unchecked")
@Test
public void testRemove() {
@ParameterizedRedisTest
void testRemove() {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -227,10 +197,9 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.members(key)).containsOnly(v3);
}
@Test // DATAREDIS-304
@ParameterizedRedisTest // DATAREDIS-304
@SuppressWarnings("unchecked")
@IfProfileValue(name = "redisVersion", value = "2.8+")
public void testSSCanReadsValuesFully() throws IOException {
void testSSCanReadsValuesFully() throws IOException {
K key = keyFactory.instance();
V v1 = valueFactory.instance();
@@ -248,8 +217,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(count).isEqualTo(setOps.size(key));
}
@Test // DATAREDIS-873
public void diffShouldReturnDifference() {
@ParameterizedRedisTest // DATAREDIS-873
void diffShouldReturnDifference() {
K sourceKey1 = keyFactory.instance();
K sourceKey2 = keyFactory.instance();
@@ -265,8 +234,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.difference(Arrays.asList(sourceKey1, sourceKey2))).contains(v1);
}
@Test // DATAREDIS-873
public void diffAndStoreShouldReturnDifferenceShouldReturnNumberOfElementsInDestination() {
@ParameterizedRedisTest // DATAREDIS-873
void diffAndStoreShouldReturnDifferenceShouldReturnNumberOfElementsInDestination() {
K sourceKey1 = keyFactory.instance();
K sourceKey2 = keyFactory.instance();
@@ -283,8 +252,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.differenceAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey)).isEqualTo(1L);
}
@Test // DATAREDIS-873
public void unionShouldConcatSets() {
@ParameterizedRedisTest // DATAREDIS-873
void unionShouldConcatSets() {
K sourceKey1 = keyFactory.instance();
K sourceKey2 = keyFactory.instance();
@@ -300,8 +269,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.union(Arrays.asList(sourceKey1, sourceKey2))).contains(v1, v2, v3, v4);
}
@Test // DATAREDIS-873
public void unionAndStoreShouldReturnDifferenceShouldReturnNumberOfElementsInDestination() {
@ParameterizedRedisTest // DATAREDIS-873
void unionAndStoreShouldReturnDifferenceShouldReturnNumberOfElementsInDestination() {
K sourceKey1 = keyFactory.instance();
K sourceKey2 = keyFactory.instance();
@@ -318,8 +287,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.unionAndStore(Arrays.asList(sourceKey1, sourceKey2), destinationKey)).isEqualTo(4L);
}
@Test // DATAREDIS-873
public void intersectShouldReturnElements() {
@ParameterizedRedisTest // DATAREDIS-873
void intersectShouldReturnElements() {
K sourceKey1 = keyFactory.instance();
K sourceKey2 = keyFactory.instance();
@@ -335,8 +304,8 @@ public class DefaultSetOperationsTests<K, V> {
assertThat(setOps.intersect(Arrays.asList(sourceKey1, sourceKey2))).hasSize(2);
}
@Test // DATAREDIS-448, DATAREDIS-873
public void intersectAndStoreShouldReturnNumberOfElementsInDestination() {
@ParameterizedRedisTest // DATAREDIS-448, DATAREDIS-873
void intersectAndStoreShouldReturnNumberOfElementsInDestination() {
K sourceKey1 = keyFactory.instance();
K sourceKey2 = keyFactory.instance();

View File

@@ -16,37 +16,35 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.assertj.core.api.Assumptions;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.domain.Range;
import org.springframework.data.domain.Range.Bound;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.stream.Consumer;
import org.springframework.data.redis.connection.stream.PendingMessages;
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
import org.springframework.data.redis.connection.stream.RecordId;
import org.springframework.data.redis.connection.stream.MapRecord;
import org.springframework.data.redis.connection.stream.ObjectRecord;
import org.springframework.data.redis.connection.stream.PendingMessages;
import org.springframework.data.redis.connection.stream.PendingMessagesSummary;
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.stream.StreamReadOptions;
import org.springframework.data.redis.connection.RedisZSetCommands.Limit;
import org.springframework.data.redis.connection.stream.StreamRecords;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.test.condition.EnabledOnCommand;
import org.springframework.data.redis.test.condition.EnabledOnRedisDriver;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link DefaultStreamOperations}
@@ -54,42 +52,39 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
public class DefaultStreamOperationsTests<K, HK, HV> {
@MethodSource("testParams")
@EnabledOnCommand("XADD")
public class DefaultStreamOperationsIntegrationTests<K, HK, HV> {
private RedisTemplate<K, ?> redisTemplate;
private final RedisTemplate<K, ?> redisTemplate;
private final @EnabledOnRedisDriver.DriverQualifier RedisConnectionFactory connectionFactory;
private ObjectFactory<K> keyFactory;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<HK> hashKeyFactory;
private final ObjectFactory<HV> hashValueFactory;
private final StreamOperations<K, HK, HV> streamOps;
private ObjectFactory<HK> hashKeyFactory;
private ObjectFactory<HV> hashValueFactory;
private StreamOperations<K, HK, HV> streamOps;
public DefaultStreamOperationsTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultStreamOperationsIntegrationTests(RedisTemplate<K, ?> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<?> objectFactory) {
// Currently, only Lettuce supports Redis Streams.
// See https://github.com/xetorthio/jedis/issues/1820
assumeTrue(redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
assumeTrue(RedisTestProfileValueSource.atLeast("redisVersion", "5.0"));
assumeThat(redisTemplate.getRequiredConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class);
this.redisTemplate = redisTemplate;
this.connectionFactory = redisTemplate.getRequiredConnectionFactory();
this.keyFactory = keyFactory;
this.hashKeyFactory = (ObjectFactory<HK>) keyFactory;
this.hashValueFactory = (ObjectFactory<HV>) objectFactory;
streamOps = redisTemplate.opsForStream();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
streamOps = redisTemplate.opsForStream();
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
@@ -97,8 +92,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
});
}
@Test // DATAREDIS-864
public void addShouldAddMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void addShouldAddMessage() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -120,8 +115,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
}
}
@Test // DATAREDIS-864
public void addShouldAddReadSimpleMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void addShouldAddReadSimpleMessage() {
K key = keyFactory.instance();
HV value = hashValueFactory.instance();
@@ -140,13 +135,13 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(message.getValue()).isEqualTo(value);
}
@Test // DATAREDIS-864
public void simpleMessageReadWriteSymmetry() {
@ParameterizedRedisTest // DATAREDIS-864
void simpleMessageReadWriteSymmetry() {
K key = keyFactory.instance();
HV value = hashValueFactory.instance();
Assumptions.assumeThat(value).isNotInstanceOf(Person.class);
assumeThat(value).isNotInstanceOf(Person.class);
RecordId messageId = streamOps.add(StreamRecords.objectBacked(value).withStreamKey(key));
@@ -162,8 +157,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(message.getValue().values()).containsExactly(value);
}
@Test // DATAREDIS-864
public void rangeShouldReportMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void rangeShouldReportMessages() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -183,8 +178,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(message.getId()).isEqualTo(messageId1);
}
@Test // DATAREDIS-864
public void reverseRangeShouldReportMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void reverseRangeShouldReportMessages() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -198,8 +193,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(messages).hasSize(2).extracting("id").containsSequence(messageId2, messageId1);
}
@Test // DATAREDIS-864
public void reverseRangeShouldConvertSimpleMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void reverseRangeShouldConvertSimpleMessages() {
K key = keyFactory.instance();
HV value = hashValueFactory.instance();
@@ -219,8 +214,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(message.getValue()).isEqualTo(value);
}
@Test // DATAREDIS-864
public void readShouldReadMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void readShouldReadMessage() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -242,8 +237,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
}
}
@Test // DATAREDIS-864
public void readShouldReadSimpleMessage() {
@ParameterizedRedisTest // DATAREDIS-864
void readShouldReadSimpleMessage() {
K key = keyFactory.instance();
HV value = hashValueFactory.instance();
@@ -263,8 +258,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(message.getValue()).isEqualTo(value);
}
@Test // DATAREDIS-864
public void readShouldReadMessages() {
@ParameterizedRedisTest // DATAREDIS-864
void readShouldReadMessages() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -279,8 +274,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(messages).hasSize(2);
}
@Test // DATAREDIS-864
public void readShouldReadMessageWithConsumerGroup() {
@ParameterizedRedisTest // DATAREDIS-864
void readShouldReadMessageWithConsumerGroup() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -304,8 +299,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
}
}
@Test // DATAREDIS-864
public void sizeShouldReportStreamSize() {
@ParameterizedRedisTest // DATAREDIS-864
void sizeShouldReportStreamSize() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -318,8 +313,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(streamOps.size(key)).isEqualTo(2);
}
@Test // DATAREDIS-1084
public void pendingShouldReadMessageSummary() {
@ParameterizedRedisTest // DATAREDIS-1084
void pendingShouldReadMessageSummary() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();
@@ -337,8 +332,8 @@ public class DefaultStreamOperationsTests<K, HK, HV> {
assertThat(pending.getGroupName()).isEqualTo("my-group");
}
@Test // DATAREDIS-1084
public void pendingShouldReadMessageDetails() {
@ParameterizedRedisTest // DATAREDIS-1084
void pendingShouldReadMessageDetails() {
K key = keyFactory.instance();
HK hashKey = hashKeyFactory.instance();

View File

@@ -16,8 +16,7 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.redis.SpinBarrier.*;
import java.text.DecimalFormat;
@@ -29,17 +28,12 @@ import java.util.Locale;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link DefaultValueOperations}
@@ -51,45 +45,37 @@ import org.springframework.data.redis.RedisTestProfileValueSource;
* @author Jiahe Cai
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
public class DefaultValueOperationsTests<K, V> {
@MethodSource("testParams")
public class DefaultValueOperationsIntegrationTests<K, V> {
private RedisTemplate<K, V> redisTemplate;
private final RedisTemplate<K, V> redisTemplate;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final ValueOperations<K, V> valueOps;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
private ValueOperations<K, V> valueOps;
public DefaultValueOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultValueOperationsIntegrationTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.valueOps = redisTemplate.opsForValue();
}
@Parameters
public static Collection<Object[]> testParams() {
static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
valueOps = redisTemplate.opsForValue();
}
@After
public void tearDown() {
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@Test // DATAREDIS-784
public void testIncrement() {
@ParameterizedRedisTest // DATAREDIS-784
void testIncrement() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -99,11 +85,11 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value);
assertThat(valueOps.increment(key)).isEqualTo(Long.valueOf((Long) value + 1));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value + 1));
assertThat(valueOps.get(key)).isEqualTo((Long) value + 1);
}
@Test
public void testIncrementLong() {
@ParameterizedRedisTest
void testIncrementLong() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -113,21 +99,19 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value);
assertThat(valueOps.increment(key, -10)).isEqualTo(Long.valueOf((Long) value - 10));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 10));
assertThat(valueOps.get(key)).isEqualTo((Long) value - 10);
valueOps.increment(key, -10);
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 20));
assertThat(valueOps.get(key)).isEqualTo((Long) value - 20);
}
@Test // DATAREDIS-247
public void testIncrementDouble() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest // DATAREDIS-247
void testIncrementDouble() {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeTrue(value instanceof Double);
assumeThat(value instanceof Double).isTrue();
valueOps.set(key, value);
@@ -140,8 +124,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(Double.valueOf(twoDForm.format((Double) value + 1.4 - 10d)));
}
@Test // DATAREDIS-784
public void testDecrement() {
@ParameterizedRedisTest // DATAREDIS-784
void testDecrement() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -151,11 +135,11 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value);
assertThat(valueOps.decrement(key)).isEqualTo(Long.valueOf((Long) value - 1));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 1));
assertThat(valueOps.get(key)).isEqualTo((Long) value - 1);
}
@Test // DATAREDIS-784
public void testDecrementByLong() {
@ParameterizedRedisTest // DATAREDIS-784
void testDecrementByLong() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -165,11 +149,11 @@ public class DefaultValueOperationsTests<K, V> {
valueOps.set(key, value);
assertThat(valueOps.decrement(key, 5)).isEqualTo(Long.valueOf((Long) value - 5));
assertThat(valueOps.get(key)).isEqualTo(Long.valueOf((Long) value - 5));
assertThat(valueOps.get(key)).isEqualTo((Long) value - 5);
}
@Test
public void testMultiSetIfAbsent() {
@ParameterizedRedisTest
void testMultiSetIfAbsent() {
Map<K, V> keysAndValues = new HashMap<>();
K key1 = keyFactory.instance();
@@ -184,8 +168,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.multiGet(keysAndValues.keySet())).containsExactlyElementsOf(keysAndValues.values());
}
@Test
public void testMultiSetIfAbsentFailure() {
@ParameterizedRedisTest
void testMultiSetIfAbsentFailure() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -202,8 +186,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.multiSetIfAbsent(keysAndValues)).isFalse();
}
@Test
public void testMultiSet() {
@ParameterizedRedisTest
void testMultiSet() {
Map<K, V> keysAndValues = new HashMap<>();
K key1 = keyFactory.instance();
@@ -219,8 +203,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.multiGet(keysAndValues.keySet())).containsExactlyElementsOf(keysAndValues.values());
}
@Test
public void testGetSet() {
@ParameterizedRedisTest
void testGetSet() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -230,8 +214,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value);
}
@Test
public void testGetAndSet() {
@ParameterizedRedisTest
void testGetAndSet() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -242,8 +226,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.getAndSet(key, value2)).isEqualTo(value1);
}
@Test
public void testSetWithExpiration() {
@ParameterizedRedisTest
void testSetWithExpiration() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -255,8 +239,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
public void testSetWithExpirationEX() {
@ParameterizedRedisTest // DATAREDIS-815
void testSetWithExpirationEX() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -268,8 +252,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
public void testSetWithExpirationPX() {
@ParameterizedRedisTest // DATAREDIS-815
void testSetWithExpirationPX() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -282,10 +266,9 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(expire).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-271
public void testSetWithExpirationWithTimeUnitMilliseconds() {
assumeThat(RedisTestProfileValueSource.matches("runLongTests", "true")).isTrue();
@ParameterizedRedisTest // DATAREDIS-271
@EnabledIfLongRunningTest
void testSetWithExpirationWithTimeUnitMilliseconds() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -295,8 +278,8 @@ public class DefaultValueOperationsTests<K, V> {
waitFor(() -> (!redisTemplate.hasKey(key)), 500);
}
@Test
public void testAppend() {
@ParameterizedRedisTest
void testAppend() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -309,8 +292,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value + "aaa");
}
@Test
public void testGetRange() {
@ParameterizedRedisTest
void testGetRange() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -322,8 +305,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key, 0, 1)).hasSize(2);
}
@Test
public void testSetRange() {
@ParameterizedRedisTest
void testSetRange() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -337,8 +320,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test
public void testSetIfAbsent() {
@ParameterizedRedisTest
void testSetIfAbsent() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -348,8 +331,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.setIfAbsent(key, value2)).isFalse();
}
@Test // DATAREDIS-782
public void testSetIfAbsentWithExpiration() {
@ParameterizedRedisTest // DATAREDIS-782
void testSetIfAbsentWithExpiration() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -363,8 +346,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
public void testSetIfAbsentWithExpirationEX() {
@ParameterizedRedisTest // DATAREDIS-815
void testSetIfAbsentWithExpirationEX() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -378,8 +361,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-815
public void testSetIfAbsentWithExpirationPX() {
@ParameterizedRedisTest // DATAREDIS-815
void testSetIfAbsentWithExpirationPX() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -393,8 +376,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(expire).isLessThan(TimeUnit.SECONDS.toMillis(6)).isGreaterThan(TimeUnit.MILLISECONDS.toMillis(1));
}
@Test // DATAREDIS-786
public void setIfPresentReturnsTrueWhenKeyExists() {
@ParameterizedRedisTest // DATAREDIS-786
void setIfPresentReturnsTrueWhenKeyExists() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -406,13 +389,13 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test // DATAREDIS-786
public void setIfPresentReturnsFalseWhenKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-786
void setIfPresentReturnsFalseWhenKeyDoesNotExist() {
assertThat(valueOps.setIfPresent(keyFactory.instance(), valueFactory.instance())).isFalse();
}
@Test // DATAREDIS-786
public void setIfPresentShouldSetExpirationCorrectly() {
@ParameterizedRedisTest // DATAREDIS-786
void setIfPresentShouldSetExpirationCorrectly() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -428,8 +411,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test // DATAREDIS-815
public void testSetIfPresentWithExpirationEX() {
@ParameterizedRedisTest // DATAREDIS-815
void testSetIfPresentWithExpirationEX() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -445,8 +428,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test // DATAREDIS-815
public void testSetIfPresentWithExpirationPX() {
@ParameterizedRedisTest // DATAREDIS-815
void testSetIfPresentWithExpirationPX() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -462,20 +445,20 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(valueOps.get(key)).isEqualTo(value2);
}
@Test
public void testSize() {
@ParameterizedRedisTest
void testSize() {
K key = keyFactory.instance();
V value = valueFactory.instance();
valueOps.set(key, value);
assertThat(valueOps.size(key) > 0).isTrue();
assertThat(valueOps.size(key)).isGreaterThan(0);
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testRawKeys() {
@ParameterizedRedisTest
void testRawKeys() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -486,20 +469,20 @@ public class DefaultValueOperationsTests<K, V> {
}
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testRawKeysCollection() {
@ParameterizedRedisTest
void testRawKeysCollection() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(Arrays.asList(new Object[] { key1, key2 }));
byte[][] rawKeys = ((DefaultValueOperations) valueOps).rawKeys(Arrays.asList(key1, key2));
assertThat(rawKeys.length).isEqualTo(2);
}
@SuppressWarnings("rawtypes")
@Test
public void testDeserializeKey() {
@ParameterizedRedisTest
void testDeserializeKey() {
K key = keyFactory.instance();
@@ -508,8 +491,8 @@ public class DefaultValueOperationsTests<K, V> {
assertThat(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key)).isNotNull();
}
@Test // DATAREDIS-197
public void testSetAndGetBit() {
@ParameterizedRedisTest // DATAREDIS-197
void testSetAndGetBit() {
assumeThat(redisTemplate).isInstanceOf(StringRedisTemplate.class);

View File

@@ -25,16 +25,8 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.DoubleAsStringObjectFactory;
import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongAsStringObjectFactory;
@@ -43,8 +35,8 @@ import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.connection.RedisZSetCommands;
import org.springframework.data.redis.connection.RedisZSetCommands.Weights;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.data.redis.test.util.MinimumRedisVersionRule;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration test of {@link DefaultZSetOperations}
@@ -58,47 +50,37 @@ import org.springframework.test.annotation.IfProfileValue;
* @param <V> Value type
*/
@SuppressWarnings("unchecked")
@RunWith(Parameterized.class)
public class DefaultZSetOperationsTests<K, V> {
@MethodSource("testParams")
public class DefaultZSetOperationsIntegrationTests<K, V> {
public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule();
private final RedisTemplate<K, V> redisTemplate;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final ZSetOperations<K, V> zSetOps;
private RedisTemplate<K, V> redisTemplate;
private ObjectFactory<K> keyFactory;
private ObjectFactory<V> valueFactory;
private ZSetOperations<K, V> zSetOps;
public DefaultZSetOperationsTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
public DefaultZSetOperationsIntegrationTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.zSetOps = redisTemplate.opsForZSet();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Before
public void setUp() {
zSetOps = redisTemplate.opsForZSet();
}
@After
public void tearDown() {
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@Test
public void testCount() {
@ParameterizedRedisTest
void testCount() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -110,8 +92,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.count(key1, 2.7, 5.7)).isEqualTo(Long.valueOf(1));
}
@Test // DATAREDIS-729
public void testLexCountUnbounded() {
@ParameterizedRedisTest // DATAREDIS-729
void testLexCountUnbounded() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -128,8 +110,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.lexCount(key, RedisZSetCommands.Range.unbounded())).isEqualTo(3);
}
@Test // DATAREDIS-729
public void testLexCountBounded() {
@ParameterizedRedisTest // DATAREDIS-729
void testLexCountBounded() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -146,8 +128,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.lexCount(key, RedisZSetCommands.Range.range().gt(value1))).isEqualTo(2);
}
@Test
public void testIncrementScore() {
@ParameterizedRedisTest
void testIncrementScore() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -161,8 +143,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuple).isEqualTo(new DefaultTypedTuple<>(value1, 5.7));
}
@Test
public void testRangeByScoreOffsetCount() {
@ParameterizedRedisTest
void testRangeByScoreOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -176,8 +158,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.rangeByScore(key, 1.5, 4.7, 0, 1)).containsOnly(value1);
}
@Test
public void testRangeByScoreWithScoresOffsetCount() {
@ParameterizedRedisTest
void testRangeByScoreWithScoresOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -192,8 +174,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(1).contains(new DefaultTypedTuple<>(value1, 1.9));
}
@Test
public void testReverseRangeByScoreOffsetCount() {
@ParameterizedRedisTest
void testReverseRangeByScoreOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -207,8 +189,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.reverseRangeByScore(key, 1.5, 4.7, 0, 1)).containsOnly(value2);
}
@Test
public void testReverseRangeByScoreWithScoresOffsetCount() {
@ParameterizedRedisTest
void testReverseRangeByScoreWithScoresOffsetCount() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -224,8 +206,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(1).contains(new DefaultTypedTuple<>(value2, 3.7));
}
@Test // DATAREDIS-407
public void testRangeByLexUnbounded() {
@ParameterizedRedisTest // DATAREDIS-407
void testRangeByLexUnbounded() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -243,8 +225,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(3).contains(value1);
}
@Test // DATAREDIS-407
public void testRangeByLexBounded() {
@ParameterizedRedisTest // DATAREDIS-407
void testRangeByLexBounded() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -262,8 +244,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(1).contains(value2);
}
@Test // DATAREDIS-407
public void testRangeByLexUnboundedWithLimit() {
@ParameterizedRedisTest // DATAREDIS-407
void testRangeByLexUnboundedWithLimit() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -282,8 +264,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(2).containsSequence(value2, value3);
}
@Test // DATAREDIS-729
public void testReverseRangeByLexUnboundedWithLimit() {
@ParameterizedRedisTest // DATAREDIS-729
void testReverseRangeByLexUnboundedWithLimit() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -302,8 +284,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(2).containsSequence(value2, value1);
}
@Test // DATAREDIS-407
public void testRangeByLexBoundedWithLimit() {
@ParameterizedRedisTest // DATAREDIS-407
void testRangeByLexBoundedWithLimit() {
assumeThat(valueFactory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class,
LongAsStringObjectFactory.class, LongObjectFactory.class);
@@ -322,8 +304,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(tuples).hasSize(1).startsWith(value2);
}
@Test
public void testAddMultiple() {
@ParameterizedRedisTest
void testAddMultiple() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -339,8 +321,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.range(key, 0, -1)).containsExactly(value3, value1, value2);
}
@Test
public void testRemove() {
@ParameterizedRedisTest
void testRemove() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -357,8 +339,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.range(key, 0, -1)).containsOnly(value2);
}
@Test
public void zCardRetrievesDataCorrectly() {
@ParameterizedRedisTest
void zCardRetrievesDataCorrectly() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -374,8 +356,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.zCard(key)).isEqualTo(3L);
}
@Test
public void sizeRetrievesDataCorrectly() {
@ParameterizedRedisTest
void sizeRetrievesDataCorrectly() {
K key = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -391,9 +373,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.size(key)).isEqualTo(3L);
}
@Test // DATAREDIS-306
@IfProfileValue(name = "redisVersion", value = "2.8+")
public void testZScanShouldReadEntireValueRange() throws IOException {
@ParameterizedRedisTest // DATAREDIS-306
void testZScanShouldReadEntireValueRange() throws IOException {
K key = keyFactory.instance();
@@ -422,8 +403,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(count).isEqualTo(3);
}
@Test // DATAREDIS-746
public void testZsetUnionWithAggregate() {
@ParameterizedRedisTest // DATAREDIS-746
void testZsetUnionWithAggregate() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -440,8 +421,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.score(key1, value2)).isCloseTo(2.0, offset(0.1));
}
@Test // DATAREDIS-746
public void testZsetUnionWithAggregateWeights() {
@ParameterizedRedisTest // DATAREDIS-746
void testZsetUnionWithAggregateWeights() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -456,8 +437,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.score(key1, value1)).isCloseTo(6.0, offset(0.1));
}
@Test // DATAREDIS-746
public void testZsetIntersectWithAggregate() {
@ParameterizedRedisTest // DATAREDIS-746
void testZsetIntersectWithAggregate() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -474,8 +455,8 @@ public class DefaultZSetOperationsTests<K, V> {
assertThat(zSetOps.score(key1, value2)).isCloseTo(2.0, offset(0.1));
}
@Test // DATAREDIS-746
public void testZsetIntersectWithAggregateWeights() {
@ParameterizedRedisTest // DATAREDIS-746
void testZsetIntersectWithAggregateWeights() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();

View File

@@ -23,47 +23,39 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Artem Bilian
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
public class MultithreadedRedisTemplateTests {
@MethodSource("testParams")
public class MultithreadedRedisTemplateIntegrationTests {
private RedisConnectionFactory factory;
private final RedisConnectionFactory factory;
public MultithreadedRedisTemplateTests(RedisConnectionFactory factory) {
public MultithreadedRedisTemplateIntegrationTests(RedisConnectionFactory factory) {
this.factory = factory;
}
@Parameters
public static Collection<Object[]> testParams() {
public static Collection<Object> testParams() {
JedisConnectionFactory jedis = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
LettuceConnectionFactory lettuce = LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
return Arrays.asList(new Object[][] { { jedis }, { lettuce } });
return Arrays.asList(jedis, lettuce);
}
@Test // DATAREDIS-300
public void assertResouresAreReleasedProperlyWhenSharingRedisTemplate() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-300
void assertResouresAreReleasedProperlyWhenSharingRedisTemplate() throws InterruptedException {
final RedisTemplate<Object, Object> template = new RedisTemplate<>();
template.setConnectionFactory(factory);

View File

@@ -21,8 +21,6 @@ import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.runners.model.Statement;
import org.springframework.data.redis.ByteBufferObjectFactory;
import org.springframework.data.redis.DoubleObjectFactory;
import org.springframework.data.redis.LongObjectFactory;
@@ -39,11 +37,13 @@ import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.OxmSerializer;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.XstreamOxmSerializerSingleton;
import org.springframework.data.redis.test.condition.RedisDetector;
import org.springframework.data.redis.test.extension.RedisCluster;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.lang.Nullable;
/**
* Parameters for testing implementations of {@link ReactiveRedisTemplate}
@@ -53,7 +53,7 @@ import org.springframework.oxm.xstream.XStreamMarshaller;
*/
abstract public class ReactiveOperationsTestParams {
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
ObjectFactory<String> stringFactory = new StringObjectFactory();
ObjectFactory<String> clusterKeyStringFactory = new PrefixStringObjectFactory("{u1}.", stringFactory);
@@ -62,14 +62,6 @@ abstract public class ReactiveOperationsTestParams {
ObjectFactory<ByteBuffer> rawFactory = new ByteBufferObjectFactory();
ObjectFactory<Person> personFactory = new PersonObjectFactory();
// XStream serializer
XStreamMarshaller xstream = new XStreamMarshaller();
try {
xstream.afterPropertiesSet();
} catch (Exception ex) {
throw new RuntimeException("Cannot init XStream", ex);
}
LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisStanalone.class);
@@ -97,7 +89,7 @@ abstract public class ReactiveOperationsTestParams {
ReactiveRedisTemplate<String, Person> personTemplate = new ReactiveRedisTemplate(lettuceConnectionFactory,
RedisSerializationContext.fromSerializer(jdkSerializationRedisSerializer));
OxmSerializer oxmSerializer = new OxmSerializer(xstream, xstream);
OxmSerializer oxmSerializer = XstreamOxmSerializerSingleton.getInstance();
ReactiveRedisTemplate<String, String> xstreamStringTemplate = new ReactiveRedisTemplate(lettuceConnectionFactory,
RedisSerializationContext.fromSerializer(oxmSerializer));
@@ -112,22 +104,23 @@ abstract public class ReactiveOperationsTestParams {
ReactiveRedisTemplate<String, Person> genericJackson2JsonPersonTemplate = new ReactiveRedisTemplate(
lettuceConnectionFactory, RedisSerializationContext.fromSerializer(genericJackson2JsonSerializer));
List<Object[]> list = Arrays.asList(new Object[][] { //
{ stringTemplate, stringFactory, stringFactory, stringRedisSerializer, "String" }, //
{ objectTemplate, personFactory, personFactory, jdkSerializationRedisSerializer, "Person/JDK" }, //
{ longTemplate, stringFactory, longFactory, longToStringSerializer, "Long" }, //
{ doubleTemplate, stringFactory, doubleFactory, doubleToStringSerializer, "Double" }, //
{ rawTemplate, rawFactory, rawFactory, null, "raw" }, //
{ personTemplate, stringFactory, personFactory, jdkSerializationRedisSerializer, "String/Person/JDK" }, //
{ xstreamStringTemplate, stringFactory, stringFactory, oxmSerializer, "String/OXM" }, //
{ xstreamPersonTemplate, stringFactory, personFactory, oxmSerializer, "String/Person/OXM" }, //
{ jackson2JsonPersonTemplate, stringFactory, personFactory, jackson2JsonSerializer, "Jackson2" }, //
{ genericJackson2JsonPersonTemplate, stringFactory, personFactory, genericJackson2JsonSerializer,
"Generic Jackson 2" } });
List<Fixture<?, ?>> list = Arrays.asList( //
new Fixture<>(stringTemplate, stringFactory, stringFactory, stringRedisSerializer, "String"), //
new Fixture<>(objectTemplate, personFactory, personFactory, jdkSerializationRedisSerializer, "Person/JDK"), //
new Fixture<>(longTemplate, stringFactory, longFactory, longToStringSerializer, "Long"), //
new Fixture<>(doubleTemplate, stringFactory, doubleFactory, doubleToStringSerializer, "Double"), //
new Fixture<>(rawTemplate, rawFactory, rawFactory, null, "raw"), //
new Fixture<>(personTemplate, stringFactory, personFactory, jdkSerializationRedisSerializer,
"String/Person/JDK"), //
new Fixture<>(xstreamStringTemplate, stringFactory, stringFactory, oxmSerializer, "String/OXM"), //
new Fixture<>(xstreamPersonTemplate, stringFactory, personFactory, oxmSerializer, "String/Person/OXM"), //
new Fixture<>(jackson2JsonPersonTemplate, stringFactory, personFactory, jackson2JsonSerializer, "Jackson2"), //
new Fixture<>(genericJackson2JsonPersonTemplate, stringFactory, personFactory, genericJackson2JsonSerializer,
"Generic Jackson 2"));
if (clusterAvailable()) {
ReactiveRedisTemplate<String, String> clusterStringTemplate = null;
ReactiveRedisTemplate<String, String> clusterStringTemplate;
LettuceConnectionFactory lettuceClusterConnectionFactory = LettuceConnectionFactoryExtension
.getConnectionFactory(RedisCluster.class);
@@ -136,26 +129,60 @@ abstract public class ReactiveOperationsTestParams {
RedisSerializationContext.string());
list = new ArrayList<>(list);
list.add(new Object[] { clusterStringTemplate, clusterKeyStringFactory, stringFactory, stringRedisSerializer,
"Cluster String" });
list.add(new Fixture<>(clusterStringTemplate, clusterKeyStringFactory, stringFactory, stringRedisSerializer,
"Cluster String"));
}
return list;
}
private static boolean clusterAvailable() {
return RedisDetector.isClusterAvailable();
}
try {
new RedisClusterRule().apply(new Statement() {
@Override
public void evaluate() throws Throwable {
static class Fixture<K, V> {
}
}, null).evaluate();
} catch (Throwable throwable) {
return false;
private final ReactiveRedisTemplate<K, V> template;
private final ObjectFactory<K> keyFactory;
private final ObjectFactory<V> valueFactory;
private final @Nullable RedisSerializer<K> serializer;
private final String label;
public Fixture(ReactiveRedisTemplate<?, ?> template, ObjectFactory<K> keyFactory, ObjectFactory<V> valueFactory,
@Nullable RedisSerializer<?> serializer, String label) {
this.template = (ReactiveRedisTemplate) template;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
this.serializer = (RedisSerializer) serializer;
this.label = label;
}
public ReactiveRedisTemplate<K, V> getTemplate() {
return template;
}
public ObjectFactory<K> getKeyFactory() {
return keyFactory;
}
public ObjectFactory<V> getValueFactory() {
return valueFactory;
}
@Nullable
public RedisSerializer getSerializer() {
return serializer;
}
public String getLabel() {
return label;
}
@Override
public String toString() {
return label;
}
return true;
}
}

View File

@@ -16,9 +16,8 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import org.springframework.data.redis.StringObjectFactory;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;
@@ -29,17 +28,13 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.PersonObjectFactory;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.ReactiveRedisClusterConnection;
import org.springframework.data.redis.connection.ReactiveSubscription.ChannelMessage;
@@ -47,14 +42,17 @@ import org.springframework.data.redis.connection.ReactiveSubscription.Message;
import org.springframework.data.redis.connection.ReactiveSubscription.PatternMessage;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.ReactiveOperationsTestParams.Fixture;
import org.springframework.data.redis.core.script.DefaultRedisScript;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.JdkSerializationRedisSerializer;
import org.springframework.data.redis.serializer.RedisElementReader;
import org.springframework.data.redis.serializer.RedisSerializationContext;
import org.springframework.data.redis.serializer.RedisSerializationContext.SerializationPair;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* Integration tests for {@link ReactiveRedisTemplate}.
@@ -62,7 +60,7 @@ import org.springframework.data.redis.serializer.StringRedisSerializer;
* @author Mark Paluch
* @author Christoph Strobl
*/
@RunWith(Parameterized.class)
@MethodSource("testParams")
public class ReactiveRedisTemplateIntegrationTests<K, V> {
private final ReactiveRedisTemplate<K, V> redisTemplate;
@@ -71,32 +69,19 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
private final ObjectFactory<V> valueFactory;
@Parameters(name = "{4}")
public static Collection<Object[]> testParams() {
public static Collection<Fixture<?, ?>> testParams() {
return ReactiveOperationsTestParams.testParams();
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
public ReactiveRedisTemplateIntegrationTests(Fixture<K, V> fixture) {
this.redisTemplate = fixture.getTemplate();
this.keyFactory = fixture.getKeyFactory();
this.valueFactory = fixture.getValueFactory();
}
/**
* @param redisTemplate
* @param keyFactory
* @param valueFactory
* @param label parameterized test label, no further use besides that.
*/
public ReactiveRedisTemplateIntegrationTests(ReactiveRedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory, RedisSerializer serializer, String label) {
this.redisTemplate = redisTemplate;
this.keyFactory = keyFactory;
this.valueFactory = valueFactory;
}
@Before
public void before() {
@BeforeEach
void before() {
RedisConnectionFactory connectionFactory = (RedisConnectionFactory) redisTemplate.getConnectionFactory();
RedisConnection connection = connectionFactory.getConnection();
@@ -104,8 +89,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
connection.close();
}
@Test // DATAREDIS-602
public void exists() {
@ParameterizedRedisTest // DATAREDIS-602
void exists() {
K key = keyFactory.instance();
@@ -117,10 +102,10 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.hasKey(key).as(StepVerifier::create).expectNext(true).verifyComplete();
}
@Test // DATAREDIS-743
public void scan() {
@ParameterizedRedisTest // DATAREDIS-743
void scan() {
assumeFalse(valueFactory.instance() instanceof Person);
assumeThat(valueFactory.instance() instanceof Person).isFalse();
Map<K, V> tuples = new HashMap<>();
tuples.put(keyFactory.instance(), valueFactory.instance());
@@ -134,8 +119,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void type() {
@ParameterizedRedisTest // DATAREDIS-602
void type() {
K key = keyFactory.instance();
@@ -147,8 +132,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.type(key).as(StepVerifier::create).expectNext(DataType.STRING).verifyComplete();
}
@Test // DATAREDIS-602
public void rename() {
@ParameterizedRedisTest // DATAREDIS-602
void rename() {
K oldName = keyFactory.instance();
K newName = keyFactory.instance();
@@ -162,8 +147,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.verify();
}
@Test // DATAREDIS-602
public void renameNx() {
@ParameterizedRedisTest // DATAREDIS-602
void renameNx() {
K oldName = keyFactory.instance();
K existing = keyFactory.instance();
@@ -187,8 +172,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.verify();
}
@Test // DATAREDIS-693
public void unlink() {
@ParameterizedRedisTest // DATAREDIS-693
void unlink() {
K single = keyFactory.instance();
@@ -200,8 +185,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.hasKey(single).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-693
public void unlinkMany() {
@ParameterizedRedisTest // DATAREDIS-693
void unlinkMany() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -217,13 +202,13 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.hasKey(key2).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-913
public void unlinkManyPublisher() {
@ParameterizedRedisTest // DATAREDIS-913
void unlinkManyPublisher() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
assumeTrue(key1 instanceof String && valueFactory instanceof StringObjectFactory);
assumeThat(key1 instanceof String && valueFactory instanceof StringObjectFactory).isTrue();
redisTemplate.opsForValue().set(key1, valueFactory.instance()).as(StepVerifier::create).expectNext(true)
.verifyComplete();
@@ -236,13 +221,13 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.hasKey(key2).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-913
public void deleteManyPublisher() {
@ParameterizedRedisTest // DATAREDIS-913
void deleteManyPublisher() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
assumeTrue(key1 instanceof String && valueFactory instanceof StringObjectFactory);
assumeThat(key1 instanceof String && valueFactory instanceof StringObjectFactory).isTrue();
redisTemplate.opsForValue().set(key1, valueFactory.instance()).as(StepVerifier::create).expectNext(true)
.verifyComplete();
@@ -255,14 +240,14 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.hasKey(key2).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-683
@ParameterizedRedisTest // DATAREDIS-683
@SuppressWarnings("unchecked")
public void executeScript() {
void executeScript() {
K key = keyFactory.instance();
V value = valueFactory.instance();
assumeFalse(value instanceof Long);
assumeThat(value instanceof Long).isFalse();
redisTemplate.opsForValue().set(key, value).as(StepVerifier::create).expectNext(true).verifyComplete();
@@ -273,8 +258,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
execute.as(StepVerifier::create).expectNext(value).verifyComplete();
}
@Test // DATAREDIS-683
public void executeScriptWithElementReaderAndWriter() {
@ParameterizedRedisTest // DATAREDIS-683
void executeScriptWithElementReaderAndWriter() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -282,7 +267,7 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
SerializationPair json = SerializationPair.fromSerializer(new Jackson2JsonRedisSerializer<>(Person.class));
RedisElementReader<String> resultReader = RedisElementReader.from(StringRedisSerializer.UTF_8);
assumeFalse(value instanceof Long);
assumeThat(value instanceof Long).isFalse();
Person person = new Person("Walter", "White", 51);
redisTemplate
@@ -298,8 +283,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
execute.as(StepVerifier::create).expectNext(person).verifyComplete();
}
@Test // DATAREDIS-602
public void expire() {
@ParameterizedRedisTest // DATAREDIS-602
void expire() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -312,8 +297,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.consumeNextWith(actual -> assertThat(actual).isGreaterThan(Duration.ofSeconds(8))).verifyComplete();
}
@Test // DATAREDIS-602
public void preciseExpire() {
@ParameterizedRedisTest // DATAREDIS-602
void preciseExpire() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -326,8 +311,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.consumeNextWith(actual -> assertThat(actual).isGreaterThan(Duration.ofSeconds(8))).verifyComplete();
}
@Test // DATAREDIS-602
public void expireAt() {
@ParameterizedRedisTest // DATAREDIS-602
void expireAt() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -343,8 +328,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void preciseExpireAt() {
@ParameterizedRedisTest // DATAREDIS-602
void preciseExpireAt() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -360,16 +345,16 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.verifyComplete();
}
@Test // DATAREDIS-602
public void getTtlForAbsentKeyShouldCompleteWithoutValue() {
@ParameterizedRedisTest // DATAREDIS-602
void getTtlForAbsentKeyShouldCompleteWithoutValue() {
K key = keyFactory.instance();
redisTemplate.getExpire(key).as(StepVerifier::create).verifyComplete();
}
@Test // DATAREDIS-602
public void getTtlForKeyWithoutExpiryShouldCompleteWithZeroDuration() {
@ParameterizedRedisTest // DATAREDIS-602
void getTtlForKeyWithoutExpiryShouldCompleteWithZeroDuration() {
K key = keyFactory.instance();
V value = valueFactory.instance();
@@ -379,13 +364,13 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.getExpire(key).as(StepVerifier::create).expectNext(Duration.ZERO).verifyComplete();
}
@Test // DATAREDIS-602
public void move() {
@ParameterizedRedisTest // DATAREDIS-602
void move() {
ReactiveRedisClusterConnection connection = null;
try {
connection = redisTemplate.getConnectionFactory().getReactiveClusterConnection();
assumeTrue(connection == null);
assumeThat(connection == null).isTrue();
} catch (InvalidDataAccessApiUsageException e) {} finally {
if (connection != null) {
connection.close();
@@ -402,8 +387,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
redisTemplate.hasKey(key).as(StepVerifier::create).expectNext(false).verifyComplete();
}
@Test // DATAREDIS-602
public void shouldApplyCustomSerializationContextToValues() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldApplyCustomSerializationContextToValues() {
Person key = new PersonObjectFactory().instance();
Person value = new PersonObjectFactory().instance();
@@ -423,8 +408,8 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
valueOperations.get(key).as(StepVerifier::create).expectNext(value).verifyComplete();
}
@Test // DATAREDIS-602
public void shouldApplyCustomSerializationContextToHash() {
@ParameterizedRedisTest // DATAREDIS-602
void shouldApplyCustomSerializationContextToHash() {
RedisSerializationContext<K, V> serializationContext = redisTemplate.getSerializationContext();
@@ -446,8 +431,9 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
hashOperations.get(key, hashField).as(StepVerifier::create).expectNext(hashValue).verifyComplete();
}
@Test // DATAREDIS-612
public void listenToChannelShouldReceiveChannelMessagesCorrectly() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-612
@EnabledIfLongRunningTest
void listenToChannelShouldReceiveChannelMessagesCorrectly() throws InterruptedException {
String channel = "my-channel";
@@ -467,8 +453,9 @@ public class ReactiveRedisTemplateIntegrationTests<K, V> {
.verify(Duration.ofSeconds(3));
}
@Test // DATAREDIS-612
public void listenToChannelPatternShouldReceiveChannelMessagesCorrectly() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-612
@EnabledIfLongRunningTest
void listenToChannelPatternShouldReceiveChannelMessagesCorrectly() throws InterruptedException {
String channel = "my-channel";
String pattern = "my-*";

View File

@@ -19,11 +19,8 @@ import static org.assertj.core.api.Assertions.*;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.runners.Parameterized.Parameters;
import org.springframework.dao.InvalidDataAccessApiUsageException;
@@ -33,116 +30,113 @@ import org.springframework.data.redis.Person;
import org.springframework.data.redis.PersonObjectFactory;
import org.springframework.data.redis.RawObjectFactory;
import org.springframework.data.redis.StringObjectFactory;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.OxmSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.XstreamOxmSerializerSingleton;
import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable;
import org.springframework.data.redis.test.extension.RedisCluster;
import org.springframework.data.redis.test.util.RedisClusterRule;
import org.springframework.oxm.xstream.XStreamMarshaller;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
/**
* @author Christoph Strobl
* @author Mark Paluch
*/
public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
@EnabledOnRedisClusterAvailable
public class RedisClusterTemplateIntegrationTests<K, V> extends RedisTemplateIntegrationTests<K, V> {
public RedisClusterTemplateTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
public RedisClusterTemplateIntegrationTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
super(redisTemplate, keyFactory, valueFactory);
}
public static @ClassRule RedisClusterRule clusterAvailable = new RedisClusterRule();
@Test
@Ignore("Pipeline not supported in cluster mode")
@ParameterizedRedisTest
@Disabled("Pipeline not supported in cluster mode")
public void testExecutePipelinedNonNullRedisCallback() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(super::testExecutePipelinedNonNullRedisCallback);
}
@Test
@Ignore("Pipeline not supported in cluster mode")
@ParameterizedRedisTest
@Disabled("Pipeline not supported in cluster mode")
public void testExecutePipelinedTx() {
super.testExecutePipelinedTx();
}
@Test
@Ignore("Watch only supported on same connection...")
@ParameterizedRedisTest
@Disabled("Watch only supported on same connection...")
public void testWatch() {
super.testWatch();
}
@Test
@Ignore("Watch only supported on same connection...")
@ParameterizedRedisTest
@Disabled("Watch only supported on same connection...")
public void testUnwatch() {
super.testUnwatch();
}
@Test
@Ignore("EXEC only supported on same connection...")
@ParameterizedRedisTest
@Disabled("EXEC only supported on same connection...")
public void testExec() {
super.testExec();
}
@Test
@Ignore("Pipeline not supported in cluster mode")
@ParameterizedRedisTest
@Disabled("Pipeline not supported in cluster mode")
public void testExecutePipelinedNonNullSessionCallback() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(super::testExecutePipelinedNonNullSessionCallback);
}
@Test
@Ignore("PubSub not supported in cluster mode")
@ParameterizedRedisTest
@Disabled("PubSub not supported in cluster mode")
public void testConvertAndSend() {
super.testConvertAndSend();
}
@Test
@Ignore("Watch only supported on same connection...")
@ParameterizedRedisTest
@Disabled("Watch only supported on same connection...")
public void testExecConversionDisabled() {
super.testExecConversionDisabled();
}
@Test
@Ignore("Discard only supported on same connection...")
@ParameterizedRedisTest
@Disabled("Discard only supported on same connection...")
public void testDiscard() {
super.testDiscard();
}
@Test
@Ignore("Pipleline not supported in cluster mode")
@ParameterizedRedisTest
@Disabled("Pipleline not supported in cluster mode")
public void testExecutePipelined() {
super.testExecutePipelined();
}
@Test
@Ignore("Watch only supported on same connection...")
@ParameterizedRedisTest
@Disabled("Watch only supported on same connection...")
public void testWatchMultipleKeys() {
super.testWatchMultipleKeys();
}
@Test
@Ignore("This one fails when using GET options on numbers")
@ParameterizedRedisTest
@Disabled("This one fails when using GET options on numbers")
public void testSortBulkMapper() {
super.testSortBulkMapper();
}
@Test
@Ignore("This one fails when using GET options on numbers")
@ParameterizedRedisTest
@Disabled("This one fails when using GET options on numbers")
public void testGetExpireMillisUsingTransactions() {
super.testGetExpireMillisUsingTransactions();
}
@Test
@Ignore("This one fails when using GET options on numbers")
@ParameterizedRedisTest
@Disabled("This one fails when using GET options on numbers")
public void testGetExpireMillisUsingPipelining() {
super.testGetExpireMillisUsingPipelining();
}
@@ -155,15 +149,8 @@ public class RedisClusterTemplateTests<K, V> extends RedisTemplateTests<K, V> {
ObjectFactory<byte[]> rawFactory = new RawObjectFactory();
ObjectFactory<Person> personFactory = new PersonObjectFactory();
// XStream serializer
XStreamMarshaller xstream = new XStreamMarshaller();
try {
xstream.afterPropertiesSet();
} catch (Exception ex) {
throw new RuntimeException("Cannot init XStream", ex);
}
OxmSerializer serializer = new OxmSerializer(xstream, xstream);
OxmSerializer serializer = XstreamOxmSerializerSingleton.getInstance();
Jackson2JsonRedisSerializer<Person> jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class);
// JEDIS

View File

@@ -17,7 +17,6 @@ package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import static org.junit.Assume.*;
import java.util.Arrays;
import java.util.Collections;
@@ -37,8 +36,6 @@ import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Reference;
import org.springframework.data.geo.Point;
import org.springframework.data.keyvalue.annotation.KeySpace;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.connection.RedisConnection;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
@@ -50,6 +47,7 @@ import org.springframework.data.redis.core.index.GeoIndexed;
import org.springframework.data.redis.core.index.IndexConfiguration;
import org.springframework.data.redis.core.index.Indexed;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
/**
* Integration tests for {@link RedisKeyValueAdapter}.
@@ -290,10 +288,9 @@ public class RedisKeyValueAdapterTests {
}
@Test // DATAREDIS-425
@EnabledIfLongRunningTest
void keyExpiredEventShouldRemoveHelperStructures() throws Exception {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("firstname", "rand");
@@ -318,10 +315,9 @@ public class RedisKeyValueAdapterTests {
}
@Test // DATAREDIS-744
@EnabledIfLongRunningTest
void keyExpiredEventShouldRemoveHelperStructuresForObjectsWithColonInId() throws Exception {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
Map<String, String> map = new LinkedHashMap<String, String>();
map.put("_class", Person.class.getName());
map.put("firstname", "rand");
@@ -346,10 +342,9 @@ public class RedisKeyValueAdapterTests {
}
@Test // DATAREDIS-589
@EnabledIfLongRunningTest
void keyExpiredEventWithoutKeyspaceShouldBeIgnored() throws Exception {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
Map<String, String> map = new LinkedHashMap<>();
map.put("_class", Person.class.getName());
map.put("firstname", "rand");

View File

@@ -16,12 +16,11 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.data.Offset.offset;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Wither;
import lombok.With;
import java.util.ArrayList;
import java.util.Arrays;
@@ -31,25 +30,20 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.data.annotation.Id;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.core.index.Indexed;
import org.springframework.data.redis.core.mapping.RedisMappingContext;
import org.springframework.data.redis.test.extension.RedisStanalone;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
import org.springframework.util.ObjectUtils;
/**
@@ -58,31 +52,29 @@ import org.springframework.util.ObjectUtils;
* @author Christoph Strobl
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
@MethodSource("params")
public class RedisKeyValueTemplateTests {
RedisConnectionFactory connectionFactory;
RedisKeyValueTemplate template;
RedisTemplate<Object, Object> nativeTemplate;
RedisMappingContext context;
RedisKeyValueAdapter adapter;
private RedisConnectionFactory connectionFactory;
private RedisKeyValueTemplate template;
private RedisTemplate<Object, Object> nativeTemplate;
private RedisMappingContext context;
private RedisKeyValueAdapter adapter;
public RedisKeyValueTemplateTests(RedisConnectionFactory connectionFactory) {
this.connectionFactory = connectionFactory;
}
@Parameters
public static List<RedisConnectionFactory> params() {
JedisConnectionFactory jedis = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
LettuceConnectionFactory lettuce = LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class);
return Arrays.<RedisConnectionFactory> asList(jedis, lettuce);
return Arrays.asList(jedis, lettuce);
}
@Before
public void setUp() {
@BeforeEach
void setUp() {
nativeTemplate = new RedisTemplate<>();
nativeTemplate.setConnectionFactory(connectionFactory);
@@ -91,23 +83,23 @@ public class RedisKeyValueTemplateTests {
context = new RedisMappingContext();
adapter = new RedisKeyValueAdapter(nativeTemplate, context);
template = new RedisKeyValueTemplate(adapter, context);
}
@After
public void tearDown() throws Exception {
nativeTemplate.execute((RedisCallback<Void>) connection -> {
connection.flushDb();
return null;
});
}
@AfterEach
void tearDown() throws Exception {
template.destroy();
adapter.destroy();
}
@Test // DATAREDIS-425
public void savesObjectCorrectly() {
@ParameterizedRedisTest // DATAREDIS-425
void savesObjectCorrectly() {
final Person rand = new Person();
rand.firstname = "rand";
@@ -121,8 +113,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-425
public void findProcessesCallbackReturningSingleIdCorrectly() {
@ParameterizedRedisTest // DATAREDIS-425
void findProcessesCallbackReturningSingleIdCorrectly() {
Person rand = new Person();
rand.firstname = "rand";
@@ -139,8 +131,8 @@ public class RedisKeyValueTemplateTests {
assertThat(result).contains(mat);
}
@Test // DATAREDIS-425
public void findProcessesCallbackReturningMultipleIdsCorrectly() {
@ParameterizedRedisTest // DATAREDIS-425
void findProcessesCallbackReturningMultipleIdsCorrectly() {
final Person rand = new Person();
rand.firstname = "rand";
@@ -158,8 +150,8 @@ public class RedisKeyValueTemplateTests {
assertThat(result).contains(rand, mat);
}
@Test // DATAREDIS-425
public void findProcessesCallbackReturningNullCorrectly() {
@ParameterizedRedisTest // DATAREDIS-425
void findProcessesCallbackReturningNullCorrectly() {
Person rand = new Person();
rand.firstname = "rand";
@@ -175,8 +167,8 @@ public class RedisKeyValueTemplateTests {
assertThat(result.size()).isEqualTo(0);
}
@Test // DATAREDIS-471
public void partialUpdate() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdate() {
final Person rand = new Person();
rand.firstname = "rand";
@@ -250,8 +242,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateSimpleType() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateSimpleType() {
final VariousTypes source = new VariousTypes();
source.stringValue = "some-value";
@@ -273,8 +265,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateComplexType() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateComplexType() {
Item callandor = new Item();
callandor.name = "Callandor";
@@ -313,8 +305,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateObjectType() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateObjectType() {
Item callandor = new Item();
callandor.name = "Callandor";
@@ -355,8 +347,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateSimpleTypedMap() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateSimpleTypedMap() {
final VariousTypes source = new VariousTypes();
source.simpleTypedMap = new LinkedHashMap<>();
@@ -386,8 +378,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateComplexTypedMap() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateComplexTypedMap() {
final VariousTypes source = new VariousTypes();
source.complexTypedMap = new LinkedHashMap<>();
@@ -445,8 +437,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateObjectTypedMap() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateObjectTypedMap() {
final VariousTypes source = new VariousTypes();
source.untypedMap = new LinkedHashMap<>();
@@ -521,8 +513,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateSimpleTypedList() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateSimpleTypedList() {
final VariousTypes source = new VariousTypes();
source.simpleTypedList = new ArrayList<>();
@@ -555,8 +547,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateComplexTypedList() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateComplexTypedList() {
final VariousTypes source = new VariousTypes();
source.complexTypedList = new ArrayList<>();
@@ -607,8 +599,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-471
public void partialUpdateObjectTypedList() {
@ParameterizedRedisTest // DATAREDIS-471
void partialUpdateObjectTypedList() {
final VariousTypes source = new VariousTypes();
source.untypedList = new ArrayList<>();
@@ -672,8 +664,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-530
public void partialUpdateShouldLeaveIndexesNotInvolvedInUpdateUntouched() {
@ParameterizedRedisTest // DATAREDIS-530
void partialUpdateShouldLeaveIndexesNotInvolvedInUpdateUntouched() {
final Person rand = new Person();
rand.firstname = "rand";
@@ -700,8 +692,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-530
public void updateShouldAlterIndexesCorrectlyWhenValuesGetRemovedFromHash() {
@ParameterizedRedisTest // DATAREDIS-530
void updateShouldAlterIndexesCorrectlyWhenValuesGetRemovedFromHash() {
final Person rand = new Person();
rand.firstname = "rand";
@@ -729,8 +721,8 @@ public class RedisKeyValueTemplateTests {
});
}
@Test // DATAREDIS-523
public void shouldReadBackExplicitTimeToLive() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-523
void shouldReadBackExplicitTimeToLive() throws InterruptedException {
WithTtl source = new WithTtl();
source.id = "ttl-1";
@@ -739,15 +731,12 @@ public class RedisKeyValueTemplateTests {
template.insert(source);
Thread.sleep(1100);
Optional<WithTtl> target = template.findById(source.id, WithTtl.class);
assertThat(target.get().ttl).isNotNull();
assertThat(target.get().ttl.doubleValue()).isCloseTo(3D, offset(1D));
assertThat(target.get().ttl).isGreaterThan(0L);
}
@Test // DATAREDIS-523
public void shouldReadBackExplicitTimeToLiveToPrimitiveField() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-523
void shouldReadBackExplicitTimeToLiveToPrimitiveField() throws InterruptedException {
WithPrimitiveTtl source = new WithPrimitiveTtl();
source.id = "ttl-1";
@@ -756,14 +745,12 @@ public class RedisKeyValueTemplateTests {
template.insert(source);
Thread.sleep(1100);
Optional<WithPrimitiveTtl> target = template.findById(source.id, WithPrimitiveTtl.class);
assertThat((double) target.get().ttl).isCloseTo(3D, offset(1D));
assertThat(target.get().ttl).isGreaterThan(0);
}
@Test // DATAREDIS-523
public void shouldReadBackExplicitTimeToLiveWhenFetchingList() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-523
void shouldReadBackExplicitTimeToLiveWhenFetchingList() throws InterruptedException {
WithTtl source = new WithTtl();
source.id = "ttl-1";
@@ -772,16 +759,14 @@ public class RedisKeyValueTemplateTests {
template.insert(source);
Thread.sleep(1100);
WithTtl target = template.findAll(WithTtl.class).iterator().next();
assertThat(target.ttl).isNotNull();
assertThat(target.ttl.doubleValue()).isCloseTo(3D, offset(1D));
assertThat(target.ttl).isGreaterThan(0);
}
@Test // DATAREDIS-523
public void shouldReadBackExplicitTimeToLiveAndSetItToMinusOnelIfPersisted() throws InterruptedException {
@ParameterizedRedisTest // DATAREDIS-523
void shouldReadBackExplicitTimeToLiveAndSetItToMinusOnelIfPersisted() throws InterruptedException {
WithTtl source = new WithTtl();
source.id = "ttl-1";
@@ -797,8 +782,8 @@ public class RedisKeyValueTemplateTests {
assertThat(target.get().ttl).isEqualTo(-1L);
}
@Test // DATAREDIS-849
public void shouldWriteImmutableType() {
@ParameterizedRedisTest // DATAREDIS-849
void shouldWriteImmutableType() {
ImmutableObject source = new ImmutableObject().withValue("foo").withTtl(1234L);
@@ -808,8 +793,8 @@ public class RedisKeyValueTemplateTests {
assertThat(inserted.id).isNotNull();
}
@Test // DATAREDIS-849
public void shouldReadImmutableType() {
@ParameterizedRedisTest // DATAREDIS-849
void shouldReadImmutableType() {
ImmutableObject source = new ImmutableObject().withValue("foo").withTtl(1234L);
ImmutableObject inserted = template.insert(source);
@@ -866,17 +851,17 @@ public class RedisKeyValueTemplateTests {
Integer age;
List<String> nicknames;
public Person() {}
Person() {}
public Person(String firstname, String lastname) {
this(null, firstname, lastname, null);
}
public Person(String id, String firstname, String lastname) {
Person(String id, String firstname, String lastname) {
this(id, firstname, lastname, null);
}
public Person(String id, String firstname, String lastname, Integer age) {
Person(String id, String firstname, String lastname, Integer age) {
this.id = id;
this.firstname = firstname;
@@ -950,7 +935,7 @@ public class RedisKeyValueTemplateTests {
}
@Data
@Wither
@With
@AllArgsConstructor
static class ImmutableObject {

View File

@@ -16,8 +16,7 @@
package org.springframework.data.redis.core;
import static org.assertj.core.api.Assertions.*;
import static org.assertj.core.api.Assumptions.assumeThat;
import static org.junit.Assume.*;
import static org.assertj.core.api.Assumptions.*;
import static org.springframework.data.redis.SpinBarrier.*;
import java.time.Duration;
@@ -26,26 +25,18 @@ import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.data.redis.ConnectionFactoryTracker;
import org.springframework.data.redis.ObjectFactory;
import org.springframework.data.redis.Person;
import org.springframework.data.redis.RedisTestProfileValueSource;
import org.springframework.data.redis.SettingsUtils;
import org.springframework.data.redis.connection.DataType;
import org.springframework.data.redis.connection.StringRedisConnection;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.core.ZSetOperations.TypedTuple;
import org.springframework.data.redis.core.query.SortQueryBuilder;
import org.springframework.data.redis.core.script.DefaultRedisScript;
@@ -53,6 +44,10 @@ import org.springframework.data.redis.serializer.GenericToStringSerializer;
import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest;
import org.springframework.data.redis.test.extension.LettuceTestClientResources;
import org.springframework.data.redis.test.extension.parametrized.MethodSource;
import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest;
import org.springframework.data.redis.test.util.CollectionAwareComparator;
/**
@@ -64,16 +59,14 @@ import org.springframework.data.redis.test.util.CollectionAwareComparator;
* @author Duobiao Ou
* @author Mark Paluch
*/
@RunWith(Parameterized.class)
public class RedisTemplateTests<K, V> {
@MethodSource("testParams")
public class RedisTemplateIntegrationTests<K, V> {
@Autowired protected RedisTemplate<K, V> redisTemplate;
protected final RedisTemplate<K, V> redisTemplate;
protected final ObjectFactory<K> keyFactory;
protected final ObjectFactory<V> valueFactory;
protected ObjectFactory<K> keyFactory;
protected ObjectFactory<V> valueFactory;
public RedisTemplateTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
RedisTemplateIntegrationTests(RedisTemplate<K, V> redisTemplate, ObjectFactory<K> keyFactory,
ObjectFactory<V> valueFactory) {
this.redisTemplate = redisTemplate;
@@ -81,27 +74,20 @@ public class RedisTemplateTests<K, V> {
this.valueFactory = valueFactory;
}
@After
public void tearDown() {
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@BeforeEach
void setUp() {
redisTemplate.execute((RedisCallback<Object>) connection -> {
connection.flushDb();
return null;
});
}
@AfterClass
public static void cleanUp() {
ConnectionFactoryTracker.cleanUp();
}
@Parameters
public static Collection<Object[]> testParams() {
return AbstractOperationsTestParams.testParams();
}
@Test
public void testDumpAndRestoreNoTtl() {
assumeThat(RedisTestProfileValueSource.matches("redisVersion", "2.6")).isTrue();
@ParameterizedRedisTest
void testDumpAndRestoreNoTtl() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
@@ -112,42 +98,41 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1);
}
@Test
public void testRestoreTtl() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest
void testRestoreTtl() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
byte[] serializedValue = redisTemplate.dump(key1);
assertThat(serializedValue).isNotNull();
redisTemplate.delete(key1);
redisTemplate.restore(key1, serializedValue, 200, TimeUnit.MILLISECONDS);
redisTemplate.restore(key1, serializedValue, 10000, TimeUnit.MILLISECONDS);
assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1);
waitFor(() -> (!redisTemplate.hasKey(key1)), 400);
assertThat(redisTemplate.getExpire(key1)).isGreaterThan(1L);
}
@SuppressWarnings("unchecked")
@Test
public void testKeys() throws Exception {
@ParameterizedRedisTest
void testKeys() throws Exception {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String || key1 instanceof byte[]);
assumeThat(key1 instanceof String || key1 instanceof byte[]).isTrue();
redisTemplate.opsForValue().set(key1, value1);
K keyPattern = key1 instanceof String ? (K) "*" : (K) "*".getBytes();
assertThat(redisTemplate.keys(keyPattern)).isNotNull();
}
@SuppressWarnings("rawtypes")
@Test(expected = IllegalArgumentException.class)
public void testTemplateNotInitialized() throws Exception {
@ParameterizedRedisTest
void testTemplateNotInitialized() throws Exception {
RedisTemplate tpl = new RedisTemplate();
tpl.setConnectionFactory(redisTemplate.getConnectionFactory());
tpl.exec();
assertThatIllegalArgumentException().isThrownBy(() -> tpl.exec());
}
@Test
public void testStringTemplateExecutesWithStringConn() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
@ParameterizedRedisTest
void testStringTemplateExecutesWithStringConn() {
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();
String value = redisTemplate.execute((RedisCallback<String>) connection -> {
StringRedisConnection stringConn = (StringRedisConnection) connection;
stringConn.set("test", "it");
@@ -156,7 +141,7 @@ public class RedisTemplateTests<K, V> {
assertThat("it").isEqualTo(value);
}
@Test
@ParameterizedRedisTest
public void testExec() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -190,7 +175,7 @@ public class RedisTemplateTests<K, V> {
list, 1L, set, true, tupleSet);
}
@Test
@ParameterizedRedisTest
public void testDiscard() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -208,9 +193,9 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1);
}
@Test
public void testExecCustomSerializer() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
@ParameterizedRedisTest
void testExecCustomSerializer() {
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();
List<Object> results = redisTemplate.execute(new SessionCallback<List<Object>>() {
@SuppressWarnings({ "rawtypes", "unchecked" })
public List<Object> execute(RedisOperations operations) throws DataAccessException {
@@ -241,7 +226,7 @@ public class RedisTemplateTests<K, V> {
assertThat(results).containsExactly(true, 5L, 1L, 1L, list, 1L, longSet, true, tupleSet, zSet, true, map);
}
@Test
@ParameterizedRedisTest
public void testExecConversionDisabled() {
LettuceConnectionFactory factory2 = new LettuceConnectionFactory(SettingsUtils.getHost(), SettingsUtils.getPort());
@@ -267,7 +252,7 @@ public class RedisTemplateTests<K, V> {
}
@SuppressWarnings("rawtypes")
@Test
@ParameterizedRedisTest
public void testExecutePipelined() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -289,10 +274,10 @@ public class RedisTemplateTests<K, V> {
}
@SuppressWarnings("rawtypes")
@Test
public void testExecutePipelinedCustomSerializer() {
@ParameterizedRedisTest
void testExecutePipelinedCustomSerializer() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();
List<Object> results = redisTemplate.executePipelined((RedisCallback) connection -> {
StringRedisConnection stringRedisConn = (StringRedisConnection) connection;
@@ -307,10 +292,10 @@ public class RedisTemplateTests<K, V> {
assertThat(results).containsExactly(true, 5L, 1L, 2L, Arrays.asList(10L, 11L));
}
@Test // DATAREDIS-500
public void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer() {
@ParameterizedRedisTest // DATAREDIS-500
void testExecutePipelinedWidthDifferentHashKeySerializerAndHashValueSerializer() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();
redisTemplate.setKeySerializer(StringRedisSerializer.UTF_8);
redisTemplate.setHashKeySerializer(new GenericToStringSerializer<>(Long.class));
@@ -328,14 +313,14 @@ public class RedisTemplateTests<K, V> {
assertThat(person).isEqualTo(((Map) results.get(0)).get(1L));
}
@Test
@ParameterizedRedisTest
public void testExecutePipelinedNonNullRedisCallback() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> redisTemplate.executePipelined((RedisCallback<String>) connection -> "Hey There"));
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
@ParameterizedRedisTest
public void testExecutePipelinedTx() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -347,24 +332,24 @@ public class RedisTemplateTests<K, V> {
operations.opsForList().size(key1);
operations.exec();
try {
// Await EXEC completion as it's executed on a dedicated connection.
Thread.sleep(100);
} catch (InterruptedException e) {}
operations.opsForValue().set(key1, value1);
operations.opsForValue().get(key1);
return null;
}
});
try {
// Await EXEC completion as it's executed on a dedicated connection.
Thread.sleep(100);
} catch (InterruptedException e) {}
operations.opsForValue().set(key1, value1);
operations.opsForValue().get(key1);
return null;
}
});
// Should contain the List of deserialized exec results and the result of the last call to get()
assertThat(pipelinedResults).usingElementComparator(CollectionAwareComparator.INSTANCE)
.containsExactly(Arrays.asList(1L, value1, 0L), true, value1);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testExecutePipelinedTxCustomSerializer() {
assumeTrue(redisTemplate instanceof StringRedisTemplate);
@ParameterizedRedisTest
void testExecutePipelinedTxCustomSerializer() {
assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue();
List<Object> pipelinedResults = redisTemplate.executePipelined(new SessionCallback() {
public Object execute(RedisOperations operations) throws DataAccessException {
operations.multi();
@@ -381,7 +366,7 @@ public class RedisTemplateTests<K, V> {
assertThat(pipelinedResults).isEqualTo(Arrays.asList(Arrays.asList(1L, 5L, 0L), true, 2L));
}
@Test
@ParameterizedRedisTest
public void testExecutePipelinedNonNullSessionCallback() {
assertThatExceptionOfType(InvalidDataAccessApiUsageException.class)
.isThrownBy(() -> redisTemplate.executePipelined(new SessionCallback<String>() {
@@ -392,8 +377,8 @@ public class RedisTemplateTests<K, V> {
}));
}
@Test // DATAREDIS-688
public void testDelete() {
@ParameterizedRedisTest // DATAREDIS-688
void testDelete() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -405,8 +390,8 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.hasKey(key1)).isFalse();
}
@Test // DATAREDIS-688
public void testDeleteMultiple() {
@ParameterizedRedisTest // DATAREDIS-688
void testDeleteMultiple() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
@@ -421,13 +406,13 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.hasKey(key2)).isFalse();
}
@Test
public void testSort() {
@ParameterizedRedisTest
void testSort() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(value1 instanceof Number);
assumeThat(value1 instanceof Number).isTrue();
redisTemplate.opsForList().rightPush(key1, value1);
@@ -435,42 +420,40 @@ public class RedisTemplateTests<K, V> {
assertThat(results).isEqualTo(Collections.singletonList(value1));
}
@Test
public void testSortStore() {
@ParameterizedRedisTest
void testSortStore() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(value1 instanceof Number);
assumeThat(value1 instanceof Number).isTrue();
redisTemplate.opsForList().rightPush(key1, value1);
assertThat(redisTemplate.sort(SortQueryBuilder.sort(key1).build(), key2)).isEqualTo(Long.valueOf(1));
assertThat(redisTemplate.boundListOps(key2).range(0, -1)).isEqualTo(Collections.singletonList(value1));
}
@Test
@ParameterizedRedisTest
public void testSortBulkMapper() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(value1 instanceof Number);
assumeThat(value1 instanceof Number).isTrue();
redisTemplate.opsForList().rightPush(key1, value1);
List<String> results = redisTemplate.sort(SortQueryBuilder.sort(key1).get("#").build(), tuple -> "FOO");
assertThat(results).isEqualTo(Collections.singletonList("FOO"));
}
@Test
public void testExpireAndGetExpireMillis() {
@ParameterizedRedisTest
void testExpireAndGetExpireMillis() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
redisTemplate.expire(key1, 500, TimeUnit.MILLISECONDS);
assertThat(redisTemplate.getExpire(key1, TimeUnit.MILLISECONDS) > 0L).isTrue();
// Timeout is longer because expire will be 1 sec if pExpire not supported
waitFor(() -> (!redisTemplate.hasKey(key1)), 1500L);
assertThat(redisTemplate.getExpire(key1, TimeUnit.MILLISECONDS)).isGreaterThan(0L);
}
@Test
public void testGetExpireNoTimeUnit() {
@ParameterizedRedisTest
void testGetExpireNoTimeUnit() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
@@ -480,8 +463,8 @@ public class RedisTemplateTests<K, V> {
assertThat(expire > 0L && expire <= 2L).isTrue();
}
@Test
public void testGetExpireSeconds() {
@ParameterizedRedisTest
void testGetExpireSeconds() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
@@ -489,43 +472,43 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.getExpire(key1, TimeUnit.SECONDS)).isEqualTo(Long.valueOf(1));
}
@Test // DATAREDIS-526
public void testGetExpireSecondsForKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-526
void testGetExpireSecondsForKeyDoesNotExist() {
Long expire = redisTemplate.getExpire(keyFactory.instance(), TimeUnit.SECONDS);
assertThat(expire < 0L).isTrue();
assertThat(expire).isLessThan(0L);
}
@Test // DATAREDIS-526
public void testGetExpireSecondsForKeyExistButHasNoAssociatedExpire() {
@ParameterizedRedisTest // DATAREDIS-526
void testGetExpireSecondsForKeyExistButHasNoAssociatedExpire() {
K key = keyFactory.instance();
Long expire = redisTemplate.getExpire(key, TimeUnit.SECONDS);
assertThat(expire < 0L).isTrue();
assertThat(expire).isLessThan(0L);
}
@Test // DATAREDIS-526
public void testGetExpireMillisForKeyDoesNotExist() {
@ParameterizedRedisTest // DATAREDIS-526
void testGetExpireMillisForKeyDoesNotExist() {
Long expire = redisTemplate.getExpire(keyFactory.instance(), TimeUnit.MILLISECONDS);
assertThat(expire < 0L).isTrue();
assertThat(expire).isLessThan(0L);
}
@Test // DATAREDIS-526
public void testGetExpireMillisForKeyExistButHasNoAssociatedExpire() {
@ParameterizedRedisTest // DATAREDIS-526
void testGetExpireMillisForKeyExistButHasNoAssociatedExpire() {
K key = keyFactory.instance();
redisTemplate.boundValueOps(key).set(valueFactory.instance());
Long expire = redisTemplate.getExpire(key, TimeUnit.MILLISECONDS);
assertThat(expire < 0L).isTrue();
assertThat(expire).isLessThan(0L);
}
@Test // DATAREDIS-526
public void testGetExpireMillis() {
@ParameterizedRedisTest // DATAREDIS-526
void testGetExpireMillis() {
K key = keyFactory.instance();
redisTemplate.boundValueOps(key).set(valueFactory.instance());
@@ -537,8 +520,8 @@ public class RedisTemplateTests<K, V> {
assertThat(ttl).isLessThan(25L);
}
@Test // DATAREDIS-611
public void testGetExpireDuration() {
@ParameterizedRedisTest // DATAREDIS-611
void testGetExpireDuration() {
K key = keyFactory.instance();
redisTemplate.boundValueOps(key).set(valueFactory.instance());
@@ -550,12 +533,12 @@ public class RedisTemplateTests<K, V> {
assertThat(ttl).isLessThan(25L);
}
@Test // DATAREDIS-526
@ParameterizedRedisTest // DATAREDIS-526
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetExpireMillisUsingTransactions() {
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
assumeThat(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory).isTrue();
K key = keyFactory.instance();
List<Object> result = redisTemplate.execute(new SessionCallback<List<Object>>() {
@@ -577,34 +560,34 @@ public class RedisTemplateTests<K, V> {
assertThat(((Long) result.get(2))).isLessThan(25L);
}
@Test // DATAREDIS-526
@ParameterizedRedisTest // DATAREDIS-526
@SuppressWarnings({ "unchecked", "rawtypes" })
public void testGetExpireMillisUsingPipelining() {
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory);
assumeThat(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory
|| redisTemplate.getConnectionFactory() instanceof LettuceConnectionFactory).isTrue();
K key = keyFactory.instance();
List<Object> result = redisTemplate.executePipelined(new SessionCallback<Object>() {
@Override
public Object execute(RedisOperations operations) throws DataAccessException {
@Override
public Object execute(RedisOperations operations) throws DataAccessException {
operations.boundValueOps(key).set(valueFactory.instance());
operations.expire(key, 1, TimeUnit.DAYS);
operations.getExpire(key, TimeUnit.HOURS);
operations.boundValueOps(key).set(valueFactory.instance());
operations.expire(key, 1, TimeUnit.DAYS);
operations.getExpire(key, TimeUnit.HOURS);
return null;
}
});
return null;
}
});
assertThat(result).hasSize(3);
assertThat(((Long) result.get(2))).isGreaterThanOrEqualTo(23L);
assertThat(((Long) result.get(2))).isLessThan(25L);
}
@Test
public void testExpireAt() {
@ParameterizedRedisTest
void testExpireAt() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
@@ -612,8 +595,8 @@ public class RedisTemplateTests<K, V> {
waitFor(() -> (!redisTemplate.hasKey(key1)), 5L);
}
@Test // DATAREDIS-611
public void testExpireAtInstant() {
@ParameterizedRedisTest // DATAREDIS-611
void testExpireAtInstant() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.boundValueOps(key1).set(value1);
@@ -621,16 +604,16 @@ public class RedisTemplateTests<K, V> {
waitFor(() -> (!redisTemplate.hasKey(key1)), 5L);
}
@Test
public void testExpireAtMillisNotSupported() {
@ParameterizedRedisTest
@EnabledIfLongRunningTest
void testExpireAtMillisNotSupported() {
assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true"));
assumeTrue(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory);
assumeThat(redisTemplate.getConnectionFactory() instanceof JedisConnectionFactory).isTrue();
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
assumeTrue(key1 instanceof String && value1 instanceof String);
assumeThat(key1 instanceof String && value1 instanceof String).isTrue();
StringRedisTemplate template2 = new StringRedisTemplate(redisTemplate.getConnectionFactory());
template2.boundValueOps((String) key1).set((String) value1);
@@ -639,10 +622,9 @@ public class RedisTemplateTests<K, V> {
waitFor(() -> (!template2.hasKey((String) key1)), 5L);
}
@Test
public void testPersist() throws Exception {
@ParameterizedRedisTest
void testPersist() throws Exception {
// Test is meaningless in Redis 2.4 because key won't expire after 10 ms
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
@@ -652,16 +634,16 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.hasKey(key1)).isTrue();
}
@Test
public void testRandomKey() {
@ParameterizedRedisTest
void testRandomKey() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
assertThat(redisTemplate.randomKey()).isEqualTo(key1);
}
@Test
public void testRename() {
@ParameterizedRedisTest
void testRename() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -670,8 +652,8 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.opsForValue().get(key2)).isEqualTo(value1);
}
@Test
public void testRenameIfAbsent() {
@ParameterizedRedisTest
void testRenameIfAbsent() {
K key1 = keyFactory.instance();
K key2 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -680,15 +662,15 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.hasKey(key2)).isTrue();
}
@Test
public void testType() {
@ParameterizedRedisTest
void testType() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
redisTemplate.opsForValue().set(key1, value1);
assertThat(redisTemplate.type(key1)).isEqualTo(DataType.STRING);
}
@Test // DATAREDIS-506
@ParameterizedRedisTest // DATAREDIS-506
public void testWatch() {
K key1 = keyFactory.instance();
V value1 = valueFactory.instance();
@@ -720,7 +702,7 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value2);
}
@Test
@ParameterizedRedisTest
public void testUnwatch() {
K key1 = keyFactory.instance();
@@ -748,11 +730,11 @@ public class RedisTemplateTests<K, V> {
}
});
assertThat(results.size() == 1).isTrue();
assertThat(results.size()).isEqualTo(1);
assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value3);
}
@Test // DATAREDIS-506
@ParameterizedRedisTest // DATAREDIS-506
public void testWatchMultipleKeys() {
K key1 = keyFactory.instance();
@@ -789,16 +771,15 @@ public class RedisTemplateTests<K, V> {
assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value2);
}
@Test
@ParameterizedRedisTest
public void testConvertAndSend() {
V value1 = valueFactory.instance();
// Make sure basic message sent without Exception on serialization
redisTemplate.convertAndSend("Channel", value1);
}
@Test
public void testExecuteScriptCustomSerializers() {
assumeTrue(RedisTestProfileValueSource.matches("redisVersion", "2.6"));
@ParameterizedRedisTest
void testExecuteScriptCustomSerializers() {
K key1 = keyFactory.instance();
DefaultRedisScript<String> script = new DefaultRedisScript<>();
script.setScriptText("return 'Hey'");
@@ -807,13 +788,13 @@ public class RedisTemplateTests<K, V> {
Collections.singletonList(key1))).isEqualTo("Hey");
}
@Test
public void clientListShouldReturnCorrectly() {
@ParameterizedRedisTest
void clientListShouldReturnCorrectly() {
assertThat(redisTemplate.getClientList().size()).isNotEqualTo(0);
}
@Test // DATAREDIS-529
public void countExistingKeysReturnsNumberOfKeysCorrectly() {
@ParameterizedRedisTest // DATAREDIS-529
void countExistingKeysReturnsNumberOfKeysCorrectly() {
Map<K, V> source = new LinkedHashMap<>(3, 1);
source.put(keyFactory.instance(), valueFactory.instance());

View File

@@ -20,13 +20,10 @@ import static org.mockito.Mockito.*;
import java.io.Serializable;
import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.dao.DataAccessException;

Some files were not shown because too many files have changed in this diff Show More