diff --git a/Jenkinsfile b/Jenkinsfile index ac3a276f3..be224c705 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -117,7 +117,7 @@ pipeline { sh 'make start' // Execute maven test - sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean test -DrunLongTests=true -U -B' + sh 'MAVEN_OPTS="-Duser.name=jenkins -Duser.home=/tmp/jenkins-home" ./mvnw -Pjava11 clean test -U -B' // Capture resulting exit code from maven (pass/fail) sh 'RESULT=\$?' diff --git a/Makefile b/Makefile index 94b0f9c91..fa68d8718 100644 --- a/Makefile +++ b/Makefile @@ -194,6 +194,13 @@ stop-26382: work/redis/bin/redis-cli stop: redis-stop sentinel-stop cluster-stop test: + $(MAKE) start + sleep 1 + ./mvnw clean test -U -P$(SPRING_PROFILE) || (echo "maven failed $$?"; exit 1) + $(MAKE) stop + $(MAKE) clean + +all-tests: $(MAKE) start sleep 1 ./mvnw clean test -U -DrunLongTests=true -P$(SPRING_PROFILE) || (echo "maven failed $$?"; exit 1) diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java index 3c965c3ee..eebde0658 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterSetCommands.java @@ -87,7 +87,13 @@ class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommands imple } return sUnion(Mono.just(SUnionCommand.keys(command.getKeys()))).next().flatMap(values -> { - Mono result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new)); + + Mono result = values.getOutput().collectList().flatMap(it -> { + + ByteBuffer[] members = it.toArray(new ByteBuffer[0]); + return cmd.sadd(command.getKey(), members); + }); + return result.map(value -> new NumericResponse<>(command, value)); }); })); @@ -147,7 +153,13 @@ class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommands imple } return sInter(Mono.just(SInterCommand.keys(command.getKeys()))).next().flatMap(values -> { - Mono result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new)); + + Mono result = values.getOutput().collectList().flatMap(it -> { + + ByteBuffer[] members = it.toArray(new ByteBuffer[0]); + return cmd.sadd(command.getKey(), members); + }); + return result.map(value -> new NumericResponse<>(command, value)); }); })); @@ -209,7 +221,13 @@ class LettuceReactiveClusterSetCommands extends LettuceReactiveSetCommands imple } return sDiff(Mono.just(SDiffCommand.keys(command.getKeys()))).next().flatMap(values -> { - Mono result = cmd.sadd(command.getKey(), values.getOutput().toStream().toArray(ByteBuffer[]::new)); + + Mono result = values.getOutput().collectList().flatMap(it -> { + + ByteBuffer[] members = it.toArray(new ByteBuffer[0]); + return cmd.sadd(command.getKey(), members); + }); + return result.map(value -> new NumericResponse<>(command, value)); }); })); diff --git a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnection.java b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnection.java index 0dac853e5..757ec89ca 100644 --- a/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnection.java +++ b/src/main/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnection.java @@ -492,7 +492,11 @@ class LettuceReactiveRedisClusterConnection extends LettuceReactiveRedisConnecti if (StringUtils.hasText(node.getId())) { return getConnection().cast(StatefulRedisClusterConnection.class) - .map(it -> it.getConnection(node.getId()).reactive()); + .flatMap(it -> { + StatefulRedisClusterConnection connection = it; + return Mono.fromCompletionStage(connection.getConnectionAsync(node.getId())) + .map(StatefulRedisConnection::reactive); + }); } return getConnection().flatMap(it -> Mono.fromCompletionStage(it.getConnectionAsync(node.getHost(), node.getPort())) diff --git a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java index cd0806670..656e1f110 100644 --- a/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/ReactiveRedisTemplate.java @@ -660,7 +660,7 @@ public class ReactiveRedisTemplate implements ReactiveRedisOperations ReactiveStreamOperations opsForStream( RedisSerializationContext serializationContext) { - return opsForStream(serializationContext, (HashMapper) new ObjectHashMapper()); + return opsForStream(serializationContext, (HashMapper) ObjectHashMapper.getSharedInstance()); } protected ReactiveStreamOperations opsForStream( diff --git a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java index efb4665a0..d7baa8d3e 100644 --- a/src/main/java/org/springframework/data/redis/core/RedisTemplate.java +++ b/src/main/java/org/springframework/data/redis/core/RedisTemplate.java @@ -106,7 +106,8 @@ public class RedisTemplate extends RedisAccessor implements RedisOperation private final ValueOperations valueOps = new DefaultValueOperations<>(this); private final ListOperations listOps = new DefaultListOperations<>(this); private final SetOperations setOps = new DefaultSetOperations<>(this); - private final StreamOperations streamOps = new DefaultStreamOperations<>(this, new ObjectHashMapper()); + private final StreamOperations streamOps = new DefaultStreamOperations<>(this, + ObjectHashMapper.getSharedInstance()); private final ZSetOperations zSetOps = new DefaultZSetOperations<>(this); private final GeoOperations geoOps = new DefaultGeoOperations<>(this); private final HyperLogLogOperations hllOps = new DefaultHyperLogLogOperations<>(this); diff --git a/src/main/java/org/springframework/data/redis/core/StreamObjectMapper.java b/src/main/java/org/springframework/data/redis/core/StreamObjectMapper.java index 0f1350504..87604f2cc 100644 --- a/src/main/java/org/springframework/data/redis/core/StreamObjectMapper.java +++ b/src/main/java/org/springframework/data/redis/core/StreamObjectMapper.java @@ -39,7 +39,7 @@ import org.springframework.util.Assert; * This utility can use generic a {@link HashMapper} or adapt specifically to {@link ObjectHashMapper}'s requirement to * convert incoming data into byte arrays. This class can be subclassed to override template methods for specific object * mapping strategies. - * + * * @author Mark Paluch * @since 2.2 * @see ObjectHashMapper @@ -47,14 +47,21 @@ import org.springframework.util.Assert; */ class StreamObjectMapper { - private final DefaultConversionService conversionService = new DefaultConversionService(); - private final RedisCustomConversions customConversions = new RedisCustomConversions(); + private final static RedisCustomConversions customConversions = new RedisCustomConversions(); + private final static ConversionService conversionService; + private final HashMapper mapper; private final @Nullable HashMapper objectHashMapper; + static { + DefaultConversionService cs = new DefaultConversionService(); + customConversions.registerConvertersIn(cs); + conversionService = cs; + } + /** * Creates a new {@link StreamObjectMapper}. - * + * * @param mapper the configured {@link HashMapper}. */ @SuppressWarnings({ "unchecked", "rawtypes" }) @@ -62,7 +69,6 @@ class StreamObjectMapper { Assert.notNull(mapper, "HashMapper must not be null"); - this.customConversions.registerConvertersIn(conversionService); this.mapper = (HashMapper) mapper; if (mapper instanceof ObjectHashMapper) { @@ -92,7 +98,7 @@ class StreamObjectMapper { /** * Convert the given {@link Record} into a {@link MapRecord}. - * + * * @param provider provider for {@link HashMapper} to apply mapping for {@link ObjectRecord}. * @param source the source value. * @return the converted {@link MapRecord}. @@ -121,7 +127,7 @@ class StreamObjectMapper { /** * Convert the given {@link Record} into an {@link ObjectRecord}. - * + * * @param provider provider for {@link HashMapper} to apply mapping for {@link ObjectRecord}. * @param source the source value. * @param targetType the desired target type. @@ -135,7 +141,7 @@ class StreamObjectMapper { /** * Map a {@link List} of {@link MapRecord}s to a {@link List} of {@link ObjectRecord}. Optimizes for empty, * single-element and multi-element list transformation.l - * + * * @param records the {@link MapRecord} that should be mapped. * @param hashMapperProvider the provider to obtain the actual {@link HashMapper} from. Must not be {@literal null}. * @param targetType the requested {@link Class target type}. @@ -175,7 +181,7 @@ class StreamObjectMapper { /** * Returns the actual {@link HashMapper}. Can be overridden by subclasses. - * + * * @param conversionService the used {@link ConversionService}. * @param targetType the target type. * @return obtain the {@link HashMapper} for a certain type. @@ -200,6 +206,6 @@ class StreamObjectMapper { * @return used {@link ConversionService}. */ ConversionService getConversionService() { - return this.conversionService; + return conversionService; } } diff --git a/src/main/java/org/springframework/data/redis/hash/ObjectHashMapper.java b/src/main/java/org/springframework/data/redis/hash/ObjectHashMapper.java index 58d8986c8..764217835 100644 --- a/src/main/java/org/springframework/data/redis/hash/ObjectHashMapper.java +++ b/src/main/java/org/springframework/data/redis/hash/ObjectHashMapper.java @@ -71,6 +71,8 @@ import org.springframework.util.Assert; */ public class ObjectHashMapper implements HashMapper { + @Nullable private volatile static ObjectHashMapper sharedInstance; + private final RedisConverter converter; /** @@ -120,6 +122,31 @@ public class ObjectHashMapper implements HashMapper { converter = mappingConverter; } + /** + * Return a shared default {@value ObjectHashMapper} instance, lazily building it once needed. + *

+ * NOTE: We highly recommend constructing individual {@link ObjectHashMapper} instances for customization + * purposes. This accessor is only meant as a fallback for code paths which need simple type coercion but cannot + * access a longer-lived {@link ObjectHashMapper} instance any other way. + * + * @return the shared {@link ObjectHashMapper} instance (never {@literal null}). + * @since 2.4 + */ + public static ObjectHashMapper getSharedInstance() { + + ObjectHashMapper cs = sharedInstance; + if (cs == null) { + synchronized (ObjectHashMapper.class) { + cs = sharedInstance; + if (cs == null) { + cs = new ObjectHashMapper(); + sharedInstance = cs; + } + } + } + return cs; + } + /* * (non-Javadoc) * @see org.springframework.data.redis.hash.HashMapper#toHash(java.lang.Object) diff --git a/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java b/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java index 3a8a4b3b4..4c17aad5d 100644 --- a/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java +++ b/src/main/java/org/springframework/data/redis/stream/StreamMessageListenerContainer.java @@ -749,7 +749,7 @@ public interface StreamMessageListenerContainer> exten hashKeySerializer(RedisSerializer.byteArray()); hashValueSerializer(RedisSerializer.byteArray()); - return (StreamMessageListenerContainerOptionsBuilder) objectMapper(new ObjectHashMapper()); + return (StreamMessageListenerContainerOptionsBuilder) objectMapper(ObjectHashMapper.getSharedInstance()); } return (StreamMessageListenerContainerOptionsBuilder) this; diff --git a/src/main/java/org/springframework/data/redis/stream/StreamReceiver.java b/src/main/java/org/springframework/data/redis/stream/StreamReceiver.java index b85d08282..771d86237 100644 --- a/src/main/java/org/springframework/data/redis/stream/StreamReceiver.java +++ b/src/main/java/org/springframework/data/redis/stream/StreamReceiver.java @@ -423,7 +423,7 @@ public interface StreamReceiver> { hashKeySerializer(SerializationPair.raw()); hashValueSerializer(SerializationPair.raw()); - return (StreamReceiverOptionsBuilder) objectMapper(new ObjectHashMapper()); + return (StreamReceiverOptionsBuilder) objectMapper(ObjectHashMapper.getSharedInstance()); } return (StreamReceiverOptionsBuilder) this; diff --git a/src/test/java/org/springframework/data/redis/PropertyEditorsTest.java b/src/test/java/org/springframework/data/redis/PropertyEditorsIntegrationTests.java similarity index 97% rename from src/test/java/org/springframework/data/redis/PropertyEditorsTest.java rename to src/test/java/org/springframework/data/redis/PropertyEditorsIntegrationTests.java index e672e22ea..06eba94c7 100644 --- a/src/test/java/org/springframework/data/redis/PropertyEditorsTest.java +++ b/src/test/java/org/springframework/data/redis/PropertyEditorsIntegrationTests.java @@ -27,7 +27,7 @@ import org.springframework.data.redis.core.RedisOperations; /** * @author Costin Leau */ -class PropertyEditorsTest { +class PropertyEditorsIntegrationTests { private GenericXmlApplicationContext ctx; diff --git a/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java b/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java deleted file mode 100644 index 9d55c72fa..000000000 --- a/src/test/java/org/springframework/data/redis/RedisTestProfileValueSource.java +++ /dev/null @@ -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)); - } -} diff --git a/src/test/java/org/springframework/data/redis/RedisVersionUtils.java b/src/test/java/org/springframework/data/redis/RedisVersionUtils.java deleted file mode 100644 index 234706037..000000000 --- a/src/test/java/org/springframework/data/redis/RedisVersionUtils.java +++ /dev/null @@ -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; - } -} diff --git a/src/test/java/org/springframework/data/redis/VersionParserUnitTests.java b/src/test/java/org/springframework/data/redis/VersionParserUnitTests.java index a8517e5fb..c32126285 100644 --- a/src/test/java/org/springframework/data/redis/VersionParserUnitTests.java +++ b/src/test/java/org/springframework/data/redis/VersionParserUnitTests.java @@ -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)); } } diff --git a/src/test/java/org/springframework/data/redis/cache/CacheTestParams.java b/src/test/java/org/springframework/data/redis/cache/CacheTestParams.java index 7d3ea8d93..a782c68fc 100644 --- a/src/test/java/org/springframework/data/redis/cache/CacheTestParams.java +++ b/src/test/java/org/springframework/data/redis/cache/CacheTestParams.java @@ -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 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 java() { + return RedisSerializer.java(); + } + + public static RedisSerializer java(@Nullable ClassLoader classLoader) { + return RedisSerializer.java(classLoader); + } + + public static RedisSerializer json() { + return RedisSerializer.json(); + } + + public static RedisSerializer string() { + return RedisSerializer.string(); + } + + public static RedisSerializer 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(); } } diff --git a/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java b/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java index b6a7027e5..013fd9472 100644 --- a/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java +++ b/src/test/java/org/springframework/data/redis/cache/DefaultRedisCacheWriterTests.java @@ -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 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); diff --git a/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java b/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java index 5cbd45d49..13e67e630 100644 --- a/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java +++ b/src/test/java/org/springframework/data/redis/cache/LegacyRedisCacheTests.java @@ -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 keyFactory; - ObjectFactory valueFactory; - RedisConnectionFactory connectionFactory; - final boolean allowCacheNullValues; + private final static String CACHE_NAME = "testCache"; + private ObjectFactory keyFactory; + private ObjectFactory valueFactory; + private RedisConnectionFactory connectionFactory; + private final boolean allowCacheNullValues; - RedisCache cache; + private RedisCache cache; public LegacyRedisCacheTests(RedisTemplate template, ObjectFactory keyFactory, ObjectFactory valueFactory, boolean allowCacheNullValues) { @@ -76,7 +73,6 @@ public class LegacyRedisCacheTests { cache = createCache(); } - @Parameters public static Collection testParams() { Collection 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 cacheLoader; - public CacheGetWithValueLoaderIsThreadSafe(Cache redisCache) { + CacheGetWithValueLoaderIsThreadSafe(Cache redisCache) { this.redisCache = redisCache; cacheLoader = new TestCacheLoader("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; } } diff --git a/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java b/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java index 0d617d516..4e87a3f26 100644 --- a/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java +++ b/src/test/java/org/springframework/data/redis/cache/RedisCacheTests.java @@ -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 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()))); diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java index 9f42341de..69baf3290 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionIntegrationTests.java @@ -16,7 +16,6 @@ package org.springframework.data.redis.connection; import static org.assertj.core.api.Assertions.*; -import static org.junit.Assume.*; import static org.springframework.data.redis.SpinBarrier.*; import static org.springframework.data.redis.connection.BitFieldSubCommands.*; import static org.springframework.data.redis.connection.BitFieldSubCommands.BitFieldIncrBy.Overflow.*; @@ -29,20 +28,15 @@ import static org.springframework.data.redis.core.ScanOptions.*; import java.time.Duration; import java.util.*; import java.util.concurrent.BlockingDeque; -import java.util.concurrent.CountDownLatch; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; import org.assertj.core.data.Offset; -import org.awaitility.Awaitility; -import org.junit.AfterClass; import org.junit.AssumptionViolatedException; -import org.junit.Ignore; -import org.junit.Rule; -import org.junit.Test; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.dao.DataAccessException; @@ -52,9 +46,7 @@ import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; -import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.RedisSystemException; -import org.springframework.data.redis.RedisVersionUtils; import org.springframework.data.redis.TestCondition; import org.springframework.data.redis.connection.RedisGeoCommands.GeoLocation; import org.springframework.data.redis.connection.RedisListCommands.Position; @@ -85,12 +77,10 @@ import org.springframework.data.redis.core.types.Expiration; import org.springframework.data.redis.core.types.RedisClientInfo; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.test.condition.EnabledOnCommand; -import org.springframework.data.redis.test.condition.EnabledOnRedisVersion; +import org.springframework.data.redis.test.condition.EnabledOnRedisDriver; +import org.springframework.data.redis.test.condition.LongRunningTest; +import org.springframework.data.redis.test.condition.RedisDriver; import org.springframework.data.redis.test.util.HexStringUtils; -import org.springframework.data.redis.test.util.RedisClientRule; -import org.springframework.data.redis.test.util.RedisDriver; -import org.springframework.data.redis.test.util.WithRedisDriver; -import org.springframework.test.annotation.IfProfileValue; /** * Base test class for AbstractConnection integration tests @@ -116,27 +106,19 @@ public abstract class AbstractConnectionIntegrationTests { protected StringRedisConnection connection; protected RedisSerializer serializer = RedisSerializer.java(); - protected RedisSerializer stringSerializer = RedisSerializer.string(); + private RedisSerializer stringSerializer = RedisSerializer.string(); private static final byte[] EMPTY_ARRAY = new byte[0]; protected List actual = new ArrayList<>(); - @Autowired protected RedisConnectionFactory connectionFactory; + @Autowired @EnabledOnRedisDriver.DriverQualifier protected RedisConnectionFactory connectionFactory; protected RedisConnection byteConnection; - public @Rule RedisClientRule clientRule = new RedisClientRule() { - public RedisConnectionFactory getConnectionFactory() { - return connectionFactory; - } - }; - @BeforeEach public void setUp() { - ConnectionFactoryTracker.add(connectionFactory); - byteConnection = connectionFactory.getConnection(); connection = new DefaultStringRedisConnection(byteConnection); ((DefaultStringRedisConnection) connection).setDeserializePipelineAndTxResults(true); @@ -157,30 +139,24 @@ public abstract class AbstractConnectionIntegrationTests { connection = null; } - @AfterClass - public static void cleanUp() { - ConnectionFactoryTracker.cleanUp(); - } - @Test public void testSelect() { // Make sure this doesn't throw Exception connection.select(1); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testExpire() throws Exception { + @LongRunningTest + void testExpire() { actual.add(connection.set("exp", "true")); actual.add(connection.expire("exp", 1)); verifyResults(Arrays.asList(true, true)); - assertThat(waitFor(new KeyExpired("exp"), 3000l)).isTrue(); + assertThat(waitFor(new KeyExpired("exp"), 3000L)).isTrue(); } @Test // DATAREDIS-1103 - public void testSetWithKeepTTL() { + void testSetWithKeepTTL() { actual.add(connection.set("exp", "true")); actual.add(connection.expire("exp", 10)); @@ -193,42 +169,41 @@ public abstract class AbstractConnectionIntegrationTests { assertThat((Long) results.get(3)).isCloseTo(10L, Offset.offset(5L)); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testExpireAt() throws Exception { + @LongRunningTest + void testExpireAt() { actual.add(connection.set("exp2", "true")); actual.add(connection.expireAt("exp2", System.currentTimeMillis() / 1000 + 1)); verifyResults(Arrays.asList(true, true)); - assertThat(waitFor(new KeyExpired("exp2"), 3000l)).isTrue(); + assertThat(waitFor(new KeyExpired("exp2"), 3000L)).isTrue(); } - @Test - public void testPExpire() { + @LongRunningTest + void testPExpire() { actual.add(connection.set("exp", "true")); actual.add(connection.pExpire("exp", 100)); verifyResults(Arrays.asList(true, true)); - assertThat(waitFor(new KeyExpired("exp"), 1000l)).isTrue(); + assertThat(waitFor(new KeyExpired("exp"), 1000L)).isTrue(); } @Test - public void testPExpireKeyNotExists() { + void testPExpireKeyNotExists() { actual.add(connection.pExpire("nonexistent", 100)); verifyResults(Arrays.asList(new Object[] { false })); } - @Test - public void testPExpireAt() { + @LongRunningTest + void testPExpireAt() { actual.add(connection.set("exp2", "true")); actual.add(connection.pExpireAt("exp2", System.currentTimeMillis() + 200)); verifyResults(Arrays.asList(true, true)); - assertThat(waitFor(new KeyExpired("exp2"), 1000l)).isTrue(); + assertThat(waitFor(new KeyExpired("exp2"), 1000L)).isTrue(); } - @Test - public void testPExpireAtKeyNotExists() { + @LongRunningTest + void testPExpireAtKeyNotExists() { actual.add(connection.pExpireAt("nonexistent", System.currentTimeMillis() + 200)); verifyResults(Arrays.asList(new Object[] { false })); } @@ -251,8 +226,8 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.evalSha(sha1, ReturnType.MULTI, 1, "key1", "arg1")); List results = getResults(); List scriptResults = (List) results.get(0); - assertThat(Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) })) - .isEqualTo(Arrays.asList(new Object[] { "key1", "arg1" })); + assertThat(Arrays.asList(new String(scriptResults.get(0)), new String(scriptResults.get(1)))) + .isEqualTo(Arrays.asList("key1", "arg1")); } @SuppressWarnings("unchecked") @@ -264,20 +239,24 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(byteConnection.evalSha(sha1, ReturnType.MULTI, 1, "key1".getBytes(), "arg1".getBytes())); List results = getResults(); List scriptResults = (List) results.get(0); - assertThat(Arrays.asList(new Object[] { new String(scriptResults.get(0)), new String(scriptResults.get(1)) })) - .isEqualTo(Arrays.asList(new Object[] { "key1", "arg1" })); + assertThat(Arrays.asList(new String(scriptResults.get(0)), new String(scriptResults.get(1)))) + .isEqualTo(Arrays.asList("key1", "arg1")); } - @Test(expected = RedisSystemException.class) + @Test public void testEvalShaArrayError() { - connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1"); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + connection.evalSha("notasha", ReturnType.MULTI, 1, "key1", "arg1"); + getResults(); + }); } - @Test(expected = RedisSystemException.class) + @Test public void testEvalShaNotFound() { - connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2"); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + connection.evalSha("somefakesha", ReturnType.VALUE, 2, "key1", "key2"); + getResults(); + }); } @Test @@ -290,19 +269,21 @@ public abstract class AbstractConnectionIntegrationTests { @Test public void testEvalReturnNumber() { actual.add(connection.eval("return 10", ReturnType.INTEGER, 0)); - verifyResults(Arrays.asList(new Object[] { 10l })); + verifyResults(Arrays.asList(new Object[] { 10L })); } @Test public void testEvalReturnSingleOK() { actual.add(connection.eval("return redis.call('set','abc','ghk')", ReturnType.STATUS, 0)); - assertThat(getResults()).isEqualTo(Arrays.asList(new Object[] { "OK" })); + assertThat(getResults()).isEqualTo(Arrays.asList("OK")); } - @Test(expected = RedisSystemException.class) + @Test public void testEvalReturnSingleError() { - connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + connection.eval("return redis.call('expire','foo')", ReturnType.BOOLEAN, 0); + getResults(); + }); } @Test @@ -322,21 +303,23 @@ public abstract class AbstractConnectionIntegrationTests { public void testEvalReturnArrayStrings() { actual.add(connection.eval("return {KEYS[1],ARGV[1]}", ReturnType.MULTI, 1, "foo", "bar")); List result = (List) getResults().get(0); - assertThat(Arrays.asList(new Object[] { new String(result.get(0)), new String(result.get(1)) })) - .isEqualTo(Arrays.asList(new Object[] { "foo", "bar" })); + assertThat(Arrays.asList(new String(result.get(0)), new String(result.get(1)))) + .isEqualTo(Arrays.asList("foo", "bar")); } @Test public void testEvalReturnArrayNumbers() { actual.add(connection.eval("return {1,2}", ReturnType.MULTI, 1, "foo", "bar")); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 2l }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(1L, 2L) })); } - @Test(expected = RedisSystemException.class) + @Test public void testEvalArrayScriptError() { - // Syntax error - connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar"); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + // Syntax error + connection.eval("return {1,2", ReturnType.MULTI, 1, "foo", "bar"); + getResults(); + }); } @SuppressWarnings("unchecked") @@ -345,20 +328,20 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.eval("return { redis.call('set','abc','ghk'), redis.call('set','abc','lfdf')}", ReturnType.MULTI, 0)); List result = (List) getResults().get(0); - assertThat(Arrays.asList(new Object[] { new String(result.get(0)), new String(result.get(1)) })) - .isEqualTo(Arrays.asList(new Object[] { "OK", "OK" })); + assertThat(Arrays.asList(new String(result.get(0)), new String(result.get(1)))) + .isEqualTo(Arrays.asList("OK", "OK")); } @Test public void testEvalReturnArrayFalses() { actual.add(connection.eval("return { false, false}", ReturnType.MULTI, 0)); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { null, null }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(null, null) })); } @Test public void testEvalReturnArrayTrues() { actual.add(connection.eval("return { true, true}", ReturnType.MULTI, 0)); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l, 1l }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(1L, 1L) })); } @Test @@ -367,34 +350,7 @@ public abstract class AbstractConnectionIntegrationTests { String sha1 = connection.scriptLoad("return 'foo'"); initConnection(); actual.add(connection.scriptExists(sha1, "98777234")); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true, false }) })); - } - - @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); - final CountDownLatch sync = new CountDownLatch(1); - Thread th = new Thread(() -> { - DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); - try { - sync.countDown(); - conn2.eval("local time=1 while time < 10000000000 do time=time+1 end", ReturnType.BOOLEAN, 0); - } catch (DataAccessException e) { - scriptDead.set(true); - } - conn2.close(); - }); - th.start(); - sync.await(2, TimeUnit.SECONDS); - Thread.sleep(200); - connection.scriptKill(); - getResults(); - - Awaitility.await().untilTrue(scriptDead); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(true, false) })); } @Test @@ -404,12 +360,11 @@ public abstract class AbstractConnectionIntegrationTests { connection.scriptFlush(); initConnection(); actual.add(connection.scriptExists(sha1)); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new Object[] { false }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(false) })); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testPersist() throws Exception { + @LongRunningTest + void testPersist() { actual.add(connection.set("exp3", "true")); actual.add(connection.expire("exp3", 30)); @@ -418,20 +373,18 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(true, true, true, -1L)); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testSetEx() throws Exception { + @LongRunningTest + void testSetEx() { - actual.add(connection.setEx("expy", 1l, "yep")); + actual.add(connection.setEx("expy", 1L, "yep")); actual.add(connection.get("expy")); verifyResults(Arrays.asList(true, "yep")); - assertThat(waitFor(new KeyExpired("expy"), 2500l)).isTrue(); + assertThat(waitFor(new KeyExpired("expy"), 2500L)).isTrue(); } - @Test // DATAREDIS-271 - @IfProfileValue(name = "runLongTests", value = "true") - public void testPsetEx() throws Exception { + @LongRunningTest // DATAREDIS-271 + void testPsetEx() { actual.add(connection.pSetEx("expy", 500L, "yep")); actual.add(connection.get("expy")); @@ -440,29 +393,26 @@ public abstract class AbstractConnectionIntegrationTests { assertThat(waitFor(new KeyExpired("expy"), 2500L)).isTrue(); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testBRPopTimeout() throws Exception { + @LongRunningTest + public void testBRPopTimeout() { actual.add(connection.bRPop(1, "alist")); verifyResults(Arrays.asList(new Object[] { null })); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testBLPopTimeout() throws Exception { + @LongRunningTest + public void testBLPopTimeout() { actual.add(connection.bLPop(1, "alist")); verifyResults(Arrays.asList(new Object[] { null })); } - @Test - @IfProfileValue(name = "runLongTests", value = "true") - public void testBRPopLPushTimeout() throws Exception { + @LongRunningTest + public void testBRPopLPushTimeout() { actual.add(connection.bRPopLPush(1, "alist", "foo")); verifyResults(Arrays.asList(new Object[] { null })); } @Test - public void testSetAndGet() { + void testSetAndGet() { String key = "foo"; String value = "blabla"; @@ -473,13 +423,13 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testPingPong() throws Exception { + void testPingPong() { actual.add(connection.ping()); verifyResults(new ArrayList<>(Collections.singletonList("PONG"))); } @Test - public void testBitSet() throws Exception { + void testBitSet() { String key = "bitset-test"; actual.add(connection.setBit(key, 0, true)); actual.add(connection.setBit(key, 0, false)); @@ -490,7 +440,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testBitCount() { + void testBitCount() { String key = "bitset-test"; actual.add(connection.setBit(key, 0, false)); actual.add(connection.setBit(key, 1, true)); @@ -500,7 +450,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testBitCountInterval() { + void testBitCountInterval() { actual.add(connection.set("mykey", "foobar")); actual.add(connection.bitCount("mykey", 1, 1)); @@ -508,13 +458,13 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testBitCountNonExistentKey() { + void testBitCountNonExistentKey() { actual.add(connection.bitCount("mykey")); - verifyResults(new ArrayList<>(Collections.singletonList(0l))); + verifyResults(new ArrayList<>(Collections.singletonList(0L))); } @Test - public void testBitOpAnd() { + void testBitOpAnd() { actual.add(connection.set("key1", "foo")); actual.add(connection.set("key2", "bar")); @@ -524,17 +474,17 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testBitOpOr() { + void testBitOpOr() { actual.add(connection.set("key1", "foo")); actual.add(connection.set("key2", "ugh")); actual.add(connection.bitOp(BitOperation.OR, "key3", "key1", "key2")); actual.add(connection.get("key3")); - verifyResults(Arrays.asList(Boolean.TRUE, Boolean.TRUE, 3l, "woo")); + verifyResults(Arrays.asList(Boolean.TRUE, Boolean.TRUE, 3L, "woo")); } @Test - public void testBitOpXOr() { + void testBitOpXOr() { actual.add(connection.set("key1", "abcd")); actual.add(connection.set("key2", "efgh")); @@ -543,24 +493,21 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testBitOpNot() { + void testBitOpNot() { actual.add(connection.set("key1", "abcd")); actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1")); verifyResults(Arrays.asList(Boolean.TRUE, 4L)); } - @Test(expected = UnsupportedOperationException.class) - public void testBitOpNotMultipleSources() { - - actual.add(connection.set("key1", "abcd")); - actual.add(connection.set("key2", "efgh")); - actual.add(connection.bitOp(BitOperation.NOT, "key3", "key1", "key2")); - getResults(); + @Test + void testBitOpNotMultipleSources() { + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> connection.bitOp(BitOperation.NOT, "key3", "key1", "key2")); } @Test - public void testInfo() throws Exception { + void testInfo() { actual.add(connection.info()); List results = getResults(); @@ -571,7 +518,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testInfoBySection() throws Exception { + public void testInfoBySection() { actual.add(connection.info("server")); List results = getResults(); Properties info = (Properties) results.get(0); @@ -581,8 +528,8 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - @Ignore("DATAREDIS-525") - public void testNullKey() throws Exception { + @Disabled("DATAREDIS-525") + public void testNullKey() { try { connection.decr((String) null); fail("Decrement should fail with null key"); @@ -592,8 +539,8 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - @Ignore("DATAREDIS-525") - public void testNullValue() throws Exception { + @Disabled("DATAREDIS-525") + public void testNullValue() { byte[] key = UUID.randomUUID().toString().getBytes(); connection.append(key, EMPTY_ARRAY); @@ -606,8 +553,8 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - @Ignore("DATAREDIS-525") - public void testHashNullKey() throws Exception { + @Disabled("DATAREDIS-525") + public void testHashNullKey() { byte[] key = UUID.randomUUID().toString().getBytes(); try { @@ -619,8 +566,8 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - @Ignore("DATAREDIS-525") - public void testHashNullValue() throws Exception { + @Disabled("DATAREDIS-525") + public void testHashNullValue() { byte[] key = UUID.randomUUID().toString().getBytes(); byte[] field = "random".getBytes(); @@ -634,24 +581,24 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testNullSerialization() throws Exception { + void testNullSerialization() { String[] keys = new String[] { "~", "[" }; actual.add(connection.mGet(keys)); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { null, null }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList(null, null) })); StringRedisTemplate stringTemplate = new StringRedisTemplate(connectionFactory); List multiGet = stringTemplate.opsForValue().multiGet(Arrays.asList(keys)); - assertThat(multiGet).isEqualTo(Arrays.asList(new String[] { null, null })); + assertThat(multiGet).isEqualTo(Arrays.asList(null, null)); } @Test - public void testAppend() { + void testAppend() { actual.add(connection.set("a", "b")); actual.add(connection.append("a", "c")); actual.add(connection.get("a")); - verifyResults(Arrays.asList(new Object[] { Boolean.TRUE, 2l, "bc" })); + verifyResults(Arrays.asList(new Object[] { Boolean.TRUE, 2L, "bc" })); } - @Test + @LongRunningTest public void testPubSubWithNamedChannels() throws Exception { final String expectedChannel = "channel1"; final String expectedMessage = "msg"; @@ -692,7 +639,7 @@ public abstract class AbstractConnectionIntegrationTests { assertThat(new String(message.getChannel())).isEqualTo(expectedChannel); } - @Test + @LongRunningTest public void testPubSubWithPatterns() throws Exception { final String expectedPattern = "channel*"; final String expectedMessage = "msg"; @@ -738,15 +685,16 @@ public abstract class AbstractConnectionIntegrationTests { assertThat(new String(message.getBody())).isEqualTo(expectedMessage); } - @Test(expected = DataAccessException.class) - public void exceptionExecuteNative() throws Exception { - connection.execute("set", "foo"); - connection.execute("ZadD", getClass() + "#foo\t0.90\titem"); - getResults(); + @Test + public void exceptionExecuteNative() { + assertThatExceptionOfType(DataAccessException.class).isThrownBy(() -> { + connection.execute("set", "foo"); + getResults(); + }); } @Test - public void testExecute() { + void testExecute() { actual.add(connection.set("foo", "bar")); actual.add(connection.execute("GET", "foo")); @@ -755,7 +703,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testExecuteNoArgs() { + void testExecuteNoArgs() { actual.add(connection.execute("PING")); List results = getResults(); @@ -764,7 +712,7 @@ public abstract class AbstractConnectionIntegrationTests { @SuppressWarnings("unchecked") @Test - public void testMultiExec() throws Exception { + public void testMultiExec() { connection.multi(); connection.set("key", "value"); @@ -777,30 +725,33 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testMultiAlreadyInTx() throws Exception { + void testMultiAlreadyInTx() { connection.multi(); // Ensure it's OK to call multi twice testMultiExec(); } - @Test(expected = RedisSystemException.class) + @Test public void testExecWithoutMulti() { - connection.exec(); - getResults(); - } - - @Test(expected = RedisSystemException.class) - public void testErrorInTx() { - connection.multi(); - connection.set("foo", "bar"); - // Try to do a list op on a value - connection.lPop("foo"); - connection.exec(); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + connection.exec(); + }); } @Test - public void testMultiDiscard() throws Exception { + public void testErrorInTx() { + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + connection.multi(); + connection.set("foo", "bar"); + // Try to do a list op on a value + connection.lPop("foo"); + connection.exec(); + getResults(); + }); + } + + @Test + public void testMultiDiscard() { DefaultStringRedisConnection conn2 = new DefaultStringRedisConnection(connectionFactory.getConnection()); conn2.set("testitnow", "willdo"); connection.multi(); @@ -808,13 +759,13 @@ public abstract class AbstractConnectionIntegrationTests { connection.discard(); actual.add(connection.get("testitnow")); List results = getResults(); - assertThat(results).isEqualTo(Arrays.asList(new String[] { "willdo" })); + assertThat(results).isEqualTo(Arrays.asList("willdo")); initConnection(); // Ensure we can run a new tx after discarding previous one testMultiExec(); } - @Test + @LongRunningTest public void testWatch() throws Exception { actual.add(connection.set("testitnow", "willdo")); @@ -833,7 +784,7 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(new Object[] { true, null, "something" })); } - @Test + @LongRunningTest public void testUnwatch() throws Exception { actual.add(connection.set("testitnow", "willdo")); @@ -855,45 +806,45 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testSort() { + void testSort() { actual.add(connection.rPush("sortlist", "foo")); actual.add(connection.rPush("sortlist", "bar")); actual.add(connection.rPush("sortlist", "baz")); actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true))); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "bar", "baz", "foo" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, Arrays.asList("bar", "baz", "foo"))); } @Test - public void testSortStore() { + void testSortStore() { actual.add(connection.rPush("sortlist", "foo")); actual.add(connection.rPush("sortlist", "bar")); actual.add(connection.rPush("sortlist", "baz")); actual.add(connection.sort("sortlist", new DefaultSortParameters(null, Order.ASC, true), "newlist")); actual.add(connection.lRange("newlist", 0, 9)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, Arrays.asList(new String[] { "bar", "baz", "foo" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, 3L, Arrays.asList("bar", "baz", "foo"))); } @Test - public void testSortNullParams() { + void testSortNullParams() { actual.add(connection.rPush("sortlist", "5")); actual.add(connection.rPush("sortlist", "2")); actual.add(connection.rPush("sortlist", "3")); actual.add(connection.sort("sortlist", null)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "2", "3", "5" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, Arrays.asList("2", "3", "5"))); } @Test - public void testSortStoreNullParams() { + void testSortStoreNullParams() { actual.add(connection.rPush("sortlist", "9")); actual.add(connection.rPush("sortlist", "3")); actual.add(connection.rPush("sortlist", "5")); actual.add(connection.sort("sortlist", null, "newlist")); actual.add(connection.lRange("newlist", 0, 9)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 3l, Arrays.asList(new String[] { "3", "5", "9" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, 3L, Arrays.asList("3", "5", "9"))); } @Test - public void testDbSize() { + void testDbSize() { actual.add(connection.set("dbparam", "foo")); actual.add(connection.dbSize()); @@ -901,10 +852,10 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testFlushDb() { + void testFlushDb() { connection.flushDb(); actual.add(connection.dbSize()); - verifyResults(Arrays.asList(new Object[] { 0l })); + verifyResults(Arrays.asList(new Object[] { 0L })); } @SuppressWarnings("unchecked") @@ -916,13 +867,13 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testEcho() { + void testEcho() { actual.add(connection.echo("Hello World")); verifyResults(Arrays.asList(new Object[] { "Hello World" })); } @Test - public void testExists() { + void testExists() { actual.add(connection.set("existent", "true")); actual.add(connection.exists("existent")); @@ -931,7 +882,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-529 - public void testExistsWithMultipleKeys() { + void testExistsWithMultipleKeys() { actual.add(connection.set("exist-1", "true")); actual.add(connection.set("exist-2", "true")); @@ -943,7 +894,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-529 - public void testExistsWithMultipleKeysNoneExists() { + void testExistsWithMultipleKeysNoneExists() { actual.add(connection.exists("no-exist-1", "no-exist-2")); @@ -951,7 +902,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-529 - public void testExistsSameKeyMultipleTimes() { + void testExistsSameKeyMultipleTimes() { actual.add(connection.set("existent", "true")); @@ -962,7 +913,7 @@ public abstract class AbstractConnectionIntegrationTests { @SuppressWarnings("unchecked") @Test - public void testKeys() throws Exception { + void testKeys() { actual.add(connection.set("keytest", "true")); actual.add(connection.keys("key*")); @@ -970,7 +921,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testRandomKey() { + void testRandomKey() { actual.add(connection.set("some", "thing")); actual.add(connection.randomKey()); @@ -979,7 +930,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testRename() { + void testRename() { actual.add(connection.set("renametest", "testit")); connection.rename("renametest", "newrenametest"); @@ -989,7 +940,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testRenameNx() { + void testRenameNx() { actual.add(connection.set("nxtest", "testit")); actual.add(connection.renameNX("nxtest", "newnxtest")); @@ -999,14 +950,14 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testTtl() { + void testTtl() { actual.add(connection.set("whatup", "yo")); actual.add(connection.ttl("whatup")); verifyResults(Arrays.asList(true, -1L)); } @Test // DATAREDIS-526 - public void testTtlWithTimeUnit() { + void testTtlWithTimeUnit() { actual.add(connection.set("whatup", "yo")); actual.add(connection.expire("whatup", 10)); @@ -1019,7 +970,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testPTtlNoExpire() { + void testPTtlNoExpire() { actual.add(connection.set("whatup", "yo")); actual.add(connection.pTtl("whatup")); @@ -1027,7 +978,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testPTtl() { + void testPTtl() { actual.add(connection.set("whatup", "yo")); actual.add(connection.pExpire("whatup", TimeUnit.SECONDS.toMillis(10))); @@ -1039,7 +990,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-526 - public void testPTtlWithTimeUnit() { + void testPTtlWithTimeUnit() { actual.add(connection.set("whatup", "yo")); actual.add(connection.pExpire("whatup", TimeUnit.MINUTES.toMillis(10))); @@ -1052,7 +1003,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testDumpAndRestore() { + void testDumpAndRestore() { connection.set("testing", "12"); actual.add(connection.dump("testing".getBytes())); @@ -1068,31 +1019,35 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testDumpNonExistentKey() { + void testDumpNonExistentKey() { actual.add(connection.dump("fakey".getBytes())); verifyResults(Arrays.asList(new Object[] { null })); } - @Test(expected = RedisSystemException.class) + @Test public void testRestoreBadData() { - // Use something other than dump-specific serialization - connection.restore("testing".getBytes(), 0, "foo".getBytes()); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + // Use something other than dump-specific serialization + connection.restore("testing".getBytes(), 0, "foo".getBytes()); + getResults(); + }); } - @Test(expected = RedisSystemException.class) + @Test public void testRestoreExistingKey() { actual.add(connection.set("testing", "12")); actual.add(connection.dump("testing".getBytes())); List results = getResults(); initConnection(); - connection.restore("testing".getBytes(), 0, (byte[]) results.get(1)); - getResults(); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> { + connection.restore("testing".getBytes(), 0, (byte[]) results.get(1)); + getResults(); + }); } @Test // DATAREDIS-696 - public void testRestoreExistingKeyWithReplaceOption() { + void testRestoreExistingKeyWithReplaceOption() { actual.add(connection.set("testing", "12")); actual.add(connection.dump("testing".getBytes())); @@ -1104,8 +1059,8 @@ public abstract class AbstractConnectionIntegrationTests { verifyResults(Arrays.asList(new Object[] { "12" })); } - @Test - public void testRestoreTtl() { + @LongRunningTest + void testRestoreTtl() { actual.add(connection.set("testing", "12")); actual.add(connection.dump("testing".getBytes())); @@ -1114,13 +1069,13 @@ public abstract class AbstractConnectionIntegrationTests { initConnection(); actual.add(connection.del("testing")); actual.add(connection.get("testing")); - connection.restore("testing".getBytes(), 100l, (byte[]) results.get(1)); - verifyResults(Arrays.asList(1l, null)); - assertThat(waitFor(new KeyExpired("testing"), 400l)).isTrue(); + connection.restore("testing".getBytes(), 100L, (byte[]) results.get(1)); + verifyResults(Arrays.asList(1L, null)); + assertThat(waitFor(new KeyExpired("testing"), 400L)).isTrue(); } @Test - public void testDel() { + void testDel() { actual.add(connection.set("testing", "123")); actual.add(connection.del("testing")); @@ -1129,7 +1084,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-693 - public void unlinkReturnsNrOfKeysRemoved() { + void unlinkReturnsNrOfKeysRemoved() { actual.add(connection.set("unlink.this", "Can't track this!")); @@ -1139,7 +1094,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-693 - public void testUnlinkBatch() { + void testUnlinkBatch() { actual.add(connection.set("testing", "123")); actual.add(connection.set("foo", "bar")); @@ -1150,7 +1105,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-693 - public void unlinkReturnsZeroIfNoKeysRemoved() { + void unlinkReturnsZeroIfNoKeysRemoved() { actual.add(connection.unlink("unlink.this")); @@ -1158,7 +1113,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testType() { + void testType() { actual.add(connection.set("something", "yo")); actual.add(connection.type("something")); @@ -1166,7 +1121,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testGetSet() { + void testGetSet() { actual.add(connection.set("testGS", "1")); actual.add(connection.getSet("testGS", "2")); actual.add(connection.get("testGS")); @@ -1174,39 +1129,39 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testMSet() { + void testMSet() { Map vals = new HashMap<>(); vals.put("color", "orange"); vals.put("size", "1"); actual.add(connection.mSetString(vals)); actual.add(connection.mGet("color", "size")); - verifyResults(Arrays.asList(true, Arrays.asList(new String[] { "orange", "1" }))); + verifyResults(Arrays.asList(true, Arrays.asList("orange", "1"))); } @Test - public void testMSetNx() { + void testMSetNx() { Map vals = new HashMap<>(); vals.put("height", "5"); vals.put("width", "1"); actual.add(connection.mSetNXString(vals)); actual.add(connection.mGet("height", "width")); - verifyResults(Arrays.asList(new Object[] { true, Arrays.asList(new String[] { "5", "1" }) })); + verifyResults(Arrays.asList(true, Arrays.asList("5", "1"))); } @Test - public void testMSetNxFailure() { + void testMSetNxFailure() { actual.add(connection.set("height", "2")); Map vals = new HashMap<>(); vals.put("height", "5"); vals.put("width", "1"); actual.add(connection.mSetNXString(vals)); actual.add(connection.mGet("height", "width")); - verifyResults(Arrays.asList(true, false, Arrays.asList(new String[] { "2", null }))); + verifyResults(Arrays.asList(true, false, Arrays.asList("2", null))); } @Test - public void testSetNx() { + void testSetNx() { actual.add(connection.setNX("notaround", "54")); actual.add(connection.get("notaround")); actual.add(connection.setNX("notaround", "55")); @@ -1215,26 +1170,26 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testGetRangeSetRange() { + void testGetRangeSetRange() { actual.add(connection.set("rangekey", "supercalifrag")); - actual.add(connection.getRange("rangekey", 0l, 2l)); + actual.add(connection.getRange("rangekey", 0L, 2L)); connection.setRange("rangekey", "ck", 2); actual.add(connection.get("rangekey")); verifyResults(Arrays.asList(true, "sup", "suckrcalifrag")); } @Test - public void testDecrByIncrBy() { + void testDecrByIncrBy() { actual.add(connection.set("tdb", "4")); - actual.add(connection.decrBy("tdb", 3l)); - actual.add(connection.incrBy("tdb", 7l)); + actual.add(connection.decrBy("tdb", 3L)); + actual.add(connection.incrBy("tdb", 7L)); verifyResults(Arrays.asList(Boolean.TRUE, 1L, 8L)); } @Test - public void testIncrByDouble() { + void testIncrByDouble() { actual.add(connection.set("tdb", "4.5")); actual.add(connection.incrBy("tdb", 7.2)); @@ -1244,7 +1199,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testIncrDecrByLong() { + void testIncrDecrByLong() { String key = "test.count"; long largeNumber = 0x123456789L; // > 32bits @@ -1252,11 +1207,11 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.incrBy(key, largeNumber)); actual.add(connection.decrBy(key, largeNumber)); actual.add(connection.decrBy(key, 2 * largeNumber)); - verifyResults(Arrays.asList(Boolean.TRUE, largeNumber, 0l, -2 * largeNumber)); + verifyResults(Arrays.asList(Boolean.TRUE, largeNumber, 0L, -2 * largeNumber)); } @Test - public void testHashIncrDecrByLong() { + void testHashIncrDecrByLong() { String key = "test.hcount"; String hkey = "hashkey"; @@ -1271,7 +1226,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testIncDecr() { + void testIncDecr() { actual.add(connection.set("incrtest", "0")); actual.add(connection.incr("incrtest")); @@ -1282,7 +1237,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testStrLen() { + void testStrLen() { actual.add(connection.set("strlentest", "cat")); actual.add(connection.strLen("strlentest")); @@ -1297,7 +1252,7 @@ public abstract class AbstractConnectionIntegrationTests { conn2.lPush("poplist", "foo"); conn2.lPush("poplist", "bar"); actual.add(connection.bLPop(100, "poplist", "otherlist")); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "poplist", "bar" }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList("poplist", "bar") })); } @Test @@ -1306,89 +1261,88 @@ public abstract class AbstractConnectionIntegrationTests { conn2.rPush("rpoplist", "bar"); conn2.rPush("rpoplist", "foo"); actual.add(connection.bRPop(1, "rpoplist")); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "rpoplist", "foo" }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList("rpoplist", "foo") })); } @Test - public void testLInsert() { + void testLInsert() { actual.add(connection.rPush("MyList", "hello")); actual.add(connection.rPush("MyList", "world")); actual.add(connection.lInsert("MyList", Position.AFTER, "hello", "big")); actual.add(connection.lRange("MyList", 0, -1)); actual.add(connection.lInsert("MyList", Position.BEFORE, "big", "very")); actual.add(connection.lRange("MyList", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "big", "world" }), 4l, - Arrays.asList(new String[] { "hello", "very", "big", "world" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, Arrays.asList("hello", "big", "world"), 4L, + Arrays.asList("hello", "very", "big", "world"))); } @Test - public void testLPop() { + void testLPop() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "world")); actual.add(connection.lPop("PopList")); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, "hello" })); + verifyResults(Arrays.asList(new Object[] { 1L, 2L, "hello" })); } @Test - public void testLRem() { + void testLRem() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "big")); actual.add(connection.rPush("PopList", "world")); actual.add(connection.rPush("PopList", "hello")); actual.add(connection.lRem("PopList", 2, "hello")); actual.add(connection.lRange("PopList", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 2l, Arrays.asList(new String[] { "big", "world" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, 4L, 2L, Arrays.asList("big", "world"))); } @Test - public void testLLen() { + void testLLen() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "big")); actual.add(connection.rPush("PopList", "world")); actual.add(connection.rPush("PopList", "hello")); actual.add(connection.lLen("PopList")); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, 4l, 4l })); + verifyResults(Arrays.asList(new Object[] { 1L, 2L, 3L, 4L, 4L })); } @Test - public void testLSet() { + void testLSet() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "big")); actual.add(connection.rPush("PopList", "world")); connection.lSet("PopList", 1, "cruel"); actual.add(connection.lRange("PopList", 0, -1)); verifyResults( - Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "hello", "cruel", "world" }) })); + Arrays.asList(1L, 2L, 3L, Arrays.asList("hello", "cruel", "world"))); } @Test - public void testLTrim() { + void testLTrim() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "big")); actual.add(connection.rPush("PopList", "world")); connection.lTrim("PopList", 1, -1); actual.add(connection.lRange("PopList", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 3l, Arrays.asList(new String[] { "big", "world" }) })); + verifyResults(Arrays.asList(1L, 2L, 3L, Arrays.asList("big", "world"))); } @Test - public void testRPop() { + void testRPop() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "world")); actual.add(connection.rPop("PopList")); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, "world" })); + verifyResults(Arrays.asList(new Object[] { 1L, 2L, "world" })); } @Test - public void testRPopLPush() { + void testRPopLPush() { actual.add(connection.rPush("PopList", "hello")); actual.add(connection.rPush("PopList", "world")); actual.add(connection.rPush("pop2", "hey")); actual.add(connection.rPopLPush("PopList", "pop2")); actual.add(connection.lRange("PopList", 0, -1)); actual.add(connection.lRange("pop2", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, 1l, "world", Arrays.asList(new String[] { "hello" }), - Arrays.asList(new String[] { "world", "hey" }) })); + verifyResults(Arrays.asList(1L, 2L, 1L, "world", Arrays.asList("hello"), Arrays.asList("world", "hey"))); } @@ -1400,60 +1354,60 @@ public abstract class AbstractConnectionIntegrationTests { conn2.rPush("pop2", "hey"); actual.add(connection.bRPopLPush(1, "PopList", "pop2")); List results = getResults(); - assertThat(results).isEqualTo(Arrays.asList(new String[] { "world" })); - assertThat(connection.lRange("PopList", 0, -1)).isEqualTo(Arrays.asList(new String[] { "hello" })); - assertThat(connection.lRange("pop2", 0, -1)).isEqualTo(Arrays.asList(new String[] { "world", "hey" })); + assertThat(results).isEqualTo(Arrays.asList("world")); + assertThat(connection.lRange("PopList", 0, -1)).isEqualTo(Arrays.asList("hello")); + assertThat(connection.lRange("pop2", 0, -1)).isEqualTo(Arrays.asList("world", "hey")); } @Test - public void testLPushX() { + void testLPushX() { actual.add(connection.rPush("mylist", "hi")); actual.add(connection.lPushX("mylist", "foo")); actual.add(connection.lRange("mylist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, Arrays.asList(new String[] { "foo", "hi" }) })); + verifyResults(Arrays.asList(1L, 2L, Arrays.asList("foo", "hi"))); } @Test - public void testRPushMultiple() { + void testRPushMultiple() { actual.add(connection.rPush("mylist", "hi", "foo")); actual.add(connection.lRange("mylist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 2l, Arrays.asList(new String[] { "hi", "foo" }) })); + verifyResults(Arrays.asList(2L, Arrays.asList("hi", "foo"))); } @Test - public void testRPushX() { + void testRPushX() { actual.add(connection.rPush("mylist", "hi")); actual.add(connection.rPushX("mylist", "foo")); actual.add(connection.lRange("mylist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, Arrays.asList(new String[] { "hi", "foo" }) })); + verifyResults(Arrays.asList(1L, 2L, Arrays.asList("hi", "foo"))); } @Test - public void testLIndex() { + void testLIndex() { actual.add(connection.lPush("testylist", "foo")); actual.add(connection.lIndex("testylist", 0)); - verifyResults(Arrays.asList(new Object[] { 1l, "foo" })); + verifyResults(Arrays.asList(new Object[] { 1L, "foo" })); } @Test - public void testLPush() throws Exception { + void testLPush() { actual.add(connection.lPush("testlist", "bar")); actual.add(connection.lPush("testlist", "baz")); actual.add(connection.lRange("testlist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 1l, 2l, Arrays.asList(new String[] { "baz", "bar" }) })); + verifyResults(Arrays.asList(1L, 2L, Arrays.asList("baz", "bar"))); } @Test - public void testLPushMultiple() { + void testLPushMultiple() { actual.add(connection.lPush("testlist", "bar", "baz")); actual.add(connection.lRange("testlist", 0, -1)); - verifyResults(Arrays.asList(new Object[] { 2l, Arrays.asList(new String[] { "baz", "bar" }) })); + verifyResults(Arrays.asList(2L, Arrays.asList("baz", "bar"))); } @Test // DATAREDIS-1196 @EnabledOnCommand("LPOS") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void lPos() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void lPos() { actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c")); actual.add(connection.lPos("mylist", "c", null, null)); @@ -1463,8 +1417,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1196 @EnabledOnCommand("LPOS") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void lPosRank() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void lPosRank() { actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c")); actual.add(connection.lPos("mylist", "c", 2, null)); @@ -1474,8 +1428,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1196 @EnabledOnCommand("LPOS") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void lPosNegativeRank() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void lPosNegativeRank() { actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c")); actual.add(connection.lPos("mylist", "c", -1, null)); @@ -1485,8 +1439,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1196 @EnabledOnCommand("LPOS") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void lPosCount() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void lPosCount() { actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c")); actual.add(connection.lPos("mylist", "c", null, 2)); @@ -1496,8 +1450,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1196 @EnabledOnCommand("LPOS") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void lPosRankCount() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void lPosRankCount() { actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c")); actual.add(connection.lPos("mylist", "c", -1, 2)); @@ -1507,8 +1461,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1196 @EnabledOnCommand("LPOS") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void lPosCountZero() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void lPosCountZero() { actual.add(connection.rPush("mylist", "a", "b", "c", "1", "2", "3", "c", "c")); actual.add(connection.lPos("mylist", "c", null, 0)); @@ -1519,97 +1473,97 @@ public abstract class AbstractConnectionIntegrationTests { // Set operations @Test - public void testSAdd() { + void testSAdd() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sMembers("myset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, new HashSet<>(Arrays.asList(new String[] { "foo", "bar" })) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, new HashSet<>(Arrays.asList("foo", "bar")) })); } @Test - public void testSAddMultiple() { + void testSAddMultiple() { actual.add(connection.sAdd("myset", "foo", "bar")); actual.add(connection.sAdd("myset", "baz")); actual.add(connection.sMembers("myset")); verifyResults( - Arrays.asList(new Object[] { 2l, 1l, new HashSet<>(Arrays.asList(new String[] { "foo", "bar", "baz" })) })); + Arrays.asList(new Object[] { 2L, 1L, new HashSet<>(Arrays.asList("foo", "bar", "baz")) })); } @Test - public void testSCard() { + void testSCard() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sCard("myset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 2l })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 2L })); } @Test - public void testSDiff() { + void testSDiff() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sDiff("myset", "otherset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<>(Collections.singletonList("foo")) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, new HashSet<>(Collections.singletonList("foo")) })); } @Test - public void testSDiffStore() { + void testSDiffStore() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sDiffStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<>(Collections.singletonList("foo")) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, 1L, new HashSet<>(Collections.singletonList("foo")) })); } @Test - public void testSInter() { + void testSInter() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sInter("myset", "otherset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, new HashSet<>(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, new HashSet<>(Collections.singletonList("bar")) })); } @Test - public void testSInterStore() { + void testSInterStore() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sInterStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<>(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, 1L, new HashSet<>(Collections.singletonList("bar")) })); } @Test - public void testSIsMember() { + void testSIsMember() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sIsMember("myset", "foo")); actual.add(connection.sIsMember("myset", "baz")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, true, false })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, true, false })); } @Test - public void testSMove() { + void testSMove() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sMove("myset", "otherset", "foo")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, true })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, true })); } @Test - public void testSPop() { + void testSPop() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sPop("myset")); - assertThat(new HashSet<>(Arrays.asList(new String[] { "foo", "bar" })).contains((String) getResults().get(2))) + assertThat(new HashSet<>(Arrays.asList("foo", "bar")).contains((String) getResults().get(2))) .isTrue(); } @Test // DATAREDIS-688 - public void testSPopWithCount() { + void testSPopWithCount() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); @@ -1620,22 +1574,22 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testSRandMember() { + void testSRandMember() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sRandMember("myset")); - assertThat(new HashSet<>(Arrays.asList(new String[] { "foo", "bar" })).contains(getResults().get(2))).isTrue(); + assertThat(new HashSet<>(Arrays.asList("foo", "bar")).contains(getResults().get(2))).isTrue(); } @Test - public void testSRandMemberKeyNotExists() { + void testSRandMemberKeyNotExists() { actual.add(connection.sRandMember("notexist")); assertThat(getResults().get(0)).isNull(); } @SuppressWarnings("rawtypes") @Test - public void testSRandMemberCount() { + void testSRandMemberCount() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("myset", "baz")); @@ -1645,52 +1599,52 @@ public abstract class AbstractConnectionIntegrationTests { @SuppressWarnings("rawtypes") @Test - public void testSRandMemberCountNegative() { + void testSRandMemberCountNegative() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sRandMember("myset", -2)); - assertThat(getResults().get(1)).isEqualTo(Arrays.asList(new String[] { "foo", "foo" })); + assertThat(getResults().get(1)).isEqualTo(Arrays.asList("foo", "foo")); } @SuppressWarnings("rawtypes") @Test - public void testSRandMemberCountKeyNotExists() { + void testSRandMemberCountKeyNotExists() { actual.add(connection.sRandMember("notexist", 2)); assertThat(((Collection) getResults().get(0)).isEmpty()).isTrue(); } @Test - public void testSRem() { + void testSRem() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sRem("myset", "foo")); actual.add(connection.sRem("myset", "baz")); actual.add(connection.sMembers("myset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 0l, new HashSet<>(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, 0L, new HashSet<>(Collections.singletonList("bar")) })); } @Test - public void testSRemMultiple() { + void testSRemMultiple() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("myset", "baz")); actual.add(connection.sRem("myset", "foo", "nope", "baz")); actual.add(connection.sMembers("myset")); - verifyResults(Arrays.asList(new Object[] { 1l, 1l, 1l, 2l, new HashSet<>(Collections.singletonList("bar")) })); + verifyResults(Arrays.asList(new Object[] { 1L, 1L, 1L, 2L, new HashSet<>(Collections.singletonList("bar")) })); } @Test - public void testSUnion() { + void testSUnion() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); actual.add(connection.sAdd("otherset", "baz")); actual.add(connection.sUnion("myset", "otherset")); verifyResults(Arrays - .asList(new Object[] { 1l, 1l, 1l, 1l, new HashSet<>(Arrays.asList(new String[] { "foo", "bar", "baz" })) })); + .asList(new Object[] { 1L, 1L, 1L, 1L, new HashSet<>(Arrays.asList("foo", "bar", "baz")) })); } @Test - public void testSUnionStore() { + void testSUnionStore() { actual.add(connection.sAdd("myset", "foo")); actual.add(connection.sAdd("myset", "bar")); actual.add(connection.sAdd("otherset", "bar")); @@ -1698,22 +1652,22 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.sUnionStore("thirdset", "myset", "otherset")); actual.add(connection.sMembers("thirdset")); verifyResults(Arrays.asList( - new Object[] { 1l, 1l, 1l, 1l, 3l, new HashSet<>(Arrays.asList(new String[] { "foo", "bar", "baz" })) })); + new Object[] { 1L, 1L, 1L, 1L, 3L, new HashSet<>(Arrays.asList("foo", "bar", "baz")) })); } // ZSet @Test - public void testZAddAndZRange() { + void testZAddAndZRange() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRange("myset", 0, -1)); verifyResults(Arrays - .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "James", "Bob" })) })); + .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("James", "Bob")) })); } @Test - public void testZAddMultiple() { + void testZAddMultiple() { Set strTuples = new HashSet<>(); strTuples.add(new DefaultStringTuple("Bob".getBytes(), "Bob", 2.0)); strTuples.add(new DefaultStringTuple("James".getBytes(), "James", 1.0)); @@ -1723,28 +1677,28 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("myset".getBytes(), tuples)); actual.add(connection.zRange("myset", 0, -1)); verifyResults(Arrays - .asList(new Object[] { 2l, 1l, new LinkedHashSet<>(Arrays.asList(new String[] { "James", "Bob", "Joe" })) })); + .asList(new Object[] { 2L, 1L, new LinkedHashSet<>(Arrays.asList("James", "Bob", "Joe")) })); } @Test - public void testZCard() { + void testZCard() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zCard("myset")); - verifyResults(Arrays.asList(new Object[] { true, true, 2l })); + verifyResults(Arrays.asList(new Object[] { true, true, 2L })); } @Test - public void testZCount() { + void testZCount() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 4, "Joe")); actual.add(connection.zCount("myset", 1, 2)); - verifyResults(Arrays.asList(new Object[] { true, true, true, 2l })); + verifyResults(Arrays.asList(new Object[] { true, true, true, 2L })); } @Test // DATAREDIS-729 - public void zLexCountTest() { + void zLexCountTest() { actual.add(connection.zAdd("myzset", 0, "a")); actual.add(connection.zAdd("myzset", 0, "b")); @@ -1770,7 +1724,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testZIncrBy() { + void testZIncrBy() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 4, "Joe")); @@ -1781,7 +1735,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testZInterStore() { + void testZInterStore() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 4, "Joe")); @@ -1789,12 +1743,12 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("otherset", 4, "James")); actual.add(connection.zInterStore("thirdset", "myset", "otherset")); actual.add(connection.zRange("thirdset", 0, -1)); - verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 2l, - new LinkedHashSet<>(Arrays.asList(new String[] { "Bob", "James" })) })); + verifyResults(Arrays + .asList(new Object[] { true, true, true, true, true, 2L, new LinkedHashSet<>(Arrays.asList("Bob", "James")) })); } @Test - public void testZInterStoreAggWeights() { + void testZInterStoreAggWeights() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 4, "Joe")); @@ -1803,175 +1757,175 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zInterStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset")); actual.add(connection.zRangeWithScores("thirdset", 0, -1)); - verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 2l, - new LinkedHashSet<>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), - new DefaultStringTuple("James".getBytes(), "James", 12d) })) })); + verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 2L, + new LinkedHashSet<>(Arrays.asList(new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), + new DefaultStringTuple("James".getBytes(), "James", 12d))) })); } @Test - public void testZRangeWithScores() { + void testZRangeWithScores() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeWithScores("myset", 0, -1)); verifyResults(Arrays.asList(new Object[] { true, true, - new LinkedHashSet<>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d), - new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) })); + new LinkedHashSet<>(Arrays.asList(new DefaultStringTuple("James".getBytes(), "James", 1d), + new DefaultStringTuple("Bob".getBytes(), "Bob", 2d))) })); } @Test - public void testZRangeByScore() { + void testZRangeByScore() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeByScore("myset", 1, 1)); verifyResults( - Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "James" })) })); + Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("James")) })); } @Test - public void testZRangeByScoreOffsetCount() { + void testZRangeByScoreOffsetCount() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeByScore("myset", 1d, 3d, 1, -1)); verifyResults( - Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob" })) })); + Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("Bob")) })); } @Test - public void testZRangeByScoreWithScores() { + void testZRangeByScoreWithScores() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeByScoreWithScores("myset", 2d, 5d)); verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<>( - Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) })); + Arrays.asList(new DefaultStringTuple("Bob".getBytes(), "Bob", 2d))) })); } @Test - public void testZRangeByScoreWithScoresOffsetCount() { + void testZRangeByScoreWithScoresOffsetCount() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRangeByScoreWithScores("myset", 1d, 5d, 0, 1)); verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<>( - Arrays.asList(new StringTuple[] { new DefaultStringTuple("James".getBytes(), "James", 1d) })) })); + Arrays.asList(new DefaultStringTuple("James".getBytes(), "James", 1d))) })); } @Test - public void testZRevRange() { + void testZRevRange() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRevRange("myset", 0, -1)); verifyResults(Arrays - .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob", "James" })) })); + .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("Bob", "James")) })); } @Test - public void testZRevRangeWithScores() { + void testZRevRangeWithScores() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRevRangeWithScores("myset", 0, -1)); verifyResults(Arrays.asList(new Object[] { true, true, - new LinkedHashSet<>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), - new DefaultStringTuple("James".getBytes(), "James", 1d) })) })); + new LinkedHashSet<>(Arrays.asList(new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), + new DefaultStringTuple("James".getBytes(), "James", 1d))) })); } @Test - public void testZRevRangeByScoreOffsetCount() { + void testZRevRangeByScoreOffsetCount() { actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes())); actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes())); actual.add(connection.zRevRangeByScore("myset", 0d, 3d, 0, 5)); verifyResults(Arrays - .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob", "James" })) })); + .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("Bob", "James")) })); } @Test - public void testZRevRangeByScore() { + void testZRevRangeByScore() { actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes())); actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes())); actual.add(connection.zRevRangeByScore("myset", 0d, 3d)); verifyResults(Arrays - .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob", "James" })) })); + .asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("Bob", "James")) })); } @Test - public void testZRevRangeByScoreWithScoresOffsetCount() { + void testZRevRangeByScoreWithScoresOffsetCount() { actual.add(connection.zAdd("myset".getBytes(), 2, "Bob".getBytes())); actual.add(connection.zAdd("myset".getBytes(), 1, "James".getBytes())); actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 3d, 0, 1)); verifyResults(Arrays.asList(new Object[] { true, true, new LinkedHashSet<>( - Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d) })) })); + Arrays.asList(new DefaultStringTuple("Bob".getBytes(), "Bob", 2d))) })); } @Test - public void testZRevRangeByScoreWithScores() { + void testZRevRangeByScoreWithScores() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 3, "Joe")); actual.add(connection.zRevRangeByScoreWithScores("myset", 0d, 2d)); verifyResults(Arrays.asList(new Object[] { true, true, true, - new LinkedHashSet<>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), - new DefaultStringTuple("James".getBytes(), "James", 1d) })) })); + new LinkedHashSet<>(Arrays.asList(new DefaultStringTuple("Bob".getBytes(), "Bob", 2d), + new DefaultStringTuple("James".getBytes(), "James", 1d))) })); } @Test - public void testZRank() { + void testZRank() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRank("myset", "James")); actual.add(connection.zRank("myset", "Bob")); - verifyResults(Arrays.asList(new Object[] { true, true, 0l, 1l })); + verifyResults(Arrays.asList(new Object[] { true, true, 0L, 1L })); } @Test - public void testZRem() { + void testZRem() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRem("myset", "James")); - actual.add(connection.zRange("myset", 0l, -1l)); + actual.add(connection.zRange("myset", 0L, -1L)); verifyResults( - Arrays.asList(new Object[] { true, true, 1l, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob" })) })); + Arrays.asList(new Object[] { true, true, 1L, new LinkedHashSet<>(Arrays.asList("Bob")) })); } @Test - public void testZRemMultiple() { + void testZRemMultiple() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 0.5, "Joe")); actual.add(connection.zAdd("myset", 2.5, "Jen")); actual.add(connection.zRem("myset", "James", "Jen")); - actual.add(connection.zRange("myset", 0l, -1l)); - verifyResults(Arrays.asList(new Object[] { true, true, true, true, 2l, - new LinkedHashSet<>(Arrays.asList(new String[] { "Joe", "Bob" })) })); + actual.add(connection.zRange("myset", 0L, -1L)); + verifyResults( + Arrays.asList(new Object[] { true, true, true, true, 2L, new LinkedHashSet<>(Arrays.asList("Joe", "Bob")) })); } @Test - public void testZRemRangeByRank() { + void testZRemRangeByRank() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); - actual.add(connection.zRemRange("myset", 0l, 3l)); - actual.add(connection.zRange("myset", 0l, -1l)); - verifyResults(Arrays.asList(new Object[] { true, true, 2l, new LinkedHashSet(0) })); + actual.add(connection.zRemRange("myset", 0L, 3L)); + actual.add(connection.zRange("myset", 0L, -1L)); + verifyResults(Arrays.asList(new Object[] { true, true, 2L, new LinkedHashSet(0) })); } @Test - public void testZRemRangeByScore() { + void testZRemRangeByScore() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zRemRangeByScore("myset", 0d, 1d)); - actual.add(connection.zRange("myset", 0l, -1l)); + actual.add(connection.zRange("myset", 0L, -1L)); verifyResults( - Arrays.asList(new Object[] { true, true, 1l, new LinkedHashSet<>(Arrays.asList(new String[] { "Bob" })) })); + Arrays.asList(new Object[] { true, true, 1L, new LinkedHashSet<>(Arrays.asList("Bob")) })); } @Test - public void testZRevRank() { + void testZRevRank() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 3, "Joe")); actual.add(connection.zRevRank("myset", "Joe")); - verifyResults(Arrays.asList(new Object[] { true, true, true, 0l })); + verifyResults(Arrays.asList(new Object[] { true, true, true, 0L })); } @Test - public void testZScore() { + void testZScore() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 3, "Joe")); @@ -1980,7 +1934,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testZUnionStore() { + void testZUnionStore() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 5, "Joe")); @@ -1988,12 +1942,12 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("otherset", 4, "James")); actual.add(connection.zUnionStore("thirdset", "myset", "otherset")); actual.add(connection.zRange("thirdset", 0, -1)); - verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3l, - new LinkedHashSet<>(Arrays.asList(new String[] { "Bob", "James", "Joe" })) })); + verifyResults(Arrays.asList( + new Object[] { true, true, true, true, true, 3L, new LinkedHashSet<>(Arrays.asList("Bob", "James", "Joe")) })); } @Test - public void testZUnionStoreAggWeights() { + void testZUnionStoreAggWeights() { actual.add(connection.zAdd("myset", 2, "Bob")); actual.add(connection.zAdd("myset", 1, "James")); actual.add(connection.zAdd("myset", 4, "Joe")); @@ -2001,16 +1955,16 @@ public abstract class AbstractConnectionIntegrationTests { actual.add(connection.zAdd("otherset", 4, "James")); actual.add(connection.zUnionStore("thirdset", Aggregate.MAX, new int[] { 2, 3 }, "myset", "otherset")); actual.add(connection.zRangeWithScores("thirdset", 0, -1)); - verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3l, - new LinkedHashSet<>(Arrays.asList(new StringTuple[] { new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), + verifyResults(Arrays.asList(new Object[] { true, true, true, true, true, 3L, new LinkedHashSet<>(Arrays.asList( + new DefaultStringTuple("Bob".getBytes(), "Bob", 4d), new DefaultStringTuple("Joe".getBytes(), "Joe", 8d), - new DefaultStringTuple("James".getBytes(), "James", 12d) })) })); + new DefaultStringTuple("James".getBytes(), "James", 12d))) })); } // Hash Ops @Test - public void testHSetGet() throws Exception { + void testHSetGet() { String hash = getClass() + ":hashtest"; String key1 = UUID.randomUUID().toString(); String key2 = UUID.randomUUID().toString(); @@ -2023,11 +1977,11 @@ public abstract class AbstractConnectionIntegrationTests { Map expected = new HashMap<>(); expected.put(key1, value1); expected.put(key2, value2); - verifyResults(Arrays.asList(new Object[] { true, true, value1, expected })); + verifyResults(Arrays.asList(true, true, value1, expected)); } @Test - public void testHSetNX() throws Exception { + void testHSetNX() { actual.add(connection.hSetNX("myhash", "key1", "foo")); actual.add(connection.hSetNX("myhash", "key1", "bar")); actual.add(connection.hGet("myhash", "key1")); @@ -2035,34 +1989,34 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testHDel() throws Exception { + void testHDel() { actual.add(connection.hSet("test", "key", "val")); actual.add(connection.hDel("test", "key")); actual.add(connection.hDel("test", "foo")); actual.add(connection.hExists("test", "key")); - verifyResults(Arrays.asList(new Object[] { true, 1l, 0l, false })); + verifyResults(Arrays.asList(new Object[] { true, 1L, 0L, false })); } @Test - public void testHDelMultiple() { + void testHDelMultiple() { actual.add(connection.hSet("test", "key", "val")); actual.add(connection.hSet("test", "foo", "bar")); actual.add(connection.hDel("test", "key", "foo")); actual.add(connection.hExists("test", "key")); actual.add(connection.hExists("test", "foo")); - verifyResults(Arrays.asList(new Object[] { true, true, 2l, false, false })); + verifyResults(Arrays.asList(new Object[] { true, true, 2L, false, false })); } @Test - public void testHIncrBy() { + void testHIncrBy() { actual.add(connection.hSet("test", "key", "2")); - actual.add(connection.hIncrBy("test", "key", 3l)); + actual.add(connection.hIncrBy("test", "key", 3L)); actual.add(connection.hGet("test", "key")); - verifyResults(Arrays.asList(new Object[] { true, 5l, "5" })); + verifyResults(Arrays.asList(new Object[] { true, 5L, "5" })); } @Test - public void testHIncrByDouble() { + void testHIncrByDouble() { actual.add(connection.hSet("test", "key", "2.9")); actual.add(connection.hIncrBy("test", "key", 3.5)); actual.add(connection.hGet("test", "key")); @@ -2070,38 +2024,38 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testHKeys() { + void testHKeys() { actual.add(connection.hSet("test", "key", "2")); actual.add(connection.hSet("test", "key2", "2")); actual.add(connection.hKeys("test")); verifyResults( - Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList(new String[] { "key", "key2" })) })); + Arrays.asList(new Object[] { true, true, new LinkedHashSet<>(Arrays.asList("key", "key2")) })); } @Test - public void testHLen() { + void testHLen() { actual.add(connection.hSet("test", "key", "2")); actual.add(connection.hSet("test", "key2", "2")); actual.add(connection.hLen("test")); - verifyResults(Arrays.asList(new Object[] { true, true, 2l })); + verifyResults(Arrays.asList(new Object[] { true, true, 2L })); } @Test - public void testHMGetSet() { + void testHMGetSet() { Map tuples = new HashMap<>(); tuples.put("key", "foo"); tuples.put("key2", "bar"); connection.hMSet("test", tuples); actual.add(connection.hMGet("test", "key", "key2")); - verifyResults(Arrays.asList(new Object[] { Arrays.asList(new String[] { "foo", "bar" }) })); + verifyResults(Arrays.asList(new Object[] { Arrays.asList("foo", "bar") })); } @Test - public void testHVals() { + void testHVals() { actual.add(connection.hSet("test", "key", "foo")); actual.add(connection.hSet("test", "key2", "bar")); actual.add(connection.hVals("test")); - verifyResults(Arrays.asList(new Object[] { true, true, Arrays.asList(new String[] { "foo", "bar" }) })); + verifyResults(Arrays.asList(true, true, Arrays.asList("foo", "bar"))); } @Test @@ -2122,14 +2076,14 @@ public abstract class AbstractConnectionIntegrationTests { } @Test - public void testLastSave() { + void testLastSave() { actual.add(connection.lastSave()); List results = getResults(); assertThat(results.get(0)).isNotNull(); } @Test // DATAREDIS-206, DATAREDIS-513 - public void testGetTimeShouldRequestServerTime() { + void testGetTimeShouldRequestServerTime() { actual.add(connection.time()); @@ -2161,7 +2115,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-290 - public void scanShouldReadEntireValueRange() { + void scanShouldReadEntireValueRange() { if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) { throw new AssumptionViolatedException("SCAN is only available for jedis and lettuce"); @@ -2207,7 +2161,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-306 - public void zScanShouldReadEntireValueRange() { + void zScanShouldReadEntireValueRange() { if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) { throw new AssumptionViolatedException("ZSCAN is only available for jedis and lettuce"); @@ -2238,7 +2192,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-304 - public void sScanShouldReadEntireValueRange() { + void sScanShouldReadEntireValueRange() { if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) { throw new AssumptionViolatedException("SCAN is only available for jedis and lettuce"); @@ -2263,7 +2217,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-305 - public void hScanShouldReadEntireValueRange() { + void hScanShouldReadEntireValueRange() { if (!ConnectionUtils.isJedis(connectionFactory) && !ConnectionUtils.isLettuce(connectionFactory)) { throw new AssumptionViolatedException("HSCAN is only available for jedis and lettuce"); @@ -2297,7 +2251,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-308 - public void pfAddShouldAddToNonExistingKeyCorrectly() { + void pfAddShouldAddToNonExistingKeyCorrectly() { actual.add(connection.pfAdd("hll", "a", "b", "c")); @@ -2306,7 +2260,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-308 - public void pfAddShouldReturnZeroWhenValueAlreadyExists() { + void pfAddShouldReturnZeroWhenValueAlreadyExists() { actual.add(connection.pfAdd("hll", "a", "b", "c")); actual.add(connection.pfAdd("hll2", "c", "d", "e")); @@ -2319,7 +2273,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-308 - public void pfCountShouldReturnCorrectly() { + void pfCountShouldReturnCorrectly() { actual.add(connection.pfAdd("hll", "a", "b", "c")); actual.add(connection.pfCount("hll")); @@ -2330,7 +2284,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-308 - public void pfCountWithMultipleKeysShouldReturnCorrectly() { + void pfCountWithMultipleKeysShouldReturnCorrectly() { actual.add(connection.pfAdd("hll", "a", "b", "c")); actual.add(connection.pfAdd("hll2", "d", "e", "f")); @@ -2343,13 +2297,13 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-308 - public void pfCountWithNullKeysShouldThrowIllegalArgumentException() { + void pfCountWithNullKeysShouldThrowIllegalArgumentException() { assertThatIllegalArgumentException().isThrownBy(() -> actual.add(connection.pfCount((String[]) null))); } @SuppressWarnings("unchecked") @Test // DATAREDIS-378, DATAREDIS-1222 - public void zRangeByLexTest() { + void zRangeByLexTest() { actual.add(connection.zAdd("myzset", 0, "a")); actual.add(connection.zAdd("myzset", 0, "b")); @@ -2381,7 +2335,7 @@ public abstract class AbstractConnectionIntegrationTests { @SuppressWarnings("unchecked") @Test // DATAREDIS-729 - public void zRevRangeByLexTest() { + void zRevRangeByLexTest() { actual.add(connection.zAdd("myzset", 0, "a")); actual.add(connection.zAdd("myzset", 0, "b")); @@ -2411,15 +2365,16 @@ public abstract class AbstractConnectionIntegrationTests { assertThat((Set) results.get(13)).contains("c", "b").doesNotContain("a", "d", "e", "f", "g"); } - @Test(expected = IllegalArgumentException.class) // DATAREDIS-316, DATAREDIS-692 - public void setWithExpirationAndNullOpionShouldThrowException() { + @Test // DATAREDIS-316, DATAREDIS-692 + void setWithExpirationAndNullOpionShouldThrowException() { String key = "exp-" + UUID.randomUUID(); - connection.set(key, "foo", Expiration.milliseconds(500), null); + assertThatIllegalArgumentException() + .isThrownBy(() -> connection.set(key, "foo", Expiration.milliseconds(500), null)); } @Test // DATAREDIS-316 - public void setWithExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesNotExist() { + void setWithExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesNotExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "foo", Expiration.milliseconds(500), SetOption.upsert())); @@ -2434,7 +2389,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesExist() { + void setWithExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "spring")); @@ -2453,7 +2408,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesExist() { + void setWithExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "spring")); @@ -2472,7 +2427,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesNotExist() { + void setWithExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesNotExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "data", Expiration.milliseconds(500), SetOption.ifAbsent())); @@ -2489,7 +2444,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithExpirationAndPresentOptionShouldSetTtlWhenKeyDoesExist() { + void setWithExpirationAndPresentOptionShouldSetTtlWhenKeyDoesExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "spring")); @@ -2508,7 +2463,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithExpirationAndPresentOptionShouldSetTtlWhenKeyDoesNotExist() { + void setWithExpirationAndPresentOptionShouldSetTtlWhenKeyDoesNotExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "data", Expiration.milliseconds(500), SetOption.ifPresent())); @@ -2523,15 +2478,15 @@ public abstract class AbstractConnectionIntegrationTests { assertThat(((Long) result.get(2)).doubleValue()).isCloseTo(-2, Offset.offset(0d)); } - @Test(expected = IllegalArgumentException.class) // DATAREDIS-316, DATAREDIS-692 - public void setWithNullExpirationAndUpsertOpionShouldThrowException() { + @Test // DATAREDIS-316, DATAREDIS-692 + void setWithNullExpirationAndUpsertOpionShouldThrowException() { String key = "exp-" + UUID.randomUUID(); - connection.set(key, "foo", null, SetOption.upsert()); + assertThatIllegalArgumentException().isThrownBy(() -> connection.set(key, "foo", null, SetOption.upsert())); } @Test // DATAREDIS-316 - public void setWithoutExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesNotExist() { + void setWithoutExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesNotExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "foo", Expiration.persistent(), SetOption.upsert())); @@ -2546,7 +2501,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithoutExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesExist() { + void setWithoutExpirationAndUpsertOpionShouldSetTtlWhenKeyDoesExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "spring")); @@ -2566,7 +2521,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithoutExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesExist() { + void setWithoutExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "spring")); @@ -2585,7 +2540,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithoutExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesNotExist() { + void setWithoutExpirationAndAbsentOptionShouldSetTtlWhenKeyDoesNotExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "data", Expiration.persistent(), SetOption.ifAbsent())); @@ -2602,7 +2557,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithoutExpirationAndPresentOptionShouldSetTtlWhenKeyDoesExist() { + void setWithoutExpirationAndPresentOptionShouldSetTtlWhenKeyDoesExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "spring")); @@ -2621,7 +2576,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-316 - public void setWithoutExpirationAndPresentOptionShouldSetTtlWhenKeyDoesNotExist() { + void setWithoutExpirationAndPresentOptionShouldSetTtlWhenKeyDoesNotExist() { String key = "exp-" + UUID.randomUUID(); actual.add(connection.set(key, "data", Expiration.persistent(), SetOption.ifPresent())); @@ -2637,7 +2592,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoAddSingleGeoLocation() { + void geoAddSingleGeoLocation() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, PALERMO)); @@ -2647,7 +2602,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoAddMultipleGeoLocations() { + void geoAddMultipleGeoLocations() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, ARIGENTO, CATANIA, PALERMO))); @@ -2657,7 +2612,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoDist() { + void geoDist() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2669,7 +2624,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-1214 - public void geoDistNotExisting() { + void geoDistNotExisting() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2680,7 +2635,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoDistWithMetric() { + void geoDistWithMetric() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2692,8 +2647,8 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - @WithRedisDriver({ RedisDriver.JEDIS }) - public void geoHash() { + @EnabledOnRedisDriver({ RedisDriver.JEDIS }) + void geoHash() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2705,8 +2660,8 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - @WithRedisDriver({ RedisDriver.JEDIS }) - public void geoHashNonExisting() { + @EnabledOnRedisDriver({ RedisDriver.JEDIS }) + void geoHashNonExisting() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2719,7 +2674,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoPosition() { + void geoPosition() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2735,7 +2690,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoPositionNonExisting() { + void geoPositionNonExisting() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(PALERMO, CATANIA))); @@ -2753,7 +2708,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoRadiusShouldReturnMembersCorrectly() { + void geoRadiusShouldReturnMembersCorrectly() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); @@ -2767,7 +2722,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoRadiusShouldReturnDistanceCorrectly() { + void geoRadiusShouldReturnDistanceCorrectly() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); @@ -2784,7 +2739,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoRadiusShouldApplyLimit() { + void geoRadiusShouldApplyLimit() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); @@ -2797,7 +2752,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoRadiusByMemberShouldReturnMembersCorrectly() { + void geoRadiusByMemberShouldReturnMembersCorrectly() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); @@ -2813,7 +2768,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoRadiusByMemberShouldReturnDistanceCorrectly() { + void geoRadiusByMemberShouldReturnDistanceCorrectly() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); @@ -2830,7 +2785,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-438 - public void geoRadiusByMemberShouldApplyLimit() { + void geoRadiusByMemberShouldApplyLimit() { String key = "geo-" + UUID.randomUUID(); actual.add(connection.geoAdd(key, Arrays.asList(ARIGENTO, CATANIA, PALERMO))); @@ -2843,7 +2798,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-698 - public void hStrLenReturnsFieldLength() { + void hStrLenReturnsFieldLength() { actual.add(connection.hSet("hash-hstrlen", "key-1", "value-1")); actual.add(connection.hSet("hash-hstrlen", "key-2", "value-2")); @@ -2853,7 +2808,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-698 - public void hStrLenReturnsZeroWhenFieldDoesNotExist() { + void hStrLenReturnsZeroWhenFieldDoesNotExist() { actual.add(connection.hSet("hash-hstrlen", "key-1", "value-1")); actual.add(connection.hStrLen("hash-hstrlen", "key-2")); @@ -2862,7 +2817,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-698 - public void hStrLenReturnsZeroWhenKeyDoesNotExist() { + void hStrLenReturnsZeroWhenKeyDoesNotExist() { actual.add(connection.hStrLen("hash-no-exist", "key-2")); @@ -2870,7 +2825,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-694 - public void touchReturnsNrOfKeysTouched() { + void touchReturnsNrOfKeysTouched() { actual.add(connection.set("touch.this", "Can't touch this! - oh-oh oh oh oh-oh-oh")); actual.add(connection.touch("touch.this", "touch.that")); @@ -2879,7 +2834,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-694 - public void touchReturnsZeroIfNoKeysTouched() { + void touchReturnsZeroIfNoKeysTouched() { actual.add(connection.touch("touch.this", "touch.that")); @@ -2887,7 +2842,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-697 - public void bitPosShouldReturnPositionCorrectly() { + void bitPosShouldReturnPositionCorrectly() { actual.add(connection.set("bitpos-1".getBytes(), HexStringUtils.hexToBytes("fff000"))); actual.add(connection.bitPos("bitpos-1", false)); @@ -2896,7 +2851,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-697 - public void bitPosShouldReturnPositionInRangeCorrectly() { + void bitPosShouldReturnPositionInRangeCorrectly() { actual.add(connection.set("bitpos-1".getBytes(), HexStringUtils.hexToBytes("fff0f0"))); actual.add(connection.bitPos("bitpos-1", true, @@ -2906,7 +2861,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-716 - public void encodingReturnsCorrectly() { + void encodingReturnsCorrectly() { actual.add(connection.set("encode.this", "1000")); @@ -2916,7 +2871,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-716 - public void encodingReturnsVacantWhenKeyDoesNotExist() { + void encodingReturnsVacantWhenKeyDoesNotExist() { actual.add(connection.encodingOf("encode.this")); @@ -2924,7 +2879,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-716 - public void idletimeReturnsCorrectly() { + void idletimeReturnsCorrectly() { actual.add(connection.set("idle.this", "1000")); actual.add(connection.get("idle.this")); @@ -2935,7 +2890,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-716 - public void idldetimeReturnsNullWhenKeyDoesNotExist() { + void idldetimeReturnsNullWhenKeyDoesNotExist() { actual.add(connection.idletime("idle.this")); @@ -2943,7 +2898,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-716 - public void refcountReturnsCorrectly() { + void refcountReturnsCorrectly() { actual.add(connection.lPush("refcount.this", "1000")); @@ -2953,7 +2908,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-716 - public void refcountReturnsNullWhenKeyDoesNotExist() { + void refcountReturnsNullWhenKeyDoesNotExist() { actual.add(connection.refcount("refcount.this")); @@ -2961,7 +2916,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-562 - public void bitFieldSetShouldWorkCorrectly() { + void bitFieldSetShouldWorkCorrectly() { actual.add(connection.bitfield(KEY_1, create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)).to(10L))); actual.add(connection.bitfield(KEY_1, create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)).to(20L))); @@ -2972,7 +2927,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-562 - public void bitFieldGetShouldWorkCorrectly() { + void bitFieldGetShouldWorkCorrectly() { actual.add(connection.bitfield(KEY_1, create().get(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L)))); @@ -2981,7 +2936,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-562 - public void bitFieldIncrByShouldWorkCorrectly() { + void bitFieldIncrByShouldWorkCorrectly() { actual .add(connection.bitfield(KEY_1, create().incr(INT_8).valueAt(BitFieldSubCommands.Offset.offset(100L)).by(1L))); @@ -2991,7 +2946,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-562 - public void bitFieldIncrByWithOverflowShouldWorkCorrectly() { + void bitFieldIncrByWithOverflowShouldWorkCorrectly() { actual.add(connection.bitfield(KEY_1, create().incr(unsigned(2)).valueAt(BitFieldSubCommands.Offset.offset(102L)).overflow(FAIL).by(1L))); @@ -3010,7 +2965,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-562 - public void bitfieldShouldAllowMultipleSubcommands() { + void bitfieldShouldAllowMultipleSubcommands() { actual.add(connection.bitfield(KEY_1, create().incr(signed(5)).valueAt(BitFieldSubCommands.Offset.offset(100L)).by(1L).get(unsigned(4)).valueAt(0L))); @@ -3019,7 +2974,7 @@ public abstract class AbstractConnectionIntegrationTests { } @Test // DATAREDIS-562 - public void bitfieldShouldWorkUsingNonZeroBasedOffset() { + void bitfieldShouldWorkUsingNonZeroBasedOffset() { actual.add(connection.bitfield(KEY_1, create().set(INT_8).valueAt(BitFieldSubCommands.Offset.offset(0L).multipliedByTypeLength()).to(100L).set(INT_8) @@ -3035,8 +2990,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-864 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xAddShouldCreateStream() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xAddShouldCreateStream() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.type(KEY_1)); @@ -3049,8 +3004,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-864 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xReadShouldReadMessage() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xReadShouldReadMessage() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xReadAsString(StreamOffset.create(KEY_1, ReadOffset.from("0")))); @@ -3065,8 +3020,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-864 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xReadGroupShouldReadMessage() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xReadGroupShouldReadMessage() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3087,8 +3042,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-864 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xGroupCreateShouldWorkWithAndWithoutExistingStream() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xGroupCreateShouldWorkWithAndWithoutExistingStream() { actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group", true)); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); @@ -3110,8 +3065,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-864 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xRangeShouldReportMessages() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xRangeShouldReportMessages() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3131,8 +3086,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-864 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xRevRangeShouldReportMessages() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xRevRangeShouldReportMessages() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3153,8 +3108,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1207 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xRevRangeShouldWorkWithBoundedRange() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xRevRangeShouldWorkWithBoundedRange() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3175,8 +3130,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldLoadOverviewCorrectly() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldLoadOverviewCorrectly() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3197,8 +3152,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldLoadEmptyOverviewCorrectly() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldLoadEmptyOverviewCorrectly() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3216,8 +3171,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldLoadPendingMessages() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldLoadPendingMessages() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3239,8 +3194,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1207 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldWorkWithBoundedRange() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldWorkWithBoundedRange() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3262,8 +3217,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldLoadPendingMessagesForConsumer() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldLoadPendingMessagesForConsumer() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3286,8 +3241,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldLoadPendingMessagesForNonExistingConsumer() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldLoadPendingMessagesForNonExistingConsumer() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3306,8 +3261,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xPendingShouldLoadEmptyPendingMessages() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xPendingShouldLoadEmptyPendingMessages() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group")); @@ -3323,7 +3278,7 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1084 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) public void xClaim() throws InterruptedException { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); @@ -3344,8 +3299,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfo() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfo() { actual.add(connection.xGroupCreate(KEY_1, ReadOffset.from("0"), "my-group-without-stream", true)); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); @@ -3373,8 +3328,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfoNoGroup() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfoNoGroup() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3398,8 +3353,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfoGroups() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfoGroups() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3423,8 +3378,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfoGroupsNoGroup() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfoGroupsNoGroup() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3440,8 +3395,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfoGroupsNoConsumer() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfoGroupsNoConsumer() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3463,8 +3418,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfoConsumers() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfoConsumers() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3487,8 +3442,8 @@ public abstract class AbstractConnectionIntegrationTests { @Test // DATAREDIS-1119 @EnabledOnCommand("XADD") - @WithRedisDriver({ RedisDriver.LETTUCE }) - public void xinfoConsumersNoConsumer() { + @EnabledOnRedisDriver({ RedisDriver.LETTUCE }) + void xinfoConsumersNoConsumer() { actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_2, VALUE_2))); actual.add(connection.xAdd(KEY_1, Collections.singletonMap(KEY_3, VALUE_3))); @@ -3517,7 +3472,7 @@ public abstract class AbstractConnectionIntegrationTests { protected class KeyExpired implements TestCondition { private String key; - public KeyExpired(String key) { + KeyExpired(String key) { this.key = key; } diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java index 6cd014e67..30dece6ef 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionPipelineIntegrationTests.java @@ -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 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 expected) { List 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 getResults() { try { diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java index 2cef28669..56b981861 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractConnectionTransactionIntegrationTests.java @@ -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 getResults() { return connection.exec(); } + @Override protected void verifyResults(List expected) { List expectedTx = new ArrayList<>(); for (int i = 0; i < actual.size(); i++) { diff --git a/src/test/java/org/springframework/data/redis/connection/AbstractTransactionalTestBase.java b/src/test/java/org/springframework/data/redis/connection/AbstractTransactionalTestBase.java index 892dc260e..8176fd635 100644 --- a/src/test/java/org/springframework/data/redis/connection/AbstractTransactionalTestBase.java +++ b/src/test/java/org/springframework/data/redis/connection/AbstractTransactionalTestBase.java @@ -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 KEYS = Arrays.asList("spring", "data", "redis"); private boolean valuesShouldHaveBeenPersisted = false; - @Before + @BeforeEach public void setUp() { valuesShouldHaveBeenPersisted = false; cleanDataStore(); diff --git a/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java index 14af9eb7e..0912056ff 100644 --- a/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/ClusterConnectionTests.java @@ -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(); diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java index 7ca20aa82..230923c2f 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTests.java @@ -22,8 +22,9 @@ import java.util.Collections; import java.util.List; import java.util.Properties; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.springframework.data.geo.Distance; import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; import org.springframework.data.redis.connection.stream.RecordId; @@ -39,7 +40,7 @@ import org.springframework.data.redis.connection.stream.StreamRecords; */ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedisConnectionTests { - @Before + @BeforeEach public void setUp() { super.setUp(); connection.setDeserializePipelineAndTxResults(true); @@ -48,37 +49,37 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testAppend() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testAppend(); } @Test public void testAppendBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testAppendBytes(); } @Test public void testBlPopBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testBlPopBytes(); } @Test public void testBlPop() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testBlPop(); } @Test public void testBrPopBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testBrPopBytes(); } @Test public void testBrPop() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testBrPop(); } @@ -96,43 +97,43 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testDbSize() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testDbSize(); } @Test public void testDecrBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testDecrBytes(); } @Test public void testDecr() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testDecr(); } @Test public void testDecrByBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testDecrByBytes(); } @Test public void testDecrBy() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testDecrBy(); } @Test public void testDelBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testDelBytes(); } @Test public void testDel() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testDel(); } @@ -149,50 +150,50 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi } @Test - public void testTxResultsNotPipelined() { + void testTxResultsNotPipelined() { doReturn(true).when(nativeConnection).isQueueing(); - List results = Arrays.asList(new Object[] { bar, 8l }); - doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline(); - doReturn(8l).when(nativeConnection).lLen(fooBytes); + List results = Arrays.asList(new Object[] { bar, 8L }); + doReturn(Collections.singletonList(results)).when(nativeConnection).closePipeline(); + doReturn(8L).when(nativeConnection).lLen(fooBytes); connection.lLen(fooBytes); connection.exec(); // closePipeline should only return the results of exec, not of llen - verifyResults(Arrays.asList(new Object[] { results })); + verifyResults(Collections.singletonList(results)); } @Test public void testExistsBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testExistsBytes(); } @Test public void testExists() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testExists(); } @Test public void testExpireBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testExpireBytes(); } @Test public void testExpire() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testExpire(); } @Test public void testExpireAtBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testExpireAtBytes(); } @Test public void testExpireAt() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testExpireAt(); } @@ -210,13 +211,13 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testGetBitBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testGetBitBytes(); } @Test public void testGetBit() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testGetBit(); } @@ -226,13 +227,13 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi Properties results = new Properties(); results.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(results)).when(nativeConnection).closePipeline(); super.testGetConfig(); } @Test public void testGetNativeConnection() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testGetNativeConnection(); } @@ -262,25 +263,25 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testHDelBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testHDelBytes(); } @Test public void testHDel() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testHDel(); } @Test public void testHExistsBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testHExistsBytes(); } @Test public void testHExists() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testHExists(); } @@ -298,145 +299,145 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testHGetAllBytes() { - doReturn(Arrays.asList(new Object[] { bytesMap })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesMap)).when(nativeConnection).closePipeline(); super.testHGetAllBytes(); } @Test public void testHGetAll() { - doReturn(Arrays.asList(new Object[] { bytesMap })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesMap)).when(nativeConnection).closePipeline(); super.testHGetAll(); } @Test public void testHIncrByBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testHIncrByBytes(); } @Test public void testHIncrBy() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testHIncrBy(); } @Test public void testHIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).closePipeline(); super.testHIncrByDoubleBytes(); } @Test public void testHIncrByDouble() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).closePipeline(); super.testHIncrByDouble(); } @Test public void testHKeysBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testHKeysBytes(); } @Test public void testHKeys() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testHKeys(); } @Test public void testHLenBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testHLenBytes(); } @Test public void testHLen() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testHLen(); } @Test public void testHMGetBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testHMGetBytes(); } @Test public void testHMGet() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testHMGet(); } @Test public void testHSetBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testHSetBytes(); } @Test public void testHSet() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testHSet(); } @Test public void testHSetNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testHSetNXBytes(); } @Test public void testHSetNX() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testHSetNX(); } @Test public void testHValsBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testHValsBytes(); } @Test public void testHVals() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testHVals(); } @Test public void testIncrBytes() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).closePipeline(); super.testIncrBytes(); } @Test public void testIncr() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).closePipeline(); super.testIncr(); } @Test public void testIncrByBytes() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).closePipeline(); super.testIncrByBytes(); } @Test public void testIncrBy() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).closePipeline(); super.testIncrBy(); } @Test public void testIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] { 2d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2d)).when(nativeConnection).closePipeline(); super.testIncrByDoubleBytes(); } @Test public void testIncrByDouble() { - doReturn(Arrays.asList(new Object[] { 2d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2d)).when(nativeConnection).closePipeline(); super.testIncrByDouble(); } @@ -444,7 +445,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi public void testInfo() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { props })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(props)).when(nativeConnection).closePipeline(); super.testInfo(); } @@ -452,25 +453,25 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi public void testInfoBySection() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { props })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(props)).when(nativeConnection).closePipeline(); super.testInfoBySection(); } @Test public void testKeysBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testKeysBytes(); } @Test public void testKeys() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testKeys(); } @Test public void testLastSave() { - doReturn(Arrays.asList(new Object[] { 6l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(6L)).when(nativeConnection).closePipeline(); super.testLastSave(); } @@ -488,25 +489,25 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testLInsertBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLInsertBytes(); } @Test public void testLInsert() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLInsert(); } @Test public void testLLenBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLLenBytes(); } @Test public void testLLen() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLLen(); } @@ -525,115 +526,115 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testLPushBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLPushBytes(); } @Test public void testLPush() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLPush(); } @Test public void testLPushXBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLPushXBytes(); } @Test public void testLPushX() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLPushX(); } @Test public void testLRangeBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testLRangeBytes(); } @Test public void testLRange() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testLRange(); } @Test public void testLRemBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLRemBytes(); } @Test public void testLRem() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).closePipeline(); super.testLRem(); } @Test public void testMGetBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testMGetBytes(); } @Test public void testMGet() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testMGet(); } @Test public void testMSetNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testMSetNXBytes(); } @Test public void testMSetNXString() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testMSetNXString(); } @Test public void testPersistBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testPersistBytes(); } @Test public void testPersist() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testPersist(); } @Test public void testMoveBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testMoveBytes(); } @Test public void testMove() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testMove(); } @Test public void testPing() { - doReturn(Arrays.asList(new Object[] { "pong" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("pong")).when(nativeConnection).closePipeline(); super.testPing(); } @Test public void testPublishBytes() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).closePipeline(); super.testPublishBytes(); } @Test public void testPublish() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).closePipeline(); super.testPublish(); } @@ -645,13 +646,13 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testRenameNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testRenameNXBytes(); } @Test public void testRenameNX() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testRenameNX(); } @@ -681,169 +682,169 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testRPushBytes() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).closePipeline(); super.testRPushBytes(); } @Test public void testRPush() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).closePipeline(); super.testRPush(); } @Test public void testRPushXBytes() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).closePipeline(); super.testRPushXBytes(); } @Test public void testRPushX() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).closePipeline(); super.testRPushX(); } @Test public void testSAddBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testSAddBytes(); } @Test public void testSAdd() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testSAdd(); } @Test public void testSCardBytes() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).closePipeline(); super.testSCardBytes(); } @Test public void testSCard() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).closePipeline(); super.testSCard(); } @Test public void testSDiffBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSDiffBytes(); } @Test public void testSDiff() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSDiff(); } @Test public void testSDiffStoreBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testSDiffStoreBytes(); } @Test public void testSDiffStore() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testSDiffStore(); } @Test public void testSetNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testSetNXBytes(); } @Test public void testSetNX() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testSetNX(); } @Test public void testSInterBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSInterBytes(); } @Test public void testSInter() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSInter(); } @Test public void testSInterStoreBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testSInterStoreBytes(); } @Test public void testSInterStore() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testSInterStore(); } @Test public void testSIsMemberBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testSIsMemberBytes(); } @Test public void testSIsMember() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testSIsMember(); } @Test public void testSMembersBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSMembersBytes(); } @Test public void testSMembers() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSMembers(); } @Test public void testSMoveBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testSMoveBytes(); } @Test public void testSMove() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testSMove(); } @Test public void testSortStoreBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testSortStoreBytes(); } @Test public void testSortStore() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).closePipeline(); super.testSortStore(); } @Test public void testSortBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testSortBytes(); } @Test public void testSort() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testSort(); } @@ -873,441 +874,442 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testSRandMemberCountBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testSRandMemberCountBytes(); } @Test public void testSRandMemberCount() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).closePipeline(); super.testSRandMemberCount(); } @Test public void testSRemBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testSRemBytes(); } @Test public void testSRem() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testSRem(); } @Test public void testStrLenBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testStrLenBytes(); } @Test public void testStrLen() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testStrLen(); } @Test public void testBitCountBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testBitCountBytes(); } @Test public void testBitCount() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testBitCount(); } @Test public void testBitCountRangeBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testBitCountRangeBytes(); } @Test public void testBitCountRange() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testBitCountRange(); } @Test public void testBitOpBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testBitOpBytes(); } @Test public void testBitOp() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testBitOp(); } @Test public void testSUnionBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSUnionBytes(); } @Test public void testSUnion() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testSUnion(); } @Test public void testSUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testSUnionStoreBytes(); } @Test public void testSUnionStore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testSUnionStore(); } @Test public void testTtlBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testTtlBytes(); } @Test public void testTtl() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testTtl(); } // DATAREDIS-526 @Override + @Test public void testTtlWithTimeUnit() { - doReturn(Arrays.asList(new Object[] { 5L })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testTtlWithTimeUnit(); } @Test public void testTypeBytes() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(DataType.HASH)).when(nativeConnection).closePipeline(); super.testTypeBytes(); } @Test public void testType() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(DataType.HASH)).when(nativeConnection).closePipeline(); super.testType(); } @Test public void testZAddBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testZAddBytes(); } @Test public void testZAdd() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testZAdd(); } @Test public void testZAddMultipleBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testZAddMultipleBytes(); } @Test public void testZAddMultiple() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testZAddMultiple(); } @Test public void testZCardBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZCardBytes(); } @Test public void testZCard() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZCard(); } @Test public void testZCountBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZCountBytes(); } @Test public void testZCount() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZCount(); } @Test public void testZIncrByBytes() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).closePipeline(); super.testZIncrByBytes(); } @Test public void testZIncrBy() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).closePipeline(); super.testZIncrBy(); } @Test public void testZInterStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZInterStoreAggWeightsBytes(); } @Test public void testZInterStoreAggWeights() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZInterStoreAggWeights(); } @Test public void testZInterStoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZInterStoreBytes(); } @Test public void testZInterStore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZInterStore(); } @Test public void testZRangeBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRangeBytes(); } @Test public void testZRange() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRange(); } @Test public void testZRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreOffsetCountBytes(); } @Test public void testZRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreOffsetCount(); } @Test public void testZRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreBytes(); } @Test public void testZRangeByScore() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRangeByScore(); } @Test public void testZRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreWithScoresOffsetCount(); } @Test public void testZRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreWithScoresBytes(); } @Test public void testZRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRangeByScoreWithScores(); } @Test public void testZRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRangeWithScoresBytes(); } @Test public void testZRangeWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRangeWithScores(); } @Test public void testZRevRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreOffsetCountBytes(); } @Test public void testZRevRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreOffsetCount(); } @Test public void testZRevRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreBytes(); } @Test public void testZRevRangeByScore() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScore(); } @Test public void testZRevRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRevRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreWithScoresOffsetCount(); } @Test public void testZRevRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreWithScoresBytes(); } @Test public void testZRevRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRevRangeByScoreWithScores(); } @Test public void testZRankBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRankBytes(); } @Test public void testZRank() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRank(); } @Test public void testZRemBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testZRemBytes(); } @Test public void testZRem() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testZRem(); } @Test public void testZRemRangeBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRemRangeBytes(); } @Test public void testZRemRange() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRemRange(); } @Test public void testZRemRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRemRangeByScoreBytes(); } @Test public void testZRemRangeByScore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRemRangeByScore(); } @Test public void testZRevRangeBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRevRangeBytes(); } @Test public void testZRevRange() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).closePipeline(); super.testZRevRange(); } @Test public void testZRevRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRevRangeWithScoresBytes(); } @Test public void testZRevRangeWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).closePipeline(); super.testZRevRangeWithScores(); } @Test public void testZRevRankBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRevRankBytes(); } @Test public void testZRevRank() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZRevRank(); } @Test public void testZScoreBytes() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).closePipeline(); super.testZScoreBytes(); } @Test public void testZScore() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).closePipeline(); super.testZScore(); } @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZUnionStoreAggWeightsBytes(); } @Test public void testZUnionStoreAggWeights() { - doReturn(Collections.singletonList(5l)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testZUnionStoreAggWeights(); } @@ -1341,6 +1343,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi // DATAREDIS-438 @Override + @Test public void testGeoAddWithGeoLocationBytes() { doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); @@ -1349,6 +1352,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi // DATAREDIS-438 @Override + @Test public void testGeoAddWithGeoLocation() { doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); @@ -1371,6 +1375,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi // DATAREDIS-438 @Override + @Test public void testGeoAddWithIterableOfGeoLocationBytes() { doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); @@ -1379,6 +1384,7 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi // DATAREDIS-438 @Override + @Test public void testGeoAddWithIterableOfGeoLocation() { doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); @@ -1388,13 +1394,15 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test // DATAREDIS-438 public void testGeoDistBytes() { - doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection) + .closePipeline(); super.testGeoDistBytes(); } @Test // DATAREDIS-438 public void testGeoDist() { - doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection) + .closePipeline(); super.testGeoDist(); } @@ -1402,148 +1410,148 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test // DATAREDIS-438 public void testGeoHashBytes() { - doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(bar))).when(nativeConnection).closePipeline(); super.testGeoHashBytes(); } @Test // DATAREDIS-438 public void testGeoHash() { - doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(bar))).when(nativeConnection).closePipeline(); super.testGeoHash(); } @Test // DATAREDIS-438 public void testGeoPosBytes() { - doReturn(Arrays.asList(points)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(points)).when(nativeConnection).closePipeline(); super.testGeoPosBytes(); } @Test // DATAREDIS-438 public void testGeoPos() { - doReturn(Arrays.asList(points)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(points)).when(nativeConnection).closePipeline(); super.testGeoPos(); } @Test // DATAREDIS-438 public void testGeoRadiusWithoutParamBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusWithoutParamBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithoutParam() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusWithoutParam(); } @Test // DATAREDIS-438 public void testGeoRadiusWithDistBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusWithDistBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithDist() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusWithDist(); } @Test // DATAREDIS-438 public void testGeoRadiusWithCoordAndDescBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusWithCoordAndDescBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithCoordAndDesc() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusWithCoordAndDesc(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithoutParamBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithoutParamBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithoutParam() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithoutParam(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithDistAndAscBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithDistAndAscBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithDistAndAsc() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithDistAndAsc(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithCoordAndCountBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithCoordAndCountBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithCoordAndCount() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithCoordAndCount(); } @Test public void testPExpireBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testPExpireBytes(); } @Test public void testPExpire() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testPExpire(); } @Test public void testPExpireAtBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testPExpireAtBytes(); } @Test public void testPExpireAt() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(true)).when(nativeConnection).closePipeline(); super.testPExpireAt(); } @Test public void testPTtlBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testPTtlBytes(); } @Test public void testPTtl() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).closePipeline(); super.testPTtl(); } @@ -1555,67 +1563,67 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi @Test public void testScriptLoadBytes() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testScriptLoadBytes(); } @Test public void testScriptLoad() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testScriptLoad(); } @Test public void testScriptExists() { List results = Collections.singletonList(true); - doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(results)).when(nativeConnection).closePipeline(); super.testScriptExists(); } @Test public void testEvalBytes() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testEvalBytes(); } @Test public void testEval() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testEval(); } @Test public void testEvalShaBytes() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testEvalShaBytes(); } @Test public void testEvalSha() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testEvalSha(); } @Test public void testExecute() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testExecute(); } @Test public void testExecuteByteArgs() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testExecuteByteArgs(); } @Test public void testExecuteStringArgs() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).closePipeline(); super.testExecuteStringArgs(); } @Test - public void testDisablePipelineDeserialize() { + void testDisablePipelineDeserialize() { connection.setDeserializePipelineAndTxResults(false); doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); @@ -1624,112 +1632,120 @@ public class DefaultStringRedisConnectionPipelineTests extends DefaultStringRedi } @Test - public void testPipelineNotSameSizeAsResults() { + void testPipelineNotSameSizeAsResults() { // Only call one method, but return 2 results from nativeConnection.closePipeline() // Emulates scenario where user has called some methods directly on the native connection // while pipeline is open - doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection).closePipeline(); + doReturn(Arrays.asList(barBytes, 3L)).when(nativeConnection).closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); - verifyResults(Arrays.asList(new Object[] { barBytes, 3l })); + verifyResults(Arrays.asList(barBytes, 3L)); } @Test // DATAREDIS-206 @Override public void testTimeIsDelegatedCorrectlyToNativeConnection() { - doReturn(Arrays.asList(1L)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.testTimeIsDelegatedCorrectlyToNativeConnection(); } @Test // DATAREDIS-864 public void xAckShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.xAckShouldDelegateAndConvertCorrectly(); } @Override // DATAREDIS-864 public void xAddShouldAppendRecordCorrectly() { - doReturn(Arrays.asList(RecordId.of("1-1"))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(RecordId.of("1-1"))).when(nativeConnection).closePipeline(); super.xAddShouldAppendRecordCorrectly(); } @Test // DATAREDIS-864 public void xDelShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.xAckShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xGroupCreateShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList("OK")).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList("OK")).when(nativeConnection).closePipeline(); super.xGroupCreateShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 - public void xGroupDelComsumerShouldDelegateAndConvertCorrectly() { + public void xGroupDelConsumerShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Boolean.TRUE)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Boolean.TRUE)).when(nativeConnection).closePipeline(); super.xGroupDelConsumerShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xLenShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.xLenShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xGroupDestroyShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Boolean.TRUE)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Boolean.TRUE)).when(nativeConnection).closePipeline(); super.xGroupDestroyShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xRangeShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList( + Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) + .when(nativeConnection).closePipeline(); super.xRangeShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xReadShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList( + Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) + .when(nativeConnection).closePipeline(); super.xReadShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xReadGroupShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList( + Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) + .when(nativeConnection).closePipeline(); super.xReadGroupShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xRevRangeShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList( + Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) + .when(nativeConnection).closePipeline(); super.xRevRangeShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xTrimShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.xTrimShouldDelegateAndConvertCorrectly(); } @Test public void xTrimApproximateShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).closePipeline(); super.xTrimApproximateShouldDelegateAndConvertCorrectly(); } diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java index e4c382a37..ab0a5c880 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionPipelineTxTests.java @@ -23,8 +23,8 @@ import java.util.Collections; import java.util.List; import java.util.Properties; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.data.geo.Distance; import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; @@ -39,7 +39,7 @@ import org.springframework.data.redis.connection.stream.StreamRecords; */ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRedisConnectionTxTests { - @Before + @BeforeEach public void setUp() { super.setUp(); when(nativeConnection.isPipelined()).thenReturn(true); @@ -47,180 +47,180 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test public void testAppend() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testAppend(); } @Test public void testAppendBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testAppendBytes(); } @Test public void testBlPopBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testBlPopBytes(); } @Test public void testBlPop() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testBlPop(); } @Test public void testBrPopBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testBrPopBytes(); } @Test public void testBrPop() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testBrPop(); } @Test public void testBrPopLPushBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testBrPopLPushBytes(); } @Test public void testBrPopLPush() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testBrPopLPush(); } @Test public void testDbSize() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testDbSize(); } @Test public void testDecrBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testDecrBytes(); } @Test public void testDecr() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testDecr(); } @Test public void testDecrByBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testDecrByBytes(); } @Test public void testDecrBy() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testDecrBy(); } @Test public void testDelBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testDelBytes(); } @Test public void testDel() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testDel(); } @Test public void testEchoBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testEchoBytes(); } @Test public void testEcho() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testEcho(); } @Test public void testExistsBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testExistsBytes(); } @Test public void testExists() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testExists(); } @Test public void testExpireBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testExpireBytes(); } @Test public void testExpire() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testExpire(); } @Test public void testExpireAtBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testExpireAtBytes(); } @Test public void testExpireAt() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testExpireAt(); } @Test public void testGetBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testGetBytes(); } @Test public void testGet() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testGet(); } @Test public void testGetBitBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testGetBitBytes(); } @Test public void testGetBit() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testGetBit(); } @@ -231,239 +231,239 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe Properties results = new Properties(); results.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { results }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(results))).when(nativeConnection) .closePipeline(); super.testGetConfig(); } @Test public void testGetNativeConnection() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testGetNativeConnection(); } @Test public void testGetRangeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testGetRangeBytes(); } @Test public void testGetRange() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testGetRange(); } @Test public void testGetSetBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testGetSetBytes(); } @Test public void testGetSet() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testGetSet(); } @Test public void testHDelBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testHDelBytes(); } @Test public void testHDel() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testHDel(); } @Test public void testHExistsBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testHExistsBytes(); } @Test public void testHExists() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testHExists(); } @Test public void testHGetBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testHGetBytes(); } @Test public void testHGet() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testHGet(); } @Test public void testHGetAllBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesMap }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesMap))).when(nativeConnection) .closePipeline(); super.testHGetAllBytes(); } @Test public void testHGetAll() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesMap }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesMap))).when(nativeConnection) .closePipeline(); super.testHGetAll(); } @Test public void testHIncrByBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testHIncrByBytes(); } @Test public void testHIncrBy() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testHIncrBy(); } @Test public void testHIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3d))).when(nativeConnection).closePipeline(); super.testHIncrByDoubleBytes(); } @Test public void testHIncrByDouble() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3d))).when(nativeConnection).closePipeline(); super.testHIncrByDouble(); } @Test public void testHKeysBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testHKeysBytes(); } @Test public void testHKeys() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testHKeys(); } @Test public void testHLenBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testHLenBytes(); } @Test public void testHLen() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testHLen(); } @Test public void testHMGetBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testHMGetBytes(); } @Test public void testHMGet() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testHMGet(); } @Test public void testHSetBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testHSetBytes(); } @Test public void testHSet() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testHSet(); } @Test public void testHSetNXBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testHSetNXBytes(); } @Test public void testHSetNX() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testHSetNX(); } @Test public void testHValsBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testHValsBytes(); } @Test public void testHVals() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testHVals(); } @Test public void testIncrBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2L))).when(nativeConnection).closePipeline(); super.testIncrBytes(); } @Test public void testIncr() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2L))).when(nativeConnection).closePipeline(); super.testIncr(); } @Test public void testIncrByBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2L))).when(nativeConnection).closePipeline(); super.testIncrByBytes(); } @Test public void testIncrBy() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2L))).when(nativeConnection).closePipeline(); super.testIncrBy(); } @Test public void testIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2d))).when(nativeConnection).closePipeline(); super.testIncrByDoubleBytes(); } @Test public void testIncrByDouble() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2d))).when(nativeConnection).closePipeline(); super.testIncrByDouble(); } @@ -471,7 +471,7 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe public void testInfo() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { props }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(props))).when(nativeConnection) .closePipeline(); super.testInfo(); } @@ -480,72 +480,72 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe public void testInfoBySection() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { props }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(props))).when(nativeConnection) .closePipeline(); super.testInfoBySection(); } @Test public void testKeysBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testKeysBytes(); } @Test public void testKeys() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testKeys(); } @Test public void testLastSave() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 6l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(6L))).when(nativeConnection).closePipeline(); super.testLastSave(); } @Test public void testLIndexBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testLIndexBytes(); } @Test public void testLIndex() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testLIndex(); } @Test public void testLInsertBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLInsertBytes(); } @Test public void testLInsert() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLInsert(); } @Test public void testLLenBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLLenBytes(); } @Test public void testLLen() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLLen(); } @Test public void testLPopBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); actual.add(connection.lPop(fooBytes)); verifyResults(Arrays.asList(new Object[] { barBytes })); @@ -553,936 +553,937 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test public void testLPop() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testLPop(); } @Test public void testLPushBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLPushBytes(); } @Test public void testLPush() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLPush(); } @Test public void testLPushXBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLPushXBytes(); } @Test public void testLPushX() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLPushX(); } @Test public void testLRangeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testLRangeBytes(); } @Test public void testLRange() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testLRange(); } @Test public void testLRemBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLRemBytes(); } @Test public void testLRem() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 8l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(8L))).when(nativeConnection).closePipeline(); super.testLRem(); } @Test public void testMGetBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testMGetBytes(); } @Test public void testMGet() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testMGet(); } @Test public void testMSetNXBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testMSetNXBytes(); } @Test public void testMSetNXString() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testMSetNXString(); } @Test public void testPersistBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testPersistBytes(); } @Test public void testPersist() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testPersist(); } @Test public void testMoveBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testMoveBytes(); } @Test public void testMove() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testMove(); } @Test public void testPing() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "pong" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("pong"))).when(nativeConnection) .closePipeline(); super.testPing(); } @Test public void testPublishBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2L))).when(nativeConnection).closePipeline(); super.testPublishBytes(); } @Test public void testPublish() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 2l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(2L))).when(nativeConnection).closePipeline(); super.testPublish(); } @Test public void testRandomKey() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { fooBytes }))).when(nativeConnection) .closePipeline(); super.testRandomKey(); } @Test public void testRenameNXBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testRenameNXBytes(); } @Test public void testRenameNX() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testRenameNX(); } @Test public void testRPopBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testRPopBytes(); } @Test public void testRPop() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testRPop(); } @Test public void testRPopLPushBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testRPopLPushBytes(); } @Test public void testRPopLPush() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testRPopLPush(); } @Test public void testRPushBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(4L))).when(nativeConnection).closePipeline(); super.testRPushBytes(); } @Test public void testRPush() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(4L))).when(nativeConnection).closePipeline(); super.testRPush(); } @Test public void testRPushXBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(4L))).when(nativeConnection).closePipeline(); super.testRPushXBytes(); } @Test public void testRPushX() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(4L))).when(nativeConnection).closePipeline(); super.testRPushX(); } @Test public void testSAddBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testSAddBytes(); } @Test public void testSAdd() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testSAdd(); } @Test public void testSCardBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(4L))).when(nativeConnection).closePipeline(); super.testSCardBytes(); } @Test public void testSCard() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 4l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(4L))).when(nativeConnection).closePipeline(); super.testSCard(); } @Test public void testSDiffBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSDiffBytes(); } @Test public void testSDiff() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSDiff(); } @Test public void testSDiffStoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testSDiffStoreBytes(); } @Test public void testSDiffStore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testSDiffStore(); } @Test public void testSetNXBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testSetNXBytes(); } @Test public void testSetNX() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testSetNX(); } @Test public void testSInterBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSInterBytes(); } @Test public void testSInter() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSInter(); } @Test public void testSInterStoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testSInterStoreBytes(); } @Test public void testSInterStore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testSInterStore(); } @Test public void testSIsMemberBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testSIsMemberBytes(); } @Test public void testSIsMember() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testSIsMember(); } @Test public void testSMembersBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSMembersBytes(); } @Test public void testSMembers() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSMembers(); } @Test public void testSMoveBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testSMoveBytes(); } @Test public void testSMove() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testSMove(); } @Test public void testSortStoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testSortStoreBytes(); } @Test public void testSortStore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3L))).when(nativeConnection).closePipeline(); super.testSortStore(); } @Test public void testSortBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testSortBytes(); } @Test public void testSort() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testSort(); } @Test public void testSPopBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testSPopBytes(); } @Test public void testSPop() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testSPop(); } @Test public void testSRandMemberBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testSRandMemberBytes(); } @Test public void testSRandMember() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testSRandMember(); } @Test public void testSRandMemberCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testSRandMemberCountBytes(); } @Test public void testSRandMemberCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesList }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesList))).when(nativeConnection) .closePipeline(); super.testSRandMemberCount(); } @Test public void testSRemBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testSRemBytes(); } @Test public void testSRem() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testSRem(); } @Test public void testStrLenBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testStrLenBytes(); } @Test public void testStrLen() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testStrLen(); } @Test public void testBitCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testBitCountBytes(); } @Test public void testBitCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testBitCount(); } @Test public void testBitCountRangeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testBitCountRangeBytes(); } @Test public void testBitCountRange() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testBitCountRange(); } @Test public void testBitOpBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testBitOpBytes(); } @Test public void testBitOp() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testBitOp(); } @Test public void testSUnionBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSUnionBytes(); } @Test public void testSUnion() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testSUnion(); } @Test public void testSUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testSUnionStoreBytes(); } @Test public void testSUnionStore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testSUnionStore(); } @Test public void testTtlBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testTtlBytes(); } @Test public void testTtl() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testTtl(); } // DATAREDIS-526 @Override + @Test public void testTtlWithTimeUnit() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5L }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testTtlWithTimeUnit(); } @Test public void testTypeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { DataType.HASH }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(DataType.HASH))).when(nativeConnection) .closePipeline(); super.testTypeBytes(); } @Test public void testType() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { DataType.HASH }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(DataType.HASH))).when(nativeConnection) .closePipeline(); super.testType(); } @Test public void testZAddBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testZAddBytes(); } @Test public void testZAdd() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testZAdd(); } @Test public void testZAddMultipleBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testZAddMultipleBytes(); } @Test public void testZAddMultiple() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testZAddMultiple(); } @Test public void testZCardBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZCardBytes(); } @Test public void testZCard() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZCard(); } @Test public void testZCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZCountBytes(); } @Test public void testZCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZCount(); } @Test public void testZIncrByBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3d))).when(nativeConnection).closePipeline(); super.testZIncrByBytes(); } @Test public void testZIncrBy() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3d))).when(nativeConnection).closePipeline(); super.testZIncrBy(); } @Test public void testZInterStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZInterStoreAggWeightsBytes(); } @Test public void testZInterStoreAggWeights() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZInterStoreAggWeights(); } @Test public void testZInterStoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZInterStoreBytes(); } @Test public void testZInterStore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZInterStore(); } @Test public void testZRangeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRangeBytes(); } @Test public void testZRange() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRange(); } @Test public void testZRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreOffsetCountBytes(); } @Test public void testZRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreOffsetCount(); } @Test public void testZRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreBytes(); } @Test public void testZRangeByScore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScore(); } @Test public void testZRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreWithScoresOffsetCount(); } @Test public void testZRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreWithScoresBytes(); } @Test public void testZRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRangeByScoreWithScores(); } @Test public void testZRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRangeWithScoresBytes(); } @Test public void testZRangeWithScores() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRangeWithScores(); } @Test public void testZRevRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreOffsetCountBytes(); } @Test public void testZRevRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreOffsetCount(); } @Test public void testZRevRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreBytes(); } @Test public void testZRevRangeByScore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScore(); } @Test public void testZRevRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRevRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreWithScoresOffsetCount(); } @Test public void testZRevRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreWithScoresBytes(); } @Test public void testZRevRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeByScoreWithScores(); } @Test public void testZRankBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRankBytes(); } @Test public void testZRank() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRank(); } @Test public void testZRemBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testZRemBytes(); } @Test public void testZRem() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testZRem(); } @Test public void testZRemRangeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRemRangeBytes(); } @Test public void testZRemRange() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRemRange(); } @Test public void testZRemRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRemRangeByScoreBytes(); } @Test public void testZRemRangeByScore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRemRangeByScore(); } @Test public void testZRevRangeBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeBytes(); } @Test public void testZRevRange() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { bytesSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(bytesSet))).when(nativeConnection) .closePipeline(); super.testZRevRange(); } @Test public void testZRevRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeWithScoresBytes(); } @Test public void testZRevRangeWithScores() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { tupleSet }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(tupleSet))).when(nativeConnection) .closePipeline(); super.testZRevRangeWithScores(); } @Test public void testZRevRankBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRevRankBytes(); } @Test public void testZRevRank() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZRevRank(); } @Test public void testZScoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3d))).when(nativeConnection).closePipeline(); super.testZScoreBytes(); } @Test public void testZScore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 3d }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(3d))).when(nativeConnection).closePipeline(); super.testZScore(); } @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZUnionStoreAggWeightsBytes(); } @Test public void testZUnionStoreAggWeights() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZUnionStoreAggWeights(); } @Test public void testZUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZUnionStoreBytes(); } @Test public void testZUnionStore() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testZUnionStore(); } @Test public void testPExpireBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testPExpireBytes(); } @Test public void testPExpire() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testPExpire(); } @Test public void testPExpireAtBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testPExpireAtBytes(); } @Test public void testPExpireAt() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { true }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(true))).when(nativeConnection) .closePipeline(); super.testPExpireAt(); } @Test public void testPTtlBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testPTtlBytes(); } @Test public void testPTtl() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 5l }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(5L))).when(nativeConnection).closePipeline(); super.testPTtl(); } @Test public void testDump() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); super.testDump(); } @Test public void testScriptLoadBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testScriptLoadBytes(); } @Test public void testScriptLoad() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testScriptLoad(); } @@ -1490,56 +1491,56 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test public void testScriptExists() { List results = Collections.singletonList(true); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { results }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(results))).when(nativeConnection) .closePipeline(); super.testScriptExists(); } @Test public void testEvalBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testEvalBytes(); } @Test public void testEval() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testEval(); } @Test public void testEvalShaBytes() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testEvalShaBytes(); } @Test public void testEvalSha() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testEvalSha(); } @Test public void testExecute() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testExecute(); } @Test public void testExecuteByteArgs() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testExecuteByteArgs(); } @Test public void testExecuteStringArgs() { - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { "foo" }) })).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList("foo"))).when(nativeConnection) .closePipeline(); super.testExecuteStringArgs(); } @@ -1549,17 +1550,17 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe // Only call one method, but return 2 results from nativeConnection.exec() // Emulates scenario where user has called some methods directly on the native connection // while tx is open - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes, 3l }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(barBytes, 3L))).when(nativeConnection) .closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); - verifyResults(Arrays.asList(new Object[] { barBytes, 3l })); + verifyResults(Arrays.asList(barBytes, 3L)); } @Test - public void testTwoTxs() { + void testTwoTxs() { doReturn(Arrays - .asList(new Object[] { Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }) })) + .asList(Arrays.asList(new Object[] { barBytes }), Arrays.asList(new Object[] { fooBytes }))) .when(nativeConnection).closePipeline(); connection.get(foo); connection.exec(); @@ -1567,69 +1568,70 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe connection.exec(); List results = connection.closePipeline(); assertThat(results).isEqualTo( - Arrays.asList(new Object[] { Arrays.asList(new Object[] { bar }), Arrays.asList(new Object[] { foo }) })); + Arrays.asList(Collections.singletonList(bar), Collections.singletonList(foo))); } @Test // DATAREDIS-438 public void testGeoAddBytes() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddBytes(); } @Test // DATAREDIS-438 public void testGeoAdd() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddBytes(); } @Test // DATAREDIS-438 public void testGeoAddWithGeoLocationBytes() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddWithGeoLocationBytes(); } @Test // DATAREDIS-438 public void testGeoAddWithGeoLocation() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddWithGeoLocation(); } @Test // DATAREDIS-438 public void testGeoAddCoordinateMapBytes() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddCoordinateMapBytes(); } @Test // DATAREDIS-438 public void testGeoAddCoordinateMap() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddCoordinateMap(); } @Test // DATAREDIS-438 public void testGeoAddWithIterableOfGeoLocationBytes() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddWithIterableOfGeoLocationBytes(); } @Test // DATAREDIS-438 public void testGeoAddWithIterableOfGeoLocation() { - doReturn(Arrays.asList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testGeoAddWithIterableOfGeoLocation(); } @Test // DATAREDIS-438 public void testGeoDistBytes() { - doReturn(Arrays.asList(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS)))).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS)))) + .when(nativeConnection) .closePipeline(); super.testGeoDistBytes(); } @@ -1637,7 +1639,8 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test // DATAREDIS-438 public void testGeoDist() { - doReturn(Arrays.asList(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS)))).when(nativeConnection) + doReturn(Collections.singletonList(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS)))) + .when(nativeConnection) .closePipeline(); super.testGeoDist(); } @@ -1645,168 +1648,171 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test // DATAREDIS-438 public void testGeoHashBytes() { - doReturn(Arrays.asList(Arrays.asList(Collections.singletonList(bar)))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(Collections.singletonList(bar)))) + .when(nativeConnection).closePipeline(); super.testGeoHashBytes(); } @Test // DATAREDIS-438 public void testGeoHash() { - doReturn(Arrays.asList(Arrays.asList(Collections.singletonList(bar)))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(Collections.singletonList(bar)))) + .when(nativeConnection).closePipeline(); super.testGeoHash(); } @Test // DATAREDIS-438 public void testGeoPosBytes() { - doReturn(Arrays.asList(Arrays.asList(points))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(points))).when(nativeConnection).closePipeline(); super.testGeoPosBytes(); } @Test // DATAREDIS-438 public void testGeoPos() { - doReturn(Arrays.asList(Arrays.asList(points))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(points))).when(nativeConnection).closePipeline(); super.testGeoPos(); } @Test // DATAREDIS-438 public void testGeoRadiusWithoutParamBytes() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusWithoutParamBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithoutParam() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusWithoutParam(); } @Test // DATAREDIS-438 public void testGeoRadiusWithDistBytes() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusWithDistBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithDist() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusWithDist(); } @Test // DATAREDIS-438 public void testGeoRadiusWithCoordAndDescBytes() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusWithCoordAndDescBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithCoordAndDesc() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusWithCoordAndDesc(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithoutParamBytes() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithoutParamBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithoutParam() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithoutParam(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithDistAndAscBytes() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithDistAndAscBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithDistAndAsc() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithDistAndAsc(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithCoordAndCountBytes() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithCoordAndCountBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithCoordAndCount() { - doReturn(Arrays.asList(Arrays.asList(geoResults))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(geoResults))).when(nativeConnection).closePipeline(); super.testGeoRadiusByMemberWithCoordAndCount(); } @Test // DATAREDIS-864 public void xAckShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.xAckShouldDelegateAndConvertCorrectly(); } @Override // DATAREDIS-864 public void xAddShouldAppendRecordCorrectly() { - doReturn(Arrays.asList(Arrays.asList(RecordId.of("1-1")))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(RecordId.of("1-1")))).when(nativeConnection) + .closePipeline(); super.xAddShouldAppendRecordCorrectly(); } @Test // DATAREDIS-864 public void xDelShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.xAckShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xGroupCreateShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList("OK"))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList("OK"))).when(nativeConnection).closePipeline(); super.xGroupCreateShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 - public void xGroupDelComsumerShouldDelegateAndConvertCorrectly() { + public void xGroupDelConsumerShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(Boolean.TRUE))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(Boolean.TRUE))).when(nativeConnection).closePipeline(); super.xGroupDelConsumerShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xLenShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.xLenShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xGroupDestroyShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(Boolean.TRUE))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(Boolean.TRUE))).when(nativeConnection).closePipeline(); super.xGroupDestroyShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xRangeShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList( + doReturn(Collections.singletonList(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap))))) .when(nativeConnection).closePipeline(); super.xRangeShouldDelegateAndConvertCorrectly(); @@ -1815,7 +1821,7 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test // DATAREDIS-864 public void xReadShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList( + doReturn(Collections.singletonList(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap))))) .when(nativeConnection).closePipeline(); super.xReadShouldDelegateAndConvertCorrectly(); @@ -1824,7 +1830,7 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test // DATAREDIS-864 public void xReadGroupShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList( + doReturn(Collections.singletonList(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap))))) .when(nativeConnection).closePipeline(); super.xReadGroupShouldDelegateAndConvertCorrectly(); @@ -1833,7 +1839,7 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test // DATAREDIS-864 public void xRevRangeShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList( + doReturn(Collections.singletonList(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap))))) .when(nativeConnection).closePipeline(); super.xRevRangeShouldDelegateAndConvertCorrectly(); @@ -1842,21 +1848,20 @@ public class DefaultStringRedisConnectionPipelineTxTests extends DefaultStringRe @Test // DATAREDIS-864 public void xTrimShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.xTrimShouldDelegateAndConvertCorrectly(); } @Test public void xTrimApproximateShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Arrays.asList(1L))).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.xTrimApproximateShouldDelegateAndConvertCorrectly(); } @SuppressWarnings("unchecked") protected List getResults() { connection.exec(); - List txResults = (List) connection.closePipeline().get(0); - return txResults; + return (List) connection.closePipeline().get(0); } } diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java index 3883607fd..fb2342159 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTests.java @@ -30,10 +30,12 @@ import java.util.Properties; import java.util.Set; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.mockito.MockitoAnnotations; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; +import org.mockito.junit.jupiter.MockitoSettings; +import org.mockito.quality.Strictness; import org.springframework.data.geo.Circle; import org.springframework.data.geo.Distance; @@ -69,12 +71,13 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * @author Ninad Divadkar * @author Mark Paluch */ +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) public class DefaultStringRedisConnectionTests { protected List actual = new ArrayList<>(); -// @Mock protected RedisConnection nativeConnection; - protected RedisConnection nativeConnection; + RedisConnection nativeConnection; protected DefaultStringRedisConnection connection; @@ -84,43 +87,41 @@ public class DefaultStringRedisConnectionTests { protected String bar = "bar"; - protected String bar2 = "bar2"; + private String bar2 = "bar2"; - protected byte[] fooBytes = serializer.serialize(foo); + byte[] fooBytes = serializer.serialize(foo); - protected byte[] barBytes = serializer.serialize(bar); + byte[] barBytes = serializer.serialize(bar); - protected byte[] bar2Bytes = serializer.serialize(bar2); + byte[] bar2Bytes = serializer.serialize(bar2); - protected List bytesList = Collections.singletonList(barBytes); + List bytesList = Collections.singletonList(barBytes); - protected List stringList = Collections.singletonList(bar); + private List stringList = Collections.singletonList(bar); - protected Set bytesSet = new LinkedHashSet<>(Collections.singletonList(barBytes)); + Set bytesSet = new LinkedHashSet<>(Collections.singletonList(barBytes)); - protected Set stringSet = new LinkedHashSet<>(Collections.singletonList(bar)); + private Set stringSet = new LinkedHashSet<>(Collections.singletonList(bar)); - protected Map bytesMap = new HashMap<>(); + Map bytesMap = new HashMap<>(); - protected Map stringMap = new HashMap<>(); + private Map stringMap = new HashMap<>(); - protected Set tupleSet = new HashSet<>(Collections.singletonList(new DefaultTuple(barBytes, 3d))); + Set tupleSet = new HashSet<>(Collections.singletonList(new DefaultTuple(barBytes, 3d))); - protected Set stringTupleSet = new HashSet<>( + private Set stringTupleSet = new HashSet<>( Collections.singletonList(new DefaultStringTuple(new DefaultTuple(barBytes, 3d), bar))); protected Point point = new Point(213.00, 324.343); - protected List points = new ArrayList<>(); + List points = new ArrayList<>(); - protected List>> geoResultList = Collections + private List>> geoResultList = Collections .singletonList(new GeoResult<>(new GeoLocation<>(barBytes, null), new Distance(0D))); - protected GeoResults> geoResults = new GeoResults<>(geoResultList); + GeoResults> geoResults = new GeoResults<>(geoResultList); - @Before + @BeforeEach public void setUp() { - - MockitoAnnotations.initMocks(this); this.nativeConnection = mock(RedisConnection.class); this.connection = new DefaultStringRedisConnection(nativeConnection); bytesMap.put(fooBytes, barBytes); @@ -130,44 +131,44 @@ public class DefaultStringRedisConnectionTests { @Test public void testAppend() { - doReturn(1l).when(nativeConnection).append(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).append(fooBytes, barBytes); actual.add(connection.append(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testAppendBytes() { - doReturn(1l).when(nativeConnection).append(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).append(fooBytes, barBytes); actual.add(connection.append(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testBlPopBytes() { doReturn(bytesList).when(nativeConnection).bLPop(1, fooBytes); actual.add(connection.bLPop(1, fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testBlPop() { doReturn(bytesList).when(nativeConnection).bLPop(1, fooBytes); actual.add(connection.bLPop(1, foo)); - verifyResults(Arrays.asList(new Object[] { stringList })); + verifyResults(Collections.singletonList(stringList)); } @Test public void testBrPopBytes() { doReturn(bytesList).when(nativeConnection).bRPop(1, fooBytes); actual.add(connection.bRPop(1, fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testBrPop() { doReturn(bytesList).when(nativeConnection).bRPop(1, fooBytes); actual.add(connection.bRPop(1, foo)); - verifyResults(Arrays.asList(new Object[] { stringList })); + verifyResults(Collections.singletonList(stringList)); } @Test @@ -181,56 +182,56 @@ public class DefaultStringRedisConnectionTests { public void testBrPopLPush() { doReturn(barBytes).when(nativeConnection).bRPopLPush(1, fooBytes, barBytes); actual.add(connection.bRPopLPush(1, foo, bar)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testDbSize() { - doReturn(3l).when(nativeConnection).dbSize(); + doReturn(3L).when(nativeConnection).dbSize(); actual.add(connection.dbSize()); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testDecrBytes() { - doReturn(3l).when(nativeConnection).decr(fooBytes); + doReturn(3L).when(nativeConnection).decr(fooBytes); actual.add(connection.decr(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testDecr() { - doReturn(3l).when(nativeConnection).decr(fooBytes); + doReturn(3L).when(nativeConnection).decr(fooBytes); actual.add(connection.decr(foo)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testDecrByBytes() { - doReturn(3l).when(nativeConnection).decrBy(fooBytes, 2l); - actual.add(connection.decrBy(fooBytes, 2l)); - verifyResults(Arrays.asList(new Object[] { 3l })); + doReturn(3L).when(nativeConnection).decrBy(fooBytes, 2L); + actual.add(connection.decrBy(fooBytes, 2L)); + verifyResults(Collections.singletonList(3L)); } @Test public void testDecrBy() { - doReturn(3l).when(nativeConnection).decrBy(fooBytes, 2l); - actual.add(connection.decrBy(foo, 2l)); - verifyResults(Arrays.asList(new Object[] { 3l })); + doReturn(3L).when(nativeConnection).decrBy(fooBytes, 2L); + actual.add(connection.decrBy(foo, 2L)); + verifyResults(Collections.singletonList(3L)); } @Test public void testDelBytes() { - doReturn(1l).when(nativeConnection).del(fooBytes); + doReturn(1L).when(nativeConnection).del(fooBytes); actual.add(connection.del(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testDel() { - doReturn(1l).when(nativeConnection).del(fooBytes); + doReturn(1L).when(nativeConnection).del(fooBytes); actual.add(connection.del(foo)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test @@ -244,49 +245,49 @@ public class DefaultStringRedisConnectionTests { public void testEcho() { doReturn(barBytes).when(nativeConnection).echo(fooBytes); actual.add(connection.echo(foo)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testExistsBytes() { doReturn(true).when(nativeConnection).exists(fooBytes); actual.add(connection.exists(fooBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testExists() { doReturn(true).when(nativeConnection).exists(fooBytes); actual.add(connection.exists(foo)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testExpireBytes() { - doReturn(true).when(nativeConnection).expire(fooBytes, 1l); - actual.add(connection.expire(fooBytes, 1l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).expire(fooBytes, 1L); + actual.add(connection.expire(fooBytes, 1L)); + verifyResults(Collections.singletonList(true)); } @Test public void testExpire() { - doReturn(true).when(nativeConnection).expire(fooBytes, 1l); - actual.add(connection.expire(foo, 1l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).expire(fooBytes, 1L); + actual.add(connection.expire(foo, 1L)); + verifyResults(Collections.singletonList(true)); } @Test public void testExpireAtBytes() { - doReturn(true).when(nativeConnection).expireAt(fooBytes, 1l); - actual.add(connection.expireAt(fooBytes, 1l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).expireAt(fooBytes, 1L); + actual.add(connection.expireAt(fooBytes, 1L)); + verifyResults(Collections.singletonList(true)); } @Test public void testExpireAt() { - doReturn(true).when(nativeConnection).expireAt(fooBytes, 1l); - actual.add(connection.expireAt(foo, 1l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).expireAt(fooBytes, 1L); + actual.add(connection.expireAt(foo, 1L)); + verifyResults(Collections.singletonList(true)); } @Test @@ -300,21 +301,21 @@ public class DefaultStringRedisConnectionTests { public void testGet() { doReturn(barBytes).when(nativeConnection).get(fooBytes); actual.add(connection.get(foo)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testGetBitBytes() { - doReturn(true).when(nativeConnection).getBit(fooBytes, 1l); - actual.add(connection.getBit(fooBytes, 1l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).getBit(fooBytes, 1L); + actual.add(connection.getBit(fooBytes, 1L)); + verifyResults(Collections.singletonList(true)); } @Test public void testGetBit() { - doReturn(true).when(nativeConnection).getBit(fooBytes, 1l); - actual.add(connection.getBit(foo, 1l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).getBit(fooBytes, 1L); + actual.add(connection.getBit(foo, 1L)); + verifyResults(Collections.singletonList(true)); } @Test // DATAREDIS-661 @@ -325,28 +326,28 @@ public class DefaultStringRedisConnectionTests { doReturn(results).when(nativeConnection).getConfig("foo"); actual.add(connection.getConfig("foo")); - verifyResults(Arrays.asList(new Object[] { results })); + verifyResults(Collections.singletonList(results)); } @Test public void testGetNativeConnection() { doReturn("foo").when(nativeConnection).getNativeConnection(); actual.add(connection.getNativeConnection()); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testGetRangeBytes() { - doReturn(barBytes).when(nativeConnection).getRange(fooBytes, 1l, 2l); - actual.add(connection.getRange(fooBytes, 1l, 2l)); + doReturn(barBytes).when(nativeConnection).getRange(fooBytes, 1L, 2L); + actual.add(connection.getRange(fooBytes, 1L, 2L)); verifyResults(Arrays.asList(new Object[] { barBytes })); } @Test public void testGetRange() { - doReturn(barBytes).when(nativeConnection).getRange(fooBytes, 1l, 2l); - actual.add(connection.getRange(foo, 1l, 2l)); - verifyResults(Arrays.asList(new Object[] { bar })); + doReturn(barBytes).when(nativeConnection).getRange(fooBytes, 1L, 2L); + actual.add(connection.getRange(foo, 1L, 2L)); + verifyResults(Collections.singletonList(bar)); } @Test @@ -360,35 +361,35 @@ public class DefaultStringRedisConnectionTests { public void testGetSet() { doReturn(barBytes).when(nativeConnection).getSet(fooBytes, barBytes); actual.add(connection.getSet(foo, bar)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testHDelBytes() { - doReturn(1l).when(nativeConnection).hDel(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).hDel(fooBytes, barBytes); actual.add(connection.hDel(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testHDel() { - doReturn(1l).when(nativeConnection).hDel(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).hDel(fooBytes, barBytes); actual.add(connection.hDel(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testHExistsBytes() { doReturn(true).when(nativeConnection).hExists(fooBytes, barBytes); actual.add(connection.hExists(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testHExists() { doReturn(true).when(nativeConnection).hExists(fooBytes, barBytes); actual.add(connection.hExists(foo, bar)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test @@ -402,175 +403,175 @@ public class DefaultStringRedisConnectionTests { public void testHGet() { doReturn(barBytes).when(nativeConnection).hGet(fooBytes, barBytes); actual.add(connection.hGet(foo, bar)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testHGetAllBytes() { doReturn(bytesMap).when(nativeConnection).hGetAll(barBytes); actual.add(connection.hGetAll(barBytes)); - verifyResults(Arrays.asList(new Object[] { bytesMap })); + verifyResults(Collections.singletonList(bytesMap)); } @Test public void testHGetAll() { doReturn(bytesMap).when(nativeConnection).hGetAll(barBytes); actual.add(connection.hGetAll(bar)); - verifyResults(Arrays.asList(new Object[] { stringMap })); + verifyResults(Collections.singletonList(stringMap)); } @Test public void testHIncrByBytes() { - doReturn(3l).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1l); - actual.add(connection.hIncrBy(fooBytes, barBytes, 1l)); - verifyResults(Arrays.asList(new Object[] { 3l })); + doReturn(3L).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1L); + actual.add(connection.hIncrBy(fooBytes, barBytes, 1L)); + verifyResults(Collections.singletonList(3L)); } @Test public void testHIncrBy() { - doReturn(3l).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1l); - actual.add(connection.hIncrBy(foo, bar, 1l)); - verifyResults(Arrays.asList(new Object[] { 3l })); + doReturn(3L).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1L); + actual.add(connection.hIncrBy(foo, bar, 1L)); + verifyResults(Collections.singletonList(3L)); } @Test public void testHIncrByDoubleBytes() { doReturn(3d).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1d); actual.add(connection.hIncrBy(fooBytes, barBytes, 1d)); - verifyResults(Arrays.asList(new Object[] { 3d })); + verifyResults(Collections.singletonList(3d)); } @Test public void testHIncrByDouble() { doReturn(3d).when(nativeConnection).hIncrBy(fooBytes, barBytes, 1d); actual.add(connection.hIncrBy(foo, bar, 1d)); - verifyResults(Arrays.asList(new Object[] { 3d })); + verifyResults(Collections.singletonList(3d)); } @Test public void testHKeysBytes() { doReturn(bytesSet).when(nativeConnection).hKeys(fooBytes); actual.add(connection.hKeys(fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testHKeys() { doReturn(bytesSet).when(nativeConnection).hKeys(fooBytes); actual.add(connection.hKeys(foo)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testHLenBytes() { - doReturn(3l).when(nativeConnection).hLen(fooBytes); + doReturn(3L).when(nativeConnection).hLen(fooBytes); actual.add(connection.hLen(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testHLen() { - doReturn(3l).when(nativeConnection).hLen(fooBytes); + doReturn(3L).when(nativeConnection).hLen(fooBytes); actual.add(connection.hLen(foo)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testHMGetBytes() { doReturn(bytesList).when(nativeConnection).hMGet(fooBytes, barBytes); actual.add(connection.hMGet(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testHMGet() { doReturn(bytesList).when(nativeConnection).hMGet(fooBytes, barBytes); actual.add(connection.hMGet(foo, bar)); - verifyResults(Arrays.asList(new Object[] { stringList })); + verifyResults(Collections.singletonList(stringList)); } @Test public void testHSetBytes() { doReturn(true).when(nativeConnection).hSet(fooBytes, barBytes, fooBytes); actual.add(connection.hSet(fooBytes, barBytes, fooBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testHSet() { doReturn(true).when(nativeConnection).hSet(fooBytes, barBytes, fooBytes); actual.add(connection.hSet(foo, bar, foo)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testHSetNXBytes() { doReturn(true).when(nativeConnection).hSetNX(fooBytes, barBytes, fooBytes); actual.add(connection.hSetNX(fooBytes, barBytes, fooBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testHSetNX() { doReturn(true).when(nativeConnection).hSetNX(fooBytes, barBytes, fooBytes); actual.add(connection.hSetNX(foo, bar, foo)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testHValsBytes() { doReturn(bytesList).when(nativeConnection).hVals(fooBytes); actual.add(connection.hVals(fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testHVals() { doReturn(bytesList).when(nativeConnection).hVals(fooBytes); actual.add(connection.hVals(foo)); - verifyResults(Arrays.asList(new Object[] { stringList })); + verifyResults(Collections.singletonList(stringList)); } @Test public void testIncrBytes() { - doReturn(2l).when(nativeConnection).incr(fooBytes); + doReturn(2L).when(nativeConnection).incr(fooBytes); actual.add(connection.incr(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 2l })); + verifyResults(Collections.singletonList(2L)); } @Test public void testIncr() { - doReturn(2l).when(nativeConnection).incr(fooBytes); + doReturn(2L).when(nativeConnection).incr(fooBytes); actual.add(connection.incr(foo)); - verifyResults(Arrays.asList(new Object[] { 2l })); + verifyResults(Collections.singletonList(2L)); } @Test public void testIncrByBytes() { - doReturn(2l).when(nativeConnection).incrBy(fooBytes, 1l); - actual.add(connection.incrBy(fooBytes, 1l)); - verifyResults(Arrays.asList(new Object[] { 2l })); + doReturn(2L).when(nativeConnection).incrBy(fooBytes, 1L); + actual.add(connection.incrBy(fooBytes, 1L)); + verifyResults(Collections.singletonList(2L)); } @Test public void testIncrBy() { - doReturn(2l).when(nativeConnection).incrBy(fooBytes, 1l); - actual.add(connection.incrBy(foo, 1l)); - verifyResults(Arrays.asList(new Object[] { 2l })); + doReturn(2L).when(nativeConnection).incrBy(fooBytes, 1L); + actual.add(connection.incrBy(foo, 1L)); + verifyResults(Collections.singletonList(2L)); } @Test public void testIncrByDoubleBytes() { doReturn(2d).when(nativeConnection).incrBy(fooBytes, 1d); actual.add(connection.incrBy(fooBytes, 1d)); - verifyResults(Arrays.asList(new Object[] { 2d })); + verifyResults(Collections.singletonList(2d)); } @Test public void testIncrByDouble() { doReturn(2d).when(nativeConnection).incrBy(fooBytes, 1d); actual.add(connection.incrBy(foo, 1d)); - verifyResults(Arrays.asList(new Object[] { 2d })); + verifyResults(Collections.singletonList(2d)); } @Test @@ -579,7 +580,7 @@ public class DefaultStringRedisConnectionTests { props.put("foo", "bar"); doReturn(props).when(nativeConnection).info(); actual.add(connection.info()); - verifyResults(Arrays.asList(new Object[] { props })); + verifyResults(Collections.singletonList(props)); } @Test @@ -588,70 +589,70 @@ public class DefaultStringRedisConnectionTests { props.put("foo", "bar"); doReturn(props).when(nativeConnection).info("foo"); actual.add(connection.info("foo")); - verifyResults(Arrays.asList(new Object[] { props })); + verifyResults(Collections.singletonList(props)); } @Test public void testKeysBytes() { doReturn(bytesSet).when(nativeConnection).keys(fooBytes); actual.add(connection.keys(fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testKeys() { doReturn(bytesSet).when(nativeConnection).keys(fooBytes); actual.add(connection.keys(foo)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testLastSave() { - doReturn(6l).when(nativeConnection).lastSave(); + doReturn(6L).when(nativeConnection).lastSave(); actual.add(connection.lastSave()); - verifyResults(Arrays.asList(new Object[] { 6l })); + verifyResults(Collections.singletonList(6L)); } @Test public void testLIndexBytes() { - doReturn(barBytes).when(nativeConnection).lIndex(fooBytes, 8l); - actual.add(connection.lIndex(fooBytes, 8l)); + doReturn(barBytes).when(nativeConnection).lIndex(fooBytes, 8L); + actual.add(connection.lIndex(fooBytes, 8L)); verifyResults(Arrays.asList(new Object[] { barBytes })); } @Test public void testLIndex() { - doReturn(barBytes).when(nativeConnection).lIndex(fooBytes, 8l); - actual.add(connection.lIndex(foo, 8l)); - verifyResults(Arrays.asList(new Object[] { bar })); + doReturn(barBytes).when(nativeConnection).lIndex(fooBytes, 8L); + actual.add(connection.lIndex(foo, 8L)); + verifyResults(Collections.singletonList(bar)); } @Test public void testLInsertBytes() { - doReturn(8l).when(nativeConnection).lInsert(fooBytes, Position.AFTER, fooBytes, barBytes); + doReturn(8L).when(nativeConnection).lInsert(fooBytes, Position.AFTER, fooBytes, barBytes); actual.add(connection.lInsert(fooBytes, Position.AFTER, fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLInsert() { - doReturn(8l).when(nativeConnection).lInsert(fooBytes, Position.AFTER, fooBytes, barBytes); + doReturn(8L).when(nativeConnection).lInsert(fooBytes, Position.AFTER, fooBytes, barBytes); actual.add(connection.lInsert(foo, Position.AFTER, foo, bar)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLLenBytes() { - doReturn(8l).when(nativeConnection).lLen(fooBytes); + doReturn(8L).when(nativeConnection).lLen(fooBytes); actual.add(connection.lLen(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLLen() { - doReturn(8l).when(nativeConnection).lLen(fooBytes); + doReturn(8L).when(nativeConnection).lLen(fooBytes); actual.add(connection.lLen(foo)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test @@ -665,141 +666,140 @@ public class DefaultStringRedisConnectionTests { public void testLPop() { doReturn(barBytes).when(nativeConnection).lPop(fooBytes); actual.add(connection.lPop(foo)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testLPushBytes() { - doReturn(8l).when(nativeConnection).lPush(fooBytes, barBytes); + doReturn(8L).when(nativeConnection).lPush(fooBytes, barBytes); actual.add(connection.lPush(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLPush() { - doReturn(8l).when(nativeConnection).lPush(fooBytes, barBytes); + doReturn(8L).when(nativeConnection).lPush(fooBytes, barBytes); actual.add(connection.lPush(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLPushXBytes() { - doReturn(8l).when(nativeConnection).lPushX(fooBytes, barBytes); + doReturn(8L).when(nativeConnection).lPushX(fooBytes, barBytes); actual.add(connection.lPushX(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLPushX() { - doReturn(8l).when(nativeConnection).lPushX(fooBytes, barBytes); + doReturn(8L).when(nativeConnection).lPushX(fooBytes, barBytes); actual.add(connection.lPushX(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 8l })); + verifyResults(Collections.singletonList(8L)); } @Test public void testLRangeBytes() { - doReturn(bytesList).when(nativeConnection).lRange(fooBytes, 1l, 2l); - actual.add(connection.lRange(fooBytes, 1l, 2l)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + doReturn(bytesList).when(nativeConnection).lRange(fooBytes, 1L, 2L); + actual.add(connection.lRange(fooBytes, 1L, 2L)); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testLRange() { - doReturn(bytesList).when(nativeConnection).lRange(fooBytes, 1l, 2l); - actual.add(connection.lRange(foo, 1l, 2l)); - verifyResults(Arrays.asList(new Object[] { stringList })); + doReturn(bytesList).when(nativeConnection).lRange(fooBytes, 1L, 2L); + actual.add(connection.lRange(foo, 1L, 2L)); + verifyResults(Collections.singletonList(stringList)); } @Test public void testLRemBytes() { - doReturn(8l).when(nativeConnection).lRem(fooBytes, 1l, barBytes); - actual.add(connection.lRem(fooBytes, 1l, barBytes)); - verifyResults(Arrays.asList(new Object[] { 8l })); + doReturn(8L).when(nativeConnection).lRem(fooBytes, 1L, barBytes); + actual.add(connection.lRem(fooBytes, 1L, barBytes)); + verifyResults(Collections.singletonList(8L)); } @Test public void testLRem() { - doReturn(8l).when(nativeConnection).lRem(fooBytes, 1l, barBytes); - actual.add(connection.lRem(foo, 1l, bar)); - verifyResults(Arrays.asList(new Object[] { 8l })); + doReturn(8L).when(nativeConnection).lRem(fooBytes, 1L, barBytes); + actual.add(connection.lRem(foo, 1L, bar)); + verifyResults(Collections.singletonList(8L)); } @Test public void testMGetBytes() { doReturn(bytesList).when(nativeConnection).mGet(fooBytes); actual.add(connection.mGet(fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testMGet() { doReturn(bytesList).when(nativeConnection).mGet(fooBytes); actual.add(connection.mGet(foo)); - verifyResults(Arrays.asList(new Object[] { stringList })); + verifyResults(Collections.singletonList(stringList)); } @Test public void testMSetNXBytes() { doReturn(true).when(nativeConnection).mSetNX(bytesMap); actual.add(connection.mSetNX(bytesMap)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } - @SuppressWarnings("unchecked") @Test public void testMSetNXString() { doReturn(true).when(nativeConnection).mSetNX(anyMap()); actual.add(connection.mSetNXString(stringMap)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testPersistBytes() { doReturn(true).when(nativeConnection).persist(fooBytes); actual.add(connection.persist(fooBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testPersist() { doReturn(true).when(nativeConnection).persist(fooBytes); actual.add(connection.persist(foo)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testMoveBytes() { doReturn(true).when(nativeConnection).move(fooBytes, 1); actual.add(connection.move(fooBytes, 1)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testMove() { doReturn(true).when(nativeConnection).move(fooBytes, 1); actual.add(connection.move(foo, 1)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testPing() { doReturn("pong").when(nativeConnection).ping(); actual.add(connection.ping()); - verifyResults(Arrays.asList(new Object[] { "pong" })); + verifyResults(Collections.singletonList("pong")); } @Test public void testPublishBytes() { - doReturn(2l).when(nativeConnection).publish(fooBytes, barBytes); + doReturn(2L).when(nativeConnection).publish(fooBytes, barBytes); actual.add(connection.publish(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 2l })); + verifyResults(Collections.singletonList(2L)); } @Test public void testPublish() { - doReturn(2l).when(nativeConnection).publish(fooBytes, barBytes); + doReturn(2L).when(nativeConnection).publish(fooBytes, barBytes); actual.add(connection.publish(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 2l })); + verifyResults(Collections.singletonList(2L)); } @Test @@ -813,14 +813,14 @@ public class DefaultStringRedisConnectionTests { public void testRenameNXBytes() { doReturn(true).when(nativeConnection).renameNX(fooBytes, barBytes); actual.add(connection.renameNX(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testRenameNX() { doReturn(true).when(nativeConnection).renameNX(fooBytes, barBytes); actual.add(connection.renameNX(foo, bar)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test @@ -834,7 +834,7 @@ public class DefaultStringRedisConnectionTests { public void testRPop() { doReturn(barBytes).when(nativeConnection).rPop(fooBytes); actual.add(connection.rPop(foo)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test @@ -848,109 +848,109 @@ public class DefaultStringRedisConnectionTests { public void testRPopLPush() { doReturn(barBytes).when(nativeConnection).rPopLPush(fooBytes, barBytes); actual.add(connection.rPopLPush(foo, bar)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testRPushBytes() { - doReturn(4l).when(nativeConnection).rPush(fooBytes, barBytes); + doReturn(4L).when(nativeConnection).rPush(fooBytes, barBytes); actual.add(connection.rPush(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 4l })); + verifyResults(Collections.singletonList(4L)); } @Test public void testRPush() { - doReturn(4l).when(nativeConnection).rPush(fooBytes, barBytes); + doReturn(4L).when(nativeConnection).rPush(fooBytes, barBytes); actual.add(connection.rPush(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 4l })); + verifyResults(Collections.singletonList(4L)); } @Test public void testRPushXBytes() { - doReturn(4l).when(nativeConnection).rPushX(fooBytes, barBytes); + doReturn(4L).when(nativeConnection).rPushX(fooBytes, barBytes); actual.add(connection.rPushX(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 4l })); + verifyResults(Collections.singletonList(4L)); } @Test public void testRPushX() { - doReturn(4l).when(nativeConnection).rPushX(fooBytes, barBytes); + doReturn(4L).when(nativeConnection).rPushX(fooBytes, barBytes); actual.add(connection.rPushX(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 4l })); + verifyResults(Collections.singletonList(4L)); } @Test public void testSAddBytes() { - doReturn(1l).when(nativeConnection).sAdd(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).sAdd(fooBytes, barBytes); actual.add(connection.sAdd(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testSAdd() { - doReturn(1l).when(nativeConnection).sAdd(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).sAdd(fooBytes, barBytes); actual.add(connection.sAdd(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testSCardBytes() { - doReturn(4l).when(nativeConnection).sCard(fooBytes); + doReturn(4L).when(nativeConnection).sCard(fooBytes); actual.add(connection.sCard(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 4l })); + verifyResults(Collections.singletonList(4L)); } @Test public void testSCard() { - doReturn(4l).when(nativeConnection).sCard(fooBytes); + doReturn(4L).when(nativeConnection).sCard(fooBytes); actual.add(connection.sCard(foo)); - verifyResults(Arrays.asList(new Object[] { 4l })); + verifyResults(Collections.singletonList(4L)); } @Test public void testSDiffBytes() { doReturn(bytesSet).when(nativeConnection).sDiff(fooBytes); actual.add(connection.sDiff(fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testSDiff() { doReturn(bytesSet).when(nativeConnection).sDiff(fooBytes); actual.add(connection.sDiff(foo)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testSDiffStoreBytes() { - doReturn(3l).when(nativeConnection).sDiffStore(fooBytes, barBytes); + doReturn(3L).when(nativeConnection).sDiffStore(fooBytes, barBytes); actual.add(connection.sDiffStore(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testSDiffStore() { - doReturn(3l).when(nativeConnection).sDiffStore(fooBytes, barBytes); + doReturn(3L).when(nativeConnection).sDiffStore(fooBytes, barBytes); actual.add(connection.sDiffStore(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testSetNXBytes() { doReturn(true).when(nativeConnection).setNX(fooBytes, barBytes); actual.add(connection.setNX(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testSetNX() { doReturn(true).when(nativeConnection).setNX(fooBytes, barBytes); actual.add(connection.setNX(foo, bar)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test // DATAREDIS-271 - public void testPSetExShouldDelegateCallToNativeConnection() { + void testPSetExShouldDelegateCallToNativeConnection() { connection.pSetEx(fooBytes, 10L, barBytes); verify(nativeConnection, times(1)).pSetEx(eq(fooBytes), eq(10L), eq(barBytes)); @@ -960,98 +960,98 @@ public class DefaultStringRedisConnectionTests { public void testSInterBytes() { doReturn(bytesSet).when(nativeConnection).sInter(fooBytes, barBytes); actual.add(connection.sInter(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testSInter() { doReturn(bytesSet).when(nativeConnection).sInter(fooBytes, barBytes); actual.add(connection.sInter(foo, bar)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testSInterStoreBytes() { - doReturn(3l).when(nativeConnection).sInterStore(fooBytes, barBytes); + doReturn(3L).when(nativeConnection).sInterStore(fooBytes, barBytes); actual.add(connection.sInterStore(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testSInterStore() { - doReturn(3l).when(nativeConnection).sInterStore(fooBytes, barBytes); + doReturn(3L).when(nativeConnection).sInterStore(fooBytes, barBytes); actual.add(connection.sInterStore(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testSIsMemberBytes() { doReturn(true).when(nativeConnection).sIsMember(fooBytes, barBytes); actual.add(connection.sIsMember(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testSIsMember() { doReturn(true).when(nativeConnection).sIsMember(fooBytes, barBytes); actual.add(connection.sIsMember(foo, bar)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testSMembersBytes() { doReturn(bytesSet).when(nativeConnection).sMembers(fooBytes); actual.add(connection.sMembers(fooBytes)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testSMembers() { doReturn(bytesSet).when(nativeConnection).sMembers(fooBytes); actual.add(connection.sMembers(foo)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testSMoveBytes() { doReturn(true).when(nativeConnection).sMove(fooBytes, barBytes, fooBytes); actual.add(connection.sMove(fooBytes, barBytes, fooBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testSMove() { doReturn(true).when(nativeConnection).sMove(fooBytes, barBytes, fooBytes); actual.add(connection.sMove(foo, bar, foo)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testSortStoreBytes() { - doReturn(3l).when(nativeConnection).sort(fooBytes, null, barBytes); + doReturn(3L).when(nativeConnection).sort(fooBytes, null, barBytes); actual.add(connection.sort(fooBytes, null, barBytes)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testSortStore() { - doReturn(3l).when(nativeConnection).sort(fooBytes, null, barBytes); + doReturn(3L).when(nativeConnection).sort(fooBytes, null, barBytes); actual.add(connection.sort(foo, null, bar)); - verifyResults(Arrays.asList(new Object[] { 3l })); + verifyResults(Collections.singletonList(3L)); } @Test public void testSortBytes() { doReturn(bytesList).when(nativeConnection).sort(fooBytes, null); actual.add(connection.sort(fooBytes, null)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testSort() { doReturn(bytesList).when(nativeConnection).sort(fooBytes, null); actual.add(connection.sort(foo, null)); - verifyResults(Arrays.asList(new Object[] { stringList })); + verifyResults(Collections.singletonList(stringList)); } @Test @@ -1065,7 +1065,7 @@ public class DefaultStringRedisConnectionTests { public void testSPop() { doReturn(barBytes).when(nativeConnection).sPop(fooBytes); actual.add(connection.sPop(foo)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test @@ -1079,133 +1079,133 @@ public class DefaultStringRedisConnectionTests { public void testSRandMember() { doReturn(barBytes).when(nativeConnection).sRandMember(fooBytes); actual.add(connection.sRandMember(foo)); - verifyResults(Arrays.asList(new Object[] { bar })); + verifyResults(Collections.singletonList(bar)); } @Test public void testSRandMemberCountBytes() { - doReturn(bytesList).when(nativeConnection).sRandMember(fooBytes, 5l); - actual.add(connection.sRandMember(fooBytes, 5l)); - verifyResults(Arrays.asList(new Object[] { bytesList })); + doReturn(bytesList).when(nativeConnection).sRandMember(fooBytes, 5L); + actual.add(connection.sRandMember(fooBytes, 5L)); + verifyResults(Collections.singletonList(bytesList)); } @Test public void testSRandMemberCount() { - doReturn(bytesList).when(nativeConnection).sRandMember(fooBytes, 5l); - actual.add(connection.sRandMember(foo, 5l)); - verifyResults(Arrays.asList(new Object[] { stringList })); + doReturn(bytesList).when(nativeConnection).sRandMember(fooBytes, 5L); + actual.add(connection.sRandMember(foo, 5L)); + verifyResults(Collections.singletonList(stringList)); } @Test public void testSRemBytes() { - doReturn(1l).when(nativeConnection).sRem(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).sRem(fooBytes, barBytes); actual.add(connection.sRem(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testSRem() { - doReturn(1l).when(nativeConnection).sRem(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).sRem(fooBytes, barBytes); actual.add(connection.sRem(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testStrLenBytes() { - doReturn(5l).when(nativeConnection).strLen(fooBytes); + doReturn(5L).when(nativeConnection).strLen(fooBytes); actual.add(connection.strLen(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testStrLen() { - doReturn(5l).when(nativeConnection).strLen(fooBytes); + doReturn(5L).when(nativeConnection).strLen(fooBytes); actual.add(connection.strLen(foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testBitCountBytes() { - doReturn(5l).when(nativeConnection).bitCount(fooBytes); + doReturn(5L).when(nativeConnection).bitCount(fooBytes); actual.add(connection.bitCount(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testBitCount() { - doReturn(5l).when(nativeConnection).bitCount(fooBytes); + doReturn(5L).when(nativeConnection).bitCount(fooBytes); actual.add(connection.bitCount(foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testBitCountRangeBytes() { - doReturn(5l).when(nativeConnection).bitCount(fooBytes, 2l, 5l); - actual.add(connection.bitCount(fooBytes, 2l, 5l)); - verifyResults(Arrays.asList(new Object[] { 5l })); + doReturn(5L).when(nativeConnection).bitCount(fooBytes, 2L, 5L); + actual.add(connection.bitCount(fooBytes, 2L, 5L)); + verifyResults(Collections.singletonList(5L)); } @Test public void testBitCountRange() { - doReturn(5l).when(nativeConnection).bitCount(fooBytes, 2l, 5l); - actual.add(connection.bitCount(foo, 2l, 5l)); - verifyResults(Arrays.asList(new Object[] { 5l })); + doReturn(5L).when(nativeConnection).bitCount(fooBytes, 2L, 5L); + actual.add(connection.bitCount(foo, 2L, 5L)); + verifyResults(Collections.singletonList(5L)); } @Test public void testBitOpBytes() { - doReturn(5l).when(nativeConnection).bitOp(BitOperation.AND, fooBytes, barBytes); + doReturn(5L).when(nativeConnection).bitOp(BitOperation.AND, fooBytes, barBytes); actual.add(connection.bitOp(BitOperation.AND, fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testBitOp() { - doReturn(5l).when(nativeConnection).bitOp(BitOperation.AND, fooBytes, barBytes); + doReturn(5L).when(nativeConnection).bitOp(BitOperation.AND, fooBytes, barBytes); actual.add(connection.bitOp(BitOperation.AND, foo, bar)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testSUnionBytes() { doReturn(bytesSet).when(nativeConnection).sUnion(fooBytes, barBytes); actual.add(connection.sUnion(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testSUnion() { doReturn(bytesSet).when(nativeConnection).sUnion(fooBytes, barBytes); actual.add(connection.sUnion(foo, bar)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testSUnionStoreBytes() { - doReturn(5l).when(nativeConnection).sUnionStore(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).sUnionStore(fooBytes, barBytes); actual.add(connection.sUnionStore(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testSUnionStore() { - doReturn(5l).when(nativeConnection).sUnionStore(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).sUnionStore(fooBytes, barBytes); actual.add(connection.sUnionStore(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testTtlBytes() { - doReturn(5l).when(nativeConnection).ttl(fooBytes); + doReturn(5L).when(nativeConnection).ttl(fooBytes); actual.add(connection.ttl(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testTtl() { - doReturn(5l).when(nativeConnection).ttl(fooBytes); + doReturn(5L).when(nativeConnection).ttl(fooBytes); actual.add(connection.ttl(foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test // DATAREDIS-526 @@ -1214,44 +1214,44 @@ public class DefaultStringRedisConnectionTests { doReturn(5L).when(nativeConnection).ttl(fooBytes, TimeUnit.SECONDS); actual.add(connection.ttl(foo, TimeUnit.SECONDS)); - verifyResults(Arrays.asList(new Object[] { 5L })); + verifyResults(Collections.singletonList(5L)); } @Test public void testTypeBytes() { doReturn(DataType.HASH).when(nativeConnection).type(fooBytes); actual.add(connection.type(fooBytes)); - verifyResults(Arrays.asList(new Object[] { DataType.HASH })); + verifyResults(Collections.singletonList(DataType.HASH)); } @Test public void testType() { doReturn(DataType.HASH).when(nativeConnection).type(fooBytes); actual.add(connection.type(foo)); - verifyResults(Arrays.asList(new Object[] { DataType.HASH })); + verifyResults(Collections.singletonList(DataType.HASH)); } @Test public void testZAddBytes() { doReturn(true).when(nativeConnection).zAdd(fooBytes, 3d, barBytes); actual.add(connection.zAdd(fooBytes, 3d, barBytes)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testZAdd() { doReturn(true).when(nativeConnection).zAdd(fooBytes, 3d, barBytes); actual.add(connection.zAdd(foo, 3d, bar)); - verifyResults(Arrays.asList(new Object[] { true })); + verifyResults(Collections.singletonList(true)); } @Test public void testZAddMultipleBytes() { Set tuples = new HashSet<>(); tuples.add(new DefaultTuple(barBytes, 3.0)); - doReturn(1l).when(nativeConnection).zAdd(fooBytes, tuples); + doReturn(1L).when(nativeConnection).zAdd(fooBytes, tuples); actual.add(connection.zAdd(fooBytes, tuples)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test @@ -1260,401 +1260,401 @@ public class DefaultStringRedisConnectionTests { tuples.add(new DefaultTuple(barBytes, 3.0)); Set strTuples = new HashSet<>(); strTuples.add(new DefaultStringTuple(barBytes, bar, 3.0)); - doReturn(1l).when(nativeConnection).zAdd(fooBytes, tuples); + doReturn(1L).when(nativeConnection).zAdd(fooBytes, tuples); actual.add(connection.zAdd(foo, strTuples)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testZCardBytes() { - doReturn(5l).when(nativeConnection).zCard(fooBytes); + doReturn(5L).when(nativeConnection).zCard(fooBytes); actual.add(connection.zCard(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZCard() { - doReturn(5l).when(nativeConnection).zCard(fooBytes); + doReturn(5L).when(nativeConnection).zCard(fooBytes); actual.add(connection.zCard(foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZCountBytes() { - doReturn(5l).when(nativeConnection).zCount(fooBytes, 2d, 3d); + doReturn(5L).when(nativeConnection).zCount(fooBytes, 2d, 3d); actual.add(connection.zCount(fooBytes, 2d, 3d)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZCount() { - doReturn(5l).when(nativeConnection).zCount(fooBytes, 2d, 3d); + doReturn(5L).when(nativeConnection).zCount(fooBytes, 2d, 3d); actual.add(connection.zCount(foo, 2d, 3d)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZIncrByBytes() { doReturn(3d).when(nativeConnection).zIncrBy(fooBytes, 2d, barBytes); actual.add(connection.zIncrBy(fooBytes, 2d, barBytes)); - verifyResults(Arrays.asList(new Object[] { 3d })); + verifyResults(Collections.singletonList(3d)); } @Test public void testZIncrBy() { doReturn(3d).when(nativeConnection).zIncrBy(fooBytes, 2d, barBytes); actual.add(connection.zIncrBy(foo, 2d, bar)); - verifyResults(Arrays.asList(new Object[] { 3d })); + verifyResults(Collections.singletonList(3d)); } @Test public void testZInterStoreAggWeightsBytes() { - doReturn(5l).when(nativeConnection).zInterStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); + doReturn(5L).when(nativeConnection).zInterStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zInterStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZInterStoreAggWeights() { - doReturn(5l).when(nativeConnection).zInterStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); + doReturn(5L).when(nativeConnection).zInterStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zInterStore(foo, Aggregate.MAX, new int[0], foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZInterStoreBytes() { - doReturn(5l).when(nativeConnection).zInterStore(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zInterStore(fooBytes, barBytes); actual.add(connection.zInterStore(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZInterStore() { - doReturn(5l).when(nativeConnection).zInterStore(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zInterStore(fooBytes, barBytes); actual.add(connection.zInterStore(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRangeBytes() { - doReturn(bytesSet).when(nativeConnection).zRange(fooBytes, 1l, 3l); - actual.add(connection.zRange(fooBytes, 1l, 3l)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + doReturn(bytesSet).when(nativeConnection).zRange(fooBytes, 1L, 3L); + actual.add(connection.zRange(fooBytes, 1L, 3L)); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testZRange() { - doReturn(bytesSet).when(nativeConnection).zRange(fooBytes, 1l, 3l); - actual.add(connection.zRange(foo, 1l, 3l)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + doReturn(bytesSet).when(nativeConnection).zRange(fooBytes, 1L, 3L); + actual.add(connection.zRange(foo, 1L, 3L)); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testZRangeByScoreOffsetCountBytes() { - doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRangeByScore(fooBytes, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRangeByScore(fooBytes, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testZRangeByScoreOffsetCount() { - doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRangeByScore(foo, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRangeByScore(foo, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testZRangeByScoreBytes() { doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d); actual.add(connection.zRangeByScore(fooBytes, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testZRangeByScore() { doReturn(bytesSet).when(nativeConnection).zRangeByScore(fooBytes, 1d, 3d); actual.add(connection.zRangeByScore(foo, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testZRangeByScoreWithScoresOffsetCountBytes() { - doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { tupleSet })); + doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRangeByScoreWithScores(fooBytes, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(tupleSet)); } @Test public void testZRangeByScoreWithScoresOffsetCount() { - doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRangeByScoreWithScores(foo, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRangeByScoreWithScores(foo, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(stringTupleSet)); } @Test public void testZRangeByScoreWithScoresBytes() { doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d); actual.add(connection.zRangeByScoreWithScores(fooBytes, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { tupleSet })); + verifyResults(Collections.singletonList(tupleSet)); } @Test public void testZRangeByScoreWithScores() { doReturn(tupleSet).when(nativeConnection).zRangeByScoreWithScores(fooBytes, 1d, 3d); actual.add(connection.zRangeByScoreWithScores(foo, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + verifyResults(Collections.singletonList(stringTupleSet)); } @Test public void testZRangeWithScoresBytes() { - doReturn(tupleSet).when(nativeConnection).zRangeWithScores(fooBytes, 1l, 3l); - actual.add(connection.zRangeWithScores(fooBytes, 1l, 3l)); - verifyResults(Arrays.asList(new Object[] { tupleSet })); + doReturn(tupleSet).when(nativeConnection).zRangeWithScores(fooBytes, 1L, 3L); + actual.add(connection.zRangeWithScores(fooBytes, 1L, 3L)); + verifyResults(Collections.singletonList(tupleSet)); } @Test public void testZRangeWithScores() { - doReturn(tupleSet).when(nativeConnection).zRangeWithScores(fooBytes, 1l, 3l); - actual.add(connection.zRangeWithScores(foo, 1l, 3l)); - verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + doReturn(tupleSet).when(nativeConnection).zRangeWithScores(fooBytes, 1L, 3L); + actual.add(connection.zRangeWithScores(foo, 1L, 3L)); + verifyResults(Collections.singletonList(stringTupleSet)); } @Test public void testZRevRangeByScoreOffsetCountBytes() { - doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRevRangeByScore(fooBytes, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRevRangeByScore(fooBytes, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testZRevRangeByScoreOffsetCount() { - doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRevRangeByScore(foo, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRevRangeByScore(foo, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testZRevRangeByScoreBytes() { doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d); actual.add(connection.zRevRangeByScore(fooBytes, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testZRevRangeByScore() { doReturn(bytesSet).when(nativeConnection).zRevRangeByScore(fooBytes, 1d, 3d); actual.add(connection.zRevRangeByScore(foo, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testZRevRangeByScoreWithScoresOffsetCountBytes() { - doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { tupleSet })); + doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(tupleSet)); } @Test public void testZRevRangeByScoreWithScoresOffsetCount() { - doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5l, 7l); - actual.add(connection.zRevRangeByScoreWithScores(foo, 1d, 3d, 5l, 7l)); - verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d, 5L, 7L); + actual.add(connection.zRevRangeByScoreWithScores(foo, 1d, 3d, 5L, 7L)); + verifyResults(Collections.singletonList(stringTupleSet)); } @Test public void testZRevRangeByScoreWithScoresBytes() { doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d); actual.add(connection.zRevRangeByScoreWithScores(fooBytes, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { tupleSet })); + verifyResults(Collections.singletonList(tupleSet)); } @Test public void testZRevRangeByScoreWithScores() { doReturn(tupleSet).when(nativeConnection).zRevRangeByScoreWithScores(fooBytes, 1d, 3d); actual.add(connection.zRevRangeByScoreWithScores(foo, 1d, 3d)); - verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + verifyResults(Collections.singletonList(stringTupleSet)); } @Test public void testZRankBytes() { - doReturn(5l).when(nativeConnection).zRank(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zRank(fooBytes, barBytes); actual.add(connection.zRank(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRank() { - doReturn(5l).when(nativeConnection).zRank(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zRank(fooBytes, barBytes); actual.add(connection.zRank(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRemBytes() { - doReturn(1l).when(nativeConnection).zRem(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).zRem(fooBytes, barBytes); actual.add(connection.zRem(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testZRem() { - doReturn(1l).when(nativeConnection).zRem(fooBytes, barBytes); + doReturn(1L).when(nativeConnection).zRem(fooBytes, barBytes); actual.add(connection.zRem(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 1l })); + verifyResults(Collections.singletonList(1L)); } @Test public void testZRemRangeBytes() { - doReturn(5l).when(nativeConnection).zRemRange(fooBytes, 2l, 5l); - actual.add(connection.zRemRange(fooBytes, 2l, 5l)); - verifyResults(Arrays.asList(new Object[] { 5l })); + doReturn(5L).when(nativeConnection).zRemRange(fooBytes, 2L, 5L); + actual.add(connection.zRemRange(fooBytes, 2L, 5L)); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRemRange() { - doReturn(5l).when(nativeConnection).zRemRange(fooBytes, 2l, 5l); - actual.add(connection.zRemRange(foo, 2l, 5l)); - verifyResults(Arrays.asList(new Object[] { 5l })); + doReturn(5L).when(nativeConnection).zRemRange(fooBytes, 2L, 5L); + actual.add(connection.zRemRange(foo, 2L, 5L)); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRemRangeByScoreBytes() { - doReturn(5l).when(nativeConnection).zRemRangeByScore(fooBytes, 2l, 5l); - actual.add(connection.zRemRangeByScore(fooBytes, 2l, 5l)); - verifyResults(Arrays.asList(new Object[] { 5l })); + doReturn(5L).when(nativeConnection).zRemRangeByScore(fooBytes, 2L, 5L); + actual.add(connection.zRemRangeByScore(fooBytes, 2L, 5L)); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRemRangeByScore() { - doReturn(5l).when(nativeConnection).zRemRangeByScore(fooBytes, 2l, 5l); - actual.add(connection.zRemRangeByScore(foo, 2l, 5l)); - verifyResults(Arrays.asList(new Object[] { 5l })); + doReturn(5L).when(nativeConnection).zRemRangeByScore(fooBytes, 2L, 5L); + actual.add(connection.zRemRangeByScore(foo, 2L, 5L)); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRevRangeBytes() { - doReturn(bytesSet).when(nativeConnection).zRevRange(fooBytes, 3l, 4l); - actual.add(connection.zRevRange(fooBytes, 3l, 4l)); - verifyResults(Arrays.asList(new Object[] { bytesSet })); + doReturn(bytesSet).when(nativeConnection).zRevRange(fooBytes, 3L, 4L); + actual.add(connection.zRevRange(fooBytes, 3L, 4L)); + verifyResults(Collections.singletonList(bytesSet)); } @Test public void testZRevRange() { - doReturn(bytesSet).when(nativeConnection).zRevRange(fooBytes, 3l, 4l); - actual.add(connection.zRevRange(foo, 3l, 4l)); - verifyResults(Arrays.asList(new Object[] { stringSet })); + doReturn(bytesSet).when(nativeConnection).zRevRange(fooBytes, 3L, 4L); + actual.add(connection.zRevRange(foo, 3L, 4L)); + verifyResults(Collections.singletonList(stringSet)); } @Test public void testZRevRangeWithScoresBytes() { - doReturn(tupleSet).when(nativeConnection).zRevRangeWithScores(fooBytes, 3l, 4l); - actual.add(connection.zRevRangeWithScores(fooBytes, 3l, 4l)); - verifyResults(Arrays.asList(new Object[] { tupleSet })); + doReturn(tupleSet).when(nativeConnection).zRevRangeWithScores(fooBytes, 3L, 4L); + actual.add(connection.zRevRangeWithScores(fooBytes, 3L, 4L)); + verifyResults(Collections.singletonList(tupleSet)); } @Test public void testZRevRangeWithScores() { - doReturn(tupleSet).when(nativeConnection).zRevRangeWithScores(fooBytes, 3l, 4l); - actual.add(connection.zRevRangeWithScores(foo, 3l, 4l)); - verifyResults(Arrays.asList(new Object[] { stringTupleSet })); + doReturn(tupleSet).when(nativeConnection).zRevRangeWithScores(fooBytes, 3L, 4L); + actual.add(connection.zRevRangeWithScores(foo, 3L, 4L)); + verifyResults(Collections.singletonList(stringTupleSet)); } @Test public void testZRevRankBytes() { - doReturn(5l).when(nativeConnection).zRevRank(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zRevRank(fooBytes, barBytes); actual.add(connection.zRevRank(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZRevRank() { - doReturn(5l).when(nativeConnection).zRevRank(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zRevRank(fooBytes, barBytes); actual.add(connection.zRevRank(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZScoreBytes() { doReturn(3d).when(nativeConnection).zScore(fooBytes, barBytes); actual.add(connection.zScore(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 3d })); + verifyResults(Collections.singletonList(3d)); } @Test public void testZScore() { doReturn(3d).when(nativeConnection).zScore(fooBytes, barBytes); actual.add(connection.zScore(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 3d })); + verifyResults(Collections.singletonList(3d)); } @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(5l).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); + doReturn(5L).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zUnionStore(fooBytes, Aggregate.MAX, new int[0], fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZUnionStoreAggWeights() { - doReturn(5l).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); + doReturn(5L).when(nativeConnection).zUnionStore(eq(fooBytes), eq(Aggregate.MAX), any(Weights.class), eq(fooBytes)); actual.add(connection.zUnionStore(foo, Aggregate.MAX, new int[0], foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZUnionStoreBytes() { - doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zUnionStore(fooBytes, barBytes); actual.add(connection.zUnionStore(fooBytes, barBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testZUnionStore() { - doReturn(5l).when(nativeConnection).zUnionStore(fooBytes, barBytes); + doReturn(5L).when(nativeConnection).zUnionStore(fooBytes, barBytes); actual.add(connection.zUnionStore(foo, bar)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testPExpireBytes() { - doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l); - actual.add(connection.pExpire(fooBytes, 34l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).pExpire(fooBytes, 34L); + actual.add(connection.pExpire(fooBytes, 34L)); + verifyResults(Collections.singletonList(true)); } @Test public void testPExpire() { - doReturn(true).when(nativeConnection).pExpire(fooBytes, 34l); - actual.add(connection.pExpire(foo, 34l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).pExpire(fooBytes, 34L); + actual.add(connection.pExpire(foo, 34L)); + verifyResults(Collections.singletonList(true)); } @Test public void testPExpireAtBytes() { - doReturn(true).when(nativeConnection).pExpireAt(fooBytes, 34l); - actual.add(connection.pExpireAt(fooBytes, 34l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).pExpireAt(fooBytes, 34L); + actual.add(connection.pExpireAt(fooBytes, 34L)); + verifyResults(Collections.singletonList(true)); } @Test public void testPExpireAt() { - doReturn(true).when(nativeConnection).pExpireAt(fooBytes, 34l); - actual.add(connection.pExpireAt(foo, 34l)); - verifyResults(Arrays.asList(new Object[] { true })); + doReturn(true).when(nativeConnection).pExpireAt(fooBytes, 34L); + actual.add(connection.pExpireAt(foo, 34L)); + verifyResults(Collections.singletonList(true)); } @Test public void testPTtlBytes() { - doReturn(5l).when(nativeConnection).pTtl(fooBytes); + doReturn(5L).when(nativeConnection).pTtl(fooBytes); actual.add(connection.pTtl(fooBytes)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test public void testPTtl() { - doReturn(5l).when(nativeConnection).pTtl(fooBytes); + doReturn(5L).when(nativeConnection).pTtl(fooBytes); actual.add(connection.pTtl(foo)); - verifyResults(Arrays.asList(new Object[] { 5l })); + verifyResults(Collections.singletonList(5L)); } @Test @@ -1668,14 +1668,14 @@ public class DefaultStringRedisConnectionTests { public void testScriptLoadBytes() { doReturn("foo").when(nativeConnection).scriptLoad(fooBytes); actual.add(connection.scriptLoad(fooBytes)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testScriptLoad() { doReturn("foo").when(nativeConnection).scriptLoad(fooBytes); actual.add(connection.scriptLoad(foo)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test @@ -1683,56 +1683,56 @@ public class DefaultStringRedisConnectionTests { List results = Collections.singletonList(true); doReturn(results).when(nativeConnection).scriptExists("456"); actual.add(connection.scriptExists("456")); - verifyResults(Arrays.asList(new Object[] { results })); + verifyResults(Collections.singletonList(results)); } @Test public void testEvalBytes() { doReturn("foo").when(nativeConnection).eval(fooBytes, ReturnType.VALUE, 3, fooBytes); actual.add(connection.eval(fooBytes, ReturnType.VALUE, 3, fooBytes)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testEval() { doReturn("foo").when(nativeConnection).eval(fooBytes, ReturnType.VALUE, 3, fooBytes); actual.add(connection.eval(foo, ReturnType.VALUE, 3, foo)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testEvalShaBytes() { doReturn("foo").when(nativeConnection).evalSha("456", ReturnType.VALUE, 3, fooBytes); actual.add(connection.evalSha("456", ReturnType.VALUE, 3, fooBytes)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testEvalSha() { doReturn("foo").when(nativeConnection).evalSha("456", ReturnType.VALUE, 3, fooBytes); actual.add(connection.evalSha("456", ReturnType.VALUE, 3, foo)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testExecute() { - doReturn("foo").when(nativeConnection).execute("something", new byte[0][]); + doReturn("foo").when(nativeConnection).execute("something"); actual.add(connection.execute("something")); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testExecuteByteArgs() { doReturn("foo").when(nativeConnection).execute("something", fooBytes); actual.add(connection.execute("something", fooBytes)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test public void testExecuteStringArgs() { doReturn("foo").when(nativeConnection).execute("something", fooBytes); actual.add(connection.execute("something", foo)); - verifyResults(Arrays.asList(new Object[] { "foo" })); + verifyResults(Collections.singletonList("foo")); } @Test // DATAREDIS-206 @@ -1740,25 +1740,25 @@ public class DefaultStringRedisConnectionTests { doReturn(1L).when(nativeConnection).time(); actual.add(connection.time()); - verifyResults(Arrays.asList(1L)); + verifyResults(Collections.singletonList(1L)); } @Test // DATAREDIS-184 - public void testShutdownInDelegatedCorrectlyToNativeConnection() { + void testShutdownInDelegatedCorrectlyToNativeConnection() { connection.shutdown(ShutdownOption.NOSAVE); verify(nativeConnection, times(1)).shutdown(eq(ShutdownOption.NOSAVE)); } @Test // DATAREDIS-269 - public void settingClientNameShouldDelegateToNativeConnection() { + void settingClientNameShouldDelegateToNativeConnection() { connection.setClientName("foo"); verify(nativeConnection, times(1)).setClientName(eq("foo".getBytes())); } @Test // DATAREDIS-308 - public void pfAddShouldDelegateToNativeConnectionCorrectly() { + void pfAddShouldDelegateToNativeConnectionCorrectly() { connection.pfAdd("hll", "spring", "data", "redis"); verify(nativeConnection, times(1)).pfAdd("hll".getBytes(), "spring".getBytes(), "data".getBytes(), @@ -1766,14 +1766,14 @@ public class DefaultStringRedisConnectionTests { } @Test // DATAREDIS-308 - public void pfCountShouldDelegateToNativeConnectionCorrectly() { + void pfCountShouldDelegateToNativeConnectionCorrectly() { connection.pfCount("hll", "hyperLogLog"); verify(nativeConnection, times(1)).pfCount("hll".getBytes(), "hyperLogLog".getBytes()); } @Test // DATAREDIS-308 - public void pfMergeShouldDelegateToNativeConnectionCorrectly() { + void pfMergeShouldDelegateToNativeConnectionCorrectly() { connection.pfMerge("merged", "spring", "data", "redis"); verify(nativeConnection, times(1)).pfMerge("merged".getBytes(), "spring".getBytes(), "data".getBytes(), @@ -1781,7 +1781,7 @@ public class DefaultStringRedisConnectionTests { } @Test // DATAREDIS-270 - public void testGetClientNameIsDelegatedCorrectlyToNativeConnection() { + void testGetClientNameIsDelegatedCorrectlyToNativeConnection() { actual.add(connection.getClientName()); verify(nativeConnection, times(1)).getClientName(); @@ -1790,7 +1790,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAddBytes() { - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes); + doReturn(1L).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes); actual.add(connection.geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes)); verifyResults(Collections.singletonList(1L)); @@ -1799,7 +1799,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAdd() { - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes); + doReturn(1L).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes); actual.add(connection.geoAdd(foo, new Point(1.23232, 34.2342434), bar)); verifyResults(Collections.singletonList(1L)); @@ -1808,7 +1808,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAddWithGeoLocationBytes() { - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434))); + doReturn(1L).when(nativeConnection).geoAdd(fooBytes, new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434))); actual.add(connection.geoAdd(fooBytes, new GeoLocation<>(barBytes, new Point(1.23232, 34.2342434)))); verifyResults(Collections.singletonList(1L)); @@ -1817,7 +1817,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAddWithGeoLocation() { - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes); + doReturn(1L).when(nativeConnection).geoAdd(fooBytes, new Point(1.23232, 34.2342434), barBytes); actual.add(connection.geoAdd(foo, new GeoLocation<>(bar, new Point(1.23232, 34.2342434)))); verifyResults(Collections.singletonList(1L)); @@ -1827,7 +1827,7 @@ public class DefaultStringRedisConnectionTests { public void testGeoAddCoordinateMapBytes() { Map memberGeoCoordinateMap = Collections.singletonMap(barBytes, new Point(1.23232, 34.2342434)); - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap); + doReturn(1L).when(nativeConnection).geoAdd(fooBytes, memberGeoCoordinateMap); actual.add(connection.geoAdd(fooBytes, memberGeoCoordinateMap)); verifyResults(Collections.singletonList(1L)); @@ -1836,7 +1836,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAddCoordinateMap() { - doReturn(1l).when(nativeConnection).geoAdd(any(byte[].class), anyMap()); + doReturn(1L).when(nativeConnection).geoAdd(any(byte[].class), anyMap()); actual.add(connection.geoAdd(foo, Collections.singletonMap(bar, new Point(1.23232, 34.2342434)))); verifyResults(Collections.singletonList(1L)); @@ -1846,7 +1846,7 @@ public class DefaultStringRedisConnectionTests { public void testGeoAddWithIterableOfGeoLocationBytes() { List> values = Collections.singletonList(new GeoLocation<>(barBytes, new Point(1, 2))); - doReturn(1l).when(nativeConnection).geoAdd(fooBytes, values); + doReturn(1L).when(nativeConnection).geoAdd(fooBytes, values); actual.add(connection.geoAdd(fooBytes, values)); verifyResults(Collections.singletonList(1L)); @@ -1855,7 +1855,7 @@ public class DefaultStringRedisConnectionTests { @Test // DATAREDIS-438 public void testGeoAddWithIterableOfGeoLocation() { - doReturn(1l).when(nativeConnection).geoAdd(eq(fooBytes), anyMap()); + doReturn(1L).when(nativeConnection).geoAdd(eq(fooBytes), anyMap()); actual.add(connection.geoAdd(foo, Collections.singletonList(new GeoLocation<>(bar, new Point(1, 2))))); verifyResults(Collections.singletonList(1L)); @@ -1887,7 +1887,7 @@ public class DefaultStringRedisConnectionTests { doReturn(stringList).when(nativeConnection).geoHash(fooBytes, barBytes); actual.add(connection.geoHash(fooBytes, barBytes)); - verifyResults(Arrays.asList(Collections.singletonList(bar))); + verifyResults(Collections.singletonList(Collections.singletonList(bar))); } @Test // DATAREDIS-438 @@ -1896,7 +1896,7 @@ public class DefaultStringRedisConnectionTests { doReturn(stringList).when(nativeConnection).geoHash(fooBytes, barBytes); actual.add(connection.geoHash(foo, bar)); - verifyResults(Arrays.asList(Collections.singletonList(bar))); + verifyResults(Collections.singletonList(Collections.singletonList(bar))); } @Test // DATAREDIS-438 @@ -1905,7 +1905,7 @@ public class DefaultStringRedisConnectionTests { doReturn(points).when(nativeConnection).geoPos(fooBytes, barBytes); actual.add(connection.geoPos(fooBytes, barBytes)); - verifyResults(Arrays.asList(points)); + verifyResults(Collections.singletonList(points)); } @Test // DATAREDIS-438 @@ -1913,7 +1913,7 @@ public class DefaultStringRedisConnectionTests { doReturn(points).when(nativeConnection).geoPos(fooBytes, barBytes); actual.add(connection.geoPos(foo, bar)); - verifyResults(Arrays.asList(points)); + verifyResults(Collections.singletonList(points)); } @Test // DATAREDIS-438 @@ -1922,7 +1922,7 @@ public class DefaultStringRedisConnectionTests { doReturn(geoResults).when(nativeConnection).geoRadius(eq(fooBytes), any()); actual.add(connection.geoRadius(fooBytes, null)); - verifyResults(Arrays.asList(geoResults)); + verifyResults(Collections.singletonList(geoResults)); } @Test // DATAREDIS-438 @@ -1932,7 +1932,8 @@ public class DefaultStringRedisConnectionTests { actual.add( connection.geoRadius(foo, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)))); - verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); + verifyResults( + Collections.singletonList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); } @Test // DATAREDIS-438 @@ -1943,7 +1944,7 @@ public class DefaultStringRedisConnectionTests { actual.add(connection.geoRadius(fooBytes, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam)); - verifyResults(Arrays.asList(geoResults)); + verifyResults(Collections.singletonList(geoResults)); } @Test // DATAREDIS-438 @@ -1954,7 +1955,8 @@ public class DefaultStringRedisConnectionTests { actual.add(connection.geoRadius(foo, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam)); - verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); + verifyResults( + Collections.singletonList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); } @Test // DATAREDIS-438 @@ -1965,7 +1967,7 @@ public class DefaultStringRedisConnectionTests { actual.add(connection.geoRadius(fooBytes, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam)); - verifyResults(Arrays.asList(geoResults)); + verifyResults(Collections.singletonList(geoResults)); } @Test // DATAREDIS-438 @@ -1975,7 +1977,8 @@ public class DefaultStringRedisConnectionTests { actual.add(connection.geoRadius(foo, new Circle(new Point(13.361389, 38.115556), new Distance(10, DistanceUnit.FEET)), geoRadiusParam)); - verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); + verifyResults( + Collections.singletonList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); } @Test // DATAREDIS-438 @@ -1985,7 +1988,7 @@ public class DefaultStringRedisConnectionTests { new Distance(38.115556, DistanceUnit.FEET)); actual.add(connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET))); - verifyResults(Arrays.asList(geoResults)); + verifyResults(Collections.singletonList(geoResults)); } @Test // DATAREDIS-438 @@ -1995,7 +1998,8 @@ public class DefaultStringRedisConnectionTests { new Distance(38.115556, DistanceUnit.FEET)); actual.add(connection.geoRadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET))); - verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); + verifyResults( + Collections.singletonList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); } @Test // DATAREDIS-438 @@ -2007,7 +2011,7 @@ public class DefaultStringRedisConnectionTests { actual.add( connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam)); - verifyResults(Arrays.asList(geoResults)); + verifyResults(Collections.singletonList(geoResults)); } @Test // DATAREDIS-438 @@ -2018,7 +2022,8 @@ public class DefaultStringRedisConnectionTests { new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam); actual.add(connection.geoRadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam)); - verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); + verifyResults( + Collections.singletonList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); } @Test // DATAREDIS-438 @@ -2030,7 +2035,7 @@ public class DefaultStringRedisConnectionTests { actual.add( connection.geoRadiusByMember(fooBytes, barBytes, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam)); - verifyResults(Arrays.asList(geoResults)); + verifyResults(Collections.singletonList(geoResults)); } @Test // DATAREDIS-438 @@ -2041,7 +2046,8 @@ public class DefaultStringRedisConnectionTests { new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam); actual.add(connection.geoRadiusByMember(foo, bar, new Distance(38.115556, DistanceUnit.FEET), geoRadiusParam)); - verifyResults(Arrays.asList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); + verifyResults( + Collections.singletonList(Converters.deserializingGeoResultsConverter(serializer).convert(geoResults))); } @Test // DATAREDIS-864 @@ -2082,7 +2088,6 @@ public class DefaultStringRedisConnectionTests { } @Test // DATAREDIS-864 - @Ignore("Why Mockito? Why?") public void xGroupDelConsumerShouldDelegateAndConvertCorrectly() { Consumer consumer = Consumer.from("consumer-group", "one"); @@ -2123,13 +2128,13 @@ public class DefaultStringRedisConnectionTests { Collections.singletonList(StreamRecords.newRecord().in(bar2).withId("stream-1").ofStrings(stringMap))); } - @Test // DATAREDIS-864 public void xReadShouldDelegateAndConvertCorrectly() { doReturn(Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap))) .when(nativeConnection).xRead(any(), any()); - actual.add(connection.xReadAsString(StreamReadOptions.empty(), StreamOffset.create("stream-1", ReadOffset.latest()))); + actual + .add(connection.xReadAsString(StreamReadOptions.empty(), StreamOffset.create("stream-1", ReadOffset.latest()))); assertThat(getResults()).containsExactly( Collections.singletonList(StreamRecords.newRecord().in(bar2).withId("stream-1").ofStrings(stringMap))); @@ -2140,7 +2145,8 @@ public class DefaultStringRedisConnectionTests { doReturn(Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap))) .when(nativeConnection).xReadGroup(any(), any(), any()); - actual.add(connection.xReadGroupAsString(Consumer.from("groupe", "one"), StreamReadOptions.empty(), StreamOffset.create("stream-1", ReadOffset.latest()))); + actual.add(connection.xReadGroupAsString(Consumer.from("groupe", "one"), StreamReadOptions.empty(), + StreamOffset.create("stream-1", ReadOffset.latest()))); assertThat(getResults()).containsExactly( Collections.singletonList(StreamRecords.newRecord().in(bar2).withId("stream-1").ofStrings(stringMap))); diff --git a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java index 2d31ee0e7..a656f99b1 100644 --- a/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java +++ b/src/test/java/org/springframework/data/redis/connection/DefaultStringRedisConnectionTxTests.java @@ -22,9 +22,9 @@ import java.util.Collections; import java.util.List; import java.util.Properties; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + import org.springframework.data.geo.Distance; import org.springframework.data.redis.connection.RedisGeoCommands.DistanceUnit; import org.springframework.data.redis.connection.stream.RecordId; @@ -37,7 +37,7 @@ import org.springframework.data.redis.connection.stream.StreamRecords; */ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConnectionTests { - @Before + @BeforeEach public void setUp() { super.setUp(); connection.setDeserializePipelineAndTxResults(true); @@ -46,37 +46,37 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testAppend() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testAppend(); } @Test public void testAppendBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testAppendBytes(); } @Test public void testBlPopBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testBlPopBytes(); } @Test public void testBlPop() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testBlPop(); } @Test public void testBrPopBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testBrPopBytes(); } @Test public void testBrPop() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testBrPop(); } @@ -94,43 +94,43 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testDbSize() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testDbSize(); } @Test public void testDecrBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testDecrBytes(); } @Test public void testDecr() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testDecr(); } @Test public void testDecrByBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testDecrByBytes(); } @Test public void testDecrBy() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testDecrBy(); } @Test public void testDelBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testDelBytes(); } @Test public void testDel() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testDel(); } @@ -148,37 +148,37 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testExistsBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testExistsBytes(); } @Test public void testExists() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testExists(); } @Test public void testExpireBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testExpireBytes(); } @Test public void testExpire() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testExpire(); } @Test public void testExpireAtBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testExpireAtBytes(); } @Test public void testExpireAt() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testExpireAt(); } @@ -196,13 +196,13 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testGetBitBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testGetBitBytes(); } @Test public void testGetBit() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testGetBit(); } @@ -212,13 +212,13 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne Properties results = new Properties(); results.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(results)).when(nativeConnection).exec(); super.testGetConfig(); } @Test public void testGetNativeConnection() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testGetNativeConnection(); } @@ -248,25 +248,25 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testHDelBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testHDelBytes(); } @Test public void testHDel() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testHDel(); } @Test public void testHExistsBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testHExistsBytes(); } @Test public void testHExists() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testHExists(); } @@ -284,145 +284,145 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testHGetAllBytes() { - doReturn(Arrays.asList(new Object[] { bytesMap })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesMap)).when(nativeConnection).exec(); super.testHGetAllBytes(); } @Test public void testHGetAll() { - doReturn(Arrays.asList(new Object[] { bytesMap })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesMap)).when(nativeConnection).exec(); super.testHGetAll(); } @Test public void testHIncrByBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testHIncrByBytes(); } @Test public void testHIncrBy() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testHIncrBy(); } @Test public void testHIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).exec(); super.testHIncrByDoubleBytes(); } @Test public void testHIncrByDouble() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).exec(); super.testHIncrByDouble(); } @Test public void testHKeysBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testHKeysBytes(); } @Test public void testHKeys() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testHKeys(); } @Test public void testHLenBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testHLenBytes(); } @Test public void testHLen() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testHLen(); } @Test public void testHMGetBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testHMGetBytes(); } @Test public void testHMGet() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testHMGet(); } @Test public void testHSetBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testHSetBytes(); } @Test public void testHSet() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testHSet(); } @Test public void testHSetNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testHSetNXBytes(); } @Test public void testHSetNX() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testHSetNX(); } @Test public void testHValsBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testHValsBytes(); } @Test public void testHVals() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testHVals(); } @Test public void testIncrBytes() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).exec(); super.testIncrBytes(); } @Test public void testIncr() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).exec(); super.testIncr(); } @Test public void testIncrByBytes() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).exec(); super.testIncrByBytes(); } @Test public void testIncrBy() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).exec(); super.testIncrBy(); } @Test public void testIncrByDoubleBytes() { - doReturn(Arrays.asList(new Object[] { 2d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2d)).when(nativeConnection).exec(); super.testIncrByDoubleBytes(); } @Test public void testIncrByDouble() { - doReturn(Arrays.asList(new Object[] { 2d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2d)).when(nativeConnection).exec(); super.testIncrByDouble(); } @@ -430,7 +430,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne public void testInfo() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { props })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(props)).when(nativeConnection).exec(); super.testInfo(); } @@ -438,25 +438,25 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne public void testInfoBySection() { Properties props = new Properties(); props.put("foo", "bar"); - doReturn(Arrays.asList(new Object[] { props })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(props)).when(nativeConnection).exec(); super.testInfoBySection(); } @Test public void testKeysBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testKeysBytes(); } @Test public void testKeys() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testKeys(); } @Test public void testLastSave() { - doReturn(Arrays.asList(new Object[] { 6l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(6L)).when(nativeConnection).exec(); super.testLastSave(); } @@ -474,25 +474,25 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testLInsertBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLInsertBytes(); } @Test public void testLInsert() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLInsert(); } @Test public void testLLenBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLLenBytes(); } @Test public void testLLen() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLLen(); } @@ -511,115 +511,115 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testLPushBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLPushBytes(); } @Test public void testLPush() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLPush(); } @Test public void testLPushXBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLPushXBytes(); } @Test public void testLPushX() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLPushX(); } @Test public void testLRangeBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testLRangeBytes(); } @Test public void testLRange() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testLRange(); } @Test public void testLRemBytes() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLRemBytes(); } @Test public void testLRem() { - doReturn(Arrays.asList(new Object[] { 8l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(8L)).when(nativeConnection).exec(); super.testLRem(); } @Test public void testMGetBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testMGetBytes(); } @Test public void testMGet() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testMGet(); } @Test public void testMSetNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testMSetNXBytes(); } @Test public void testMSetNXString() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testMSetNXString(); } @Test public void testPersistBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testPersistBytes(); } @Test public void testPersist() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testPersist(); } @Test public void testMoveBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testMoveBytes(); } @Test public void testMove() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testMove(); } @Test public void testPing() { - doReturn(Arrays.asList(new Object[] { "pong" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("pong")).when(nativeConnection).exec(); super.testPing(); } @Test public void testPublishBytes() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).exec(); super.testPublishBytes(); } @Test public void testPublish() { - doReturn(Arrays.asList(new Object[] { 2l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(2L)).when(nativeConnection).exec(); super.testPublish(); } @@ -631,13 +631,13 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testRenameNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testRenameNXBytes(); } @Test public void testRenameNX() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testRenameNX(); } @@ -667,169 +667,169 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testRPushBytes() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).exec(); super.testRPushBytes(); } @Test public void testRPush() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).exec(); super.testRPush(); } @Test public void testRPushXBytes() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).exec(); super.testRPushXBytes(); } @Test public void testRPushX() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).exec(); super.testRPushX(); } @Test public void testSAddBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testSAddBytes(); } @Test public void testSAdd() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testSAdd(); } @Test public void testSCardBytes() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).exec(); super.testSCardBytes(); } @Test public void testSCard() { - doReturn(Arrays.asList(new Object[] { 4l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(4L)).when(nativeConnection).exec(); super.testSCard(); } @Test public void testSDiffBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSDiffBytes(); } @Test public void testSDiff() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSDiff(); } @Test public void testSDiffStoreBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testSDiffStoreBytes(); } @Test public void testSDiffStore() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testSDiffStore(); } @Test public void testSetNXBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testSetNXBytes(); } @Test public void testSetNX() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testSetNX(); } @Test public void testSInterBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSInterBytes(); } @Test public void testSInter() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSInter(); } @Test public void testSInterStoreBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testSInterStoreBytes(); } @Test public void testSInterStore() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testSInterStore(); } @Test public void testSIsMemberBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testSIsMemberBytes(); } @Test public void testSIsMember() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testSIsMember(); } @Test public void testSMembersBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSMembersBytes(); } @Test public void testSMembers() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSMembers(); } @Test public void testSMoveBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testSMoveBytes(); } @Test public void testSMove() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testSMove(); } @Test public void testSortStoreBytes() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testSortStoreBytes(); } @Test public void testSortStore() { - doReturn(Arrays.asList(new Object[] { 3l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3L)).when(nativeConnection).exec(); super.testSortStore(); } @Test public void testSortBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testSortBytes(); } @Test public void testSort() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testSort(); } @@ -859,489 +859,490 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testSRandMemberCountBytes() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testSRandMemberCountBytes(); } @Test public void testSRandMemberCount() { - doReturn(Arrays.asList(new Object[] { bytesList })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesList)).when(nativeConnection).exec(); super.testSRandMemberCount(); } @Test public void testSRemBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testSRemBytes(); } @Test public void testSRem() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testSRem(); } @Test public void testStrLenBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testStrLenBytes(); } @Test public void testStrLen() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testStrLen(); } @Test public void testBitCountBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testBitCountBytes(); } @Test public void testBitCount() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testBitCount(); } @Test public void testBitCountRangeBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testBitCountRangeBytes(); } @Test public void testBitCountRange() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testBitCountRange(); } @Test public void testBitOpBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testBitOpBytes(); } @Test public void testBitOp() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testBitOp(); } @Test public void testSUnionBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSUnionBytes(); } @Test public void testSUnion() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testSUnion(); } @Test public void testSUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testSUnionStoreBytes(); } @Test public void testSUnionStore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testSUnionStore(); } @Test public void testTtlBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testTtlBytes(); } @Test public void testTtl() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testTtl(); } // DATAREDIS-526 @Override + @Test public void testTtlWithTimeUnit() { - doReturn(Arrays.asList(new Object[] { 5L })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testTtl(); } @Test public void testTypeBytes() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(DataType.HASH)).when(nativeConnection).exec(); super.testTypeBytes(); } @Test public void testType() { - doReturn(Arrays.asList(new Object[] { DataType.HASH })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(DataType.HASH)).when(nativeConnection).exec(); super.testType(); } @Test public void testZAddBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testZAddBytes(); } @Test public void testZAdd() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testZAdd(); } @Test public void testZAddMultipleBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testZAddMultipleBytes(); } @Test public void testZAddMultiple() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testZAddMultiple(); } @Test public void testZCardBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZCardBytes(); } @Test public void testZCard() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZCard(); } @Test public void testZCountBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZCountBytes(); } @Test public void testZCount() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZCount(); } @Test public void testZIncrByBytes() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).exec(); super.testZIncrByBytes(); } @Test public void testZIncrBy() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).exec(); super.testZIncrBy(); } @Test public void testZInterStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZInterStoreAggWeightsBytes(); } @Test public void testZInterStoreAggWeights() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZInterStoreAggWeights(); } @Test public void testZInterStoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZInterStoreBytes(); } @Test public void testZInterStore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZInterStore(); } @Test public void testZRangeBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRangeBytes(); } @Test public void testZRange() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRange(); } @Test public void testZRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRangeByScoreOffsetCountBytes(); } @Test public void testZRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRangeByScoreOffsetCount(); } @Test public void testZRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRangeByScoreBytes(); } @Test public void testZRangeByScore() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRangeByScore(); } @Test public void testZRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRangeByScoreWithScoresOffsetCount(); } @Test public void testZRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRangeByScoreWithScoresBytes(); } @Test public void testZRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRangeByScoreWithScores(); } @Test public void testZRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRangeWithScoresBytes(); } @Test public void testZRangeWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRangeWithScores(); } @Test public void testZRevRangeByScoreOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreOffsetCountBytes(); } @Test public void testZRevRangeByScoreOffsetCount() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreOffsetCount(); } @Test public void testZRevRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreBytes(); } @Test public void testZRevRangeByScore() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRevRangeByScore(); } @Test public void testZRevRangeByScoreWithScoresOffsetCountBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreWithScoresOffsetCountBytes(); } @Test public void testZRevRangeByScoreWithScoresOffsetCount() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreWithScoresOffsetCount(); } @Test public void testZRevRangeByScoreWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreWithScoresBytes(); } @Test public void testZRevRangeByScoreWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRevRangeByScoreWithScores(); } @Test public void testZRankBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRankBytes(); } @Test public void testZRank() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRank(); } @Test public void testZRemBytes() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testZRemBytes(); } @Test public void testZRem() { - doReturn(Arrays.asList(new Object[] { 1l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.testZRem(); } @Test public void testZRemRangeBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRemRangeBytes(); } @Test public void testZRemRange() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRemRange(); } @Test public void testZRemRangeByScoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRemRangeByScoreBytes(); } @Test public void testZRemRangeByScore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRemRangeByScore(); } @Test public void testZRevRangeBytes() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRevRangeBytes(); } @Test public void testZRevRange() { - doReturn(Arrays.asList(new Object[] { bytesSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(bytesSet)).when(nativeConnection).exec(); super.testZRevRange(); } @Test public void testZRevRangeWithScoresBytes() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRevRangeWithScoresBytes(); } @Test public void testZRevRangeWithScores() { - doReturn(Arrays.asList(new Object[] { tupleSet })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(tupleSet)).when(nativeConnection).exec(); super.testZRevRangeWithScores(); } @Test public void testZRevRankBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRevRankBytes(); } @Test public void testZRevRank() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZRevRank(); } @Test public void testZScoreBytes() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).exec(); super.testZScoreBytes(); } @Test public void testZScore() { - doReturn(Arrays.asList(new Object[] { 3d })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(3d)).when(nativeConnection).exec(); super.testZScore(); } @Test public void testZUnionStoreAggWeightsBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZUnionStoreAggWeightsBytes(); } @Test public void testZUnionStoreAggWeights() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZUnionStoreAggWeights(); } @Test public void testZUnionStoreBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZUnionStoreBytes(); } @Test public void testZUnionStore() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testZUnionStore(); } @Test public void testPExpireBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testPExpireBytes(); } @Test public void testPExpire() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testPExpire(); } @Test public void testPExpireAtBytes() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testPExpireAtBytes(); } @Test public void testPExpireAt() { - doReturn(Arrays.asList(new Object[] { true })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(true)).when(nativeConnection).exec(); super.testPExpireAt(); } @Test public void testPTtlBytes() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testPTtlBytes(); } @Test public void testPTtl() { - doReturn(Arrays.asList(new Object[] { 5l })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(5L)).when(nativeConnection).exec(); super.testPTtl(); } @@ -1353,70 +1354,70 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test public void testScriptLoadBytes() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testScriptLoadBytes(); } @Test public void testScriptLoad() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testScriptLoad(); } @Test public void testScriptExists() { List results = Collections.singletonList(true); - doReturn(Arrays.asList(new Object[] { results })).when(nativeConnection).exec(); + doReturn(Collections.singletonList(results)).when(nativeConnection).exec(); super.testScriptExists(); } @Test public void testEvalBytes() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testEvalBytes(); } @Test public void testEval() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testEval(); } @Test public void testEvalShaBytes() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testEvalShaBytes(); } @Test public void testEvalSha() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testEvalSha(); } @Test public void testExecute() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testExecute(); } @Test public void testExecuteByteArgs() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testExecuteByteArgs(); } @Test public void testExecuteStringArgs() { - doReturn(Arrays.asList(new Object[] { "foo" })).when(nativeConnection).exec(); + doReturn(Collections.singletonList("foo")).when(nativeConnection).exec(); super.testExecuteStringArgs(); } @Test - public void testDisablePipelineAndTxDeserialize() { + void testDisablePipelineAndTxDeserialize() { connection.setDeserializePipelineAndTxResults(false); doReturn(Arrays.asList(new Object[] { barBytes })).when(nativeConnection).exec(); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { barBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { barBytes }))).when(nativeConnection) .closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); @@ -1428,16 +1429,16 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne // Only call one method, but return 2 results from nativeConnection.exec() // Emulates scenario where user has called some methods directly on the native connection // while tx is open - doReturn(Arrays.asList(new Object[] { barBytes, 3l })).when(nativeConnection).exec(); + doReturn(Arrays.asList(barBytes, 3L)).when(nativeConnection).exec(); doReturn(barBytes).when(nativeConnection).get(fooBytes); connection.get(foo); - verifyResults(Arrays.asList(new Object[] { barBytes, 3l })); + verifyResults(Arrays.asList(barBytes, 3L)); } @Test - public void testDiscard() { + void testDiscard() { doReturn(Arrays.asList(new Object[] { fooBytes })).when(nativeConnection).exec(); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { fooBytes }) })).when(nativeConnection) + doReturn(Collections.singletonList(Arrays.asList(new Object[] { fooBytes }))).when(nativeConnection) .closePipeline(); doReturn(barBytes).when(nativeConnection).get(fooBytes); doReturn(fooBytes).when(nativeConnection).get(barBytes); @@ -1445,15 +1446,15 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne connection.discard(); connection.get(bar); // Converted results of get(bar) should be included - verifyResults(Arrays.asList(new Object[] { foo })); + verifyResults(Collections.singletonList(foo)); } @Test // DATAREDIS-206 @Override public void testTimeIsDelegatedCorrectlyToNativeConnection() { - doReturn(Arrays.asList(new Object[] { 1L })).when(nativeConnection).exec(); - doReturn(Arrays.asList(new Object[] { Arrays.asList(new Object[] { 1L }) })).when(nativeConnection).closePipeline(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(Collections.singletonList(1L))).when(nativeConnection).closePipeline(); super.testTimeIsDelegatedCorrectlyToNativeConnection(); } @@ -1470,7 +1471,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne super.testGeoAddBytes(); } - // DATAREDIS-438 + @Test // DATAREDIS-438 @Override public void testGeoAddWithGeoLocationBytes() { @@ -1478,7 +1479,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne super.testGeoAddWithGeoLocationBytes(); } - // DATAREDIS-438 + @Test // DATAREDIS-438 @Override public void testGeoAddWithGeoLocation() { @@ -1498,7 +1499,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne super.testGeoAddCoordinateMap(); } - // DATAREDIS-438 + @Test // DATAREDIS-438 @Override public void testGeoAddWithIterableOfGeoLocationBytes() { @@ -1506,7 +1507,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne super.testGeoAddWithIterableOfGeoLocationBytes(); } - // DATAREDIS-438 + @Test // DATAREDIS-438 @Override public void testGeoAddWithIterableOfGeoLocation() { @@ -1517,183 +1518,182 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test // DATAREDIS-438 public void testGeoDistBytes() { - doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec(); + doReturn(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec(); super.testGeoDistBytes(); } @Test // DATAREDIS-438 public void testGeoDist() { - doReturn(Arrays.asList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec(); + doReturn(Collections.singletonList(new Distance(102121.12d, DistanceUnit.METERS))).when(nativeConnection).exec(); super.testGeoDist(); } @Test // DATAREDIS-438 public void testGeoHashBytes() { - doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).exec(); + doReturn(Collections.singletonList(Collections.singletonList(bar))).when(nativeConnection).exec(); super.testGeoHashBytes(); } @Test // DATAREDIS-438 public void testGeoHash() { - doReturn(Arrays.asList(Collections.singletonList(bar))).when(nativeConnection).exec(); + doReturn(Collections.singletonList(Collections.singletonList(bar))).when(nativeConnection).exec(); super.testGeoHash(); } @Test // DATAREDIS-438 public void testGeoPosBytes() { - doReturn(Arrays.asList(points)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(points)).when(nativeConnection).exec(); super.testGeoPosBytes(); } @Test // DATAREDIS-438 public void testGeoPos() { - doReturn(Arrays.asList(points)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(points)).when(nativeConnection).exec(); super.testGeoPos(); } @Test // DATAREDIS-438 public void testGeoRadiusWithoutParamBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusWithoutParamBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithoutParam() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusWithoutParam(); } @Test // DATAREDIS-438 public void testGeoRadiusWithDistBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusWithDistBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithDist() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusWithDist(); } @Test public void testGeoRadiusWithCoordAndDescBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusWithCoordAndDescBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusWithCoordAndDesc() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusWithCoordAndDesc(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithoutParamBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusByMemberWithoutParamBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithoutParam() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusByMemberWithoutParam(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithDistAndAscBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusByMemberWithDistAndAscBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithDistAndAsc() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusByMemberWithDistAndAsc(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithCoordAndCountBytes() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusByMemberWithCoordAndCountBytes(); } @Test // DATAREDIS-438 public void testGeoRadiusByMemberWithCoordAndCount() { - doReturn(Arrays.asList(geoResults)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(geoResults)).when(nativeConnection).exec(); super.testGeoRadiusByMemberWithCoordAndCount(); } @Test // DATAREDIS-864 public void xAckShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.xAckShouldDelegateAndConvertCorrectly(); } @Override // DATAREDIS-864 public void xAddShouldAppendRecordCorrectly() { - doReturn(Arrays.asList(RecordId.of("1-1"))).when(nativeConnection).exec(); + doReturn(Collections.singletonList(RecordId.of("1-1"))).when(nativeConnection).exec(); super.xAddShouldAppendRecordCorrectly(); } @Test // DATAREDIS-864 public void xDelShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.xAckShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xGroupCreateShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList("OK")).when(nativeConnection).exec(); + doReturn(Collections.singletonList("OK")).when(nativeConnection).exec(); super.xGroupCreateShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 - @Ignore public void xGroupDelConsumerShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Boolean.TRUE)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(Boolean.TRUE)).when(nativeConnection).exec(); super.xGroupDelConsumerShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xLenShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.xLenShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xGroupDestroyShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(Boolean.TRUE)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(Boolean.TRUE)).when(nativeConnection).exec(); super.xGroupDestroyShouldDelegateAndConvertCorrectly(); } @Test // DATAREDIS-864 public void xRangeShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList( + doReturn(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) .when(nativeConnection).exec(); super.xRangeShouldDelegateAndConvertCorrectly(); @@ -1702,7 +1702,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test // DATAREDIS-864 public void xReadShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList( + doReturn(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) .when(nativeConnection).exec(); super.xReadShouldDelegateAndConvertCorrectly(); @@ -1711,7 +1711,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test // DATAREDIS-864 public void xReadGroupShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList( + doReturn(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) .when(nativeConnection).exec(); super.xReadGroupShouldDelegateAndConvertCorrectly(); @@ -1720,7 +1720,7 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test // DATAREDIS-864 public void xRevRangeShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList( + doReturn(Collections.singletonList( Collections.singletonList(StreamRecords.newRecord().in(bar2Bytes).withId("stream-1").ofBytes(bytesMap)))) .when(nativeConnection).exec(); super.xRevRangeShouldDelegateAndConvertCorrectly(); @@ -1729,14 +1729,14 @@ public class DefaultStringRedisConnectionTxTests extends DefaultStringRedisConne @Test // DATAREDIS-864 public void xTrimShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.xTrimShouldDelegateAndConvertCorrectly(); } @Test public void xTrimApproximateShouldDelegateAndConvertCorrectly() { - doReturn(Arrays.asList(1L)).when(nativeConnection).exec(); + doReturn(Collections.singletonList(1L)).when(nativeConnection).exec(); super.xTrimApproximateShouldDelegateAndConvertCorrectly(); } diff --git a/src/test/java/org/springframework/data/redis/connection/RedisClusterConfigurationUnitTests.java b/src/test/java/org/springframework/data/redis/connection/RedisClusterConfigurationUnitTests.java index 7b91c0731..23b190f3b 100644 --- a/src/test/java/org/springframework/data/redis/connection/RedisClusterConfigurationUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/RedisClusterConfigurationUnitTests.java @@ -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. singleton(null))); } @Test // DATAREDIS-315 - public void shouldNotFailWhenListOfHostAndPortIsEmpty() { + void shouldNotFailWhenListOfHostAndPortIsEmpty() { RedisClusterConfiguration config = new RedisClusterConfiguration(Collections. 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", diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java index c998a60b0..418fd3dcd 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisClusterConnectionTests.java @@ -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"); diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactoryUnitTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactoryUnitTests.java index 1bfb49fb6..a1cf965ca 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionFactoryUnitTests.java @@ -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(); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java index 4e3b7806b..45ea96c3a 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionIntegrationTests.java @@ -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 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"); diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java index 7af550ca3..9967d391d 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineIntegrationTests.java @@ -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") + @Disabled("Jedis issue: Pipeline tries to return String instead of List") 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() {} } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java index d09b7ee2f..35ce6d44f 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionPipelineTxIntegrationTests.java @@ -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") + @Disabled("Jedis issue: Pipeline tries to return String instead of List") @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() {} } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java index 9eee741c6..4c717d071 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisConnectionTransactionIntegrationTests.java @@ -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") + @Disabled("Jedis issue: Transaction tries to return String instead of List") 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 diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisSentinelIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisSentinelIntegrationTests.java index c2004083f..2c8f6cb73 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisSentinelIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisSentinelIntegrationTests.java @@ -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 servers = (List) 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 servers = (List) sentinelConnection.masters(); - assertThat(servers.size()).isEqualTo(1); + assertThat(servers).hasSize(1); Collection 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() {} } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/JedisTransactionalConnectionStarvationTest.java b/src/test/java/org/springframework/data/redis/connection/jedis/JedisTransactionalConnectionStarvationTest.java index 9a263fc68..ae3f4d615 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/JedisTransactionalConnectionStarvationTest.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/JedisTransactionalConnectionStarvationTest.java @@ -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 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); } diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java b/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java index 4a3bb8f33..b66dc35cd 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/ScanTests.java @@ -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 redisOperations; + private RedisConnectionFactory factory; + private RedisTemplate 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 params() { JedisConnectionFactory jedisConnectionFactory = JedisConnectionFactoryExtension @@ -70,18 +65,18 @@ public class ScanTests { LettuceConnectionFactory lettuceConnectionFactory = LettuceConnectionFactoryExtension .getConnectionFactory(RedisStanalone.class); - return Arrays. 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 hash = redisOperations.boundHashOps("hash"); final AtomicReference exception = new AtomicReference<>(); diff --git a/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java b/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java index bacc938ec..4d193b19a 100644 --- a/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java +++ b/src/test/java/org/springframework/data/redis/connection/jedis/extension/JedisConnectionFactoryExtension.java @@ -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 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 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 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(); + } + }; + } } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java index 3fc9310bf..7c1f2707a 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/AuthenticatingRedisClientTests.java @@ -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 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 conn = client.connect(LettuceConnection.CODEC); conn.sync().ping(); conn.close(); } @Test - public void connectAsync() { + void connectAsync() { StatefulRedisConnection conn = client.connect(); conn.sync().ping(); conn.close(); } @Test - public void codecConnectAsync() { + void codecConnectAsync() { StatefulRedisConnection conn = client.connect(LettuceConnection.CODEC); conn.sync().ping(); conn.close(); } @Test - public void connectPubSub() { + void connectPubSub() { StatefulRedisPubSubConnection conn = client.connectPubSub(); conn.sync().ping(); conn.close(); } @Test - public void codecConnectPubSub() { + void codecConnectPubSub() { StatefulRedisPubSubConnection conn = client.connectPubSub(LettuceConnection.CODEC); conn.sync().ping(); conn.close(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java index f4801b379..244b7277b 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/DefaultLettucePoolTests.java @@ -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 client = (StatefulRedisConnection) 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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceAclIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceAclIntegrationTests.java index ec6d76723..e1d92c580 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceAclIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceAclIntegrationTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java index 1fa652205..1059bef8d 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClientConfigurationUnitTests.java @@ -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(" ")); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java index 3ccebbb5e..47fbc0804 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionTests.java @@ -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 PALERMO = new GeoLocation<>("palermo", POINT_PALERMO); private static final GeoLocation ARIGENTO_BYTES = new GeoLocation<>( - "arigento".getBytes(Charset.forName("UTF-8")), + "arigento".getBytes(StandardCharsets.UTF_8), POINT_ARIGENTO); private static final GeoLocation CATANIA_BYTES = new GeoLocation<>( - "catania".getBytes(Charset.forName("UTF-8")), + "catania".getBytes(StandardCharsets.UTF_8), POINT_CATANIA); private static final GeoLocation 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( diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionUnitTests.java index de5088870..b748788dd 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterConnectionUnitTests.java @@ -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 clusterConnection2Mock; @Mock RedisClusterCommands 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. emptyList()); when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections. emptyList()); @@ -207,7 +210,7 @@ public class LettuceClusterConnectionUnitTests { } @Test // DATAREDIS-315 - public void keysShouldOnlyBeRunOnDedicatedNodeWhenPinned() { + void keysShouldOnlyBeRunOnDedicatedNodeWhenPinned() { when(clusterConnection2Mock.keys(any(byte[].class))).thenReturn(Collections. 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 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 sync = mock(RedisAdvancedClusterCommands.class); @@ -372,7 +375,7 @@ public class LettuceClusterConnectionUnitTests { } @Test // DATAREDIS-731, DATAREDIS-545 - public void shouldExecuteOnDedicatedConnection() { + void shouldExecuteOnDedicatedConnection() { RedisCommands sync = mock(RedisCommands.class); StatefulRedisConnection dedicatedConnection = mock(StatefulRedisConnection.class); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyspaceNotificationsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyspaceNotificationsTests.java index 69ac4aff2..9619427c2 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyspaceNotificationsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceClusterKeyspaceNotificationsTests.java @@ -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 expiry = new CompletableFuture<>(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java index 1ade22808..d7223db7b 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryTests.java @@ -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 nativeConn = (RedisAsyncCommands) connection .getNativeConnection(); factory.resetConnection(); @@ -254,7 +252,7 @@ public class LettuceConnectionFactoryTests { @SuppressWarnings("unchecked") @Test - public void testInitConnection() { + void testInitConnection() { RedisAsyncCommands nativeConn = (RedisAsyncCommands) connection .getNativeConnection(); factory.initConnection(); @@ -265,7 +263,7 @@ public class LettuceConnectionFactoryTests { @SuppressWarnings("unchecked") @Test - public void testResetAndInitConnection() { + void testResetAndInitConnection() { RedisAsyncCommands nativeConn = (RedisAsyncCommands) 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()); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java index b73f7e95c..e04ee4cf6 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionFactoryUnitTests.java @@ -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 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 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 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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java index d5635eecf..413401539 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionIntegrationTests.java @@ -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)); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineFlushOnEndIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineFlushOnEndIntegrationTests.java index f4b515f90..4e243f798 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineFlushOnEndIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineFlushOnEndIntegrationTests.java @@ -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 { } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java index 4afc92f1a..eea9a7e30 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineIntegrationTests.java @@ -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() { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java index 5e57811c4..5dada9842 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionPipelineTxIntegrationTests.java @@ -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); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java index 3e314fe58..34e62d977 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConnectionTransactionIntegrationTests.java @@ -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); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConvertersUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConvertersUnitTests.java index 8e7532588..ae4540202 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConvertersUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceConvertersUnitTests.java @@ -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. emptyList()); } @Test // DATAREDIS-268 - public void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() { + void convertingNullToListOfRedisClientInfoShouldReturnEmptyList() { assertThat(LettuceConverters.toListOfRedisClientInformation(null)) .isEqualTo(Collections. 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(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingClientConfigurationUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingClientConfigurationUnitTests.java index 9c8650c84..e6894959a 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingClientConfigurationUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingClientConfigurationUnitTests.java @@ -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(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProviderUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProviderUnitTests.java index 583107d0a..df4c805bf 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProviderUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettucePoolingConnectionProviderUnitTests.java @@ -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 connectionMock; @Mock RedisAsyncCommands 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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsIntegrationTests.java similarity index 84% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsIntegrationTests.java index 83da4c2ee..5c88824e6 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsIntegrationTests.java @@ -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) // diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterHyperLogLogCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterHyperLogLogCommandsIntegrationTests.java similarity index 83% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterHyperLogLogCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterHyperLogLogCommandsIntegrationTests.java index 9451efcad..e455a2522 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterHyperLogLogCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterHyperLogLogCommandsIntegrationTests.java @@ -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 }); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommandsIntegrationTests.java similarity index 80% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommandsIntegrationTests.java index bbeb10027..2565181ed 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterKeyCommandsIntegrationTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterListCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterListCommandsIntegrationTests.java similarity index 85% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterListCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterListCommandsIntegrationTests.java index 85b2460a4..138b98eb5 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterListCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterListCommandsIntegrationTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java similarity index 83% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java index 4d29ba368..3621a8f15 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterServerCommandsIntegrationTests.java @@ -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(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterStringCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterStringCommandsIntegrationTests.java similarity index 84% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterStringCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterStringCommandsIntegrationTests.java index 6a7f33a5e..9a7381acb 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterStringCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterStringCommandsIntegrationTests.java @@ -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 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()); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsTestsBase.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterTestSupport.java similarity index 68% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsTestsBase.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterTestSupport.java index 72c8f28d2..a65185d04 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterCommandsTestsBase.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterTestSupport.java @@ -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 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) { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterZSetCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterZSetCommandsIntegrationTests.java similarity index 86% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterZSetCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterZSetCommandsIntegrationTests.java index 91e4f6ef0..9285498d6 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterZSetCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveClusterZSetCommandsIntegrationTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestsBase.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java similarity index 59% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestsBase.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java index 5e68ea702..1e7ecfd20 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestsBase.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveCommandsTestSupport.java @@ -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 nativeCommands; RedisClusterCommands nativeBinaryCommands; - @Parameterized.Parameters(name = "{3}") - public static List 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 parameters() { - List parameters = new ArrayList<>(); + LettuceExtension extension = new LettuceExtension(); - StandaloneConnectionProvider standaloneProvider = new StandaloneConnectionProvider(standalone.getClient(), + List 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) { diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java similarity index 86% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java index ce571bf96..47682a461 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveGeoCommandsIntegrationTests.java @@ -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 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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsIntegrationTests.java similarity index 72% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsIntegrationTests.java index 688f5082e..888454a97 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHashCommandsIntegrationTests.java @@ -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 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 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(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHyperLogLogCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHyperLogLogCommandsTests.java index 7ed6fb4fe..c384f8a1d 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHyperLogLogCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveHyperLogLogCommandsTests.java @@ -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); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsIntegrationTests.java similarity index 74% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsIntegrationTests.java index 6e4a978e3..0f97ef4d1 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveKeyCommandsIntegrationTests.java @@ -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(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java similarity index 75% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java index c2136469d..558c1073d 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveListCommandIntegrationTests.java @@ -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"); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveNumberCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveNumberCommandsIntegrationTests.java similarity index 64% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveNumberCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveNumberCommandsIntegrationTests.java index b4d297620..4b007fe02 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveNumberCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveNumberCommandsIntegrationTests.java @@ -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"); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnectionUnitTests.java index 8caba340a..148b76faf 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisClusterConnectionUnitTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnectionUnitTests.java index 83475d0e3..54d47101a 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveRedisConnectionUnitTests.java @@ -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 sharedConnection; @Mock RedisReactiveCommands 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> 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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveScriptingCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveScriptingCommandsIntegrationTests.java similarity index 62% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveScriptingCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveScriptingCommandsIntegrationTests.java index 565edfd67..32127233e 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveScriptingCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveScriptingCommandsIntegrationTests.java @@ -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()); } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java similarity index 76% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java index 22e1ac5e9..61ad9d94a 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveServerCommandsIntegrationTests.java @@ -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(); } } diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsIntegrationIntegrationTests.java similarity index 73% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsIntegrationIntegrationTests.java index c181b9af3..89e74776c 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSetCommandsIntegrationIntegrationTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStreamCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStreamCommandsIntegrationTests.java similarity index 87% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStreamCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStreamCommandsIntegrationTests.java index 7a3f14b13..f0a2e84f2 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStreamCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStreamCommandsIntegrationTests.java @@ -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"); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsIntegrationTests.java similarity index 79% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsIntegrationTests.java index 7d9592ae7..9941b8b7a 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveStringCommandsIntegrationTests.java @@ -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 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 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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSubscriptionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSubscriptionUnitTests.java index 0aefefdec..63077f216 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSubscriptionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveSubscriptionUnitTests.java @@ -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 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> emitter = DirectProcessor .create(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsIntegrationTests.java similarity index 77% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsIntegrationTests.java index be90882b3..8184d098c 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceReactiveZSetCommandsIntegrationTests.java @@ -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 ONE_TO_TWO = Range.closed(1L, 2L); @@ -45,13 +44,17 @@ public class LettuceReactiveZSetCommandsTests extends LettuceReactiveCommandsTes private static final Range TWO_INCLUSIVE_TO_THREE_EXCLUSIVE = Range.rightOpen(2D, 3D); private static final Range 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"); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnectionUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnectionUnitTests.java index 361ce79a2..7074bd4d2 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelConnectionUnitTests.java @@ -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.> 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.> 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.> 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"); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java index ef04db625..da317a241 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSentinelIntegrationTests.java @@ -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 parameters() { - - List 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 servers = (List) 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 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(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionUnitTests.java similarity index 89% rename from src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java rename to src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionUnitTests.java index 5018b5fc5..52ecc6503 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/LettuceSubscriptionUnitTests.java @@ -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(); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/PipeliningFlushPolicyUnitTests.java b/src/test/java/org/springframework/data/redis/connection/lettuce/PipeliningFlushPolicyUnitTests.java index ea216ce1c..dcb20546c 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/PipeliningFlushPolicyUnitTests.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/PipeliningFlushPolicyUnitTests.java @@ -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); diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/TestEventLoopGroupProvider.java b/src/test/java/org/springframework/data/redis/connection/lettuce/TestEventLoopGroupProvider.java deleted file mode 100644 index 8223df236..000000000 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/TestEventLoopGroupProvider.java +++ /dev/null @@ -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; diff --git a/src/test/java/org/springframework/data/redis/connection/lettuce/extension/LettuceConnectionFactoryExtension.java b/src/test/java/org/springframework/data/redis/connection/lettuce/extension/LettuceConnectionFactoryExtension.java index 6fc68b463..e132a2075 100644 --- a/src/test/java/org/springframework/data/redis/connection/lettuce/extension/LettuceConnectionFactoryExtension.java +++ b/src/test/java/org/springframework/data/redis/connection/lettuce/extension/LettuceConnectionFactoryExtension.java @@ -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(); + } + }; + } } } diff --git a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java index 12ec25b65..672df3a58 100644 --- a/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/core/AbstractOperationsTestParams.java @@ -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 rawFactory = new RawObjectFactory(); ObjectFactory 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 xstreamStringTemplate = new RedisTemplate<>(); xstreamStringTemplate.setConnectionFactory(lettuceConnectionFactory); xstreamStringTemplate.setDefaultSerializer(serializer); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java similarity index 84% rename from src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java index 618d5e12b..6c983be87 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultGeoOperationsIntegrationTests.java @@ -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 { - - public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); +@MethodSource("testParams") +@EnabledOnCommand("GEOADD") +public class DefaultGeoOperationsIntegrationTests { 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 { private static final double DISTANCE_PALERMO_CATANIA_MILES = 103.31822459492733; private static final double DISTANCE_PALERMO_CATANIA_FEET = 545518.8699790037; - private RedisTemplate redisTemplate; - private ObjectFactory keyFactory; - private ObjectFactory valueFactory; - private GeoOperations geoOperations; + private final RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; + private final ObjectFactory valueFactory; + private final GeoOperations geoOperations; - public DefaultGeoOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultGeoOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; + this.geoOperations = redisTemplate.opsForGeo(); } - @Parameters public static Collection testParams() { return AbstractOperationsTestParams.testParams(); } - @Before - public void setUp() { - geoOperations = redisTemplate.opsForGeo(); - } - - @After - public void tearDown() { - + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) 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 memberCoordinateMap = new HashMap<>(); memberCoordinateMap.put(valueFactory.instance(), POINT_PALERMO); @@ -119,8 +104,8 @@ public class DefaultGeoOperationsTests { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsIntegrationTests.java similarity index 74% rename from src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultHashOperationsIntegrationTests.java index 240b54f15..c0173ff18 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultHashOperationsIntegrationTests.java @@ -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 Hash key type * @param Hash value type */ -@RunWith(Parameterized.class) -public class DefaultHashOperationsTests { +@MethodSource("testParams") +public class DefaultHashOperationsIntegrationTests { - public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); + private final RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; + private final ObjectFactory hashKeyFactory; + private final ObjectFactory hashValueFactory; + private final HashOperations hashOps; - private RedisTemplate redisTemplate; - - private ObjectFactory keyFactory; - - private ObjectFactory hashKeyFactory; - - private ObjectFactory hashValueFactory; - - private HashOperations hashOps; - - public DefaultHashOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultHashOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory hashKeyFactory, ObjectFactory hashValueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.hashKeyFactory = hashKeyFactory; this.hashValueFactory = hashValueFactory; + this.hashOps = redisTemplate.opsForHash(); } - @Parameters public static Collection testParams() { ObjectFactory stringFactory = new StringObjectFactory(); ObjectFactory rawFactory = new RawObjectFactory(); @@ -97,21 +82,16 @@ public class DefaultHashOperationsTests { { rawTemplate, rawFactory, rawFactory, rawFactory } }); } - @Before - public void setUp() { - hashOps = redisTemplate.opsForHash(); - } - - @After - public void tearDown() { + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) 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 { } } - @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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultHyperLogLogOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultHyperLogLogOperationsIntegrationTests.java similarity index 64% rename from src/test/java/org/springframework/data/redis/core/DefaultHyperLogLogOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultHyperLogLogOperationsIntegrationTests.java index a67289629..1a8776461 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultHyperLogLogOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultHyperLogLogOperationsIntegrationTests.java @@ -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 { +@MethodSource("testParams") +public class DefaultHyperLogLogOperationsIntegrationTests { - private RedisTemplate redisTemplate; + private final RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; + private final ObjectFactory valueFactory; + private final HyperLogLogOperations hyperLogLogOps; - private ObjectFactory keyFactory; - - private ObjectFactory valueFactory; - - private HyperLogLogOperations hyperLogLogOps; - - public static @ClassRule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); - - public DefaultHyperLogLogOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultHyperLogLogOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; + this.hyperLogLogOps = redisTemplate.opsForHyperLogLog(); } - @Parameters public static Collection 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) 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 { 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 { 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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultListOperationsIntegrationIntegrationTests.java similarity index 70% rename from src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultListOperationsIntegrationIntegrationTests.java index f7755b206..4ab667ce9 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultListOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultListOperationsIntegrationIntegrationTests.java @@ -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 Key test * @param Value test */ -@RunWith(Parameterized.class) -public class DefaultListOperationsTests { +@MethodSource("testParams") +public class DefaultListOperationsIntegrationIntegrationTests { - @Rule public MinimumRedisVersionRule redisVersion = new MinimumRedisVersionRule(); + private final RedisTemplate redisTemplate; - private RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; - private ObjectFactory keyFactory; + private final ObjectFactory valueFactory; - private ObjectFactory valueFactory; + private final ListOperations listOps; - private ListOperations listOps; - - public DefaultListOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultListOperationsIntegrationIntegrationTests(RedisTemplate redisTemplate, + ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; + this.listOps = redisTemplate.opsForList(); } - @Parameters public static Collection 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) 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 { 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 { } @SuppressWarnings("unchecked") - @Test - public void testLeftPushAll() { + @ParameterizedRedisTest + void testLeftPushAll() { K key = keyFactory.instance(); V v1 = valueFactory.instance(); @@ -134,12 +118,12 @@ public class DefaultListOperationsTests { 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 { 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 { 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 { 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 { 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 { 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 { 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 { } @SuppressWarnings("unchecked") - @Test - public void testRightPushAll() { + @ParameterizedRedisTest + void testRightPushAll() { K key = keyFactory.instance(); V v1 = valueFactory.instance(); @@ -249,9 +233,9 @@ public class DefaultListOperationsTests { 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 { 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. 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) 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 { 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. 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) 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java index a129d6913..118b70d49 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveGeoOperationsIntegrationTests.java @@ -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 { - 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 { private final ObjectFactory keyFactory; private final ObjectFactory valueFactory; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - /** - * @param redisTemplate - * @param keyFactory - * @param valueFactory - * @param label parameterized test label, no further use besides that. - */ - public DefaultReactiveGeoOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveGeoOperationsIntegrationTests(Fixture 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 { 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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .verifyComplete(); } - @Test // DATAREDIS-602, DATAREDIS-614 - public void delete() { + @ParameterizedRedisTest // DATAREDIS-602, DATAREDIS-614 + void delete() { K key = keyFactory.instance(); V member1 = valueFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java index 0d880fd7a..cb65cae55 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveHashOperationsIntegrationTests.java @@ -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 { @@ -62,7 +59,16 @@ public class DefaultReactiveHashOperationsIntegrationTests { private final ObjectFactory hashKeyFactory; private final ObjectFactory hashValueFactory; - @Parameters(name = "{4}") + public DefaultReactiveHashOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, + ObjectFactory keyFactory, ObjectFactory hashKeyFactory, ObjectFactory hashValueFactory) { + + this.redisTemplate = redisTemplate; + this.hashOperations = redisTemplate.opsForHash(); + this.keyFactory = keyFactory; + this.hashKeyFactory = hashKeyFactory; + this.hashValueFactory = hashValueFactory; + } + public static Collection testParams() { ObjectFactory stringFactory = new StringObjectFactory(); @@ -86,26 +92,8 @@ public class DefaultReactiveHashOperationsIntegrationTests { { rawTemplate, rawFactory, rawFactory, rawFactory, "raw" } }); } - @AfterClass - public static void cleanUp() { - ConnectionFactoryTracker.cleanUp(); - } - - public DefaultReactiveHashOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory hashKeyFactory, ObjectFactory 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 { 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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .verifyComplete(); } - @Test // DATAREDIS-602 - public void delete() { + @ParameterizedRedisTest // DATAREDIS-602 + void delete() { K key = keyFactory.instance(); HK hashkey = hashKeyFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveHyperLogLogOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveHyperLogLogOperationsIntegrationTests.java index 7b9ab943a..7e8bbf2e0 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveHyperLogLogOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveHyperLogLogOperationsIntegrationTests.java @@ -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 { @@ -50,28 +46,20 @@ public class DefaultReactiveHyperLogLogOperationsIntegrationTests { private final ObjectFactory keyFactory; private final ObjectFactory valueFactory; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - /** - * @param redisTemplate - * @param keyFactory - * @param valueFactory - * @param label parameterized test label, no further use besides that. - */ - public DefaultReactiveHyperLogLogOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveHyperLogLogOperationsIntegrationTests(Fixture 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 { 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 { 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 { }).verifyComplete(); } - @Test // DATAREDIS-602 - public void delete() { + @ParameterizedRedisTest // DATAREDIS-602 + void delete() { K key = keyFactory.instance(); V value1 = valueFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java index 900e90c8e..60db5ddac 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveListOperationsIntegrationTests.java @@ -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 { - @Rule public MinimumRedisVersionRule redisVersion = new MinimumRedisVersionRule(); private final ReactiveRedisTemplate redisTemplate; private final ReactiveListOperations listOperations; @@ -56,28 +52,20 @@ public class DefaultReactiveListOperationsIntegrationTests { private final ObjectFactory keyFactory; private final ObjectFactory valueFactory; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - /** - * @param redisTemplate - * @param keyFactory - * @param valueFactory - * @param label parameterized test label, no further use besides that. - */ - public DefaultReactiveListOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveListOperationsIntegrationTests(Fixture 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 { 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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { .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 { 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 { .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 { .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 { .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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java index 936e94d0c..a87b15df0 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveSetOperationsIntegrationTests.java @@ -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 { @@ -52,28 +49,20 @@ public class DefaultReactiveSetOperationsIntegrationTests { private final ObjectFactory keyFactory; private final ObjectFactory valueFactory; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - /** - * @param redisTemplate - * @param keyFactory - * @param valueFactory - * @param label parameterized test label, no further use besides that. - */ - public DefaultReactiveSetOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveSetOperationsIntegrationTests(Fixture 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 { 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 { 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 { 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 { }).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 { 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 { 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 { 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 { .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 { 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 { .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 { 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 { .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 { 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 { .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 { .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 { }).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 { 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 { .verifyComplete(); } - @Test // DATAREDIS-602 - public void delete() { + @ParameterizedRedisTest // DATAREDIS-602 + void delete() { K key = keyFactory.instance(); V value = valueFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsIntegrationTests.java similarity index 83% rename from src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsIntegrationTests.java index 701e1282e..4a3bd0bec 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveStreamOperationsIntegrationTests.java @@ -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 { +@EnabledOnCommand("XADD") +public class DefaultReactiveStreamOperationsIntegrationTests { private final ReactiveRedisTemplate redisTemplate; private final ReactiveStreamOperations streamOperations; @@ -73,53 +71,41 @@ public class DefaultReactiveStreamOperationsTests { private final ObjectFactory hashKeyFactory; private final ObjectFactory valueFactory; - RedisSerializer serializer; + private final RedisSerializer serializer; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> 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 redisTemplate, ObjectFactory keyFactory, - ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveStreamOperationsIntegrationTests(Fixture 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) keyFactory; + this.valueFactory = fixture.getValueFactory(); RedisSerializationContext 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) 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 { 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 { .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 { .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 { .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 { .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 { .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 { .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 { }).verifyComplete(); } - @Test // DATAREDIS-864 - public void readShouldReadMessages() { + @ParameterizedRedisTest // DATAREDIS-864 + void readShouldReadMessages() { assumeFalse(valueFactory instanceof PersonObjectFactory); @@ -302,8 +288,8 @@ public class DefaultReactiveStreamOperationsTests { .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 { .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 { }).verifyComplete(); } - @Test // DATAREDIS-1084 - public void pendingShouldReadMessageDetails() { + @ParameterizedRedisTest // DATAREDIS-1084 + void pendingShouldReadMessageDetails() { K key = keyFactory.instance(); HK hashKey = hashKeyFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java index 2f4c5c0bf..d631c8b94 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveValueOperationsIntegrationTests.java @@ -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 { @@ -62,31 +60,23 @@ public class DefaultReactiveValueOperationsIntegrationTests { private final ObjectFactory keyFactory; private final ObjectFactory valueFactory; - private final RedisSerializer serializer; + private final RedisSerializer serializer; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - /** - * @param redisTemplate - * @param keyFactory - * @param valueFactory - * @param label parameterized test label, no further use besides that. - */ - public DefaultReactiveValueOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveValueOperationsIntegrationTests(Fixture 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 { 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 { 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 { .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 { 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 { }).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 { 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 { }).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 { 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 { 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 { 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 { 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 { .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 { 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 { 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 { }).verifyComplete(); } - @Test // DATAREDIS-602 - public void size() { + @ParameterizedRedisTest // DATAREDIS-602 + void size() { assumeTrue(serializer instanceof StringRedisSerializer); @@ -351,8 +341,8 @@ public class DefaultReactiveValueOperationsIntegrationTests { .verify(); } - @Test // DATAREDIS-602 - public void setBit() { + @ParameterizedRedisTest // DATAREDIS-602 + void setBit() { K key = keyFactory.instance(); @@ -360,8 +350,8 @@ public class DefaultReactiveValueOperationsIntegrationTests { 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 { 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 { .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 { 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 { 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 { 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 { 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 { valueOperations.decrement(key).as(StepVerifier::create).expectNext(-2L).verifyComplete(); } - @Test // DATAREDIS-784 - public void decrementByLongDelta() { + @ParameterizedRedisTest // DATAREDIS-784 + void decrementByLongDelta() { K key = keyFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java index d4029046b..2f8be8709 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultReactiveZSetOperationsIntegrationTests.java @@ -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 { @@ -66,30 +64,22 @@ public class DefaultReactiveZSetOperationsIntegrationTests { private final ObjectFactory keyFactory; private final ObjectFactory valueFactory; - private final RedisSerializer serializer; + private final RedisSerializer serializer; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - /** - * @param redisTemplate - * @param keyFactory - * @param valueFactory - * @param label parameterized test label, no further use besides that. - */ - public DefaultReactiveZSetOperationsIntegrationTests(ReactiveRedisTemplate redisTemplate, - ObjectFactory keyFactory, ObjectFactory valueFactory, RedisSerializer serializer, String label) { + public DefaultReactiveZSetOperationsIntegrationTests(Fixture 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { } - @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 { .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 { .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 { .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 { .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 { .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 { } - @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 { .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 { .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 { .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 { .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 { .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 { .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 { 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 { 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 { 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 { 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 { 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 { .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 { 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 { 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 { .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 { .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 { } - @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 { .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 { .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 { .verifyComplete(); } - @Test // DATAREDIS-602 - public void delete() { + @ParameterizedRedisTest // DATAREDIS-602 + void delete() { K key = keyFactory.instance(); V value = valueFactory.instance(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java similarity index 72% rename from src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java index b0b0d208b..44d722884 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultSetOperationsIntegrationTests.java @@ -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 { +public class DefaultSetOperationsIntegrationTests { - private RedisTemplate redisTemplate; + private final RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; + private final ObjectFactory valueFactory; + private final SetOperations setOps; - private ObjectFactory keyFactory; - - private ObjectFactory valueFactory; - - private SetOperations setOps; - - public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); - - public DefaultSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultSetOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; + this.setOps = redisTemplate.opsForSet(); } - @Parameters public static Collection testParams() { return AbstractOperationsTestParams.testParams(); } - @Before - public void setUp() { - setOps = redisTemplate.opsForSet(); - } - - @After - public void tearDown() { + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) connection -> { connection.flushDb(); return null; @@ -88,10 +68,8 @@ public class DefaultSetOperationsTests { } @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 { setOps.add(setKey, v1); setOps.add(setKey, v2); - setOps.add(setKey, v3); Set 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 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 { } 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 { } @SuppressWarnings("unchecked") - @Test - public void testMove() { + @ParameterizedRedisTest + void testMove() { K key1 = keyFactory.instance(); K key2 = keyFactory.instance(); @@ -162,8 +132,8 @@ public class DefaultSetOperationsTests { } @SuppressWarnings("unchecked") - @Test - public void testPop() { + @ParameterizedRedisTest + void testPop() { K key = keyFactory.instance(); V v1 = valueFactory.instance(); @@ -174,8 +144,8 @@ public class DefaultSetOperationsTests { 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 { 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 { 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 { } @SuppressWarnings("unchecked") - @Test - public void testRemove() { + @ParameterizedRedisTest + void testRemove() { K key = keyFactory.instance(); V v1 = valueFactory.instance(); @@ -227,10 +197,9 @@ public class DefaultSetOperationsTests { 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 { 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 { 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 { 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 { 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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsIntegrationTests.java similarity index 80% rename from src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsIntegrationTests.java index eecc1f022..75f7a9178 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultStreamOperationsIntegrationTests.java @@ -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 { +@MethodSource("testParams") +@EnabledOnCommand("XADD") +public class DefaultStreamOperationsIntegrationTests { - private RedisTemplate redisTemplate; + private final RedisTemplate redisTemplate; + private final @EnabledOnRedisDriver.DriverQualifier RedisConnectionFactory connectionFactory; - private ObjectFactory keyFactory; + private final ObjectFactory keyFactory; + private final ObjectFactory hashKeyFactory; + private final ObjectFactory hashValueFactory; + private final StreamOperations streamOps; - private ObjectFactory hashKeyFactory; - - private ObjectFactory hashValueFactory; - - private StreamOperations streamOps; - - public DefaultStreamOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultStreamOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory 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) keyFactory; this.hashValueFactory = (ObjectFactory) objectFactory; + streamOps = redisTemplate.opsForStream(); } - @Parameters public static Collection testParams() { return AbstractOperationsTestParams.testParams(); } - @Before - public void setUp() { - streamOps = redisTemplate.opsForStream(); + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) connection -> { connection.flushDb(); @@ -97,8 +92,8 @@ public class DefaultStreamOperationsTests { }); } - @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 { } } - @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 { 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 { 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 { 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 { 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 { 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 { } } - @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 { 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 { 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 { } } - @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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsIntegrationTests.java similarity index 77% rename from src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultValueOperationsIntegrationTests.java index 3331428c7..276feaa6c 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultValueOperationsIntegrationTests.java @@ -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 { +@MethodSource("testParams") +public class DefaultValueOperationsIntegrationTests { - private RedisTemplate redisTemplate; + private final RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; + private final ObjectFactory valueFactory; + private final ValueOperations valueOps; - private ObjectFactory keyFactory; - - private ObjectFactory valueFactory; - - private ValueOperations valueOps; - - public DefaultValueOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultValueOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; + this.valueOps = redisTemplate.opsForValue(); } - @Parameters - public static Collection testParams() { + static Collection testParams() { return AbstractOperationsTestParams.testParams(); } - @Before - public void setUp() { - valueOps = redisTemplate.opsForValue(); - } - - @After - public void tearDown() { + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) 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 { 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 { 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 { 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 { 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 { 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 keysAndValues = new HashMap<>(); K key1 = keyFactory.instance(); @@ -184,8 +168,8 @@ public class DefaultValueOperationsTests { 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 { assertThat(valueOps.multiSetIfAbsent(keysAndValues)).isFalse(); } - @Test - public void testMultiSet() { + @ParameterizedRedisTest + void testMultiSet() { Map keysAndValues = new HashMap<>(); K key1 = keyFactory.instance(); @@ -219,8 +203,8 @@ public class DefaultValueOperationsTests { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { } @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 { assertThat(((DefaultValueOperations) valueOps).deserializeKey((byte[]) key)).isNotNull(); } - @Test // DATAREDIS-197 - public void testSetAndGetBit() { + @ParameterizedRedisTest // DATAREDIS-197 + void testSetAndGetBit() { assumeThat(redisTemplate).isInstanceOf(StringRedisTemplate.class); diff --git a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java similarity index 83% rename from src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java rename to src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java index d53523990..639220afb 100644 --- a/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsTests.java +++ b/src/test/java/org/springframework/data/redis/core/DefaultZSetOperationsIntegrationTests.java @@ -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 Value type */ @SuppressWarnings("unchecked") -@RunWith(Parameterized.class) -public class DefaultZSetOperationsTests { +@MethodSource("testParams") +public class DefaultZSetOperationsIntegrationTests { - public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); + private final RedisTemplate redisTemplate; + private final ObjectFactory keyFactory; + private final ObjectFactory valueFactory; + private final ZSetOperations zSetOps; - private RedisTemplate redisTemplate; - - private ObjectFactory keyFactory; - - private ObjectFactory valueFactory; - - private ZSetOperations zSetOps; - - public DefaultZSetOperationsTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public DefaultZSetOperationsIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; this.keyFactory = keyFactory; this.valueFactory = valueFactory; + this.zSetOps = redisTemplate.opsForZSet(); } - @Parameters public static Collection testParams() { return AbstractOperationsTestParams.testParams(); } - @Before - public void setUp() { - zSetOps = redisTemplate.opsForZSet(); - } - - @After - public void tearDown() { + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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 { 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(); diff --git a/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateIntegrationTests.java similarity index 73% rename from src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java rename to src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateIntegrationTests.java index 899879009..14c7bc53f 100644 --- a/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/MultithreadedRedisTemplateIntegrationTests.java @@ -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 testParams() { + public static Collection 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 template = new RedisTemplate<>(); template.setConnectionFactory(factory); diff --git a/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java b/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java index b9b56bf1a..aac50bc15 100644 --- a/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/core/ReactiveOperationsTestParams.java @@ -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 testParams() { + public static Collection> testParams() { ObjectFactory stringFactory = new StringObjectFactory(); ObjectFactory clusterKeyStringFactory = new PrefixStringObjectFactory("{u1}.", stringFactory); @@ -62,14 +62,6 @@ abstract public class ReactiveOperationsTestParams { ObjectFactory rawFactory = new ByteBufferObjectFactory(); ObjectFactory 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 personTemplate = new ReactiveRedisTemplate(lettuceConnectionFactory, RedisSerializationContext.fromSerializer(jdkSerializationRedisSerializer)); - OxmSerializer oxmSerializer = new OxmSerializer(xstream, xstream); + OxmSerializer oxmSerializer = XstreamOxmSerializerSingleton.getInstance(); ReactiveRedisTemplate xstreamStringTemplate = new ReactiveRedisTemplate(lettuceConnectionFactory, RedisSerializationContext.fromSerializer(oxmSerializer)); @@ -112,22 +104,23 @@ abstract public class ReactiveOperationsTestParams { ReactiveRedisTemplate genericJackson2JsonPersonTemplate = new ReactiveRedisTemplate( lettuceConnectionFactory, RedisSerializationContext.fromSerializer(genericJackson2JsonSerializer)); - List 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> 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 clusterStringTemplate = null; + ReactiveRedisTemplate 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 { - } - }, null).evaluate(); - } catch (Throwable throwable) { - return false; + private final ReactiveRedisTemplate template; + private final ObjectFactory keyFactory; + private final ObjectFactory valueFactory; + private final @Nullable RedisSerializer serializer; + private final String label; + + public Fixture(ReactiveRedisTemplate template, ObjectFactory keyFactory, ObjectFactory 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 getTemplate() { + return template; + } + + public ObjectFactory getKeyFactory() { + return keyFactory; + } + + public ObjectFactory getValueFactory() { + return valueFactory; + } + + @Nullable + public RedisSerializer getSerializer() { + return serializer; + } + + public String getLabel() { + return label; + } + + @Override + public String toString() { + return label; } - return true; } } diff --git a/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java b/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java index ef2a38b93..cf0820df8 100644 --- a/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/core/ReactiveRedisTemplateIntegrationTests.java @@ -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 { private final ReactiveRedisTemplate redisTemplate; @@ -71,32 +69,19 @@ public class ReactiveRedisTemplateIntegrationTests { private final ObjectFactory valueFactory; - @Parameters(name = "{4}") - public static Collection testParams() { + public static Collection> testParams() { return ReactiveOperationsTestParams.testParams(); } - @AfterClass - public static void cleanUp() { - ConnectionFactoryTracker.cleanUp(); + public ReactiveRedisTemplateIntegrationTests(Fixture 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 redisTemplate, ObjectFactory keyFactory, - ObjectFactory 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 { connection.close(); } - @Test // DATAREDIS-602 - public void exists() { + @ParameterizedRedisTest // DATAREDIS-602 + void exists() { K key = keyFactory.instance(); @@ -117,10 +102,10 @@ public class ReactiveRedisTemplateIntegrationTests { 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 tuples = new HashMap<>(); tuples.put(keyFactory.instance(), valueFactory.instance()); @@ -134,8 +119,8 @@ public class ReactiveRedisTemplateIntegrationTests { .verifyComplete(); } - @Test // DATAREDIS-602 - public void type() { + @ParameterizedRedisTest // DATAREDIS-602 + void type() { K key = keyFactory.instance(); @@ -147,8 +132,8 @@ public class ReactiveRedisTemplateIntegrationTests { 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 { .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 { .verify(); } - @Test // DATAREDIS-693 - public void unlink() { + @ParameterizedRedisTest // DATAREDIS-693 + void unlink() { K single = keyFactory.instance(); @@ -200,8 +185,8 @@ public class ReactiveRedisTemplateIntegrationTests { 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 { 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 { 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 { 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 { 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 { SerializationPair json = SerializationPair.fromSerializer(new Jackson2JsonRedisSerializer<>(Person.class)); RedisElementReader 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 { 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 { .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 { .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 { .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 { .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 { 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 { 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 { valueOperations.get(key).as(StepVerifier::create).expectNext(value).verifyComplete(); } - @Test // DATAREDIS-602 - public void shouldApplyCustomSerializationContextToHash() { + @ParameterizedRedisTest // DATAREDIS-602 + void shouldApplyCustomSerializationContextToHash() { RedisSerializationContext serializationContext = redisTemplate.getSerializationContext(); @@ -446,8 +431,9 @@ public class ReactiveRedisTemplateIntegrationTests { 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 { .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-*"; diff --git a/src/test/java/org/springframework/data/redis/core/RedisClusterTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisClusterTemplateIntegrationTests.java similarity index 81% rename from src/test/java/org/springframework/data/redis/core/RedisClusterTemplateTests.java rename to src/test/java/org/springframework/data/redis/core/RedisClusterTemplateIntegrationTests.java index a14c66265..073fdfc11 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisClusterTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisClusterTemplateIntegrationTests.java @@ -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 extends RedisTemplateTests { +@EnabledOnRedisClusterAvailable +public class RedisClusterTemplateIntegrationTests extends RedisTemplateIntegrationTests { - public RedisClusterTemplateTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + public RedisClusterTemplateIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory 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 extends RedisTemplateTests { ObjectFactory rawFactory = new RawObjectFactory(); ObjectFactory 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 jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class); // JEDIS diff --git a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java index 94c2cff46..b1551ead9 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisKeyValueAdapterTests.java @@ -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 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 map = new LinkedHashMap(); 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 map = new LinkedHashMap<>(); map.put("_class", Person.class.getName()); map.put("firstname", "rand"); diff --git a/src/test/java/org/springframework/data/redis/core/RedisKeyValueTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisKeyValueTemplateTests.java index 670e2bb33..c03e7d5ab 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisKeyValueTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisKeyValueTemplateTests.java @@ -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 nativeTemplate; - RedisMappingContext context; - RedisKeyValueAdapter adapter; + private RedisConnectionFactory connectionFactory; + private RedisKeyValueTemplate template; + private RedisTemplate nativeTemplate; + private RedisMappingContext context; + private RedisKeyValueAdapter adapter; public RedisKeyValueTemplateTests(RedisConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; } - @Parameters public static List params() { JedisConnectionFactory jedis = JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class); - LettuceConnectionFactory lettuce = LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class); - return Arrays. 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) 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 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 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 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 { diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java similarity index 82% rename from src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java rename to src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java index c9bd53735..e62d2e8d4 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateIntegrationTests.java @@ -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 { +@MethodSource("testParams") +public class RedisTemplateIntegrationTests { - @Autowired protected RedisTemplate redisTemplate; + protected final RedisTemplate redisTemplate; + protected final ObjectFactory keyFactory; + protected final ObjectFactory valueFactory; - protected ObjectFactory keyFactory; - - protected ObjectFactory valueFactory; - - public RedisTemplateTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, + RedisTemplateIntegrationTests(RedisTemplate redisTemplate, ObjectFactory keyFactory, ObjectFactory valueFactory) { this.redisTemplate = redisTemplate; @@ -81,27 +74,20 @@ public class RedisTemplateTests { this.valueFactory = valueFactory; } - @After - public void tearDown() { + public static Collection testParams() { + return AbstractOperationsTestParams.testParams(); + } + + @BeforeEach + void setUp() { redisTemplate.execute((RedisCallback) connection -> { connection.flushDb(); return null; }); } - @AfterClass - public static void cleanUp() { - ConnectionFactoryTracker.cleanUp(); - } - - @Parameters - public static Collection 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 { 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) connection -> { StringRedisConnection stringConn = (StringRedisConnection) connection; stringConn.set("test", "it"); @@ -156,7 +141,7 @@ public class RedisTemplateTests { assertThat("it").isEqualTo(value); } - @Test + @ParameterizedRedisTest public void testExec() { K key1 = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -190,7 +175,7 @@ public class RedisTemplateTests { 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 { assertThat(redisTemplate.boundValueOps(key1).get()).isEqualTo(value1); } - @Test - public void testExecCustomSerializer() { - assumeTrue(redisTemplate instanceof StringRedisTemplate); + @ParameterizedRedisTest + void testExecCustomSerializer() { + assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue(); List results = redisTemplate.execute(new SessionCallback>() { @SuppressWarnings({ "rawtypes", "unchecked" }) public List execute(RedisOperations operations) throws DataAccessException { @@ -241,7 +226,7 @@ public class RedisTemplateTests { 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 { } @SuppressWarnings("rawtypes") - @Test + @ParameterizedRedisTest public void testExecutePipelined() { K key1 = keyFactory.instance(); V value1 = valueFactory.instance(); @@ -289,10 +274,10 @@ public class RedisTemplateTests { } @SuppressWarnings("rawtypes") - @Test - public void testExecutePipelinedCustomSerializer() { + @ParameterizedRedisTest + void testExecutePipelinedCustomSerializer() { - assumeTrue(redisTemplate instanceof StringRedisTemplate); + assumeThat(redisTemplate instanceof StringRedisTemplate).isTrue(); List results = redisTemplate.executePipelined((RedisCallback) connection -> { StringRedisConnection stringRedisConn = (StringRedisConnection) connection; @@ -307,10 +292,10 @@ public class RedisTemplateTests { 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 { assertThat(person).isEqualTo(((Map) results.get(0)).get(1L)); } - @Test + @ParameterizedRedisTest public void testExecutePipelinedNonNullRedisCallback() { assertThatExceptionOfType(InvalidDataAccessApiUsageException.class) .isThrownBy(() -> redisTemplate.executePipelined((RedisCallback) 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 { 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 pipelinedResults = redisTemplate.executePipelined(new SessionCallback() { public Object execute(RedisOperations operations) throws DataAccessException { operations.multi(); @@ -381,7 +366,7 @@ public class RedisTemplateTests { 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() { @@ -392,8 +377,8 @@ public class RedisTemplateTests { })); } - @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 { 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 { 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 { 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 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 { 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 { 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 { 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 { 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 result = redisTemplate.execute(new SessionCallback>() { @@ -577,34 +560,34 @@ public class RedisTemplateTests { 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 result = redisTemplate.executePipelined(new SessionCallback() { - @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 { 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 { 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 { 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 { 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 { 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 { 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 { assertThat(redisTemplate.opsForValue().get(key1)).isEqualTo(value2); } - @Test + @ParameterizedRedisTest public void testUnwatch() { K key1 = keyFactory.instance(); @@ -748,11 +730,11 @@ public class RedisTemplateTests { } }); - 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 { 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 script = new DefaultRedisScript<>(); script.setScriptText("return 'Hey'"); @@ -807,13 +788,13 @@ public class RedisTemplateTests { 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 source = new LinkedHashMap<>(3, 1); source.put(keyFactory.instance(), valueFactory.instance()); diff --git a/src/test/java/org/springframework/data/redis/core/RedisTemplateUnitTests.java b/src/test/java/org/springframework/data/redis/core/RedisTemplateUnitTests.java index 6ea50e94e..0093199fc 100644 --- a/src/test/java/org/springframework/data/redis/core/RedisTemplateUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/RedisTemplateUnitTests.java @@ -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; diff --git a/src/test/java/org/springframework/data/redis/core/convert/BinaryKeyspaceIdentifierUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/BinaryKeyspaceIdentifierUnitTests.java index 4e9d158b3..890c8ab94 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/BinaryKeyspaceIdentifierUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/BinaryKeyspaceIdentifierUnitTests.java @@ -17,7 +17,7 @@ package org.springframework.data.redis.core.convert; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.redis.core.convert.MappingRedisConverter.BinaryKeyspaceIdentifier; @@ -26,10 +26,10 @@ import org.springframework.data.redis.core.convert.MappingRedisConverter.BinaryK * * @author Mark Paluch */ -public class BinaryKeyspaceIdentifierUnitTests { +class BinaryKeyspaceIdentifierUnitTests { @Test // DATAREDIS-744 - public void shouldReturnIfKeyIsValid() { + void shouldReturnIfKeyIsValid() { assertThat(BinaryKeyspaceIdentifier.isValid("foo".getBytes())).isFalse(); assertThat(BinaryKeyspaceIdentifier.isValid("".getBytes())).isFalse(); @@ -39,7 +39,7 @@ public class BinaryKeyspaceIdentifierUnitTests { } @Test // DATAREDIS-744 - public void shouldReturnKeyspace() { + void shouldReturnKeyspace() { assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).getKeyspace()).isEqualTo("foo".getBytes()); assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).getKeyspace()).isEqualTo("foo".getBytes()); @@ -47,7 +47,7 @@ public class BinaryKeyspaceIdentifierUnitTests { } @Test // DATAREDIS-744 - public void shouldReturnId() { + void shouldReturnId() { assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).getId()).isEqualTo("bar".getBytes()); assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).getId()).isEqualTo("bar:baz".getBytes()); @@ -55,7 +55,7 @@ public class BinaryKeyspaceIdentifierUnitTests { } @Test // DATAREDIS-744 - public void shouldReturnPhantomKey() { + void shouldReturnPhantomKey() { assertThat(BinaryKeyspaceIdentifier.of("foo:bar".getBytes()).isPhantomKey()).isFalse(); assertThat(BinaryKeyspaceIdentifier.of("foo:bar:baz".getBytes()).isPhantomKey()).isFalse(); diff --git a/src/test/java/org/springframework/data/redis/core/convert/CompositeIndexResolverUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/CompositeIndexResolverUnitTests.java index 314bc1d1f..84c25e8b9 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/CompositeIndexResolverUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/CompositeIndexResolverUnitTests.java @@ -21,36 +21,36 @@ import static org.mockito.Mockito.*; import java.util.Arrays; import java.util.Collections; -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; import org.springframework.data.util.TypeInformation; /** * @author Christoph Strobl */ -@RunWith(MockitoJUnitRunner.class) -public class CompositeIndexResolverUnitTests { +@ExtendWith(MockitoExtension.class) +class CompositeIndexResolverUnitTests { @Mock IndexResolver resolver1; @Mock IndexResolver resolver2; @Mock TypeInformation typeInfoMock; @Test // DATAREDIS-425 - public void shouldRejectNull() { + void shouldRejectNull() { assertThatIllegalArgumentException().isThrownBy(() -> new CompositeIndexResolver(null)); } @Test // DATAREDIS-425 - public void shouldRejectCollectionWithNullValues() { + void shouldRejectCollectionWithNullValues() { assertThatIllegalArgumentException() .isThrownBy(() -> new CompositeIndexResolver(Arrays.asList(resolver1, null, resolver2))); } @Test // DATAREDIS-425 - public void shouldCollectionIndexesFromResolvers() { + void shouldCollectionIndexesFromResolvers() { when(resolver1.resolveIndexesFor(any(TypeInformation.class), any())).thenReturn( Collections. singleton(new SimpleIndexedPropertyValue("spring", "data", "redis"))); diff --git a/src/test/java/org/springframework/data/redis/core/convert/DefaultRedisTypeMapperUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/DefaultRedisTypeMapperUnitTests.java index f92644c80..aba294c53 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/DefaultRedisTypeMapperUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/DefaultRedisTypeMapperUnitTests.java @@ -21,8 +21,8 @@ import static org.assertj.core.api.Assertions.*; import java.util.Arrays; import java.util.Collections; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.core.convert.support.GenericConversionService; import org.springframework.data.convert.ConfigurableTypeInformationMapper; import org.springframework.data.convert.SimpleTypeInformationMapper; @@ -34,15 +34,15 @@ import org.springframework.lang.Nullable; * * @author Mark Paluch */ -public class DefaultRedisTypeMapperUnitTests { +class DefaultRedisTypeMapperUnitTests { - GenericConversionService conversionService; - ConfigurableTypeInformationMapper configurableTypeInformationMapper; - SimpleTypeInformationMapper simpleTypeInformationMapper; - DefaultRedisTypeMapper typeMapper; + private GenericConversionService conversionService; + private ConfigurableTypeInformationMapper configurableTypeInformationMapper; + private SimpleTypeInformationMapper simpleTypeInformationMapper; + private DefaultRedisTypeMapper typeMapper; - @Before - public void setUp() { + @BeforeEach + void setUp() { conversionService = new GenericConversionService(); new RedisCustomConversions().registerConvertersIn(conversionService); @@ -54,12 +54,12 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void defaultInstanceWritesClasses() { + void defaultInstanceWritesClasses() { writesTypeToField(new Bucket(), String.class, String.class.getName()); } @Test // DATAREDIS-543 - public void defaultInstanceReadsClasses() { + void defaultInstanceReadsClasses() { Bucket bucket = Bucket .newBucketFromStringMap(singletonMap(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, String.class.getName())); @@ -67,7 +67,7 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void writesMapKeyForType() { + void writesMapKeyForType() { typeMapper = new DefaultRedisTypeMapper(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, Collections.singletonList(configurableTypeInformationMapper)); @@ -77,7 +77,7 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void writesClassNamesForUnmappedValuesIfConfigured() { + void writesClassNamesForUnmappedValuesIfConfigured() { typeMapper = new DefaultRedisTypeMapper(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, Arrays.asList(configurableTypeInformationMapper, simpleTypeInformationMapper)); @@ -87,7 +87,7 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void readsTypeForMapKey() { + void readsTypeForMapKey() { typeMapper = new DefaultRedisTypeMapper(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, Collections.singletonList(configurableTypeInformationMapper)); @@ -99,7 +99,7 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void readsTypeLoadingClassesForUnmappedTypesIfConfigured() { + void readsTypeLoadingClassesForUnmappedTypesIfConfigured() { typeMapper = new DefaultRedisTypeMapper(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, Arrays.asList(configurableTypeInformationMapper, simpleTypeInformationMapper)); @@ -111,57 +111,57 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void addsFullyQualifiedClassNameUnderDefaultKeyByDefault() { + void addsFullyQualifiedClassNameUnderDefaultKeyByDefault() { writesTypeToField(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, new Bucket(), String.class); } @Test // DATAREDIS-543 - public void writesTypeToCustomFieldIfConfigured() { + void writesTypeToCustomFieldIfConfigured() { typeMapper = new DefaultRedisTypeMapper("_custom"); writesTypeToField("_custom", new Bucket(), String.class); } @Test // DATAREDIS-543 - public void doesNotWriteTypeInformationInCaseKeyIsSetToNull() { + void doesNotWriteTypeInformationInCaseKeyIsSetToNull() { typeMapper = new DefaultRedisTypeMapper(null); writesTypeToField(null, new Bucket(), String.class); } @Test // DATAREDIS-543 - public void readsTypeFromDefaultKeyByDefault() { + void readsTypeFromDefaultKeyByDefault() { readsTypeFromField( Bucket.newBucketFromStringMap(singletonMap(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, String.class.getName())), String.class); } @Test // DATAREDIS-543 - public void readsTypeFromCustomFieldConfigured() { + void readsTypeFromCustomFieldConfigured() { typeMapper = new DefaultRedisTypeMapper("_custom"); readsTypeFromField(Bucket.newBucketFromStringMap(singletonMap("_custom", String.class.getName())), String.class); } @Test // DATAREDIS-543 - public void returnsListForBasicDBLists() { + void returnsListForBasicDBLists() { readsTypeFromField(new Bucket(), null); } @Test // DATAREDIS-543 - public void returnsNullIfNoTypeInfoInBucket() { + void returnsNullIfNoTypeInfoInBucket() { readsTypeFromField(new Bucket(), null); readsTypeFromField(Bucket.newBucketFromStringMap(singletonMap(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, "")), null); } @Test // DATAREDIS-543 - public void returnsNullIfClassCannotBeLoaded() { + void returnsNullIfClassCannotBeLoaded() { readsTypeFromField(Bucket.newBucketFromStringMap(singletonMap(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY, "fooBar")), null); } @Test // DATAREDIS-543 - public void returnsNullIfTypeKeySetToNull() { + void returnsNullIfTypeKeySetToNull() { typeMapper = new DefaultRedisTypeMapper(null); readsTypeFromField( @@ -170,7 +170,7 @@ public class DefaultRedisTypeMapperUnitTests { } @Test // DATAREDIS-543 - public void returnsCorrectTypeKey() { + void returnsCorrectTypeKey() { assertThat(typeMapper.isTypeKey(DefaultRedisTypeMapper.DEFAULT_TYPE_KEY)).isTrue(); diff --git a/src/test/java/org/springframework/data/redis/core/convert/KeyspaceIdentifierUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/KeyspaceIdentifierUnitTests.java index 4cd3b2934..7ca98454b 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/KeyspaceIdentifierUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/KeyspaceIdentifierUnitTests.java @@ -17,7 +17,7 @@ package org.springframework.data.redis.core.convert; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.data.redis.core.convert.MappingRedisConverter.KeyspaceIdentifier; @@ -26,10 +26,10 @@ import org.springframework.data.redis.core.convert.MappingRedisConverter.Keyspac * * @author Mark Paluch */ -public class KeyspaceIdentifierUnitTests { +class KeyspaceIdentifierUnitTests { @Test // DATAREDIS-744 - public void shouldReturnIfKeyIsValid() { + void shouldReturnIfKeyIsValid() { assertThat(KeyspaceIdentifier.isValid(null)).isFalse(); assertThat(KeyspaceIdentifier.isValid("foo")).isFalse(); @@ -40,7 +40,7 @@ public class KeyspaceIdentifierUnitTests { } @Test // DATAREDIS-744 - public void shouldReturnKeyspace() { + void shouldReturnKeyspace() { assertThat(KeyspaceIdentifier.of("foo:bar").getKeyspace()).isEqualTo("foo"); assertThat(KeyspaceIdentifier.of("foo:bar:baz").getKeyspace()).isEqualTo("foo"); @@ -48,7 +48,7 @@ public class KeyspaceIdentifierUnitTests { } @Test // DATAREDIS-744 - public void shouldReturnId() { + void shouldReturnId() { assertThat(KeyspaceIdentifier.of("foo:bar").getId()).isEqualTo("bar"); assertThat(KeyspaceIdentifier.of("foo:bar:baz").getId()).isEqualTo("bar:baz"); @@ -56,7 +56,7 @@ public class KeyspaceIdentifierUnitTests { } @Test // DATAREDIS-744 - public void shouldReturnPhantomKey() { + void shouldReturnPhantomKey() { assertThat(KeyspaceIdentifier.of("foo:bar").isPhantomKey()).isFalse(); assertThat(KeyspaceIdentifier.of("foo:bar:baz").isPhantomKey()).isFalse(); diff --git a/src/test/java/org/springframework/data/redis/core/convert/MappingRedisConverterUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/MappingRedisConverterUnitTests.java index 07c49f283..b35ea63ce 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/MappingRedisConverterUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/MappingRedisConverterUnitTests.java @@ -40,13 +40,12 @@ import java.util.List; import java.util.Map; import java.util.UUID; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.core.convert.converter.Converter; import org.springframework.data.convert.ReadingConverter; import org.springframework.data.convert.WritingConverter; @@ -70,16 +69,15 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Mark Paluch * @author Golam Mazid Sajib */ -@RunWith(MockitoJUnitRunner.class) -public class MappingRedisConverterUnitTests { +@ExtendWith(MockitoExtension.class) +class MappingRedisConverterUnitTests { - public @Rule ExpectedException exception = ExpectedException.none(); @Mock ReferenceResolver resolverMock; - MappingRedisConverter converter; - Person rand; + private MappingRedisConverter converter; + private Person rand; - @Before - public void setUp() { + @BeforeEach + void setUp() { converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); converter.afterPropertiesSet(); @@ -88,12 +86,12 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsTypeHintForRootCorrectly() { + void writeAppendsTypeHintForRootCorrectly() { assertThat(write(rand)).containingTypeHint("_class", Person.class); } @Test // DATAREDIS-543 - public void writeSkipsTypeHintIfConfigured() { + void writeSkipsTypeHintIfConfigured() { converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); converter.afterPropertiesSet(); @@ -102,7 +100,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsKeyCorrectly() { + void writeAppendsKeyCorrectly() { rand.id = "1"; @@ -110,7 +108,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsKeyCorrectlyWhenThereIsAnAdditionalIdFieldInNestedElement() { + void writeAppendsKeyCorrectlyWhenThereIsAnAdditionalIdFieldInNestedElement() { AddressWithId address = new AddressWithId(); address.id = "tear"; @@ -126,7 +124,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeDoesNotAppendPropertiesWithNullValues() { + void writeDoesNotAppendPropertiesWithNullValues() { rand.firstname = "rand"; @@ -134,7 +132,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeDoesNotAppendPropertiesWithEmptyCollections() { + void writeDoesNotAppendPropertiesWithEmptyCollections() { rand.firstname = "rand"; @@ -142,7 +140,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsSimpleRootPropertyCorrectly() { + void writeAppendsSimpleRootPropertyCorrectly() { rand.firstname = "nynaeve"; @@ -150,7 +148,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsListOfSimplePropertiesCorrectly() { + void writeAppendsListOfSimplePropertiesCorrectly() { rand.nicknames = Arrays.asList("dragon reborn", "lews therin"); @@ -160,7 +158,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsComplexObjectCorrectly() { + void writeAppendsComplexObjectCorrectly() { Address address = new Address(); address.city = "two rivers"; @@ -173,7 +171,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsListOfComplexObjectsCorrectly() { + void writeAppendsListOfComplexObjectsCorrectly() { Person mat = new Person(); mat.firstname = "mat"; @@ -197,7 +195,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeDoesNotAddClassTypeInformationCorrectlyForMatchingTypes() { + void writeDoesNotAddClassTypeInformationCorrectlyForMatchingTypes() { Address address = new Address(); address.city = "two rivers"; @@ -210,7 +208,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425, DATAREDIS-543 - public void writeAddsClassTypeInformationCorrectlyForNonMatchingTypes() { + void writeAddsClassTypeInformationCorrectlyForNonMatchingTypes() { AddressWithPostcode address = new AddressWithPostcode(); address.city = "two rivers"; @@ -224,7 +222,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readConsidersClassTypeInformationCorrectlyForNonMatchingTypes() { + void readConsidersClassTypeInformationCorrectlyForNonMatchingTypes() { Map map = new HashMap<>(); map.put("address._class", AddressWithPostcode.class.getName()); @@ -236,7 +234,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-544 - public void readEntityViaConstructor() { + void readEntityViaConstructor() { Map map = new HashMap<>(); map.put("id", "bart"); @@ -261,7 +259,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAddsClassTypeInformationCorrectlyForNonMatchingTypesInCollections() { + void writeAddsClassTypeInformationCorrectlyForNonMatchingTypesInCollections() { Person mat = new TaVeren(); mat.firstname = "mat"; @@ -274,7 +272,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readConvertsSimplePropertiesCorrectly() { + void readConvertsSimplePropertiesCorrectly() { RedisData rdo = new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("firstname", "rand"))); @@ -282,7 +280,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readConvertsListOfSimplePropertiesCorrectly() { + void readConvertsListOfSimplePropertiesCorrectly() { Map map = new LinkedHashMap<>(); map.put("nicknames.[0]", "dragon reborn"); @@ -293,7 +291,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readConvertsUnorderedListOfSimplePropertiesCorrectly() { + void readConvertsUnorderedListOfSimplePropertiesCorrectly() { Map map = new LinkedHashMap<>(); map.put("nicknames.[9]", "car'a'carn"); @@ -306,7 +304,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void readConvertsUnorderedListOfSimpleIntegerPropertiesCorrectly() { + void readConvertsUnorderedListOfSimpleIntegerPropertiesCorrectly() { Map map = new LinkedHashMap<>(); map.put("positions.[9]", "0"); @@ -318,7 +316,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readComplexPropertyCorrectly() { + void readComplexPropertyCorrectly() { Map map = new LinkedHashMap<>(); map.put("address.city", "two rivers"); @@ -333,7 +331,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readListComplexPropertyCorrectly() { + void readListComplexPropertyCorrectly() { Map map = new LinkedHashMap<>(); map.put("coworkers.[0].firstname", "mat"); @@ -356,7 +354,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readUnorderedListOfComplexPropertyCorrectly() { + void readUnorderedListOfComplexPropertyCorrectly() { Map map = new LinkedHashMap<>(); map.put("coworkers.[10].firstname", "perrin"); @@ -380,7 +378,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readListComplexPropertyCorrectlyAndConsidersClassTypeInformation() { + void readListComplexPropertyCorrectlyAndConsidersClassTypeInformation() { Map map = new LinkedHashMap<>(); map.put("coworkers.[0]._class", TaVeren.class.getName()); @@ -396,7 +394,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsMapWithSimpleKeyCorrectly() { + void writeAppendsMapWithSimpleKeyCorrectly() { Map map = new LinkedHashMap<>(); map.put("hair-color", "red"); @@ -411,7 +409,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsMapWithSimpleKeyOnNestedObjectCorrectly() { + void writeAppendsMapWithSimpleKeyOnNestedObjectCorrectly() { Map map = new LinkedHashMap<>(); map.put("hair-color", "red"); @@ -428,7 +426,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readSimpleMapValuesCorrectly() { + void readSimpleMapValuesCorrectly() { Map map = new LinkedHashMap<>(); map.put("physicalAttributes.[hair-color]", "red"); @@ -444,7 +442,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void readSimpleIntegerMapValuesCorrectly() { + void readSimpleIntegerMapValuesCorrectly() { Map map = new LinkedHashMap<>(); map.put("integerMapKeyMapping.[1]", "2"); @@ -460,7 +458,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void readMapWithDecimalMapKeyCorrectly() { + void readMapWithDecimalMapKeyCorrectly() { Map map = new LinkedHashMap<>(); map.put("decimalMapKeyMapping.[1.7]", "2"); @@ -476,7 +474,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void writeMapWithDecimalMapKeyCorrectly() { + void writeMapWithDecimalMapKeyCorrectly() { TypeWithMaps source = new TypeWithMaps(); source.decimalMapKeyMapping = new LinkedHashMap<>(); @@ -490,7 +488,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void readMapWithDateMapKeyCorrectly() { + void readMapWithDateMapKeyCorrectly() { Date judgmentDay = Date.from(Instant.parse("1979-08-29T12:00:00Z")); @@ -506,7 +504,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void writeMapWithDateMapKeyCorrectly() { + void writeMapWithDateMapKeyCorrectly() { Date judgmentDay = Date.from(Instant.parse("1979-08-29T12:00:00Z")); @@ -517,7 +515,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsMapWithComplexObjectsCorrectly() { + void writeAppendsMapWithComplexObjectsCorrectly() { Map map = new LinkedHashMap<>(); Person janduin = new Person(); @@ -536,7 +534,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readMapWithComplexObjectsCorrectly() { + void readMapWithComplexObjectsCorrectly() { Map map = new LinkedHashMap<>(); map.put("relatives.[father].firstname", "janduin"); @@ -552,7 +550,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-768 - public void readMapWithIntegerKeysAndComplexObjectsCorrectly() { + void readMapWithIntegerKeysAndComplexObjectsCorrectly() { Map map = new LinkedHashMap<>(); map.put("favoredRelatives.[1].firstname", "janduin"); @@ -568,7 +566,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeAppendsClassTypeInformationCorrectlyForMapWithComplexObjects() { + void writeAppendsClassTypeInformationCorrectlyForMapWithComplexObjects() { Map map = new LinkedHashMap<>(); Person lews = new TaVeren(); @@ -583,7 +581,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readConsidersClassTypeInformationCorrectlyForMapWithComplexObjects() { + void readConsidersClassTypeInformationCorrectlyForMapWithComplexObjects() { Map map = new LinkedHashMap<>(); map.put("relatives.[previous-incarnation]._class", TaVeren.class.getName()); @@ -597,7 +595,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesIntegerValuesCorrectly() { + void writesIntegerValuesCorrectly() { rand.age = 20; @@ -605,7 +603,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesLocalDateTimeValuesCorrectly() { + void writesLocalDateTimeValuesCorrectly() { rand.localDateTime = LocalDateTime.parse("2016-02-19T10:18:01"); @@ -613,7 +611,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsLocalDateTimeValuesCorrectly() { + void readsLocalDateTimeValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("localDateTime", "2016-02-19T10:18:01")))); @@ -622,7 +620,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesLocalDateValuesCorrectly() { + void writesLocalDateValuesCorrectly() { rand.localDate = LocalDate.parse("2016-02-19"); @@ -630,7 +628,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsLocalDateValuesCorrectly() { + void readsLocalDateValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("localDate", "2016-02-19")))); @@ -639,7 +637,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesLocalTimeValuesCorrectly() { + void writesLocalTimeValuesCorrectly() { rand.localTime = LocalTime.parse("11:12:13"); @@ -647,7 +645,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsLocalTimeValuesCorrectly() { + void readsLocalTimeValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("localTime", "11:12")))); @@ -656,7 +654,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesZonedDateTimeValuesCorrectly() { + void writesZonedDateTimeValuesCorrectly() { rand.zonedDateTime = ZonedDateTime.parse("2007-12-03T10:15:30+01:00[Europe/Paris]"); @@ -664,7 +662,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsZonedDateTimeValuesCorrectly() { + void readsZonedDateTimeValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket .newBucketFromStringMap(Collections.singletonMap("zonedDateTime", "2007-12-03T10:15:30+01:00[Europe/Paris]")))); @@ -673,7 +671,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesInstantValuesCorrectly() { + void writesInstantValuesCorrectly() { rand.instant = Instant.parse("2007-12-03T10:15:30.01Z"); @@ -681,7 +679,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsInstantValuesCorrectly() { + void readsInstantValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("instant", "2007-12-03T10:15:30.01Z")))); @@ -690,7 +688,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesZoneIdValuesCorrectly() { + void writesZoneIdValuesCorrectly() { rand.zoneId = ZoneId.of("Europe/Paris"); @@ -698,7 +696,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsZoneIdValuesCorrectly() { + void readsZoneIdValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("zoneId", "Europe/Paris")))); @@ -707,7 +705,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesDurationValuesCorrectly() { + void writesDurationValuesCorrectly() { rand.duration = Duration.parse("P2DT3H4M"); @@ -715,7 +713,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsDurationValuesCorrectly() { + void readsDurationValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("duration", "PT51H4M")))); @@ -724,7 +722,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesPeriodValuesCorrectly() { + void writesPeriodValuesCorrectly() { rand.period = Period.parse("P1Y2M25D"); @@ -732,7 +730,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsPeriodValuesCorrectly() { + void readsPeriodValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("period", "P1Y2M25D")))); @@ -741,7 +739,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425, DATAREDIS-593 - public void writesEnumValuesCorrectly() { + void writesEnumValuesCorrectly() { rand.gender = Gender.FEMALE; @@ -749,7 +747,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425, DATAREDIS-593 - public void readsEnumValuesCorrectly() { + void readsEnumValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("gender", "FEMALE")))); @@ -758,7 +756,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesBooleanValuesCorrectly() { + void writesBooleanValuesCorrectly() { rand.alive = Boolean.TRUE; @@ -766,7 +764,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsBooleanValuesCorrectly() { + void readsBooleanValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("alive", "1")))); @@ -775,7 +773,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsStringBooleanValuesCorrectly() { + void readsStringBooleanValuesCorrectly() { Person target = converter.read(Person.class, new RedisData(Bucket.newBucketFromStringMap(Collections.singletonMap("alive", "true")))); @@ -784,7 +782,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writesDateValuesCorrectly() { + void writesDateValuesCorrectly() { Calendar cal = Calendar.getInstance(); cal.set(1978, Calendar.NOVEMBER, 25); @@ -795,7 +793,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readsDateValuesCorrectly() { + void readsDateValuesCorrectly() { Calendar cal = Calendar.getInstance(); cal.set(1978, Calendar.NOVEMBER, 25); @@ -809,7 +807,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeSingleReferenceOnRootCorrectly() { + void writeSingleReferenceOnRootCorrectly() { Location location = new Location(); location.id = "1"; @@ -825,7 +823,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readLoadsReferenceDataOnRootCorrectly() { + void readLoadsReferenceDataOnRootCorrectly() { Location location = new Location(); location.id = "1"; @@ -847,7 +845,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeSingleReferenceOnNestedElementCorrectly() { + void writeSingleReferenceOnNestedElementCorrectly() { Location location = new Location(); location.id = "1"; @@ -864,7 +862,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readLoadsReferenceDataOnNestedElementCorrectly() { + void readLoadsReferenceDataOnNestedElementCorrectly() { Location location = new Location(); location.id = "1"; @@ -886,7 +884,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeListOfReferencesOnRootCorrectly() { + void writeListOfReferencesOnRootCorrectly() { Location tarValon = new Location(); tarValon.id = "1"; @@ -910,7 +908,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readLoadsListOfReferencesOnRootCorrectly() { + void readLoadsListOfReferencesOnRootCorrectly() { Location tarValon = new Location(); tarValon.id = "1"; @@ -958,7 +956,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeSetsAnnotatedTimeToLiveCorrectly() { + void writeSetsAnnotatedTimeToLiveCorrectly() { ExpiringPerson birgitte = new ExpiringPerson(); birgitte.id = "birgitte"; @@ -968,7 +966,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeDoesNotTTLWhenNotPresent() { + void writeDoesNotTTLWhenNotPresent() { Location tear = new Location(); tear.id = "tear"; @@ -978,7 +976,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldConsiderKeyspaceConfiguration() { + void writeShouldConsiderKeyspaceConfiguration() { this.converter.getMappingContext().getMappingConfiguration().getKeyspaceConfiguration() .addKeyspaceSettings(new KeyspaceSettings(Address.class, "o_O")); @@ -990,7 +988,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldConsiderTimeToLiveConfiguration() { + void writeShouldConsiderTimeToLiveConfiguration() { KeyspaceSettings assignment = new KeyspaceSettings(Address.class, "o_O"); assignment.setTimeToLive(5L); @@ -1005,7 +1003,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425, DATAREDIS-634 - public void writeShouldHonorCustomConversionOnRootType() { + void writeShouldHonorCustomConversionOnRootType() { RedisCustomConversions customConversions = new RedisCustomConversions( Collections.singletonList(new AddressToBytesConverter())); @@ -1025,7 +1023,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425, DATAREDIS-634 - public void writeShouldHonorCustomConversionOnNestedType() { + void writeShouldHonorCustomConversionOnNestedType() { RedisCustomConversions customConversions = new RedisCustomConversions( Collections.singletonList(new AddressToBytesConverter())); @@ -1046,7 +1044,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldHonorIndexOnCustomConversionForNestedType() { + void writeShouldHonorIndexOnCustomConversionForNestedType() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1062,7 +1060,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldHonorIndexAnnotationsOnWhenCustomConversionOnNestedype() { + void writeShouldHonorIndexAnnotationsOnWhenCustomConversionOnNestedype() { this.converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); this.converter @@ -1078,7 +1076,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readShouldHonorCustomConversionOnRootType() { + void readShouldHonorCustomConversionOnRootType() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1095,7 +1093,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readShouldHonorCustomConversionOnNestedType() { + void readShouldHonorCustomConversionOnNestedType() { this.converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); this.converter @@ -1113,7 +1111,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-544 - public void readShouldHonorCustomConversionOnNestedTypeViaConstructorCreation() { + void readShouldHonorCustomConversionOnNestedTypeViaConstructorCreation() { this.converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); this.converter @@ -1132,7 +1130,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldPickUpTimeToLiveFromPropertyIfPresent() { + void writeShouldPickUpTimeToLiveFromPropertyIfPresent() { ExipringPersonWithExplicitProperty aviendha = new ExipringPersonWithExplicitProperty(); aviendha.id = "aviendha"; @@ -1142,7 +1140,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldUseDefaultTimeToLiveIfPropertyIsPresentButNull() { + void writeShouldUseDefaultTimeToLiveIfPropertyIsPresentButNull() { ExipringPersonWithExplicitProperty aviendha = new ExipringPersonWithExplicitProperty(); aviendha.id = "aviendha"; @@ -1151,7 +1149,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldConsiderMapConvertersForRootType() { + void writeShouldConsiderMapConvertersForRootType() { this.converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); this.converter @@ -1167,7 +1165,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldConsiderMapConvertersForNestedType() { + void writeShouldConsiderMapConvertersForNestedType() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1181,7 +1179,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readShouldConsiderMapConvertersForRootType() { + void readShouldConsiderMapConvertersForRootType() { this.converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); this.converter @@ -1197,7 +1195,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readShouldConsiderMapConvertersForNestedType() { + void readShouldConsiderMapConvertersForNestedType() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1214,7 +1212,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void writeShouldConsiderMapConvertersInsideLists() { + void writeShouldConsiderMapConvertersInsideLists() { this.converter = new MappingRedisConverter(new RedisMappingContext(), null, resolverMock); this.converter @@ -1234,7 +1232,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-425 - public void readShouldConsiderMapConvertersForValuesInList() { + void readShouldConsiderMapConvertersForValuesInList() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1253,7 +1251,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-492 - public void writeHandlesArraysOfSimpleTypeProperly() { + void writeHandlesArraysOfSimpleTypeProperly() { WithArrays source = new WithArrays(); source.arrayOfSimpleTypes = new String[] { "rand", "mat", "perrin" }; @@ -1263,7 +1261,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-492 - public void readHandlesArraysOfSimpleTypeProperly() { + void readHandlesArraysOfSimpleTypeProperly() { Map source = new LinkedHashMap<>(); source.put("arrayOfSimpleTypes.[0]", "rand"); @@ -1276,7 +1274,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-492 - public void writeHandlesArraysOfComplexTypeProperly() { + void writeHandlesArraysOfComplexTypeProperly() { WithArrays source = new WithArrays(); @@ -1297,7 +1295,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-492 - public void readHandlesArraysOfComplexTypeProperly() { + void readHandlesArraysOfComplexTypeProperly() { Map source = new LinkedHashMap<>(); source.put("arrayOfCompexTypes.[0].name", "trolloc"); @@ -1316,7 +1314,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void writeHandlesArraysOfObjectTypeProperly() { + void writeHandlesArraysOfObjectTypeProperly() { Species trolloc = new Species(); trolloc.name = "trolloc"; @@ -1333,7 +1331,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void readHandlesArraysOfObjectTypeProperly() { + void readHandlesArraysOfObjectTypeProperly() { Map source = new LinkedHashMap<>(); source.put("arrayOfObject.[0]", "rand"); @@ -1354,7 +1352,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void writeShouldAppendTyeHintToObjectPropertyValueTypesCorrectly() { + void writeShouldAppendTyeHintToObjectPropertyValueTypesCorrectly() { TypeWithObjectValueTypes sample = new TypeWithObjectValueTypes(); sample.object = "bar"; @@ -1365,7 +1363,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void shouldWriteReadObjectPropertyValueTypeCorrectly() { + void shouldWriteReadObjectPropertyValueTypeCorrectly() { TypeWithObjectValueTypes di = new TypeWithObjectValueTypes(); di.object = "foo"; @@ -1377,7 +1375,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void writeShouldAppendTyeHintToObjectMapValueTypesCorrectly() { + void writeShouldAppendTyeHintToObjectMapValueTypesCorrectly() { TypeWithObjectValueTypes sample = new TypeWithObjectValueTypes(); sample.map.put("string", "bar"); @@ -1392,7 +1390,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void shouldWriteReadObjectMapValueTypeCorrectly() { + void shouldWriteReadObjectMapValueTypeCorrectly() { TypeWithObjectValueTypes sample = new TypeWithObjectValueTypes(); sample.map.put("string", "bar"); @@ -1408,7 +1406,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void writeShouldAppendTyeHintToObjectListValueTypesCorrectly() { + void writeShouldAppendTyeHintToObjectListValueTypesCorrectly() { TypeWithObjectValueTypes sample = new TypeWithObjectValueTypes(); sample.list.add("string"); @@ -1423,7 +1421,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-489 - public void shouldWriteReadObjectListValueTypeCorrectly() { + void shouldWriteReadObjectListValueTypeCorrectly() { TypeWithObjectValueTypes sample = new TypeWithObjectValueTypes(); sample.list.add("string"); @@ -1439,7 +1437,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-909 - public void shouldWriteReadObjectWithConstructorConversion() { + void shouldWriteReadObjectWithConstructorConversion() { Device sample = new Device(Instant.now(), Collections.singleton("foo")); @@ -1451,7 +1449,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-509 - public void writeHandlesArraysOfPrimitivesProperly() { + void writeHandlesArraysOfPrimitivesProperly() { Map source = new LinkedHashMap<>(); source.put("arrayOfPrimitives.[0]", "1"); @@ -1466,7 +1464,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-509 - public void readHandlesArraysOfPrimitivesProperly() { + void readHandlesArraysOfPrimitivesProperly() { WithArrays source = new WithArrays(); source.arrayOfPrimitives = new int[] { 1, 2, 3 }; @@ -1475,7 +1473,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldNotAppendClassTypeHint() { + void writeShouldNotAppendClassTypeHint() { Person value = new Person(); value.firstname = "rand"; @@ -1487,7 +1485,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdateSimpleValueCorrectly() { + void writeShouldWritePartialUpdateSimpleValueCorrectly() { Person value = new Person(); value.firstname = "rand"; @@ -1499,7 +1497,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleValueCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleValueCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("firstname", "rand").set("age", 24); @@ -1507,7 +1505,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdateNestedPathWithSimpleValueCorrectly() { + void writeShouldWritePartialUpdateNestedPathWithSimpleValueCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("address.city", "two rivers"); @@ -1515,7 +1513,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithComplexValueCorrectly() { + void writeShouldWritePartialUpdatePathWithComplexValueCorrectly() { Address address = new Address(); address.city = "two rivers"; @@ -1527,7 +1525,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleListValueCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleListValueCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("nicknames", Arrays.asList("dragon", "lews")); @@ -1536,7 +1534,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithComplexListValueCorrectly() { + void writeShouldWritePartialUpdatePathWithComplexListValueCorrectly() { Person mat = new Person(); mat.firstname = "mat"; @@ -1553,7 +1551,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("nicknames", "dragon"); @@ -1561,7 +1559,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithComplexListValueWhenNotPassedInAsCollectionCorrectly() { + void writeShouldWritePartialUpdatePathWithComplexListValueWhenNotPassedInAsCollectionCorrectly() { Person mat = new Person(); mat.firstname = "mat"; @@ -1573,7 +1571,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("nicknames.[5]", "dragon"); @@ -1581,7 +1579,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithComplexListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() { + void writeShouldWritePartialUpdatePathWithComplexListValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() { Person mat = new Person(); mat.firstname = "mat"; @@ -1593,7 +1591,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleMapValueCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleMapValueCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("physicalAttributes", Collections.singletonMap("eye-color", "grey")); @@ -1602,7 +1600,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithComplexMapValueCorrectly() { + void writeShouldWritePartialUpdatePathWithComplexMapValueCorrectly() { Person tam = new Person(); tam.firstname = "tam"; @@ -1616,7 +1614,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("physicalAttributes", Collections.singletonMap("eye-color", "grey").entrySet().iterator().next()); @@ -1625,7 +1623,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithComplexMapValueWhenNotPassedInAsCollectionCorrectly() { + void writeShouldWritePartialUpdatePathWithComplexMapValueWhenNotPassedInAsCollectionCorrectly() { Person tam = new Person(); tam.firstname = "tam"; @@ -1639,7 +1637,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleMapValueWhenNotPassedInAsCollectionWithPositionalParameterCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("physicalAttributes.[eye-color]", "grey"); @@ -1648,23 +1646,23 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithSimpleMapValueOnNestedElementCorrectly() { + void writeShouldWritePartialUpdatePathWithSimpleMapValueOnNestedElementCorrectly() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("relatives.[father].firstname", "tam"); assertThat(write(update)).containsEntry("relatives.[father].firstname", "tam"); } - @Test(expected = MappingException.class) // DATAREDIS-471 - public void writeShouldThrowExceptionOnPartialUpdatePathWithSimpleMapValueWhenItsASingleValueWithoutPath() { + @Test // DATAREDIS-471 + void writeShouldThrowExceptionOnPartialUpdatePathWithSimpleMapValueWhenItsASingleValueWithoutPath() { PartialUpdate update = new PartialUpdate<>("123", Person.class).set("physicalAttributes", "grey"); - write(update); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> write(update)); } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithRegisteredCustomConversionCorrectly() { + void writeShouldWritePartialUpdatePathWithRegisteredCustomConversionCorrectly() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1681,7 +1679,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithReferenceCorrectly() { + void writeShouldWritePartialUpdatePathWithReferenceCorrectly() { Location tar = new Location(); tar.id = "1"; @@ -1699,7 +1697,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldWritePartialUpdatePathWithListOfReferencesCorrectly() { + void writeShouldWritePartialUpdatePathWithListOfReferencesCorrectly() { Location location = new Location(); location.id = "1"; @@ -1714,77 +1712,62 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-471 - public void writeShouldThrowExceptionForUpdateValueNotAssignableToDomainTypeProperty() { - - exception.expect(MappingException.class); - exception.expectMessage("java.lang.String cannot be assigned"); - exception.expectMessage("java.lang.Integer"); - exception.expectMessage("age"); + void writeShouldThrowExceptionForUpdateValueNotAssignableToDomainTypeProperty() { PartialUpdate update = new PartialUpdate<>("123", Person.class) // .set("age", "twenty-four"); - assertThat(write(update).getBucket().get("_class")).isNull(); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> write(update)) + .withMessageContaining("java.lang.String cannot be assigned"); } @Test // DATAREDIS-471 - public void writeShouldThrowExceptionForUpdateCollectionValueNotAssignableToDomainTypeProperty() { - - exception.expect(MappingException.class); - exception.expectMessage("java.lang.String cannot be assigned"); - exception.expectMessage(Person.class.getName()); - exception.expectMessage("coworkers.[0]"); + void writeShouldThrowExceptionForUpdateCollectionValueNotAssignableToDomainTypeProperty() { PartialUpdate update = new PartialUpdate<>("123", Person.class) // .set("coworkers.[0]", "buh buh the bear"); - assertThat(write(update).getBucket().get("_class")).isNull(); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> write(update)) + .withMessageContaining("java.lang.String cannot be assigned").withMessageContaining(Person.class.getName()) + .withMessageContaining("coworkers.[0]"); } @Test // DATAREDIS-471 - public void writeShouldThrowExceptionForUpdateValueInCollectionNotAssignableToDomainTypeProperty() { + void writeShouldThrowExceptionForUpdateValueInCollectionNotAssignableToDomainTypeProperty() { - exception.expect(MappingException.class); - exception.expectMessage("java.lang.String cannot be assigned"); - exception.expectMessage(Person.class.getName()); - exception.expectMessage("coworkers"); PartialUpdate update = new PartialUpdate<>("123", Person.class) // .set("coworkers", Collections.singletonList("foo")); - assertThat(write(update).getBucket().get("_class")).isNull(); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> write(update)) + .withMessageContaining("java.lang.String cannot be assigned").withMessageContaining(Person.class.getName()) + .withMessageContaining("coworkers"); } @Test // DATAREDIS-471 - public void writeShouldThrowExceptionForUpdateMapValueNotAssignableToDomainTypeProperty() { - - exception.expect(MappingException.class); - exception.expectMessage("java.lang.String cannot be assigned"); - exception.expectMessage(Person.class.getName()); - exception.expectMessage("relatives.[father]"); + void writeShouldThrowExceptionForUpdateMapValueNotAssignableToDomainTypeProperty() { PartialUpdate update = new PartialUpdate<>("123", Person.class) // .set("relatives.[father]", "buh buh the bear"); - assertThat(write(update).getBucket().get("_class")).isNull(); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> write(update)) + .withMessageContaining("java.lang.String cannot be assigned").withMessageContaining(Person.class.getName()) + .withMessageContaining("relatives.[father]"); } @Test // DATAREDIS-471 - public void writeShouldThrowExceptionForUpdateValueInMapNotAssignableToDomainTypeProperty() { - - exception.expect(MappingException.class); - exception.expectMessage("java.lang.String cannot be assigned"); - exception.expectMessage(Person.class.getName()); - exception.expectMessage("relatives.[father]"); + void writeShouldThrowExceptionForUpdateValueInMapNotAssignableToDomainTypeProperty() { PartialUpdate update = new PartialUpdate<>("123", Person.class) // .set("relatives", Collections.singletonMap("father", "buh buh the bear")); - assertThat(write(update).getBucket().get("_class")).isNull(); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> write(update)) + .withMessageContaining("java.lang.String cannot be assigned").withMessageContaining(Person.class.getName()) + .withMessageContaining("relatives.[father]"); } @Test // DATAREDIS-875 - public void shouldNotWriteTypeHintForPrimitveTypes() { + void shouldNotWriteTypeHintForPrimitveTypes() { Size source = new Size(); source.height = 1; @@ -1793,7 +1776,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-875 - public void shouldReadPrimitveTypes() { + void shouldReadPrimitveTypes() { Map source = new LinkedHashMap<>(); source.put("height", "1000"); @@ -1802,7 +1785,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-925 - public void readUUID() { + void readUUID() { UUID uuid = UUID.randomUUID(); Map source = new LinkedHashMap<>(); @@ -1812,7 +1795,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-925 - public void writeUUID() { + void writeUUID() { JustSomeDifferentPropertyTypes source = new JustSomeDifferentPropertyTypes(); source.uuid = UUID.randomUUID(); @@ -1821,7 +1804,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-955 - public void readInnerListShouldNotInfluenceOuterWithSameName() { + void readInnerListShouldNotInfluenceOuterWithSameName() { Map source = new LinkedHashMap<>(); source.put("inners.[0].values.[0]", "i-1"); @@ -1836,7 +1819,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-955 - public void readInnerListShouldNotInfluenceOuterWithSameNameWhenNull() { + void readInnerListShouldNotInfluenceOuterWithSameNameWhenNull() { Map source = new LinkedHashMap<>(); source.put("inners.[0].values.[0]", "i-1"); @@ -1849,7 +1832,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-911 - public void writeEntityWithCustomConverter() { + void writeEntityWithCustomConverter() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1865,7 +1848,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-911 - public void readEntityWithCustomConverter() { + void readEntityWithCustomConverter() { this.converter = new MappingRedisConverter(null, null, resolverMock); this.converter @@ -1886,13 +1869,11 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-1175 - public void writePlainList() { + void writePlainList() { List source = Arrays.asList("Hello", "stream", "message", 100L); RedisTestData target = write(source); - System.out.println(target.getBucket().toString()); - assertThat(target).containsEntry("[0]", "Hello") // .containsEntry("[1]", "stream") // .containsEntry("[2]", "message") // @@ -1900,7 +1881,7 @@ public class MappingRedisConverterUnitTests { } @Test // DATAREDIS-1175 - public void readPlainList() { + void readPlainList() { Map source = new LinkedHashMap<>(); source.put("[0]._class", "java.lang.String"); diff --git a/src/test/java/org/springframework/data/redis/core/convert/PathIndexResolverUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/PathIndexResolverUnitTests.java index 908be4b17..9974038fc 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/PathIndexResolverUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/PathIndexResolverUnitTests.java @@ -26,13 +26,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.geo.Point; import org.springframework.data.mapping.PersistentProperty; @@ -48,18 +48,17 @@ import org.springframework.data.util.ClassTypeInformation; * @author Christoph Strobl * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.Silent.class) -public class PathIndexResolverUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class PathIndexResolverUnitTests { - public @Rule ExpectedException exception = ExpectedException.none(); - - IndexConfiguration indexConfig; - PathIndexResolver indexResolver; + private IndexConfiguration indexConfig; + private PathIndexResolver indexResolver; @Mock PersistentProperty propertyMock; - @Before - public void setUp() { + @BeforeEach + void setUp() { indexConfig = new IndexConfiguration(); this.indexResolver = new PathIndexResolver( @@ -67,35 +66,35 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void shouldThrowExceptionOnNullMappingContext() { + void shouldThrowExceptionOnNullMappingContext() { assertThatIllegalArgumentException().isThrownBy(() -> new PathIndexResolver(null)); } @Test // DATAREDIS-425 - public void shouldResolveAnnotatedIndexOnRootWhenValueIsNotNull() { + void shouldResolveAnnotatedIndexOnRootWhenValueIsNotNull() { Address address = new Address(); address.country = "andor"; Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Address.class), address); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes).contains(new SimpleIndexedPropertyValue(Address.class.getName(), "country", "andor")); } @Test // DATAREDIS-425 - public void shouldNotResolveAnnotatedIndexOnRootWhenValueIsNull() { + void shouldNotResolveAnnotatedIndexOnRootWhenValueIsNull() { Address address = new Address(); address.country = null; Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Address.class), address); - assertThat(indexes.size()).isEqualTo(0); + assertThat(indexes).isEmpty(); } @Test // DATAREDIS-425 - public void shouldResolveAnnotatedIndexOnNestedObjectWhenValueIsNotNull() { + void shouldResolveAnnotatedIndexOnNestedObjectWhenValueIsNotNull() { Person person = new Person(); person.address = new Address(); @@ -103,12 +102,12 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), person); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "address.country", "andor")); } @Test // DATAREDIS-425 - public void shouldResolveMultipleAnnotatedIndexesInLists() { + void shouldResolveMultipleAnnotatedIndexesInLists() { TheWheelOfTime twot = new TheWheelOfTime(); twot.mainCharacters = new ArrayList<>(); @@ -126,14 +125,14 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TheWheelOfTime.class), twot); - assertThat(indexes.size()).isEqualTo(2); + assertThat(indexes).hasSize(2); assertThat(indexes).contains( new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "mainCharacters.address.country", "andor"), new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "mainCharacters.address.country", "saldaea")); } @Test // DATAREDIS-425 - public void shouldResolveAnnotatedIndexesInMap() { + void shouldResolveAnnotatedIndexesInMap() { TheWheelOfTime twot = new TheWheelOfTime(); twot.places = new LinkedHashMap<>(); @@ -148,13 +147,13 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TheWheelOfTime.class), twot); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes) .contains(new SimpleIndexedPropertyValue(KEYSPACE_TWOT, "places.stone-of-tear.address.country", "illian")); } @Test // DATAREDIS-425 - public void shouldResolveConfiguredIndexesInMapOfSimpleTypes() { + void shouldResolveConfiguredIndexesInMapOfSimpleTypes() { indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "physicalAttributes.eye-color")); @@ -164,13 +163,13 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes) .contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "physicalAttributes.eye-color", "grey")); } @Test // DATAREDIS-425 - public void shouldResolveConfiguredIndexesInMapOfComplexTypes() { + void shouldResolveConfiguredIndexesInMapOfComplexTypes() { indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "relatives.father.firstname")); @@ -184,13 +183,13 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes) .contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "relatives.father.firstname", "janduin")); } @Test // DATAREDIS-425, DATAREDIS-471 - public void shouldIgnoreConfiguredIndexesInMapWhenValueIsNull() { + void shouldIgnoreConfiguredIndexesInMapWhenValueIsNull() { indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "physicalAttributes.eye-color")); @@ -200,12 +199,12 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(Person.class), rand); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes.iterator().next()).isInstanceOf(RemoveIndexedData.class); } @Test // DATAREDIS-425 - public void shouldNotResolveIndexOnReferencedEntity() { + void shouldNotResolveIndexOnReferencedEntity() { PersonWithAddressReference rand = new PersonWithAddressReference(); rand.addressRef = new AddressWithId(); @@ -215,18 +214,18 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver .resolveIndexesFor(ClassTypeInformation.from(PersonWithAddressReference.class), rand); - assertThat(indexes.size()).isEqualTo(0); + assertThat(indexes).isEmpty(); } @Test // DATAREDIS-425 - public void resolveIndexShouldReturnNullWhenNoIndexConfigured() { + void resolveIndexShouldReturnNullWhenNoIndexConfigured() { when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(false); assertThat(resolve("foo", "rand")).isNull(); } @Test // DATAREDIS-425 - public void resolveIndexShouldReturnDataWhenIndexConfigured() { + void resolveIndexShouldReturnDataWhenIndexConfigured() { when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(false); indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "foo")); @@ -235,7 +234,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolveIndexShouldReturnDataWhenNoIndexConfiguredButPropertyAnnotated() { + void resolveIndexShouldReturnDataWhenNoIndexConfiguredButPropertyAnnotated() { when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true); when(propertyMock.findAnnotation(eq(Indexed.class))).thenReturn(createIndexedInstance()); @@ -244,7 +243,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolveIndexShouldRemovePositionIndicatorForValuesInLists() { + void resolveIndexShouldRemovePositionIndicatorForValuesInLists() { when(propertyMock.isCollectionLike()).thenReturn(true); when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true); @@ -256,7 +255,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolveIndexShouldRemoveKeyIndicatorForValuesInMap() { + void resolveIndexShouldRemoveKeyIndicatorForValuesInMap() { when(propertyMock.isMap()).thenReturn(true); when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true); @@ -268,7 +267,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolveIndexShouldKeepNumericalKeyForValuesInMap() { + void resolveIndexShouldKeepNumericalKeyForValuesInMap() { when(propertyMock.isMap()).thenReturn(true); when(propertyMock.isAnnotationPresent(eq(Indexed.class))).thenReturn(true); @@ -280,7 +279,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolveIndexShouldInspectObjectTypeProperties() { + void resolveIndexShouldInspectObjectTypeProperties() { Item hat = new Item(); hat.type = "hat"; @@ -290,12 +289,12 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "feature.type", "hat")); } @Test // DATAREDIS-425 - public void resolveIndexShouldInspectObjectTypePropertiesButIgnoreNullValues() { + void resolveIndexShouldInspectObjectTypePropertiesButIgnoreNullValues() { Item hat = new Item(); hat.description = "wide brimmed hat"; @@ -305,11 +304,11 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat); - assertThat(indexes.size()).isEqualTo(0); + assertThat(indexes).isEmpty(); } @Test // DATAREDIS-425 - public void resolveIndexShouldInspectObjectTypeValuesInMapProperties() { + void resolveIndexShouldInspectObjectTypeValuesInMapProperties() { Item hat = new Item(); hat.type = "hat"; @@ -321,13 +320,13 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes) .contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "characteristics.clothing.type", "hat")); } @Test // DATAREDIS-425 - public void resolveIndexShouldInspectObjectTypeValuesInListProperties() { + void resolveIndexShouldInspectObjectTypeValuesInListProperties() { Item hat = new Item(); hat.type = "hat"; @@ -339,12 +338,12 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "items.type", "hat")); } @Test // DATAREDIS-425 - public void resolveIndexAllowCustomIndexName() { + void resolveIndexAllowCustomIndexName() { indexConfig.addIndexDefinition(new SimpleIndexDefinition(KEYSPACE_PERSON, "items.type", "itemsType")); @@ -358,12 +357,12 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(TaVeren.class), mat); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes).contains(new SimpleIndexedPropertyValue(KEYSPACE_PERSON, "itemsType", "hat")); } @Test // DATAREDIS-425 - public void resolveIndexForTypeThatHasNoIndexDefined() { + void resolveIndexForTypeThatHasNoIndexDefined() { Size size = new Size(); size.height = 10; @@ -375,7 +374,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolveIndexOnMapField() { + void resolveIndexOnMapField() { IndexedOnMapField source = new IndexedOnMapField(); source.values = new LinkedHashMap<>(); @@ -386,14 +385,14 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(IndexedOnMapField.class), source); - assertThat(indexes.size()).isEqualTo(2); + assertThat(indexes).hasSize(2); assertThat(indexes).contains( new SimpleIndexedPropertyValue(IndexedOnMapField.class.getName(), "values.jon", "snow"), new SimpleIndexedPropertyValue(IndexedOnMapField.class.getName(), "values.arya", "stark")); } @Test // DATAREDIS-425 - public void resolveIndexOnListField() { + void resolveIndexOnListField() { IndexedOnListField source = new IndexedOnListField(); source.values = new ArrayList<>(); @@ -404,13 +403,13 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(IndexedOnListField.class), source); - assertThat(indexes.size()).isEqualTo(2); + assertThat(indexes).hasSize(2); assertThat(indexes).contains(new SimpleIndexedPropertyValue(IndexedOnListField.class.getName(), "values", "jon"), new SimpleIndexedPropertyValue(IndexedOnListField.class.getName(), "values", "arya")); } @Test // DATAREDIS-509 - public void resolveIndexOnPrimitiveArrayField() { + void resolveIndexOnPrimitiveArrayField() { IndexedOnPrimitiveArrayField source = new IndexedOnPrimitiveArrayField(); source.values = new int[] { 1, 2, 3 }; @@ -418,7 +417,7 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver .resolveIndexesFor(ClassTypeInformation.from(IndexedOnPrimitiveArrayField.class), source); - assertThat(indexes.size()).isEqualTo(3); + assertThat(indexes).hasSize(3); assertThat(indexes).contains( new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 1), new SimpleIndexedPropertyValue(IndexedOnPrimitiveArrayField.class.getName(), "values", 2), @@ -426,7 +425,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-533 - public void resolveGeoIndexShouldMapNameCorrectly() { + void resolveGeoIndexShouldMapNameCorrectly() { when(propertyMock.isMap()).thenReturn(true); when(propertyMock.isAnnotationPresent(eq(GeoIndexed.class))).thenReturn(true); @@ -438,7 +437,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-533 - public void resolveGeoIndexShouldMapNameForNestedPropertyCorrectly() { + void resolveGeoIndexShouldMapNameForNestedPropertyCorrectly() { when(propertyMock.isMap()).thenReturn(true); when(propertyMock.isAnnotationPresent(eq(GeoIndexed.class))).thenReturn(true); @@ -450,7 +449,7 @@ public class PathIndexResolverUnitTests { } @Test // DATAREDIS-533 - public void resolveGeoIndexOnPointField() { + void resolveGeoIndexOnPointField() { GeoIndexedOnPoint source = new GeoIndexedOnPoint(); source.location = new Point(1D, 2D); @@ -458,21 +457,20 @@ public class PathIndexResolverUnitTests { Set indexes = indexResolver.resolveIndexesFor(ClassTypeInformation.from(GeoIndexedOnPoint.class), source); - assertThat(indexes.size()).isEqualTo(1); + assertThat(indexes).hasSize(1); assertThat(indexes) .contains(new GeoIndexedPropertyValue(GeoIndexedOnPoint.class.getName(), "location", source.location)); } @Test // DATAREDIS-533 - public void resolveGeoIndexOnArrayFieldThrowsError() { - - exception.expect(IllegalArgumentException.class); - exception.expectMessage("GeoIndexed property needs to be of type Point or GeoLocation"); + void resolveGeoIndexOnArrayFieldThrowsError() { GeoIndexedOnArray source = new GeoIndexedOnArray(); source.location = new double[] { 10D, 20D }; - indexResolver.resolveIndexesFor(ClassTypeInformation.from(GeoIndexedOnArray.class), source); + assertThatIllegalArgumentException() + .isThrownBy(() -> indexResolver.resolveIndexesFor(ClassTypeInformation.from(GeoIndexedOnArray.class), source)) + .withMessageContaining("GeoIndexed property needs to be of type Point or GeoLocation"); } private IndexedData resolve(String path, Object value) { @@ -483,7 +481,7 @@ public class PathIndexResolverUnitTests { return null; } - assertThat(data.size()).isEqualTo(1); + assertThat(data).hasSize(1); return data.iterator().next(); } diff --git a/src/test/java/org/springframework/data/redis/core/convert/SpelIndexResolverUnitTests.java b/src/test/java/org/springframework/data/redis/core/convert/SpelIndexResolverUnitTests.java index 16e582626..ba5b7e10a 100644 --- a/src/test/java/org/springframework/data/redis/core/convert/SpelIndexResolverUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/convert/SpelIndexResolverUnitTests.java @@ -21,8 +21,8 @@ import java.util.HashMap; import java.util.Map; import java.util.Set; -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.core.convert.KeyspaceConfiguration.KeyspaceSettings; import org.springframework.data.redis.core.index.IndexConfiguration; @@ -38,26 +38,26 @@ import org.springframework.expression.spel.SpelEvaluationException; */ public class SpelIndexResolverUnitTests { - String keyspace; + private String keyspace; - String indexName; + private String indexName; - String username; + private String username; - SpelIndexResolver resolver; + private SpelIndexResolver resolver; - Session session; + private Session session; - ClassTypeInformation typeInformation; + private ClassTypeInformation typeInformation; - String securityContextAttrName; + private String securityContextAttrName; - RedisMappingContext mappingContext; + private RedisMappingContext mappingContext; RedisPersistentEntity entity; - @Before - public void setup() { + @BeforeEach + void setup() { username = "rob"; keyspace = "spring:session:sessions"; @@ -70,20 +70,20 @@ public class SpelIndexResolverUnitTests { resolver = createWithExpression("getAttribute('" + securityContextAttrName + "')?.authentication?.name"); } - @Test(expected = IllegalArgumentException.class) // DATAREDIS-425 - public void constructorNullRedisMappingContext() { + @Test // DATAREDIS-425 + void constructorNullRedisMappingContext() { mappingContext = null; - new SpelIndexResolver(mappingContext); + assertThatIllegalArgumentException().isThrownBy(() -> new SpelIndexResolver(mappingContext)); } @Test // DATAREDIS-425 - public void constructorNullSpelExpressionParser() { + void constructorNullSpelExpressionParser() { assertThatIllegalArgumentException().isThrownBy(() -> new SpelIndexResolver(mappingContext, null)); } @Test // DATAREDIS-425 - public void nullValue() { + void nullValue() { Set indexes = resolver.resolveIndexesFor(typeInformation, null); @@ -91,7 +91,7 @@ public class SpelIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void wrongKeyspace() { + void wrongKeyspace() { typeInformation = ClassTypeInformation.from(String.class); Set indexes = resolver.resolveIndexesFor(typeInformation, ""); @@ -100,7 +100,7 @@ public class SpelIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void sessionAttributeNull() { + void sessionAttributeNull() { session = new Session(); Set indexes = resolver.resolveIndexesFor(typeInformation, session); @@ -109,23 +109,24 @@ public class SpelIndexResolverUnitTests { } @Test // DATAREDIS-425 - public void resolvePrincipalName() { + void resolvePrincipalName() { Set indexes = resolver.resolveIndexesFor(typeInformation, session); assertThat(indexes).contains(new SimpleIndexedPropertyValue(keyspace, indexName, username)); } - @Test(expected = SpelEvaluationException.class) // DATAREDIS-425 - public void spelError() { + @Test // DATAREDIS-425 + void spelError() { session.setAttribute(securityContextAttrName, ""); - resolver.resolveIndexesFor(typeInformation, session); + assertThatExceptionOfType(SpelEvaluationException.class) + .isThrownBy(() -> resolver.resolveIndexesFor(typeInformation, session)); } @Test // DATAREDIS-425 - public void withBeanAndThis() { + void withBeanAndThis() { this.resolver = createWithExpression("@bean.run(#this)"); this.resolver.setBeanResolver((context, beanName) -> new Object() { @@ -168,7 +169,7 @@ public class SpelIndexResolverUnitTests { private Map sessionAttrs = new HashMap<>(); - public void setAttribute(String attrName, Object attrValue) { + void setAttribute(String attrName, Object attrValue) { this.sessionAttrs.put(attrName, attrValue); } @@ -180,7 +181,7 @@ public class SpelIndexResolverUnitTests { static class SecurityContextImpl { private final Authentication authentication; - public SecurityContextImpl(Authentication authentication) { + SecurityContextImpl(Authentication authentication) { this.authentication = authentication; } @@ -192,7 +193,7 @@ public class SpelIndexResolverUnitTests { public static class Authentication { private final String principalName; - public Authentication(String principalName) { + Authentication(String principalName) { this.principalName = principalName; } diff --git a/src/test/java/org/springframework/data/redis/core/index/IndexConfigurationUnitTests.java b/src/test/java/org/springframework/data/redis/core/index/IndexConfigurationUnitTests.java index d07f3a7f4..b4dbc9060 100644 --- a/src/test/java/org/springframework/data/redis/core/index/IndexConfigurationUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/index/IndexConfigurationUnitTests.java @@ -17,16 +17,16 @@ package org.springframework.data.redis.core.index; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Rob Winch * @author Christoph Strobl */ -public class IndexConfigurationUnitTests { +class IndexConfigurationUnitTests { @Test // DATAREDIS-425 - public void redisIndexSettingIndexNameDefaulted() { + void redisIndexSettingIndexNameDefaulted() { String path = "path"; SimpleIndexDefinition setting = new SimpleIndexDefinition("keyspace", path); @@ -34,7 +34,7 @@ public class IndexConfigurationUnitTests { } @Test // DATAREDIS-425 - public void redisIndexSettingIndexNameExplicit() { + void redisIndexSettingIndexNameExplicit() { String indexName = "indexName"; SimpleIndexDefinition setting = new SimpleIndexDefinition("keyspace", "index", indexName); @@ -42,7 +42,7 @@ public class IndexConfigurationUnitTests { } @Test // DATAREDIS-425 - public void redisIndexSettingIndexNameUsedInEquals() { + void redisIndexSettingIndexNameUsedInEquals() { SimpleIndexDefinition setting1 = new SimpleIndexDefinition("keyspace", "path", "indexName1"); SimpleIndexDefinition setting2 = new SimpleIndexDefinition(setting1.getKeyspace(), "path", setting1.getIndexName() @@ -52,7 +52,7 @@ public class IndexConfigurationUnitTests { } @Test // DATAREDIS-425 - public void redisIndexSettingIndexNameUsedInHashCode() { + void redisIndexSettingIndexNameUsedInHashCode() { SimpleIndexDefinition setting1 = new SimpleIndexDefinition("keyspace", "path", "indexName1"); SimpleIndexDefinition setting2 = new SimpleIndexDefinition(setting1.getKeyspace(), "path", setting1.getIndexName() diff --git a/src/test/java/org/springframework/data/redis/core/mapping/BasicRedisPersistentEntityUnitTests.java b/src/test/java/org/springframework/data/redis/core/mapping/BasicRedisPersistentEntityUnitTests.java index 49998bacd..e3435242f 100644 --- a/src/test/java/org/springframework/data/redis/core/mapping/BasicRedisPersistentEntityUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/mapping/BasicRedisPersistentEntityUnitTests.java @@ -18,13 +18,11 @@ package org.springframework.data.redis.core.mapping; import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; -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.keyvalue.core.mapping.KeySpaceResolver; import org.springframework.data.mapping.MappingException; @@ -38,31 +36,26 @@ import org.springframework.data.util.TypeInformation; * @param * @param */ -@RunWith(MockitoJUnitRunner.class) -public class BasicRedisPersistentEntityUnitTests { - - public @Rule ExpectedException expectedException = ExpectedException.none(); +@ExtendWith(MockitoExtension.class) +class BasicRedisPersistentEntityUnitTests { @Mock TypeInformation entityInformation; @Mock KeySpaceResolver keySpaceResolver; @Mock TimeToLiveAccessor ttlAccessor; - BasicRedisPersistentEntity entity; + private BasicRedisPersistentEntity entity; - @Before + @BeforeEach @SuppressWarnings("unchecked") - public void setUp() { + void setUp() { when(entityInformation.getType()).thenReturn((Class) ConversionTestEntities.Person.class); entity = new BasicRedisPersistentEntity<>(entityInformation, keySpaceResolver, ttlAccessor); } @Test // DATAREDIS-425 - public void addingMultipleIdPropertiesWithoutAnExplicitOneThrowsException() { + void addingMultipleIdPropertiesWithoutAnExplicitOneThrowsException() { - expectedException.expect(MappingException.class); - expectedException.expectMessage("Attempt to add id property"); - expectedException.expectMessage("but already have an property"); RedisPersistentProperty property1 = mock(RedisPersistentProperty.class); when(property1.isIdProperty()).thenReturn(true); @@ -71,16 +64,14 @@ public class BasicRedisPersistentEntityUnitTests { when(property2.isIdProperty()).thenReturn(true); entity.addPersistentProperty(property1); - entity.addPersistentProperty(property2); + + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> entity.addPersistentProperty(property2)) + .withMessageContaining("Attempt to add id property").withMessageContaining("but already have an property"); } @Test // DATAREDIS-425 @SuppressWarnings("unchecked") - public void addingMultipleExplicitIdPropertiesThrowsException() { - - expectedException.expect(MappingException.class); - expectedException.expectMessage("Attempt to add explicit id property"); - expectedException.expectMessage("but already have an property"); + void addingMultipleExplicitIdPropertiesThrowsException() { RedisPersistentProperty property1 = mock(RedisPersistentProperty.class); when(property1.isIdProperty()).thenReturn(true); @@ -91,12 +82,14 @@ public class BasicRedisPersistentEntityUnitTests { when(property2.isAnnotationPresent(any(Class.class))).thenReturn(true); entity.addPersistentProperty(property1); - entity.addPersistentProperty(property2); + assertThatExceptionOfType(MappingException.class).isThrownBy(() -> entity.addPersistentProperty(property2)) + .withMessageContaining("Attempt to add explicit id property") + .withMessageContaining("but already have an property"); } @Test // DATAREDIS-425 @SuppressWarnings("unchecked") - public void explicitIdPropertiyShouldBeFavoredOverNonExplicit() { + void explicitIdPropertiyShouldBeFavoredOverNonExplicit() { RedisPersistentProperty property1 = mock(RedisPersistentProperty.class); when(property1.isIdProperty()).thenReturn(true); diff --git a/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareKeySpaceResolverUnitTests.java b/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareKeySpaceResolverUnitTests.java index e2d5012fe..bbb0cf0eb 100644 --- a/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareKeySpaceResolverUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareKeySpaceResolverUnitTests.java @@ -17,8 +17,8 @@ package org.springframework.data.redis.core.mapping; import static org.assertj.core.api.Assertions.*; -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.core.convert.KeyspaceConfiguration; import org.springframework.data.redis.core.convert.KeyspaceConfiguration.KeyspaceSettings; @@ -27,36 +27,36 @@ import org.springframework.data.redis.core.mapping.RedisMappingContext.ConfigAwa /** * @author Christoph Strobl */ -public class ConfigAwareKeySpaceResolverUnitTests { +class ConfigAwareKeySpaceResolverUnitTests { static final String CUSTOM_KEYSPACE = "car'a'carn"; - KeyspaceConfiguration config = new KeyspaceConfiguration(); - ConfigAwareKeySpaceResolver resolver; + private KeyspaceConfiguration config = new KeyspaceConfiguration(); + private ConfigAwareKeySpaceResolver resolver; - @Before - public void setUp() { + @BeforeEach + void setUp() { this.resolver = new ConfigAwareKeySpaceResolver(config); } @Test // DATAREDIS-425 - public void resolveShouldThrowExceptionWhenTypeIsNull() { + void resolveShouldThrowExceptionWhenTypeIsNull() { assertThatIllegalArgumentException().isThrownBy(() -> resolver.resolveKeySpace(null)); } @Test // DATAREDIS-425 - public void resolveShouldUseClassNameAsDefaultKeyspace() { + void resolveShouldUseClassNameAsDefaultKeyspace() { assertThat(resolver.resolveKeySpace(TypeWithoutAnySettings.class)) .isEqualTo(TypeWithoutAnySettings.class.getName()); } @Test // DATAREDIS-425 - public void resolveShouldFavorConfiguredNameOverClassName() { + void resolveShouldFavorConfiguredNameOverClassName() { config.addKeyspaceSettings(new KeyspaceSettings(TypeWithoutAnySettings.class, "ji'e'toh")); assertThat(resolver.resolveKeySpace(TypeWithoutAnySettings.class)).isEqualTo("ji'e'toh"); } - static class TypeWithoutAnySettings { + private static class TypeWithoutAnySettings { } diff --git a/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareTimeToLiveAccessorUnitTests.java b/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareTimeToLiveAccessorUnitTests.java index f2068fa00..825302f17 100644 --- a/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareTimeToLiveAccessorUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/mapping/ConfigAwareTimeToLiveAccessorUnitTests.java @@ -17,8 +17,8 @@ package org.springframework.data.redis.core.mapping; import static org.assertj.core.api.Assertions.*; -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.core.PartialUpdate; import org.springframework.data.redis.core.RedisHash; @@ -33,30 +33,30 @@ import org.springframework.data.redis.core.mapping.RedisMappingContext.ConfigAwa * @author Christoph Strobl * @author Mark Paluch */ -public class ConfigAwareTimeToLiveAccessorUnitTests { +class ConfigAwareTimeToLiveAccessorUnitTests { - ConfigAwareTimeToLiveAccessor accessor; - KeyspaceConfiguration config; + private ConfigAwareTimeToLiveAccessor accessor; + private KeyspaceConfiguration config; - @Before - public void setUp() { + @BeforeEach + void setUp() { config = new KeyspaceConfiguration(); accessor = new ConfigAwareTimeToLiveAccessor(config, new RedisMappingContext()); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldThrowExceptionWhenSourceObjectIsNull() { + void getTimeToLiveShouldThrowExceptionWhenSourceObjectIsNull() { assertThatIllegalArgumentException().isThrownBy(() -> accessor.getTimeToLive(null)); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnNullIfNothingConfiguredOrAnnotated() { + void getTimeToLiveShouldReturnNullIfNothingConfiguredOrAnnotated() { assertThat(accessor.getTimeToLive(new SimpleType())).isNull(); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnConfiguredValueForSimpleType() { + void getTimeToLiveShouldReturnConfiguredValueForSimpleType() { KeyspaceSettings setting = new KeyspaceSettings(SimpleType.class, null); setting.setTimeToLive(10L); @@ -66,12 +66,12 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnValueWhenTypeIsAnnotated() { + void getTimeToLiveShouldReturnValueWhenTypeIsAnnotated() { assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotation())).isEqualTo(5L); } @Test // DATAREDIS-425 - public void getTimeToLiveConsidersAnnotationOverConfig() { + void getTimeToLiveConsidersAnnotationOverConfig() { KeyspaceSettings setting = new KeyspaceSettings(TypeWithRedisHashAnnotation.class, null); setting.setTimeToLive(10L); @@ -81,22 +81,22 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnValueWhenPropertyIsAnnotatedAndHasValue() { + void getTimeToLiveShouldReturnValueWhenPropertyIsAnnotatedAndHasValue() { assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotationAndTTLProperty(20L))).isEqualTo(20L); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnValueFromTypeAnnotationWhenPropertyIsAnnotatedAndHasNullValue() { + void getTimeToLiveShouldReturnValueFromTypeAnnotationWhenPropertyIsAnnotatedAndHasNullValue() { assertThat(accessor.getTimeToLive(new TypeWithRedisHashAnnotationAndTTLProperty())).isEqualTo(10L); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnNullWhenPropertyIsAnnotatedAndHasNullValue() { + void getTimeToLiveShouldReturnNullWhenPropertyIsAnnotatedAndHasNullValue() { assertThat(accessor.getTimeToLive(new SimpleTypeWithTTLProperty())).isNull(); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnConfiguredValueWhenPropertyIsAnnotatedAndHasNullValue() { + void getTimeToLiveShouldReturnConfiguredValueWhenPropertyIsAnnotatedAndHasNullValue() { KeyspaceSettings setting = new KeyspaceSettings(SimpleTypeWithTTLProperty.class, null); setting.setTimeToLive(10L); @@ -106,7 +106,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-425 - public void getTimeToLiveShouldFavorAnnotatedNotNullPropertyValueOverConfiguredOne() { + void getTimeToLiveShouldFavorAnnotatedNotNullPropertyValueOverConfiguredOne() { KeyspaceSettings setting = new KeyspaceSettings(SimpleTypeWithTTLProperty.class, null); setting.setTimeToLive(10L); @@ -116,12 +116,12 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnMethodLevelTimeToLiveIfPresent() { + void getTimeToLiveShouldReturnMethodLevelTimeToLiveIfPresent() { assertThat(accessor.getTimeToLive(new TypeWithTtlOnMethod(10L))).isEqualTo(10L); } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnConfiguredValueWhenMethodLevelTimeToLiveIfPresentButHasNullValue() { + void getTimeToLiveShouldReturnConfiguredValueWhenMethodLevelTimeToLiveIfPresentButHasNullValue() { KeyspaceSettings setting = new KeyspaceSettings(TypeWithTtlOnMethod.class, null); setting.setTimeToLive(10L); @@ -131,7 +131,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-425 - public void getTimeToLiveShouldReturnValueWhenMethodLevelTimeToLiveIfPresentAlthoughConfiguredValuePresent() { + void getTimeToLiveShouldReturnValueWhenMethodLevelTimeToLiveIfPresentAlthoughConfiguredValuePresent() { KeyspaceSettings setting = new KeyspaceSettings(TypeWithTtlOnMethod.class, null); setting.setTimeToLive(10L); @@ -141,12 +141,12 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-538 - public void getTimeToLiveShouldReturnMethodLevelTimeToLiveOfNonPublicTypeIfPresent() { + void getTimeToLiveShouldReturnMethodLevelTimeToLiveOfNonPublicTypeIfPresent() { assertThat(accessor.getTimeToLive(new PrivateTypeWithTtlOnMethod(10L))).isEqualTo(10L); } @Test // DATAREDIS-471 - public void getTimeToLiveShouldReturnDefaultValue() { + void getTimeToLiveShouldReturnDefaultValue() { Long ttl = accessor .getTimeToLive(new PartialUpdate<>("123", new TypeWithRedisHashAnnotation())); @@ -155,7 +155,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-471 - public void getTimeToLiveShouldReturnValueWhenUpdateModifiesTtlProperty() { + void getTimeToLiveShouldReturnValueWhenUpdateModifiesTtlProperty() { Long ttl = accessor .getTimeToLive(new PartialUpdate<>("123", new SimpleTypeWithTTLProperty()) @@ -165,7 +165,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-471 - public void getTimeToLiveShouldReturnPropertyValueWhenUpdateModifiesTtlProperty() { + void getTimeToLiveShouldReturnPropertyValueWhenUpdateModifiesTtlProperty() { Long ttl = accessor.getTimeToLive( new PartialUpdate<>("123", @@ -175,7 +175,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @Test // DATAREDIS-471 - public void getTimeToLiveShouldReturnDefaultValueWhenUpdateDoesNotModifyTtlProperty() { + void getTimeToLiveShouldReturnDefaultValueWhenUpdateDoesNotModifyTtlProperty() { Long ttl = accessor .getTimeToLive(new PartialUpdate<>("123", @@ -184,7 +184,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { assertThat(ttl).isEqualTo(10L); } - static class SimpleType {} + private static class SimpleType {} static class SimpleTypeWithTTLProperty { @@ -198,7 +198,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { } @RedisHash(timeToLive = 5) - static class TypeWithRedisHashAnnotation {} + private static class TypeWithRedisHashAnnotation {} @RedisHash(timeToLive = 10) static class TypeWithRedisHashAnnotationAndTTLProperty { @@ -216,7 +216,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { Long value; - public TypeWithTtlOnMethod(Long value) { + TypeWithTtlOnMethod(Long value) { this.value = value; } @@ -232,7 +232,7 @@ public class ConfigAwareTimeToLiveAccessorUnitTests { Long value; - public PrivateTypeWithTtlOnMethod(Long value) { + PrivateTypeWithTtlOnMethod(Long value) { this.value = value; } diff --git a/src/test/java/org/springframework/data/redis/core/script/DefaultReactiveScriptExecutorUnitTests.java b/src/test/java/org/springframework/data/redis/core/script/DefaultReactiveScriptExecutorUnitTests.java index 41149e6ff..574ae57f2 100644 --- a/src/test/java/org/springframework/data/redis/core/script/DefaultReactiveScriptExecutorUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/script/DefaultReactiveScriptExecutorUnitTests.java @@ -24,11 +24,12 @@ import reactor.test.StepVerifier; import java.nio.ByteBuffer; import java.util.Collections; -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.Person; import org.springframework.data.redis.RedisSystemException; import org.springframework.data.redis.connection.ReactiveRedisConnection; @@ -43,8 +44,8 @@ import org.springframework.data.redis.serializer.RedisSerializationContext; * @author Mark Paluch * @author Christoph Strobl */ -@RunWith(MockitoJUnitRunner.class) -public class DefaultReactiveScriptExecutorUnitTests { +@ExtendWith(MockitoExtension.class) +class DefaultReactiveScriptExecutorUnitTests { private final DefaultRedisScript SCRIPT = new DefaultRedisScript<>("return KEYS[0]", String.class); @@ -52,10 +53,10 @@ public class DefaultReactiveScriptExecutorUnitTests { @Mock ReactiveRedisConnection connectionMock; @Mock ReactiveScriptingCommands scriptingCommandsMock; - DefaultReactiveScriptExecutor executor; + private DefaultReactiveScriptExecutor executor; - @Before - public void setUp() { + @BeforeEach + void setUp() { when(connectionFactoryMock.getReactiveConnection()).thenReturn(connectionMock); when(connectionMock.scriptingCommands()).thenReturn(scriptingCommandsMock); @@ -65,7 +66,7 @@ public class DefaultReactiveScriptExecutorUnitTests { } @Test // DATAREDIS-683 - public void executeCheckForPresenceOfScriptViaEvalSha1() { + void executeCheckForPresenceOfScriptViaEvalSha1() { when(scriptingCommandsMock.evalSha(anyString(), any(ReturnType.class), anyInt())) .thenReturn(Flux.just(ByteBuffer.wrap("FOO".getBytes()))); @@ -77,7 +78,7 @@ public class DefaultReactiveScriptExecutorUnitTests { } @Test // DATAREDIS-683 - public void executeShouldUseEvalInCaseNoSha1PresentForGivenScript() { + void executeShouldUseEvalInCaseNoSha1PresentForGivenScript() { when(scriptingCommandsMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenReturn( Flux.error(new RedisSystemException("NOSCRIPT No matching script. Please use EVAL.", new Exception()))); @@ -92,7 +93,7 @@ public class DefaultReactiveScriptExecutorUnitTests { } @Test // DATAREDIS-683 - public void executeShouldThrowExceptionInCaseEvalShaFailsWithOtherThanRedisSystemException() { + void executeShouldThrowExceptionInCaseEvalShaFailsWithOtherThanRedisSystemException() { when(scriptingCommandsMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenReturn(Flux .error(new UnsupportedOperationException("NOSCRIPT No matching script. Please use EVAL.", new Exception()))); @@ -101,7 +102,7 @@ public class DefaultReactiveScriptExecutorUnitTests { } @Test // DATAREDIS-683 - public void releasesConnectionAfterExecution() { + void releasesConnectionAfterExecution() { when(scriptingCommandsMock.evalSha(anyString(), any(ReturnType.class), anyInt())) .thenReturn(Flux.just(ByteBuffer.wrap("FOO".getBytes()))); @@ -117,7 +118,7 @@ public class DefaultReactiveScriptExecutorUnitTests { } @Test // DATAREDIS-683 - public void releasesConnectionOnError() { + void releasesConnectionOnError() { when(scriptingCommandsMock.evalSha(anyString(), any(ReturnType.class), anyInt())) .thenReturn(Flux.error(new RuntimeException())); @@ -129,7 +130,7 @@ public class DefaultReactiveScriptExecutorUnitTests { } @Test // DATAREDIS-683 - public void doesNotConvertRawResult() { + void doesNotConvertRawResult() { Person returnValue = new Person(); diff --git a/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java b/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java index 9a23c928f..cf63886b1 100644 --- a/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java +++ b/src/test/java/org/springframework/data/redis/core/script/DefaultRedisScriptTests.java @@ -17,7 +17,7 @@ package org.springframework.data.redis.core.script; import static org.assertj.core.api.Assertions.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.scripting.support.ResourceScriptSource; @@ -30,10 +30,10 @@ import org.springframework.scripting.support.StaticScriptSource; * @author Christoph Strobl * @author Mark Paluch */ -public class DefaultRedisScriptTests { +class DefaultRedisScriptTests { @Test - public void testGetSha1() { + void testGetSha1() { StaticScriptSource script = new StaticScriptSource("return KEYS[1]"); DefaultRedisScript redisScript = new DefaultRedisScript<>(); @@ -44,11 +44,11 @@ public class DefaultRedisScriptTests { assertThat(redisScript.getSha1()).isEqualTo(sha1); script.setScript("return KEYS[2]"); // Sha should now be different as script text has changed - assertThat(sha1.equals(redisScript.getSha1())).isFalse(); + assertThat(sha1).isNotEqualTo(redisScript.getSha1()); } @Test - public void testGetScriptAsString() { + void testGetScriptAsString() { DefaultRedisScript redisScript = new DefaultRedisScript<>(); redisScript.setScriptText("return ARGS[1]"); @@ -57,26 +57,27 @@ public class DefaultRedisScriptTests { } @Test // DATAREDIS-1030 - public void testGetScriptAsStringFromResource() { + void testGetScriptAsStringFromResource() { RedisScript redisScript = RedisScript .of(new ClassPathResource("org/springframework/data/redis/core/script/cas.lua")); assertThat(redisScript.getScriptAsString()).startsWith("local current = redis.call('GET', KEYS[1])"); } - @Test(expected = ScriptingException.class) - public void testGetScriptAsStringError() { + @Test + void testGetScriptAsStringError() { DefaultRedisScript redisScript = new DefaultRedisScript<>(); redisScript.setScriptSource(new ResourceScriptSource(new ClassPathResource("nonexistent"))); redisScript.setResultType(Long.class); - redisScript.getScriptAsString(); + + assertThatExceptionOfType(ScriptingException.class).isThrownBy(redisScript::getScriptAsString); } - @Test(expected = IllegalStateException.class) - public void initializeWithNoScript() throws Exception { + @Test + void initializeWithNoScript() throws Exception { DefaultRedisScript redisScript = new DefaultRedisScript<>(); - redisScript.afterPropertiesSet(); + assertThatIllegalStateException().isThrownBy(redisScript::afterPropertiesSet); } } diff --git a/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorUnitTests.java b/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorUnitTests.java index d272cba8c..40637e1c5 100644 --- a/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/script/DefaultScriptExecutorUnitTests.java @@ -15,13 +15,15 @@ */ package org.springframework.data.redis.core.script; +import static org.assertj.core.api.Assertions.*; import static org.mockito.Mockito.*; -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.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -31,8 +33,8 @@ import org.springframework.data.redis.core.StringRedisTemplate; /** * @author Christoph Strobl */ -@RunWith(MockitoJUnitRunner.class) -public class DefaultScriptExecutorUnitTests { +@ExtendWith(MockitoExtension.class) +class DefaultScriptExecutorUnitTests { private final DefaultRedisScript SCRIPT = new DefaultRedisScript<>("return KEYS[0]", String.class); @@ -42,8 +44,8 @@ public class DefaultScriptExecutorUnitTests { private DefaultScriptExecutor executor; - @Before - public void setUp() { + @BeforeEach + void setUp() { when(connectionFactoryMock.getConnection()).thenReturn(redisConnectionMock); template = spy(new StringRedisTemplate(connectionFactoryMock)); @@ -53,7 +55,7 @@ public class DefaultScriptExecutorUnitTests { } @Test // DATAREDIS-347 - public void excuteCheckForPresenceOfScriptViaEvalSha1() { + void excuteCheckForPresenceOfScriptViaEvalSha1() { when(redisConnectionMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenReturn("FOO".getBytes()); @@ -63,7 +65,7 @@ public class DefaultScriptExecutorUnitTests { } @Test // DATAREDIS-347 - public void excuteShouldNotCallEvalWhenSha1Exists() { + void excuteShouldNotCallEvalWhenSha1Exists() { when(redisConnectionMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenReturn("FOO".getBytes()); @@ -73,7 +75,7 @@ public class DefaultScriptExecutorUnitTests { } @Test // DATAREDIS-347 - public void excuteShouldUseEvalInCaseNoSha1PresentForGivenScript() { + void excuteShouldUseEvalInCaseNoSha1PresentForGivenScript() { when(redisConnectionMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenThrow( new RedisSystemException("NOSCRIPT No matching script. Please use EVAL.", new Exception())); @@ -83,21 +85,21 @@ public class DefaultScriptExecutorUnitTests { verify(redisConnectionMock, times(1)).eval(any(byte[].class), any(ReturnType.class), anyInt()); } - @Test(expected = UnsupportedOperationException.class) // DATAREDIS-347 - public void excuteShouldThrowExceptionInCaseEvalShaFailsWithOtherThanRedisSystemException() { + @Test // DATAREDIS-347 + void excuteShouldThrowExceptionInCaseEvalShaFailsWithOtherThanRedisSystemException() { when(redisConnectionMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenThrow( new UnsupportedOperationException("NOSCRIPT No matching script. Please use EVAL.", new Exception())); - executor.execute(SCRIPT, null); + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> executor.execute(SCRIPT, null)); } - @Test(expected = RedisSystemException.class) // DATAREDIS-347 - public void excuteShouldThrowExceptionInCaseEvalShaFailsWithAlthoughTheScriptExists() { + @Test // DATAREDIS-347 + void excuteShouldThrowExceptionInCaseEvalShaFailsWithAlthoughTheScriptExists() { when(redisConnectionMock.evalSha(anyString(), any(ReturnType.class), anyInt())).thenThrow( new RedisSystemException("Found Script but could not execute it.", new Exception())); - executor.execute(SCRIPT, null); + assertThatExceptionOfType(RedisSystemException.class).isThrownBy(() -> executor.execute(SCRIPT, null)); } } diff --git a/src/test/java/org/springframework/data/redis/core/types/ExpirationUnitTests.java b/src/test/java/org/springframework/data/redis/core/types/ExpirationUnitTests.java index f2365c547..b08fd44ba 100644 --- a/src/test/java/org/springframework/data/redis/core/types/ExpirationUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/types/ExpirationUnitTests.java @@ -20,15 +20,15 @@ import static org.assertj.core.api.Assertions.*; import java.util.concurrent.TimeUnit; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * @author Mark Paluch */ -public class ExpirationUnitTests { +class ExpirationUnitTests { @Test // DATAREDIS-316 - public void fromDefault() throws Exception { + void fromDefault() { Expiration expiration = Expiration.from(5, null); @@ -37,7 +37,7 @@ public class ExpirationUnitTests { } @Test // DATAREDIS-316 - public void fromNanos() throws Exception { + void fromNanos() { Expiration expiration = Expiration.from(5L * 1000 * 1000, TimeUnit.NANOSECONDS); @@ -46,7 +46,7 @@ public class ExpirationUnitTests { } @Test // DATAREDIS-316 - public void fromMinutes() throws Exception { + void fromMinutes() { Expiration expiration = Expiration.from(5, TimeUnit.MINUTES); diff --git a/src/test/java/org/springframework/data/redis/core/types/RedisClientInfoUnitTests.java b/src/test/java/org/springframework/data/redis/core/types/RedisClientInfoUnitTests.java index 0758cc324..c58197391 100644 --- a/src/test/java/org/springframework/data/redis/core/types/RedisClientInfoUnitTests.java +++ b/src/test/java/org/springframework/data/redis/core/types/RedisClientInfoUnitTests.java @@ -17,15 +17,15 @@ package org.springframework.data.redis.core.types; import static org.assertj.core.api.Assertions.*; -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.core.types.RedisClientInfo.RedisClientInfoBuilder; /** * @author Christoph Strobl */ -public class RedisClientInfoUnitTests { +class RedisClientInfoUnitTests { private final String SOURCE_WITH_PLACEHOLDER = "addr=127.0.0.1:57013#fd=6#name=client-1#age=16#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"; private final String SINGLE_LINE = SOURCE_WITH_PLACEHOLDER.replace('#', ' '); @@ -33,28 +33,28 @@ public class RedisClientInfoUnitTests { private RedisClientInfo info; - @Before - public void setUp() { + @BeforeEach + void setUp() { info = RedisClientInfoBuilder.fromString(SINGLE_LINE); } @Test - public void testBuilderShouldReadsInfoCorrectlyFromSingleLineString() { + void testBuilderShouldReadsInfoCorrectlyFromSingleLineString() { assertValues(info, VALUES); } @Test - public void testGetRequiresNonNullKey() { + void testGetRequiresNonNullKey() { assertThatIllegalArgumentException().isThrownBy(() -> info.get((String) null)); } @Test - public void testGetRequiresNonBlankKey() { + void testGetRequiresNonBlankKey() { assertThatIllegalArgumentException().isThrownBy(() -> info.get("")); } @Test - public void testGetReturnsNullForPropertiesNotAvailable() { + void testGetReturnsNullForPropertiesNotAvailable() { assertThat(info.get("foo-bar")).isEqualTo(null); } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java index f945eef75..2bcaa7c2f 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubResubscribeTests.java @@ -31,30 +31,26 @@ import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Before; -import org.junit.BeforeClass; -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.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor; -import org.springframework.data.redis.ConnectionFactoryTracker; -import org.springframework.data.redis.RedisTestProfileValueSource; import org.springframework.data.redis.SettingsUtils; -import org.springframework.data.redis.connection.ClusterTestVariables; -import org.springframework.data.redis.connection.RedisClusterConfiguration; 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.test.extension.LettuceTestClientResources; +import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; -import org.springframework.data.redis.test.util.RedisClusterRule; +import org.springframework.data.redis.test.condition.EnabledIfLongRunningTest; +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.extension.parametrized.MethodSource; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; /** * @author Costin Leau @@ -62,7 +58,8 @@ import org.springframework.data.redis.test.util.RedisClusterRule; * @author Christoph Strobl * @author Mark Paluch */ -@RunWith(Parameterized.class) +@MethodSource("testParams") +@EnabledIfLongRunningTest public class PubSubResubscribeTests { private static final String CHANNEL = "pubsub::test"; @@ -78,21 +75,9 @@ public class PubSubResubscribeTests { private RedisTemplate template; public PubSubResubscribeTests(RedisConnectionFactory connectionFactory) { - this.factory = connectionFactory; } - @BeforeClass - public static void shouldRun() { - assumeTrue(RedisTestProfileValueSource.matches("runLongTests", "true")); - } - - @AfterClass - public static void cleanUp() { - ConnectionFactoryTracker.cleanUp(); - } - - @Parameters public static Collection testParams() { int port = SettingsUtils.getPort(); @@ -101,35 +86,21 @@ public class PubSubResubscribeTests { List factories = new ArrayList<>(3); // Jedis - JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); - jedisConnFactory.setUsePool(false); - jedisConnFactory.setPort(port); - jedisConnFactory.setHostName(host); - jedisConnFactory.setDatabase(2); - jedisConnFactory.afterPropertiesSet(); + JedisConnectionFactory jedisConnFactory = JedisConnectionFactoryExtension + .getConnectionFactory(RedisStanalone.class); factories.add(jedisConnFactory); // Lettuce - LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory(); - lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources()); - lettuceConnFactory.setPort(port); - lettuceConnFactory.setHostName(host); - lettuceConnFactory.setDatabase(2); - lettuceConnFactory.setValidateConnection(true); - lettuceConnFactory.afterPropertiesSet(); + LettuceConnectionFactory lettuceConnFactory = LettuceConnectionFactoryExtension + .getConnectionFactory(RedisStanalone.class); factories.add(lettuceConnFactory); if (clusterAvailable()) { - LettuceConnectionFactory lettuceClusterConnFactory = new LettuceConnectionFactory( - new RedisClusterConfiguration().clusterNode(ClusterTestVariables.CLUSTER_NODE_1)); - lettuceClusterConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources()); - lettuceClusterConnFactory.setPort(port); - lettuceClusterConnFactory.setHostName(host); - lettuceClusterConnFactory.setValidateConnection(true); - lettuceClusterConnFactory.afterPropertiesSet(); + LettuceConnectionFactory lettuceClusterConnFactory = LettuceConnectionFactoryExtension + .getConnectionFactory(RedisCluster.class); factories.add(lettuceClusterConnFactory); } @@ -137,8 +108,8 @@ public class PubSubResubscribeTests { return factories.stream().map(factory -> new Object[] { factory }).collect(Collectors.toList()); } - @Before - public void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { template = new StringRedisTemplate(factory); @@ -154,14 +125,15 @@ public class PubSubResubscribeTests { container.start(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { container.stop(); bag.clear(); } - @Test - public void testContainerPatternResubscribe() throws Exception { + @ParameterizedRedisTest + @EnabledIfLongRunningTest + void testContainerPatternResubscribe() throws Exception { String payload1 = "do"; String payload2 = "re mi"; @@ -190,8 +162,8 @@ public class PubSubResubscribeTests { msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS)); assertThat(msgs.size()).isEqualTo(2); - assertThat(msgs.contains(payload1)).isTrue(); - assertThat(msgs.contains(payload2)).isTrue(); + assertThat(msgs).contains(payload1); + assertThat(msgs).contains(payload2); msgs.clear(); // unsubscribed adapter did not receive message @@ -211,7 +183,7 @@ public class PubSubResubscribeTests { msgs.add(bag.poll(500, TimeUnit.MILLISECONDS)); msgs.add(bag.poll(500, TimeUnit.MILLISECONDS)); - assertThat(msgs.contains(payload2)).isTrue(); + assertThat(msgs).contains(payload2); assertThat(msgs.contains(null)).isTrue(); // another listener receives messages on both channels @@ -219,12 +191,12 @@ public class PubSubResubscribeTests { msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS)); msgs.add(bag2.poll(500, TimeUnit.MILLISECONDS)); assertThat(msgs.size()).isEqualTo(2); - assertThat(msgs.contains(payload1)).isTrue(); - assertThat(msgs.contains(payload2)).isTrue(); + assertThat(msgs).contains(payload1); + assertThat(msgs).contains(payload2); } - @Test - public void testContainerChannelResubscribe() throws Exception { + @ParameterizedRedisTest + void testContainerChannelResubscribe() throws Exception { String payload1 = "do"; String payload2 = "re mi"; @@ -267,8 +239,8 @@ public class PubSubResubscribeTests { * * @throws Exception */ - @Test - public void testInitializeContainerWithMultipleTopicsIncludingPattern() throws Exception { + @ParameterizedRedisTest + void testInitializeContainerWithMultipleTopicsIncludingPattern() throws Exception { assumeFalse(isClusterAware(template.getConnectionFactory())); @@ -301,7 +273,7 @@ public class PubSubResubscribeTests { private final BlockingDeque bag; private final String name; - public MessageHandler(String name, BlockingDeque bag) { + MessageHandler(String name, BlockingDeque bag) { this.bag = bag; this.name = name; @@ -314,7 +286,7 @@ public class PubSubResubscribeTests { } private static boolean clusterAvailable() { - return new RedisClusterRule().isAvailable(); + return RedisDetector.isClusterAvailable(); } private static boolean isClusterAware(RedisConnectionFactory connectionFactory) { diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java index 5da02b5e4..9d57cc5f6 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTestParams.java @@ -18,13 +18,10 @@ package org.springframework.data.redis.listener; import java.util.ArrayList; import java.util.Collection; -import org.junit.runners.model.Statement; - 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.jedis.JedisConnectionFactory; import org.springframework.data.redis.connection.jedis.extension.JedisConnectionFactoryExtension; @@ -32,9 +29,9 @@ import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactor import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; -import org.springframework.data.redis.test.extension.LettuceTestClientResources; +import org.springframework.data.redis.test.condition.RedisDetector; import org.springframework.data.redis.test.extension.RedisCluster; -import org.springframework.data.redis.test.util.RedisClusterRule; +import org.springframework.data.redis.test.extension.RedisStanalone; /** * @author Costin Leau @@ -49,11 +46,8 @@ public class PubSubTestParams { ObjectFactory personFactory = new PersonObjectFactory(); ObjectFactory rawFactory = new RawObjectFactory(); - JedisConnectionFactory jedisConnFactory = new JedisConnectionFactory(); - jedisConnFactory.setUsePool(true); - jedisConnFactory.setPort(SettingsUtils.getPort()); - jedisConnFactory.setHostName(SettingsUtils.getHost()); - jedisConnFactory.setDatabase(2); + JedisConnectionFactory jedisConnFactory = JedisConnectionFactoryExtension + .getConnectionFactory(RedisStanalone.class); jedisConnFactory.afterPropertiesSet(); @@ -67,11 +61,8 @@ public class PubSubTestParams { rawTemplate.afterPropertiesSet(); // add Lettuce - LettuceConnectionFactory lettuceConnFactory = new LettuceConnectionFactory(); - lettuceConnFactory.setClientResources(LettuceTestClientResources.getSharedClientResources()); - lettuceConnFactory.setPort(SettingsUtils.getPort()); - lettuceConnFactory.setHostName(SettingsUtils.getHost()); - lettuceConnFactory.afterPropertiesSet(); + LettuceConnectionFactory lettuceConnFactory = LettuceConnectionFactoryExtension + .getConnectionFactory(RedisStanalone.class); RedisTemplate stringTemplateLtc = new StringRedisTemplate(lettuceConnFactory); RedisTemplate personTemplateLtc = new RedisTemplate<>(); @@ -111,17 +102,6 @@ public class PubSubTestParams { } private static boolean clusterAvailable() { - - try { - new RedisClusterRule().apply(new Statement() { - @Override - public void evaluate() { - - } - }, null).evaluate(); - } catch (Throwable throwable) { - return false; - } - return true; + return RedisDetector.isClusterAvailable(); } } diff --git a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java index 3e45e3977..0407f61e2 100644 --- a/src/test/java/org/springframework/data/redis/listener/PubSubTests.java +++ b/src/test/java/org/springframework/data/redis/listener/PubSubTests.java @@ -16,7 +16,7 @@ package org.springframework.data.redis.listener; 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.Collection; @@ -28,17 +28,11 @@ import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.Phaser; 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.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor; -import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.connection.ConnectionUtils; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -46,6 +40,9 @@ import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; +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; /** * Base test class for PubSub integration tests @@ -54,7 +51,7 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; * @author Jennifer Hickey * @author Mark Paluch */ -@RunWith(Parameterized.class) +@MethodSource("testParams") public class PubSubTests { private static final String CHANNEL = "pubsub::test"; @@ -74,8 +71,18 @@ public class PubSubTests { private final MessageListenerAdapter adapter = new MessageListenerAdapter(handler); - @Before - public void setUp() throws Exception { + @SuppressWarnings("rawtypes") + public PubSubTests(ObjectFactory factory, RedisTemplate template) { + this.factory = factory; + this.template = template; + } + + public static Collection testParams() { + return PubSubTestParams.testParams(); + } + + @BeforeEach + void setUp() throws Exception { bag.clear(); adapter.setSerializer(template.getValueSerializer()); @@ -104,35 +111,23 @@ public class PubSubTests { Thread.sleep(50); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { container.destroy(); } - @SuppressWarnings("rawtypes") - public PubSubTests(ObjectFactory factory, RedisTemplate template) { - this.factory = factory; - this.template = template; - ConnectionFactoryTracker.add(template.getConnectionFactory()); - } - - @Parameters - public static Collection testParams() { - return PubSubTestParams.testParams(); - } - /** * Return a new instance of T * * @return */ - protected T getT() { + T getT() { return factory.instance(); } @SuppressWarnings("unchecked") - @Test - public void testContainerSubscribe() throws Exception { + @ParameterizedRedisTest + void testContainerSubscribe() throws Exception { T payload1 = getT(); T payload2 = getT(); @@ -146,8 +141,8 @@ public class PubSubTests { assertThat(set).contains(payload1, payload2); } - @Test - public void testMessageBatch() throws Exception { + @ParameterizedRedisTest + void testMessageBatch() throws Exception { int COUNT = 10; for (int i = 0; i < COUNT; i++) { template.convertAndSend(CHANNEL, getT()); @@ -158,8 +153,9 @@ public class PubSubTests { } } - @Test - public void testContainerUnsubscribe() throws Exception { + @ParameterizedRedisTest + @EnabledIfLongRunningTest + void testContainerUnsubscribe() throws Exception { T payload1 = getT(); T payload2 = getT(); @@ -170,8 +166,8 @@ public class PubSubTests { assertThat(bag.poll(200, TimeUnit.MILLISECONDS)).isNull(); } - @Test - public void testStartNoListeners() { + @ParameterizedRedisTest + void testStartNoListeners() { container.removeMessageListener(adapter, new ChannelTopic(CHANNEL)); container.stop(); // DATREDIS-207 This test previously took 5 seconds on start due to monitor wait @@ -179,11 +175,11 @@ public class PubSubTests { } @SuppressWarnings("unchecked") - @Test // DATAREDIS-251 - public void testStartListenersToNoSpecificChannelTest() throws InterruptedException { + @ParameterizedRedisTest // DATAREDIS-251 + void testStartListenersToNoSpecificChannelTest() throws InterruptedException { - assumeFalse(isClusterAware(template.getConnectionFactory())); - assumeTrue(ConnectionUtils.isJedis(template.getConnectionFactory())); + assumeThat(isClusterAware(template.getConnectionFactory())).isFalse(); + assumeThat(ConnectionUtils.isJedis(template.getConnectionFactory())).isTrue(); PubSubAwaitUtil.runAndAwaitPatternSubscription(template.getRequiredConnectionFactory(), () -> { diff --git a/src/test/java/org/springframework/data/redis/listener/ReactiveOperationsTestParams.java b/src/test/java/org/springframework/data/redis/listener/ReactiveOperationsTestParams.java index 3c19548f4..2c76a5699 100644 --- a/src/test/java/org/springframework/data/redis/listener/ReactiveOperationsTestParams.java +++ b/src/test/java/org/springframework/data/redis/listener/ReactiveOperationsTestParams.java @@ -22,14 +22,12 @@ import java.util.Arrays; import java.util.Collection; import java.util.List; -import org.junit.runners.model.Statement; - import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.RedisClusterNode; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.connection.lettuce.extension.LettuceConnectionFactoryExtension; +import org.springframework.data.redis.test.condition.RedisDetector; import org.springframework.data.redis.test.extension.RedisStanalone; -import org.springframework.data.redis.test.util.RedisClusterRule; /** * Parameters for testing implementations of {@link ReactiveRedisMessageListenerContainer} @@ -66,18 +64,7 @@ class ReactiveOperationsTestParams { } private static boolean clusterAvailable() { - - try { - new RedisClusterRule().apply(new Statement() { - @Override - public void evaluate() { - - } - }, null).evaluate(); - } catch (Throwable throwable) { - return false; - } - return true; + return RedisDetector.isClusterAvailable(); } } diff --git a/src/test/java/org/springframework/data/redis/listener/ReactiveRedisMessageListenerContainerIntegrationTests.java b/src/test/java/org/springframework/data/redis/listener/ReactiveRedisMessageListenerContainerIntegrationTests.java index 21b78d1f6..92ba62c1a 100644 --- a/src/test/java/org/springframework/data/redis/listener/ReactiveRedisMessageListenerContainerIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/listener/ReactiveRedisMessageListenerContainerIntegrationTests.java @@ -28,15 +28,9 @@ import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import org.awaitility.Awaitility; -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.redis.ConnectionFactoryTracker; import org.springframework.data.redis.connection.ReactiveSubscription; import org.springframework.data.redis.connection.ReactiveSubscription.ChannelMessage; import org.springframework.data.redis.connection.ReactiveSubscription.PatternMessage; @@ -44,6 +38,8 @@ import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.ReactiveRedisTemplate; import org.springframework.data.redis.serializer.RedisSerializationContext; +import org.springframework.data.redis.test.extension.parametrized.MethodSource; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; import org.springframework.lang.Nullable; /** @@ -51,21 +47,16 @@ import org.springframework.lang.Nullable; * * @author Mark Paluch */ -@RunWith(Parameterized.class) +@MethodSource("testParams") public class ReactiveRedisMessageListenerContainerIntegrationTests { - static final String CHANNEL1 = "my-channel"; - static final String PATTERN1 = "my-chan*"; - static final String MESSAGE = "hello world"; + private static final String CHANNEL1 = "my-channel"; + private static final String PATTERN1 = "my-chan*"; + private static final String MESSAGE = "hello world"; private final LettuceConnectionFactory connectionFactory; private @Nullable RedisConnection connection; - @Parameters(name = "{1}") - public static Collection testParams() { - return ReactiveOperationsTestParams.testParams(); - } - /** * @param connectionFactory * @param label parameterized test label, no further use besides that. @@ -75,21 +66,25 @@ public class ReactiveRedisMessageListenerContainerIntegrationTests { this.connectionFactory = connectionFactory; } - @Before - public void before() { + public static Collection testParams() { + return ReactiveOperationsTestParams.testParams(); + } + + @BeforeEach + void before() { connection = connectionFactory.getConnection(); } - @After - public void tearDown() { + @AfterEach + void tearDown() { if (connection != null) { connection.close(); } } - @Test // DATAREDIS-612 - public void shouldReceiveChannelMessages() { + @ParameterizedRedisTest // DATAREDIS-612 + void shouldReceiveChannelMessages() { ReactiveRedisMessageListenerContainer container = new ReactiveRedisMessageListenerContainer(connectionFactory); @@ -106,8 +101,8 @@ public class ReactiveRedisMessageListenerContainerIntegrationTests { container.destroy(); } - @Test // DATAREDIS-612 - public void shouldReceivePatternMessages() { + @ParameterizedRedisTest // DATAREDIS-612 + void shouldReceivePatternMessages() { ReactiveRedisMessageListenerContainer container = new ReactiveRedisMessageListenerContainer(connectionFactory); @@ -125,8 +120,8 @@ public class ReactiveRedisMessageListenerContainerIntegrationTests { container.destroy(); } - @Test // DATAREDIS-612 - public void shouldPublishAndReceiveMessage() throws InterruptedException { + @ParameterizedRedisTest // DATAREDIS-612 + void shouldPublishAndReceiveMessage() throws InterruptedException { ReactiveRedisMessageListenerContainer container = new ReactiveRedisMessageListenerContainer(connectionFactory); ReactiveRedisTemplate template = new ReactiveRedisTemplate<>(connectionFactory, @@ -151,8 +146,8 @@ public class ReactiveRedisMessageListenerContainerIntegrationTests { container.destroy(); } - @Test // DATAREDIS-612 - public void listenToChannelShouldReceiveChannelMessagesCorrectly() throws InterruptedException { + @ParameterizedRedisTest // DATAREDIS-612 + void listenToChannelShouldReceiveChannelMessagesCorrectly() throws InterruptedException { ReactiveRedisTemplate template = new ReactiveRedisTemplate<>(connectionFactory, RedisSerializationContext.string()); @@ -170,8 +165,8 @@ public class ReactiveRedisMessageListenerContainerIntegrationTests { .verify(); } - @Test // DATAREDIS-612 - public void listenToPatternShouldReceiveMessagesCorrectly() { + @ParameterizedRedisTest // DATAREDIS-612 + void listenToPatternShouldReceiveMessagesCorrectly() { ReactiveRedisTemplate template = new ReactiveRedisTemplate<>(connectionFactory, RedisSerializationContext.string()); diff --git a/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerUnitTests.java b/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerUnitTests.java index a1f785630..ea3e21b71 100644 --- a/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerUnitTests.java +++ b/src/test/java/org/springframework/data/redis/listener/RedisMessageListenerContainerUnitTests.java @@ -20,8 +20,8 @@ import static org.mockito.Mockito.*; import java.util.concurrent.Executor; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.springframework.core.task.SyncTaskExecutor; import org.springframework.data.redis.connection.RedisConnection; @@ -36,7 +36,7 @@ import org.springframework.data.redis.listener.adapter.MessageListenerAdapter; * @author Mark Paluch * @author Christoph Strobl */ -public class RedisMessageListenerContainerUnitTests { +class RedisMessageListenerContainerUnitTests { private final Object handler = new Object() { @@ -53,8 +53,8 @@ public class RedisMessageListenerContainerUnitTests { private Subscription subscriptionMock; private Executor executorMock; - @Before - public void setUp() { + @BeforeEach + void setUp() { executorMock = mock(Executor.class); connectionFactoryMock = mock(LettuceConnectionFactory.class); @@ -71,7 +71,7 @@ public class RedisMessageListenerContainerUnitTests { } @Test // DATAREDIS-840 - public void containerShouldStopGracefullyOnUnsubscribeErrors() { + void containerShouldStopGracefullyOnUnsubscribeErrors() { when(connectionFactoryMock.getConnection()).thenReturn(connectionMock); doThrow(new IllegalStateException()).when(subscriptionMock).pUnsubscribe(); diff --git a/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java b/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java index 097f1d462..eb85efeae 100644 --- a/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java +++ b/src/test/java/org/springframework/data/redis/listener/SubscriptionConnectionTests.java @@ -23,15 +23,10 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -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.AfterEach; + import org.springframework.core.task.SimpleAsyncTaskExecutor; import org.springframework.core.task.SyncTaskExecutor; -import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.SettingsUtils; import org.springframework.data.redis.connection.MessageListener; import org.springframework.data.redis.connection.RedisConnection; @@ -40,9 +35,10 @@ 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.listener.adapter.MessageListenerAdapter; 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 confirming that {@link RedisMessageListenerContainer} closes connections after unsubscribing @@ -52,7 +48,7 @@ import org.springframework.data.redis.test.extension.RedisStanalone; * @author Christoph Strobl * @author Mark Paluch */ -@RunWith(Parameterized.class) +@MethodSource("testParams") public class SubscriptionConnectionTests { private static final Log logger = LogFactory.getLog(SubscriptionConnectionTests.class); @@ -73,16 +69,6 @@ public class SubscriptionConnectionTests { this.connectionFactory = connectionFactory; } - @After - public void tearDown() throws Exception { - for (RedisMessageListenerContainer container : containers) { - if (container.isActive()) { - container.destroy(); - } - } - } - - @Parameters public static Collection testParams() { int port = SettingsUtils.getPort(); String host = SettingsUtils.getHost(); @@ -98,8 +84,17 @@ public class SubscriptionConnectionTests { return Arrays.asList(new Object[][] { { jedisConnFactory }, { lettuceConnFactory } }); } - @Test - public void testStopMessageListenerContainers() throws Exception { + @AfterEach + void tearDown() throws Exception { + for (RedisMessageListenerContainer container : containers) { + if (container.isActive()) { + container.destroy(); + } + } + } + + @ParameterizedRedisTest + void testStopMessageListenerContainers() throws Exception { // Grab all 8 connections from the pool. They should be released on // container stop for (int i = 0; i < 8; i++) { @@ -128,8 +123,8 @@ public class SubscriptionConnectionTests { connection.close(); } - @Test - public void testRemoveLastListener() throws Exception { + @ParameterizedRedisTest + void testRemoveLastListener() throws Exception { // Grab all 8 connections from the pool MessageListener listener = new MessageListenerAdapter(handler); for (int i = 0; i < 8; i++) { @@ -153,8 +148,8 @@ public class SubscriptionConnectionTests { connection.close(); } - @Test - public void testStopListening() throws InterruptedException { + @ParameterizedRedisTest + void testStopListening() throws InterruptedException { // Grab all 8 connections from the pool. MessageListener listener = new MessageListenerAdapter(handler); for (int i = 0; i < 8; i++) { diff --git a/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java b/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupIntegrationTests.java similarity index 97% rename from src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java rename to src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupIntegrationTests.java index e25c68f04..49147b256 100644 --- a/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupTest.java +++ b/src/test/java/org/springframework/data/redis/listener/adapter/ContainerXmlSetupIntegrationTests.java @@ -33,7 +33,7 @@ import org.springframework.test.context.junit.jupiter.SpringExtension; @ExtendWith(SpringExtension.class) @EnabledOnRedisAvailable @ContextConfiguration("/org/springframework/data/redis/listener/container.xml") -class ContainerXmlSetupTest { +class ContainerXmlSetupIntegrationTests { @Autowired RedisMessageListenerContainer container; diff --git a/src/test/java/org/springframework/data/redis/mapping/Jackson2HashMapperTests.java b/src/test/java/org/springframework/data/redis/mapping/Jackson2HashMapperIntegrationTests.java similarity index 85% rename from src/test/java/org/springframework/data/redis/mapping/Jackson2HashMapperTests.java rename to src/test/java/org/springframework/data/redis/mapping/Jackson2HashMapperIntegrationTests.java index c1d225461..3fd2b8bba 100644 --- a/src/test/java/org/springframework/data/redis/mapping/Jackson2HashMapperTests.java +++ b/src/test/java/org/springframework/data/redis/mapping/Jackson2HashMapperIntegrationTests.java @@ -20,11 +20,7 @@ import static org.assertj.core.api.Assertions.*; import java.util.Arrays; import java.util.Collection; -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.beans.factory.InitializingBean; import org.springframework.data.redis.Address; @@ -35,6 +31,8 @@ import org.springframework.data.redis.connection.lettuce.extension.LettuceConnec import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.hash.Jackson2HashMapper; 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 Jackson2HashMapper}. @@ -42,14 +40,14 @@ import org.springframework.data.redis.test.extension.RedisStanalone; * @author Christoph Strobl * @author Mark Paluch */ -@RunWith(Parameterized.class) -public class Jackson2HashMapperTests { +@MethodSource("params") +public class Jackson2HashMapperIntegrationTests { RedisTemplate template; RedisConnectionFactory factory; Jackson2HashMapper mapper; - public Jackson2HashMapperTests(RedisConnectionFactory factory) throws Exception { + public Jackson2HashMapperIntegrationTests(RedisConnectionFactory factory) throws Exception { this.factory = factory; if (factory instanceof InitializingBean) { @@ -57,14 +55,13 @@ public class Jackson2HashMapperTests { } } - @Parameters public static Collection params() { return Arrays.asList(JedisConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class), LettuceConnectionFactoryExtension.getConnectionFactory(RedisStanalone.class)); } - @Before + @BeforeEach public void setUp() { this.template = new RedisTemplate<>(); @@ -74,7 +71,7 @@ public class Jackson2HashMapperTests { this.mapper = new Jackson2HashMapper(true); } - @Test // DATAREDIS-423 + @ParameterizedRedisTest // DATAREDIS-423 public void shouldWriteReadHashCorrectly() { Person jon = new Person("jon", "snow", 19); diff --git a/src/test/java/org/springframework/data/redis/repository/RedisRepositoryClusterIntegrationTests.java b/src/test/java/org/springframework/data/redis/repository/RedisRepositoryClusterIntegrationTests.java index 9afc9fa38..eb0836e3e 100644 --- a/src/test/java/org/springframework/data/redis/repository/RedisRepositoryClusterIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/repository/RedisRepositoryClusterIntegrationTests.java @@ -20,9 +20,8 @@ import static org.springframework.data.redis.connection.ClusterTestVariables.*; import java.util.Arrays; import java.util.List; -import org.junit.ClassRule; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.runner.RunWith; + import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; @@ -31,10 +30,9 @@ import org.springframework.data.redis.connection.RedisClusterConfiguration; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; -import org.springframework.data.redis.test.util.RedisClusterRule; +import org.springframework.data.redis.test.condition.EnabledOnRedisClusterAvailable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit.jupiter.SpringExtension; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Christoph Strobl @@ -42,16 +40,12 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; */ @ExtendWith(SpringExtension.class) @ContextConfiguration -public class RedisRepositoryClusterIntegrationTests extends RedisRepositoryIntegrationTestBase { +@EnabledOnRedisClusterAvailable +class RedisRepositoryClusterIntegrationTests extends RedisRepositoryIntegrationTestBase { static final List CLUSTER_NODES = Arrays.asList(CLUSTER_NODE_1.asString(), CLUSTER_NODE_2.asString(), CLUSTER_NODE_3.asString()); - /** - * ONLY RUN WHEN CLUSTER AVAILABLE - */ - public static @ClassRule RedisClusterRule clusterRule = new RedisClusterRule(); - @Configuration @EnableRedisRepositories(considerNestedRepositories = true, indexConfiguration = MyIndexConfiguration.class, keyspaceConfiguration = MyKeyspaceConfiguration.class, diff --git a/src/test/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializerUnitTests.java b/src/test/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializerUnitTests.java index 1a3f9692d..9290a79c9 100644 --- a/src/test/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializerUnitTests.java +++ b/src/test/java/org/springframework/data/redis/serializer/GenericJackson2JsonRedisSerializerUnitTests.java @@ -168,12 +168,12 @@ class GenericJackson2JsonRedisSerializerUnitTests { static class ComplexObject { - String stringValue; - SimpleObject simpleObject; + public String stringValue; + public SimpleObject simpleObject; public ComplexObject() {} - ComplexObject(String stringValue, SimpleObject simpleObject) { + public ComplexObject(String stringValue, SimpleObject simpleObject) { this.stringValue = stringValue; this.simpleObject = simpleObject; } @@ -203,11 +203,11 @@ class GenericJackson2JsonRedisSerializerUnitTests { static class SimpleObject { - Long longValue; + public Long longValue; public SimpleObject() {} - SimpleObject(Long longValue) { + public SimpleObject(Long longValue) { this.longValue = longValue; } diff --git a/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java b/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java index 4db559f21..8def825fb 100644 --- a/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java +++ b/src/test/java/org/springframework/data/redis/serializer/SimpleRedisSerializerTests.java @@ -26,8 +26,8 @@ import org.junit.jupiter.api.Test; import org.springframework.data.redis.Address; import org.springframework.data.redis.Person; +import org.springframework.data.redis.test.XstreamOxmSerializerSingleton; import org.springframework.instrument.classloading.ShadowingClassLoader; -import org.springframework.oxm.xstream.XStreamMarshaller; /** * @author Jennifer Hickey @@ -97,10 +97,8 @@ class SimpleRedisSerializerTests { @Test void testOxmSerializer() throws Exception { - XStreamMarshaller xstream = new XStreamMarshaller(); - xstream.afterPropertiesSet(); - OxmSerializer serializer = new OxmSerializer(xstream, xstream); + OxmSerializer serializer = XstreamOxmSerializerSingleton.getInstance(); String value = UUID.randomUUID().toString(); Person p1 = new Person(value, value, 1, new Address(value, 2)); diff --git a/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java b/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsIntegrationTests.java similarity index 81% rename from src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java rename to src/test/java/org/springframework/data/redis/support/BoundKeyOperationsIntegrationTests.java index b178afde8..2166301d1 100644 --- a/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsTest.java +++ b/src/test/java/org/springframework/data/redis/support/BoundKeyOperationsIntegrationTests.java @@ -21,21 +21,17 @@ import java.util.Collection; 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.AfterEach; +import org.junit.jupiter.api.BeforeEach; -import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.core.BoundKeyOperations; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.support.atomic.RedisAtomicInteger; import org.springframework.data.redis.support.atomic.RedisAtomicLong; +import org.springframework.data.redis.test.extension.parametrized.MethodSource; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; /** * @author Costin Leau @@ -43,8 +39,8 @@ import org.springframework.data.redis.support.atomic.RedisAtomicLong; * @author Thomas Darimont * @author Christoph Strobl */ -@RunWith(Parameterized.class) -public class BoundKeyOperationsTest { +@MethodSource("testParams") +public class BoundKeyOperationsIntegrationTests { @SuppressWarnings("rawtypes") // private BoundKeyOperations keyOps; @@ -55,35 +51,34 @@ public class BoundKeyOperationsTest { private RedisTemplate template; @SuppressWarnings("rawtypes") - public BoundKeyOperationsTest(BoundKeyOperations keyOps, ObjectFactory objFactory, + public BoundKeyOperationsIntegrationTests(BoundKeyOperations keyOps, ObjectFactory objFactory, RedisTemplate template) { this.objFactory = objFactory; this.keyOps = keyOps; this.template = template; } - @Before - public void setUp() { + public static Collection testParams() { + return BoundKeyParams.testParams(); + } + + @BeforeEach + void setUp() { populateBoundKey(); } @SuppressWarnings("unchecked") - @After - public void tearDown() { + @AfterEach + void tearDown() { template.execute((RedisCallback) connection -> { connection.flushDb(); return null; }); } - @Parameters - public static Collection testParams() { - return BoundKeyParams.testParams(); - } - @SuppressWarnings("unchecked") - @Test - public void testRename() throws Exception { + @ParameterizedRedisTest + void testRename() throws Exception { Object key = keyOps.getKey(); Object newName = objFactory.instance(); @@ -95,8 +90,8 @@ public class BoundKeyOperationsTest { assertThat(keyOps.getKey()).isEqualTo(key); } - @Test // DATAREDIS-251 - public void testExpire() throws Exception { + @ParameterizedRedisTest // DATAREDIS-251 + void testExpire() throws Exception { assertThat(keyOps.getExpire()).as(keyOps.getClass().getName() + " -> " + keyOps.getKey()) .isEqualTo(Long.valueOf(-1)); @@ -107,8 +102,8 @@ public class BoundKeyOperationsTest { } } - @Test // DATAREDIS-251 - public void testPersist() throws Exception { + @ParameterizedRedisTest // DATAREDIS-251 + void testPersist() throws Exception { keyOps.persist(); diff --git a/src/test/java/org/springframework/data/redis/support/atomic/AbstractRedisAtomicsTests.java b/src/test/java/org/springframework/data/redis/support/atomic/AbstractRedisAtomicsTests.java deleted file mode 100644 index 30f79d8c3..000000000 --- a/src/test/java/org/springframework/data/redis/support/atomic/AbstractRedisAtomicsTests.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2014-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.support.atomic; - -import org.junit.Rule; -import org.junit.rules.ExpectedException; - -/** - * @author Thomas Darimont - */ -public abstract class AbstractRedisAtomicsTests { - - @Rule public ExpectedException expectedException = ExpectedException.none(); - -} diff --git a/src/test/java/org/springframework/data/redis/support/atomic/CompareAndSetIntegrationTests.java b/src/test/java/org/springframework/data/redis/support/atomic/CompareAndSetIntegrationIntegrationTests.java similarity index 83% rename from src/test/java/org/springframework/data/redis/support/atomic/CompareAndSetIntegrationTests.java rename to src/test/java/org/springframework/data/redis/support/atomic/CompareAndSetIntegrationIntegrationTests.java index 0f50d8732..29185c968 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/CompareAndSetIntegrationTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/CompareAndSetIntegrationIntegrationTests.java @@ -19,19 +19,16 @@ import static org.assertj.core.api.Assertions.*; import java.util.Collection; -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.springframework.data.redis.ConnectionFactoryTracker; +import org.junit.jupiter.api.BeforeEach; + import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.serializer.GenericToStringSerializer; 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 CompareAndSet}. @@ -39,8 +36,8 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * @author Mark Paluch * @author Christoph Strobl */ -@RunWith(Parameterized.class) -public class CompareAndSetIntegrationTests { +@MethodSource("testParams") +public class CompareAndSetIntegrationIntegrationTests { private static final String KEY = "key"; @@ -48,7 +45,7 @@ public class CompareAndSetIntegrationTests { private final RedisTemplate template; private final ValueOperations valueOps; - public CompareAndSetIntegrationTests(RedisConnectionFactory factory) { + public CompareAndSetIntegrationIntegrationTests(RedisConnectionFactory factory) { this.factory = factory; @@ -61,21 +58,20 @@ public class CompareAndSetIntegrationTests { this.valueOps = this.template.opsForValue(); } - @Parameters public static Collection testParams() { return AtomicCountersParam.testParams(); } - @After - public void tearDown() { + @BeforeEach + void setUp() { RedisConnection connection = factory.getConnection(); connection.flushDb(); connection.close(); } - @Test // DATAREDIS-843 - public void shouldUpdateCounter() { + @ParameterizedRedisTest // DATAREDIS-843 + void shouldUpdateCounter() { long expected = 5; long actual = 5; @@ -88,8 +84,8 @@ public class CompareAndSetIntegrationTests { assertThat(valueOps.get(KEY)).isEqualTo(update); } - @Test // DATAREDIS-843 - public void expectationNotMet() { + @ParameterizedRedisTest // DATAREDIS-843 + void expectationNotMet() { long expected = 5; long actual = 7; @@ -102,8 +98,8 @@ public class CompareAndSetIntegrationTests { assertThat(valueOps.get(KEY)).isNull(); } - @Test // DATAREDIS-843 - public void concurrentUpdate() { + @ParameterizedRedisTest // DATAREDIS-843 + void concurrentUpdate() { long expected = 5; long actual = 5; diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleIntegrationTests.java similarity index 71% rename from src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java rename to src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleIntegrationTests.java index 44cb9d14a..e28edc269 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleIntegrationTests.java @@ -25,11 +25,7 @@ import java.util.function.DoubleBinaryOperator; import java.util.function.DoubleUnaryOperator; import org.assertj.core.data.Offset; -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.DataRetrievalFailureException; import org.springframework.data.redis.connection.RedisConnection; @@ -37,6 +33,8 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.GenericToStringSerializer; 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 test of {@link RedisAtomicDouble} @@ -47,14 +45,15 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * @author Mark Paluch * @author Graham MacMaster */ -@RunWith(Parameterized.class) -public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { +@MethodSource("testParams") +public class RedisAtomicDoubleIntegrationTests { + + private final RedisConnectionFactory factory; + private final RedisTemplate template; private RedisAtomicDouble doubleCounter; - private RedisConnectionFactory factory; - private RedisTemplate template; - public RedisAtomicDoubleTests(RedisConnectionFactory factory) { + public RedisAtomicDoubleIntegrationTests(RedisConnectionFactory factory) { this.factory = factory; @@ -65,13 +64,12 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { this.template.afterPropertiesSet(); } - @Parameters public static Collection testParams() { return AtomicCountersParam.testParams(); } - @Before - public void before() { + @BeforeEach + void before() { RedisConnection connection = factory.getConnection(); connection.flushDb(); @@ -80,8 +78,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { this.doubleCounter = new RedisAtomicDouble(getClass().getSimpleName() + ":double", factory); } - @Test // DATAREDIS-198 - public void testCheckAndSet() { + @ParameterizedRedisTest // DATAREDIS-198 + void testCheckAndSet() { doubleCounter.set(0); assertThat(doubleCounter.compareAndSet(1.2, 10.6)).isFalse(); @@ -89,77 +87,77 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(doubleCounter.compareAndSet(10.6, 0)).isTrue(); } - @Test // DATAREDIS-198 - public void testIncrementAndGet() { + @ParameterizedRedisTest // DATAREDIS-198 + void testIncrementAndGet() { doubleCounter.set(0); assertThat(doubleCounter.incrementAndGet()).isEqualTo(1.0); } - @Test // DATAREDIS-198 - public void testAddAndGet() { + @ParameterizedRedisTest // DATAREDIS-198 + void testAddAndGet() { doubleCounter.set(0); double delta = 1.3; assertThat(doubleCounter.addAndGet(delta)).isCloseTo(delta, Offset.offset(.0001)); } - @Test // DATAREDIS-198 - public void testDecrementAndGet() { + @ParameterizedRedisTest // DATAREDIS-198 + void testDecrementAndGet() { doubleCounter.set(1); assertThat(doubleCounter.decrementAndGet()).isZero(); } - @Test // DATAREDIS-198 - public void testGetAndSet() { + @ParameterizedRedisTest // DATAREDIS-198 + void testGetAndSet() { doubleCounter.set(3.4); assertThat(doubleCounter.getAndSet(1.2)).isEqualTo(3.4); assertThat(doubleCounter.get()).isEqualTo(1.2); } - @Test // DATAREDIS-198 - public void testGetAndIncrement() { + @ParameterizedRedisTest // DATAREDIS-198 + void testGetAndIncrement() { doubleCounter.set(2.3); assertThat(doubleCounter.getAndIncrement()).isEqualTo(2.3); assertThat(doubleCounter.get()).isEqualTo(3.3); } - @Test // DATAREDIS-198 - public void testGetAndDecrement() { + @ParameterizedRedisTest // DATAREDIS-198 + void testGetAndDecrement() { doubleCounter.set(0.5); assertThat(doubleCounter.getAndDecrement()).isEqualTo(0.5); assertThat(doubleCounter.get()).isEqualTo(-0.5); } - @Test // DATAREDIS-198 - public void testGetAndAdd() { + @ParameterizedRedisTest // DATAREDIS-198 + void testGetAndAdd() { doubleCounter.set(0.5); assertThat(doubleCounter.getAndAdd(0.7)).isEqualTo(0.5); assertThat(doubleCounter.get()).isEqualTo(1.2); } - @Test // DATAREDIS-198 - public void testExpire() { + @ParameterizedRedisTest // DATAREDIS-198 + void testExpire() { assertThat(doubleCounter.expire(1, TimeUnit.SECONDS)).isTrue(); - assertThat(doubleCounter.getExpire() > 0).isTrue(); + assertThat(doubleCounter.getExpire()).isGreaterThan(0); } - @Test // DATAREDIS-198 - public void testExpireAt() { + @ParameterizedRedisTest // DATAREDIS-198 + void testExpireAt() { doubleCounter.set(7.8); assertThat(doubleCounter.expireAt(new Date(System.currentTimeMillis() + 10000))).isTrue(); - assertThat(doubleCounter.getExpire() > 0).isTrue(); + assertThat(doubleCounter.getExpire()).isGreaterThan(0); } - @Test // DATAREDIS-198 - public void testRename() { + @ParameterizedRedisTest // DATAREDIS-198 + void testRename() { doubleCounter.set(5.6); doubleCounter.rename("foodouble"); @@ -167,28 +165,27 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(factory.getConnection().get((getClass().getSimpleName() + ":double").getBytes())).isNull(); } - @Test // DATAREDIS-317 - public void testShouldThrowExceptionIfRedisAtomicDoubleIsUsedWithRedisTemplateAndNoKeySerializer() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldThrowExceptionIfRedisAtomicDoubleIsUsedWithRedisTemplateAndNoKeySerializer() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a valid key serializer in template is required"); - - new RedisAtomicDouble("foo", new RedisTemplate<>()); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new RedisAtomicDouble("foo", new RedisTemplate<>())) + .withMessageContaining("a valid key serializer in template is required"); } - @Test // DATAREDIS-317 - public void testShouldThrowExceptionIfRedisAtomicDoubleIsUsedWithRedisTemplateAndNoValueSerializer() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldThrowExceptionIfRedisAtomicDoubleIsUsedWithRedisTemplateAndNoValueSerializer() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a valid value serializer in template is required"); RedisTemplate template = new RedisTemplate<>(); template.setKeySerializer(StringRedisSerializer.UTF_8); - new RedisAtomicDouble("foo", template); + + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new RedisAtomicDouble("foo", template)) + .withMessageContaining("a valid value serializer in template is required"); } - @Test // DATAREDIS-317 - public void testShouldBeAbleToUseRedisAtomicDoubleWithProperlyConfiguredRedisTemplate() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldBeAbleToUseRedisAtomicDoubleWithProperlyConfiguredRedisTemplate() { RedisAtomicDouble ral = new RedisAtomicDouble("DATAREDIS-317.atomicDouble", template); ral.set(32.23); @@ -196,11 +193,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(ral.get()).isEqualTo(32.23); } - @Test // DATAREDIS-469 - public void getThrowsExceptionWhenKeyHasBeenRemoved() { - - expectedException.expect(DataRetrievalFailureException.class); - expectedException.expectMessage("'test' seems to no longer exist"); + @ParameterizedRedisTest // DATAREDIS-469 + void getThrowsExceptionWhenKeyHasBeenRemoved() { // setup double RedisAtomicDouble test = new RedisAtomicDouble("test", factory, 1); @@ -208,11 +202,12 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { template.delete("test"); - test.get(); + assertThatExceptionOfType(DataRetrievalFailureException.class).isThrownBy(() -> test.get()) + .withMessageContaining("'test' seems to no longer exist"); } - @Test // DATAREDIS-469 - public void getAndSetReturnsZeroWhenKeyHasBeenRemoved() { + @ParameterizedRedisTest // DATAREDIS-469 + void getAndSetReturnsZeroWhenKeyHasBeenRemoved() { // setup double RedisAtomicDouble test = new RedisAtomicDouble("test", factory, 1); @@ -223,8 +218,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(test.getAndSet(2)).isZero(); } - @Test // DATAREDIS-874 - public void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -245,8 +240,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void updateAndGetUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void updateAndGetUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -266,8 +261,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -288,8 +283,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndUpdateUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndUpdateUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -309,8 +304,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -331,8 +326,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void accumulateAndGetUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void accumulateAndGetUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -353,8 +348,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; @@ -375,8 +370,8 @@ public class RedisAtomicDoubleTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndAccumulateUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndAccumulateUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); double initialValue = 5.3; diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleUnitTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleUnitTests.java index cc811d1d5..8b5694db9 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleUnitTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicDoubleUnitTests.java @@ -17,28 +17,29 @@ package org.springframework.data.redis.support.atomic; import static org.mockito.Mockito.*; -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; + import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.serializer.RedisSerializer; /** * Unit tests for {@link RedisAtomicDouble}. - * + * * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.class) -public class RedisAtomicDoubleUnitTests { +@ExtendWith(MockitoExtension.class) +class RedisAtomicDoubleUnitTests { @Mock RedisOperations operationsMock; @Mock ValueOperations valueOperationsMock; @Test // DATAREDIS-872 @SuppressWarnings("unchecked") - public void shouldUseSetIfAbsentForInitialValue() { + void shouldUseSetIfAbsentForInitialValue() { when(operationsMock.opsForValue()).thenReturn(valueOperationsMock); when(operationsMock.getKeySerializer()).thenReturn(mock(RedisSerializer.class)); diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerIntegrationTests.java similarity index 72% rename from src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java rename to src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerIntegrationTests.java index 5c776aa91..339189865 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerIntegrationTests.java @@ -23,11 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.IntBinaryOperator; import java.util.function.IntUnaryOperator; -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.DataRetrievalFailureException; import org.springframework.data.redis.connection.RedisConnection; @@ -35,6 +31,8 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.GenericToStringSerializer; 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 test of {@link RedisAtomicInteger} @@ -46,14 +44,15 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * @author Mark Paluch * @author Graham MacMaster */ -@RunWith(Parameterized.class) -public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { +@MethodSource("testParams") +public class RedisAtomicIntegerIntegrationTests { + + private final RedisConnectionFactory factory; + private final RedisTemplate template; private RedisAtomicInteger intCounter; - private RedisConnectionFactory factory; - private RedisTemplate template; - public RedisAtomicIntegerTests(RedisConnectionFactory factory) { + public RedisAtomicIntegerIntegrationTests(RedisConnectionFactory factory) { this.factory = factory; @@ -64,13 +63,12 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { this.template.afterPropertiesSet(); } - @Parameters public static Collection testParams() { return AtomicCountersParam.testParams(); } - @Before - public void before() { + @BeforeEach + void before() { RedisConnection connection = factory.getConnection(); connection.flushDb(); @@ -79,8 +77,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { this.intCounter = new RedisAtomicInteger(getClass().getSimpleName() + ":int", factory); } - @Test - public void testCheckAndSet() { + @ParameterizedRedisTest + void testCheckAndSet() { intCounter.set(0); assertThat(intCounter.compareAndSet(1, 10)).isFalse(); @@ -88,62 +86,62 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(intCounter.compareAndSet(10, 0)).isTrue(); } - @Test - public void testIncrementAndGet() { + @ParameterizedRedisTest + void testIncrementAndGet() { intCounter.set(0); assertThat(intCounter.incrementAndGet()).isOne(); } - @Test - public void testAddAndGet() { + @ParameterizedRedisTest + void testAddAndGet() { intCounter.set(0); int delta = 5; assertThat(intCounter.addAndGet(delta)).isEqualTo(delta); } - @Test - public void testDecrementAndGet() { + @ParameterizedRedisTest + void testDecrementAndGet() { intCounter.set(1); assertThat(intCounter.decrementAndGet()).isZero(); } - @Test // DATAREDIS-469 - public void testGetAndIncrement() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndIncrement() { intCounter.set(1); assertThat(intCounter.getAndIncrement()).isOne(); assertThat(intCounter.get()).isEqualTo(2); } - @Test // DATAREDIS-469 - public void testGetAndAdd() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndAdd() { intCounter.set(1); assertThat(intCounter.getAndAdd(5)).isOne(); assertThat(intCounter.get()).isEqualTo(6); } - @Test // DATAREDIS-469 - public void testGetAndDecrement() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndDecrement() { intCounter.set(1); assertThat(intCounter.getAndDecrement()).isOne(); assertThat(intCounter.get()).isZero(); } - @Test // DATAREDIS-469 - public void testGetAndSet() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndSet() { intCounter.set(1); assertThat(intCounter.getAndSet(5)).isOne(); assertThat(intCounter.get()).isEqualTo(5); } - @Test // DATAREDIS-108, DATAREDIS-843 - public void testCompareSet() throws Exception { + @ParameterizedRedisTest // DATAREDIS-108, DATAREDIS-843 + void testCompareSet() throws Exception { AtomicBoolean alreadySet = new AtomicBoolean(false); int NUM = 50; @@ -174,28 +172,26 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(failed.get()).withFailMessage("counter already modified").isFalse(); } - @Test // DATAREDIS-317 - public void testShouldThrowExceptionIfRedisAtomicIntegerIsUsedWithRedisTemplateAndNoKeySerializer() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldThrowExceptionIfRedisAtomicIntegerIsUsedWithRedisTemplateAndNoKeySerializer() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a valid key serializer in template is required"); - - new RedisAtomicInteger("foo", new RedisTemplate<>()); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new RedisAtomicInteger("foo", new RedisTemplate<>())) + .withMessageContaining("a valid key serializer in template is required"); } - @Test // DATAREDIS-317 - public void testShouldThrowExceptionIfRedisAtomicIntegerIsUsedWithRedisTemplateAndNoValueSerializer() { - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a valid value serializer in template is required"); + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldThrowExceptionIfRedisAtomicIntegerIsUsedWithRedisTemplateAndNoValueSerializer() { RedisTemplate template = new RedisTemplate<>(); template.setKeySerializer(StringRedisSerializer.UTF_8); - new RedisAtomicInteger("foo", template); + + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new RedisAtomicInteger("foo", template)) + .withMessageContaining("a valid value serializer in template is required"); } - @Test // DATAREDIS-317 - public void testShouldBeAbleToUseRedisAtomicIntegerWithProperlyConfiguredRedisTemplate() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldBeAbleToUseRedisAtomicIntegerWithProperlyConfiguredRedisTemplate() { RedisAtomicInteger ral = new RedisAtomicInteger("DATAREDIS-317.atomicInteger", template); ral.set(32); @@ -203,11 +199,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(ral.get()).isEqualTo(32); } - @Test // DATAREDIS-469 - public void getThrowsExceptionWhenKeyHasBeenRemoved() { - - expectedException.expect(DataRetrievalFailureException.class); - expectedException.expectMessage("'test' seems to no longer exist"); + @ParameterizedRedisTest // DATAREDIS-469 + void getThrowsExceptionWhenKeyHasBeenRemoved() { // setup integer RedisAtomicInteger test = new RedisAtomicInteger("test", factory, 1); @@ -215,11 +208,12 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { template.delete("test"); - test.get(); + assertThatExceptionOfType(DataRetrievalFailureException.class).isThrownBy(test::get) + .withMessageContaining("'test' seems to no longer exist"); } - @Test // DATAREDIS-469 - public void getAndSetReturnsZeroWhenKeyHasBeenRemoved() { + @ParameterizedRedisTest // DATAREDIS-469 + void getAndSetReturnsZeroWhenKeyHasBeenRemoved() { // setup integer RedisAtomicInteger test = new RedisAtomicInteger("test", factory, 1); @@ -230,8 +224,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(test.getAndSet(2)).isZero(); } - @Test // DATAREDIS-874 - public void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; @@ -252,8 +246,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void updateAndGetUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void updateAndGetUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; @@ -273,8 +267,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; @@ -295,8 +289,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndUpdateUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndUpdateUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; @@ -316,8 +310,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; @@ -338,8 +332,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void accumulateAndGetUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void accumulateAndGetUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; @@ -360,8 +354,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(false); int initialValue = 5; @@ -382,8 +376,8 @@ public class RedisAtomicIntegerTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndAccumulateUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndAccumulateUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); int initialValue = 5; diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerUnitTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerUnitTests.java index 4eabd5233..bee254195 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerUnitTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicIntegerUnitTests.java @@ -17,28 +17,29 @@ package org.springframework.data.redis.support.atomic; import static org.mockito.Mockito.*; -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; + import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.serializer.RedisSerializer; /** * Unit tests for {@link RedisAtomicInteger}. - * + * * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.class) -public class RedisAtomicIntegerUnitTests { +@ExtendWith(MockitoExtension.class) +class RedisAtomicIntegerUnitTests { @Mock RedisOperations operationsMock; @Mock ValueOperations valueOperationsMock; @Test // DATAREDIS-872 @SuppressWarnings("unchecked") - public void shouldUseSetIfAbsentForInitialValue() { + void shouldUseSetIfAbsentForInitialValue() { when(operationsMock.opsForValue()).thenReturn(valueOperationsMock); when(operationsMock.getKeySerializer()).thenReturn(mock(RedisSerializer.class)); diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongIntegrationTests.java similarity index 72% rename from src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java rename to src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongIntegrationTests.java index 5cbdfc6e9..7385b16ff 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongIntegrationTests.java @@ -22,11 +22,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.LongBinaryOperator; import java.util.function.LongUnaryOperator; -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.DataRetrievalFailureException; import org.springframework.data.redis.connection.RedisConnection; @@ -34,6 +30,8 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.GenericToStringSerializer; 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 test of {@link RedisAtomicLong} @@ -45,14 +43,15 @@ import org.springframework.data.redis.serializer.StringRedisSerializer; * @author Mark Paluch * @author Graham MacMaster */ -@RunWith(Parameterized.class) -public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { +@MethodSource("testParams") +public class RedisAtomicLongIntegrationTests { + + private final RedisConnectionFactory factory; + private final RedisTemplate template; private RedisAtomicLong longCounter; - private RedisConnectionFactory factory; - private RedisTemplate template; - public RedisAtomicLongTests(RedisConnectionFactory factory) { + public RedisAtomicLongIntegrationTests(RedisConnectionFactory factory) { this.factory = factory; @@ -63,13 +62,12 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { this.template.afterPropertiesSet(); } - @Parameters public static Collection testParams() { return AtomicCountersParam.testParams(); } - @Before - public void before() { + @BeforeEach + void before() { RedisConnection connection = factory.getConnection(); connection.flushDb(); @@ -78,8 +76,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { this.longCounter = new RedisAtomicLong(getClass().getSimpleName() + ":long", factory); } - @Test - public void testCheckAndSet() { + @ParameterizedRedisTest + void testCheckAndSet() { longCounter.set(0); assertThat(longCounter.compareAndSet(1, 10)).isFalse(); @@ -87,91 +85,88 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(longCounter.compareAndSet(10, 0)).isTrue(); } - @Test - public void testIncrementAndGet() { + @ParameterizedRedisTest + void testIncrementAndGet() { longCounter.set(0); assertThat(longCounter.incrementAndGet()).isOne(); } - @Test - public void testAddAndGet() { + @ParameterizedRedisTest + void testAddAndGet() { longCounter.set(0); long delta = 5; assertThat(longCounter.addAndGet(delta)).isEqualTo(delta); } - @Test - public void testDecrementAndGet() { + @ParameterizedRedisTest + void testDecrementAndGet() { longCounter.set(1); assertThat(longCounter.decrementAndGet()).isZero(); } - @Test // DATAREDIS-469 - public void testGetAndIncrement() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndIncrement() { longCounter.set(1); assertThat(longCounter.getAndIncrement()).isOne(); assertThat(longCounter.get()).isEqualTo(2); } - @Test // DATAREDIS-469 - public void testGetAndAdd() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndAdd() { longCounter.set(1); assertThat(longCounter.getAndAdd(5)).isOne(); assertThat(longCounter.get()).isEqualTo(6); } - @Test // DATAREDIS-469 - public void testGetAndDecrement() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndDecrement() { longCounter.set(1); assertThat(longCounter.getAndDecrement()).isOne(); assertThat(longCounter.get()).isZero(); } - @Test // DATAREDIS-469 - public void testGetAndSet() { + @ParameterizedRedisTest // DATAREDIS-469 + void testGetAndSet() { longCounter.set(1); assertThat(longCounter.getAndSet(5)).isOne(); assertThat(longCounter.get()).isEqualTo(5); } - @Test - public void testGetExistingValue() { + @ParameterizedRedisTest + void testGetExistingValue() { longCounter.set(5); RedisAtomicLong keyCopy = new RedisAtomicLong(longCounter.getKey(), factory); assertThat(longCounter.get()).isEqualTo(keyCopy.get()); } - @Test // DATAREDIS-317 - public void testShouldThrowExceptionIfAtomicLongIsUsedWithRedisTemplateAndNoKeySerializer() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldThrowExceptionIfAtomicLongIsUsedWithRedisTemplateAndNoKeySerializer() { - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a valid key serializer in template is required"); - - RedisTemplate template = new RedisTemplate<>(); - new RedisAtomicLong("foo", template); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> new RedisAtomicLong("foo", new RedisTemplate<>())) + .withMessageContaining("a valid key serializer in template is required"); } - @Test // DATAREDIS-317 - public void testShouldThrowExceptionIfAtomicLongIsUsedWithRedisTemplateAndNoValueSerializer() { - - expectedException.expect(IllegalArgumentException.class); - expectedException.expectMessage("a valid value serializer in template is required"); + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldThrowExceptionIfAtomicLongIsUsedWithRedisTemplateAndNoValueSerializer() { RedisTemplate template = new RedisTemplate<>(); template.setKeySerializer(StringRedisSerializer.UTF_8); - new RedisAtomicLong("foo", template); + + assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> new RedisAtomicLong("foo", template)) + .withMessageContaining("a valid value serializer in template is required"); } - @Test // DATAREDIS-317 - public void testShouldBeAbleToUseRedisAtomicLongWithProperlyConfiguredRedisTemplate() { + @ParameterizedRedisTest // DATAREDIS-317 + void testShouldBeAbleToUseRedisAtomicLongWithProperlyConfiguredRedisTemplate() { RedisTemplate template = new RedisTemplate<>(); template.setConnectionFactory(factory); @@ -185,11 +180,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(ral.get()).isEqualTo(32L); } - @Test // DATAREDIS-469 - public void getThrowsExceptionWhenKeyHasBeenRemoved() { - - expectedException.expect(DataRetrievalFailureException.class); - expectedException.expectMessage("'test' seems to no longer exist"); + @ParameterizedRedisTest // DATAREDIS-469 + void getThrowsExceptionWhenKeyHasBeenRemoved() { // setup long RedisAtomicLong test = new RedisAtomicLong("test", factory, 1); @@ -197,11 +189,12 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { template.delete("test"); - test.get(); + assertThatExceptionOfType(DataRetrievalFailureException.class).isThrownBy(test::get) + .withMessageContaining("'test' seems to no longer exist"); } - @Test // DATAREDIS-469 - public void getAndSetReturnsZeroWhenKeyHasBeenRemoved() { + @ParameterizedRedisTest // DATAREDIS-469 + void getAndSetReturnsZeroWhenKeyHasBeenRemoved() { // setup long RedisAtomicLong test = new RedisAtomicLong("test", factory, 1); @@ -212,8 +205,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(test.getAndSet(2)).isZero(); } - @Test // DATAREDIS-874 - public void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void updateAndGetAppliesGivenUpdateFunctionAndReturnsUpdatedValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -234,8 +227,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void updateAndGetUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void updateAndGetUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -255,8 +248,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndUpdateAppliesGivenUpdateFunctionAndReturnsOriginalValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -277,8 +270,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndUpdateUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndUpdateUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -298,8 +291,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void accumulateAndGetAppliesGivenAccumulatorFunctionAndReturnsUpdatedValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -320,8 +313,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void accumulateAndGetUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void accumulateAndGetUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -342,8 +335,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndAccumulateAppliesGivenAccumulatorFunctionAndReturnsOriginalValue() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; @@ -364,8 +357,8 @@ public class RedisAtomicLongTests extends AbstractRedisAtomicsTests { assertThat(operatorHasBeenApplied).isTrue(); } - @Test // DATAREDIS-874 - public void getAndAccumulateUsesCorrectArguments() { + @ParameterizedRedisTest // DATAREDIS-874 + void getAndAccumulateUsesCorrectArguments() { AtomicBoolean operatorHasBeenApplied = new AtomicBoolean(); long initialValue = 5; diff --git a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongUnitTests.java b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongUnitTests.java index 9f9c29d91..5f85b9aa0 100644 --- a/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongUnitTests.java +++ b/src/test/java/org/springframework/data/redis/support/atomic/RedisAtomicLongUnitTests.java @@ -17,28 +17,29 @@ package org.springframework.data.redis.support.atomic; import static org.mockito.Mockito.*; -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; + import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.ValueOperations; import org.springframework.data.redis.serializer.RedisSerializer; /** * Unit tests for {@link RedisAtomicLong}. - * + * * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.class) -public class RedisAtomicLongUnitTests { +@ExtendWith(MockitoExtension.class) +class RedisAtomicLongUnitTests { @Mock RedisOperations operationsMock; @Mock ValueOperations valueOperationsMock; @Test // DATAREDIS-872 @SuppressWarnings("unchecked") - public void shouldUseSetIfAbsentForInitialValue() { + void shouldUseSetIfAbsentForInitialValue() { when(operationsMock.opsForValue()).thenReturn(valueOperationsMock); when(operationsMock.getKeySerializer()).thenReturn(mock(RedisSerializer.class)); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionIntegrationTests.java similarity index 78% rename from src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java rename to src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionIntegrationTests.java index 70b80bac3..4df8bd6b7 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionIntegrationTests.java @@ -23,18 +23,14 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -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.redis.ConnectionFactoryTracker; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.core.RedisCallback; 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; /** * Base test for Redis collections. @@ -42,14 +38,14 @@ import org.springframework.data.redis.core.RedisTemplate; * @author Costin Leau * @author Mark Paluch */ -@RunWith(Parameterized.class) -public abstract class AbstractRedisCollectionTests { +@MethodSource("testParams") +public abstract class AbstractRedisCollectionIntegrationTests { protected AbstractRedisCollection collection; protected ObjectFactory factory; @SuppressWarnings("rawtypes") protected RedisTemplate template; - @Before + @BeforeEach public void setUp() throws Exception { collection = createCollection(); } @@ -59,12 +55,11 @@ public abstract class AbstractRedisCollectionTests { abstract RedisStore copyStore(RedisStore store); @SuppressWarnings("rawtypes") - public AbstractRedisCollectionTests(ObjectFactory factory, RedisTemplate template) { + AbstractRedisCollectionIntegrationTests(ObjectFactory factory, RedisTemplate template) { this.factory = factory; this.template = template; } - @Parameters public static Collection testParams() { return CollectionTestParams.testParams(); } @@ -74,13 +69,13 @@ public abstract class AbstractRedisCollectionTests { * * @return */ - protected T getT() { + T getT() { return factory.instance(); } @SuppressWarnings("unchecked") - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { // remove the collection entirely since clear() doesn't always work collection.getOperations().delete(Collections.singleton(collection.getKey())); template.execute((RedisCallback) connection -> { @@ -89,17 +84,17 @@ public abstract class AbstractRedisCollectionTests { }); } - @Test + @ParameterizedRedisTest public void testAdd() { T t1 = getT(); assertThat(collection.add(t1)).isTrue(); assertThat(collection).contains(t1); - assertThat(collection.size()).isEqualTo(1); + assertThat(collection).hasSize(1); } @SuppressWarnings("unchecked") - @Test - public void testAddAll() { + @ParameterizedRedisTest + void testAddAll() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -113,18 +108,18 @@ public abstract class AbstractRedisCollectionTests { assertThat(3).isEqualTo(collection.size()); } - @Test - public void testClear() { + @ParameterizedRedisTest + void testClear() { T t1 = getT(); - assertThat(collection.size()).isEqualTo(0); + assertThat(collection).isEmpty(); collection.add(t1); - assertThat(collection.size()).isEqualTo(1); + assertThat(collection).hasSize(1); collection.clear(); - assertThat(collection.size()).isEqualTo(0); + assertThat(collection).isEmpty(); } - @Test - public void testContainsObject() { + @ParameterizedRedisTest + void testContainsObject() { T t1 = getT(); assertThat(collection).doesNotContain(t1); assertThat(collection.add(t1)).isTrue(); @@ -132,8 +127,8 @@ public abstract class AbstractRedisCollectionTests { } @SuppressWarnings("unchecked") - @Test - public void testContainsAll() { + @ParameterizedRedisTest + void testContainsAll() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -145,29 +140,29 @@ public abstract class AbstractRedisCollectionTests { assertThat(collection).contains(t1, t2, t3); } - @Test - public void testEquals() { + @ParameterizedRedisTest + void testEquals() { // assertEquals(collection, copyStore(collection)); } - @Test - public void testHashCode() { + @ParameterizedRedisTest + void testHashCode() { assertThat(collection.hashCode()).isNotEqualTo(collection.getKey().hashCode()); } - @Test - public void testIsEmpty() { - assertThat(collection.size()).isEqualTo(0); + @ParameterizedRedisTest + void testIsEmpty() { + assertThat(collection).isEmpty(); assertThat(collection.isEmpty()).isTrue(); collection.add(getT()); - assertThat(collection.size()).isEqualTo(1); + assertThat(collection).hasSize(1); assertThat(collection.isEmpty()).isFalse(); collection.clear(); assertThat(collection.isEmpty()).isTrue(); } @SuppressWarnings("unchecked") - @Test + @ParameterizedRedisTest public void testIterator() { T t1 = getT(); T t2 = getT(); @@ -186,27 +181,27 @@ public abstract class AbstractRedisCollectionTests { assertThat(iterator.hasNext()).isFalse(); } - @Test - public void testRemoveObject() { + @ParameterizedRedisTest + void testRemoveObject() { T t1 = getT(); T t2 = getT(); T t3 = getT(); - assertThat(collection.size()).isEqualTo(0); + assertThat(collection).isEmpty(); assertThat(collection.add(t1)).isTrue(); assertThat(collection.add(t2)).isTrue(); - assertThat(collection.size()).isEqualTo(2); + assertThat(collection).hasSize(2); assertThat(collection.remove(t3)).isFalse(); assertThat(collection.remove(t2)).isTrue(); assertThat(collection.remove(t2)).isFalse(); - assertThat(collection.size()).isEqualTo(1); + assertThat(collection).hasSize(1); assertThat(collection.remove(t1)).isTrue(); - assertThat(collection.size()).isEqualTo(0); + assertThat(collection).isEmpty(); } @SuppressWarnings("unchecked") - @Test - public void removeAll() { + @ParameterizedRedisTest + void removeAll() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -228,7 +223,7 @@ public abstract class AbstractRedisCollectionTests { assertThat(collection).doesNotContain(t2, t3); } - // @Test(expected = UnsupportedOperationException.class) + // @ParameterizedRedisTest(expected = UnsupportedOperationException.class) @SuppressWarnings("unchecked") public void testRetainAll() { T t1 = getT(); @@ -245,19 +240,19 @@ public abstract class AbstractRedisCollectionTests { assertThat(collection).contains(t2); } - @Test - public void testSize() { - assertThat(collection.size()).isEqualTo(0); + @ParameterizedRedisTest + void testSize() { + assertThat(collection).isEmpty(); assertThat(collection.isEmpty()).isTrue(); collection.add(getT()); - assertThat(collection.size()).isEqualTo(1); + assertThat(collection).hasSize(1); collection.add(getT()); collection.add(getT()); - assertThat(collection.size()).isEqualTo(3); + assertThat(collection).hasSize(3); } @SuppressWarnings("unchecked") - @Test + @ParameterizedRedisTest public void testToArray() { Object[] expectedArray = new Object[] { getT(), getT(), getT() }; List list = (List) Arrays.asList(expectedArray); @@ -269,7 +264,7 @@ public abstract class AbstractRedisCollectionTests { } @SuppressWarnings("unchecked") - @Test + @ParameterizedRedisTest public void testToArrayWithGenerics() { Object[] expectedArray = new Object[] { getT(), getT(), getT() }; List list = (List) Arrays.asList(expectedArray); @@ -280,15 +275,15 @@ public abstract class AbstractRedisCollectionTests { assertThat(array).isEqualTo(expectedArray); } - @Test - public void testToString() { + @ParameterizedRedisTest + void testToString() { String name = collection.toString(); collection.add(getT()); assertThat(collection.toString()).isEqualTo(name); } - @Test - public void testGetKey() throws Exception { + @ParameterizedRedisTest + void testGetKey() throws Exception { assertThat(collection.getKey()).isNotNull(); } } diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionUnitTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionUnitTests.java index 07a324f02..02b1643b6 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionUnitTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisCollectionUnitTests.java @@ -21,11 +21,14 @@ import java.util.ArrayList; import java.util.Iterator; 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.DataType; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; @@ -34,8 +37,9 @@ import org.springframework.data.redis.core.RedisTemplate; /** * @author Christoph Strobl */ -@RunWith(MockitoJUnitRunner.class) -public class AbstractRedisCollectionUnitTests { +@ExtendWith(MockitoExtension.class) +@MockitoSettings(strictness = Strictness.LENIENT) +class AbstractRedisCollectionUnitTests { private AbstractRedisCollection collection; @@ -45,8 +49,8 @@ public class AbstractRedisCollectionUnitTests { private @Mock RedisConnection connectionMock; @SuppressWarnings({ "unchecked", "rawtypes" }) - @Before - public void setUp() { + @BeforeEach + void setUp() { redisTemplateSpy = spy(new RedisTemplate() { @@ -93,7 +97,7 @@ public class AbstractRedisCollectionUnitTests { @SuppressWarnings("unchecked") @Test // DATAREDIS-188 - public void testRenameOfEmptyCollectionShouldNotTriggerRedisOperation() { + void testRenameOfEmptyCollectionShouldNotTriggerRedisOperation() { collection.rename("new-key"); verify(redisTemplateSpy, never()).rename(eq("key"), eq("new-key")); @@ -101,7 +105,7 @@ public class AbstractRedisCollectionUnitTests { @SuppressWarnings("unchecked") @Test // DATAREDIS-188 - public void testRenameCollectionShouldTriggerRedisOperation() { + void testRenameCollectionShouldTriggerRedisOperation() { when(redisTemplateSpy.hasKey(any())).thenReturn(Boolean.TRUE); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListIntegrationTests.java similarity index 71% rename from src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java rename to src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListIntegrationTests.java index c74769866..97270f84e 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisListIntegrationTests.java @@ -25,15 +25,13 @@ import java.util.List; import java.util.NoSuchElementException; import java.util.concurrent.TimeUnit; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; -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 test for RedisList @@ -41,9 +39,7 @@ import org.springframework.test.annotation.IfProfileValue; * @author Costin Leau * @author Jennifer Hickey */ -public abstract class AbstractRedisListTests extends AbstractRedisCollectionTests { - - @Rule public MinimumRedisVersionRule redisVersion = new MinimumRedisVersionRule(); +public abstract class AbstractRedisListIntegrationTests extends AbstractRedisCollectionIntegrationTests { protected RedisList list; @@ -54,20 +50,20 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT * @param template */ @SuppressWarnings("rawtypes") - public AbstractRedisListTests(ObjectFactory factory, RedisTemplate template) { + AbstractRedisListIntegrationTests(ObjectFactory factory, RedisTemplate template) { super(factory, template); } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); list = (RedisList) collection; } - @Test - public void testAddIndexObjectHead() { + @ParameterizedRedisTest + void testAddIndexObjectHead() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -80,8 +76,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.get(0)).isEqualTo(t3); } - @Test - public void testAddIndexObjectTail() { + @ParameterizedRedisTest + void testAddIndexObjectTail() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -94,8 +90,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.get(2)).isEqualTo(t3); } - @Test(expected = IllegalArgumentException.class) - public void testAddIndexObjectMiddle() { + @ParameterizedRedisTest + void testAddIndexObjectMiddle() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -104,12 +100,11 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT list.add(t2); assertThat(list.get(0)).isEqualTo(t1); - list.add(1, t3); + assertThatIllegalArgumentException().isThrownBy(() -> list.add(1, t3)); } - @SuppressWarnings("unchecked") - @Test - public void addAllIndexCollectionHead() { + @ParameterizedRedisTest + void addAllIndexCollectionHead() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -127,9 +122,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.get(1)).isEqualTo(t4); } - @SuppressWarnings("unchecked") - @Test - public void addAllIndexCollectionTail() { + @ParameterizedRedisTest + void addAllIndexCollectionTail() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -148,9 +142,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.get(3)).isEqualTo(t4); } - @SuppressWarnings("unchecked") - @Test(expected = IllegalArgumentException.class) - public void addAllIndexCollectionMiddle() { + @ParameterizedRedisTest + void addAllIndexCollectionMiddle() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -162,12 +155,12 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT List asList = Arrays.asList(t3, t4); assertThat(list.get(0)).isEqualTo(t1); - assertThat(list.addAll(1, asList)).isTrue(); + assertThatIllegalArgumentException().isThrownBy(() -> list.addAll(1, asList)); } - @Test // DATAREDIS-1196 - @IfProfileValue(name = "redisVersion", value = "6.0.6+") - public void testIndexOfObject() { + @ParameterizedRedisTest // DATAREDIS-1196 + @EnabledOnCommand("LPOS") + void testIndexOfObject() { assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class); @@ -183,16 +176,16 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.indexOf(t2)).isEqualTo(1); } - @Test - public void testOffer() { + @ParameterizedRedisTest + void testOffer() { T t1 = getT(); assertThat(list.offer(t1)).isTrue(); assertThat(list.get(0)).isEqualTo(t1); } - @Test - public void testPeek() { + @ParameterizedRedisTest + void testPeek() { assertThat(list.peek()).isNull(); T t1 = getT(); list.add(t1); @@ -201,8 +194,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.peek()).isNull(); } - @Test - public void testElement() { + @ParameterizedRedisTest + void testElement() { assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(list::element); @@ -213,13 +206,13 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(list::element); } - @Test - public void testPop() { + @ParameterizedRedisTest + void testPop() { testPoll(); } - @Test - public void testPoll() { + @ParameterizedRedisTest + void testPoll() { assertThat(list.poll()).isNull(); T t1 = getT(); list.add(t1); @@ -227,16 +220,16 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.poll()).isNull(); } - @Test - public void testPollTimeout() throws InterruptedException { + @ParameterizedRedisTest + void testPollTimeout() throws InterruptedException { T t1 = getT(); list.add(t1); assertThat(list.poll(1, TimeUnit.MILLISECONDS)).isEqualTo(t1); } - @Test - public void testRemove() { + @ParameterizedRedisTest + void testRemove() { assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(list::remove); T t1 = getT(); @@ -245,8 +238,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(list::remove); } - @Test - public void testRange() { + @ParameterizedRedisTest + void testRange() { T t1 = getT(); T t2 = getT(); @@ -258,21 +251,13 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.range(1, 1).get(0)).isEqualTo(t2); } - @Test(expected = UnsupportedOperationException.class) - public void testRemoveIndex() { - T t1 = getT(); - T t2 = getT(); - - assertThat(list.remove(0)).isNull(); - list.add(t1); - list.add(t2); - assertThat(list.remove(2)).isNull(); - assertThat(list.remove(1)).isEqualTo(t2); - assertThat(list.remove(0)).isEqualTo(t1); + @ParameterizedRedisTest + void testRemoveIndex() { + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> list.remove(0)); } - @Test - public void testSet() { + @ParameterizedRedisTest + void testSet() { T t1 = getT(); T t2 = getT(); list.add(t1); @@ -281,8 +266,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.get(0)).isEqualTo(t2); } - @Test - public void testTrim() { + @ParameterizedRedisTest + void testTrim() { T t1 = getT(); T t2 = getT(); @@ -296,8 +281,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT } @SuppressWarnings("unchecked") - @Test - public void testCappedCollection() throws Exception { + @ParameterizedRedisTest + void testCappedCollection() throws Exception { RedisList cappedList = new DefaultRedisList(template.boundListOps(collection.getKey() + ":capped"), 1); T first = getT(); cappedList.offer(first); @@ -310,8 +295,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(cappedList.get(0)).isEqualTo(first); } - @Test - public void testAddFirst() { + @ParameterizedRedisTest + void testAddFirst() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -326,13 +311,13 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(iterator.next()).isEqualTo(t1); } - @Test - public void testAddLast() { + @ParameterizedRedisTest + void testAddLast() { testAdd(); } - @Test - public void testDescendingIterator() { + @ParameterizedRedisTest + void testDescendingIterator() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -348,9 +333,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT } - @SuppressWarnings("unchecked") - @Test - public void testDrainToCollectionWithMaxElements() { + @ParameterizedRedisTest + void testDrainToCollectionWithMaxElements() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -366,9 +350,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(c).hasSize(2).contains(t1, t2); } - @SuppressWarnings("unchecked") - @Test - public void testDrainToCollection() { + @ParameterizedRedisTest + void testDrainToCollection() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -384,8 +367,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(c).hasSize(3).contains(t1, t2, t3); } - @Test - public void testGetFirst() { + @ParameterizedRedisTest + void testGetFirst() { T t1 = getT(); T t2 = getT(); @@ -395,28 +378,28 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list.getFirst()).isEqualTo(t1); } - @Test - public void testLast() { + @ParameterizedRedisTest + void testLast() { testAdd(); } - @Test - public void testOfferFirst() { + @ParameterizedRedisTest + void testOfferFirst() { testAddFirst(); } - @Test - public void testOfferLast() { + @ParameterizedRedisTest + void testOfferLast() { testAddLast(); } - @Test - public void testPeekFirst() { + @ParameterizedRedisTest + void testPeekFirst() { testPeek(); } - @Test - public void testPeekLast() { + @ParameterizedRedisTest + void testPeekLast() { T t1 = getT(); T t2 = getT(); @@ -427,13 +410,13 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list).hasSize(2); } - @Test - public void testPollFirst() { + @ParameterizedRedisTest + void testPollFirst() { testPoll(); } - @Test - public void testPollLast() { + @ParameterizedRedisTest + void testPollLast() { T t1 = getT(); T t2 = getT(); @@ -445,8 +428,8 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list).hasSize(1).contains(t1); } - @Test - public void testPollLastTimeout() throws InterruptedException { + @ParameterizedRedisTest + void testPollLastTimeout() throws InterruptedException { T t1 = getT(); T t2 = getT(); @@ -459,43 +442,43 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list).hasSize(1).contains(t1); } - @Test - public void testPut() { + @ParameterizedRedisTest + void testPut() { testOffer(); } - @Test - public void testPutFirst() { + @ParameterizedRedisTest + void testPutFirst() { testAdd(); } - @Test - public void testPutLast() { + @ParameterizedRedisTest + void testPutLast() { testPut(); } - @Test - public void testRemainingCapacity() { + @ParameterizedRedisTest + void testRemainingCapacity() { assertThat(list.remainingCapacity()).isEqualTo(Integer.MAX_VALUE); } - @Test - public void testRemoveFirst() { + @ParameterizedRedisTest + void testRemoveFirst() { testPop(); } - @Test - public void testRemoveFirstOccurrence() { + @ParameterizedRedisTest + void testRemoveFirstOccurrence() { testRemove(); } - @Test - public void testRemoveLast() { + @ParameterizedRedisTest + void testRemoveLast() { testPollLast(); } - @Test - public void testRmoveLastOccurrence() { + @ParameterizedRedisTest + void testRmoveLastOccurrence() { T t1 = getT(); T t2 = getT(); @@ -509,24 +492,24 @@ public abstract class AbstractRedisListTests extends AbstractRedisCollectionT assertThat(list).hasSize(3).containsExactly(t1, t2, t1); } - @Test - public void testTake() { + @ParameterizedRedisTest + void testTake() { testPoll(); } - @Test - public void testTakeFirst() { + @ParameterizedRedisTest + void testTakeFirst() { testTake(); } - @Test - public void testTakeLast() { + @ParameterizedRedisTest + void testTakeLast() { testPollLast(); } - @Test // DATAREDIS-1196 - @IfProfileValue(name = "redisVersion", value = "6.0.6+") - public void lastIndexOf() { + @ParameterizedRedisTest // DATAREDIS-1196 + @EnabledOnCommand("LPOS") + void lastIndexOf() { assumeThat(template.getConnectionFactory()).isInstanceOf(LettuceConnectionFactory.class); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapIntegrationTests.java similarity index 77% rename from src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java rename to src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapIntegrationTests.java index 055ef89e0..c781be6eb 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisMapIntegrationTests.java @@ -16,7 +16,7 @@ package org.springframework.data.redis.support.collections; 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.text.DecimalFormat; @@ -28,24 +28,19 @@ import java.util.Map; import java.util.Map.Entry; import java.util.Set; -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.jupiter.api.BeforeEach; import org.springframework.dao.InvalidDataAccessApiUsageException; import org.springframework.data.redis.DoubleAsStringObjectFactory; import org.springframework.data.redis.LongAsStringObjectFactory; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.RedisSystemException; -import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisCallback; import org.springframework.data.redis.core.RedisOperations; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.test.util.MinimumRedisVersionRule; -import org.springframework.data.redis.test.util.RedisClientRule; +import org.springframework.data.redis.test.extension.parametrized.MethodSource; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; /** * Integration test for Redis Map. @@ -56,36 +51,32 @@ import org.springframework.data.redis.test.util.RedisClientRule; * @author Thomas Darimont * @author Christian Bühler */ -@RunWith(Parameterized.class) -public abstract class AbstractRedisMapTests { - - public @Rule RedisClientRule clientRule = new RedisClientRule() { - public RedisConnectionFactory getConnectionFactory() { - return template.getConnectionFactory(); - } - }; - - public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); +@MethodSource("testParams") +public abstract class AbstractRedisMapIntegrationTests { protected RedisMap map; protected ObjectFactory keyFactory; protected ObjectFactory valueFactory; @SuppressWarnings("rawtypes") protected RedisTemplate template; - abstract RedisMap createMap(); - - @Before - public void setUp() { - map = createMap(); - } - @SuppressWarnings("rawtypes") - public AbstractRedisMapTests(ObjectFactory keyFactory, ObjectFactory valueFactory, RedisTemplate template) { + AbstractRedisMapIntegrationTests(ObjectFactory keyFactory, ObjectFactory valueFactory, RedisTemplate template) { this.keyFactory = keyFactory; this.valueFactory = valueFactory; this.template = template; } + abstract RedisMap createMap(); + + @BeforeEach + void setUp() { + template.execute((RedisCallback) connection -> { + connection.flushAll(); + return null; + }); + map = createMap(); + } + protected K getKey() { return keyFactory.instance(); } @@ -99,17 +90,8 @@ public abstract class AbstractRedisMapTests { return new DefaultRedisMap(store.getKey(), store.getOperations()); } - @SuppressWarnings("unchecked") - @Before - public void before() throws Exception { - template.execute((RedisCallback) connection -> { - connection.flushAll(); - return null; - }); - } - - @Test - public void testClear() { + @ParameterizedRedisTest + void testClear() { map.clear(); assertThat(map.size()).isEqualTo(0); map.put(getKey(), getValue()); @@ -118,8 +100,8 @@ public abstract class AbstractRedisMapTests { assertThat(map.size()).isEqualTo(0); } - @Test - public void testContainsKey() { + @ParameterizedRedisTest + void testContainsKey() { K k1 = getKey(); K k2 = getKey(); @@ -131,41 +113,31 @@ public abstract class AbstractRedisMapTests { assertThat(map.containsKey(k2)).isTrue(); } - @Test(expected = UnsupportedOperationException.class) - public void testContainsValue() { + @ParameterizedRedisTest + void testContainsValue() { V v1 = getValue(); - V v2 = getValue(); - assertThat(map.containsValue(v1)).isFalse(); - assertThat(map.containsValue(v2)).isFalse(); - map.put(getKey(), v1); - assertThat(map.containsValue(v1)).isTrue(); - map.put(getKey(), v2); - assertThat(map.containsValue(v2)).isTrue(); + assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> map.containsValue(v1)); } - public Set> entrySet() { - return map.entrySet(); - } - - @Test - public void testEquals() { + @ParameterizedRedisTest + void testEquals() { RedisStore clone = copyStore(map); assertThat(map).isEqualTo(clone); assertThat(clone).isEqualTo(clone); assertThat(map).isEqualTo(map); } - @Test - public void testNotEquals() { + @ParameterizedRedisTest + void testNotEquals() { RedisOperations ops = map.getOperations(); RedisStore newInstance = new DefaultRedisMap<>(ops. boundHashOps(map.getKey() + ":new")); assertThat(map.equals(newInstance)).isFalse(); assertThat(newInstance.equals(map)).isFalse(); } - @Test - public void testGet() { + @ParameterizedRedisTest + void testGet() { K k1 = getKey(); V v1 = getValue(); @@ -174,25 +146,25 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k1)).isEqualTo(v1); } - @Test - public void testGetKey() { + @ParameterizedRedisTest + void testGetKey() { assertThat(map.getKey()).isNotNull(); } - @Test + @ParameterizedRedisTest public void testGetOperations() { assertThat(map.getOperations()).isEqualTo(template); } - @Test - public void testHashCode() { + @ParameterizedRedisTest + void testHashCode() { assertThat(map.hashCode()).isNotEqualTo(map.getKey().hashCode()); assertThat(copyStore(map).hashCode()).isEqualTo(map.hashCode()); } - @Test - public void testIncrementNotNumber() { - assumeTrue(!(valueFactory instanceof LongAsStringObjectFactory)); + @ParameterizedRedisTest + void testIncrementNotNumber() { + assumeThat(!(valueFactory instanceof LongAsStringObjectFactory)).isTrue(); K k1 = getKey(); V v1 = getValue(); @@ -206,18 +178,18 @@ public abstract class AbstractRedisMapTests { } } - @Test - public void testIncrement() { - assumeTrue(valueFactory instanceof LongAsStringObjectFactory); + @ParameterizedRedisTest + void testIncrement() { + assumeThat(valueFactory instanceof LongAsStringObjectFactory).isTrue(); K k1 = getKey(); V v1 = getValue(); map.put(k1, v1); assertThat(map.increment(k1, 10)).isEqualTo(Long.valueOf(Long.valueOf((String) v1) + 10)); } - @Test - public void testIncrementDouble() { - assumeTrue(valueFactory instanceof DoubleAsStringObjectFactory); + @ParameterizedRedisTest + void testIncrementDouble() { + assumeThat(valueFactory instanceof DoubleAsStringObjectFactory).isTrue(); K k1 = getKey(); V v1 = getValue(); map.put(k1, v1); @@ -225,8 +197,8 @@ public abstract class AbstractRedisMapTests { assertThat(twoDForm.format(map.increment(k1, 3.4))).isEqualTo(twoDForm.format(Double.valueOf((String) v1) + 3.4)); } - @Test - public void testIsEmpty() { + @ParameterizedRedisTest + void testIsEmpty() { map.clear(); assertThat(map.isEmpty()).isTrue(); map.put(getKey(), getValue()); @@ -236,8 +208,8 @@ public abstract class AbstractRedisMapTests { } @SuppressWarnings("unchecked") - @Test - public void testKeySet() { + @ParameterizedRedisTest + void testKeySet() { map.clear(); assertThat(map.keySet().isEmpty()).isTrue(); K k1 = getKey(); @@ -253,8 +225,8 @@ public abstract class AbstractRedisMapTests { assertThat(keySet.size()).isEqualTo(3); } - @Test - public void testPut() { + @ParameterizedRedisTest + void testPut() { K k1 = getKey(); K k2 = getKey(); V v1 = getValue(); @@ -267,8 +239,8 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k2)).isEqualTo(v2); } - @Test - public void testPutAll() { + @ParameterizedRedisTest + void testPutAll() { Map m = new LinkedHashMap<>(); K k1 = getKey(); @@ -289,8 +261,8 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k2)).isEqualTo(v2); } - @Test - public void testRemove() { + @ParameterizedRedisTest + void testRemove() { K k1 = getKey(); K k2 = getKey(); @@ -312,8 +284,8 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k2)).isNull(); } - @Test - public void testSize() { + @ParameterizedRedisTest + void testSize() { assertThat(map.size()).isEqualTo(0); map.put(getKey(), getValue()); assertThat(map.size()).isEqualTo(1); @@ -328,8 +300,8 @@ public abstract class AbstractRedisMapTests { } @SuppressWarnings("unchecked") - @Test - public void testValues() { + @ParameterizedRedisTest + void testValues() { V v1 = getValue(); V v2 = getValue(); V v3 = getValue(); @@ -348,8 +320,8 @@ public abstract class AbstractRedisMapTests { } @SuppressWarnings("unchecked") - @Test - public void testEntrySet() { + @ParameterizedRedisTest + void testEntrySet() { Set> entries = map.entrySet(); assertThat(entries.isEmpty()).isTrue(); @@ -380,8 +352,8 @@ public abstract class AbstractRedisMapTests { assertThat(values).doesNotContain(v2); } - @Test - public void testPutIfAbsent() { + @ParameterizedRedisTest + void testPutIfAbsent() { K k1 = getKey(); K k2 = getKey(); @@ -400,14 +372,14 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k2)).isEqualTo(v2); } - @Test - public void testConcurrentRemove() { + @ParameterizedRedisTest + void testConcurrentRemove() { K k1 = getKey(); V v1 = getValue(); V v2 = getValue(); // No point testing this with byte[], they will never be equal - assumeTrue(!(v1 instanceof byte[])); + assumeThat(!(v1 instanceof byte[])).isTrue(); map.put(k1, v2); assertThat(map.remove(k1, v1)).isFalse(); assertThat(map.get(k1)).isEqualTo(v2); @@ -415,19 +387,19 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k1)).isNull(); } - @Test - public void testRemoveNullValue() { + @ParameterizedRedisTest + void testRemoveNullValue() { assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> map.remove(getKey(), null)); } - @Test - public void testConcurrentReplaceTwoArgs() { + @ParameterizedRedisTest + void testConcurrentReplaceTwoArgs() { K k1 = getKey(); V v1 = getValue(); V v2 = getValue(); // No point testing binary data here, as equals will always be false - assumeTrue(!(v1 instanceof byte[])); + assumeThat(!(v1 instanceof byte[])).isTrue(); map.put(k1, v1); @@ -437,18 +409,18 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k1)).isEqualTo(v2); } - @Test - public void testReplaceNullOldValue() { + @ParameterizedRedisTest + void testReplaceNullOldValue() { assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> map.replace(getKey(), null, getValue())); } - @Test - public void testReplaceNullNewValue() { + @ParameterizedRedisTest + void testReplaceNullNewValue() { assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> map.replace(getKey(), getValue(), null)); } - @Test - public void testConcurrentReplaceOneArg() { + @ParameterizedRedisTest + void testConcurrentReplaceOneArg() { K k1 = getKey(); V v1 = getValue(); @@ -461,12 +433,12 @@ public abstract class AbstractRedisMapTests { assertThat(map.get(k1)).isEqualTo(v2); } - @Test - public void testReplaceNullValue() { + @ParameterizedRedisTest + void testReplaceNullValue() { assertThatExceptionOfType(NullPointerException.class).isThrownBy(() -> map.replace(getKey(), null)); } - @Test // DATAREDIS-314 + @ParameterizedRedisTest // DATAREDIS-314 public void testScanWorksCorrectly() throws IOException { K k1 = getKey(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetIntegrationTests.java similarity index 84% rename from src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java rename to src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetIntegrationTests.java index accfab3a2..673aa531c 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisSetIntegrationTests.java @@ -24,20 +24,13 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.springframework.data.redis.ObjectFactory; -import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.BoundSetOperations; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.test.util.MinimumRedisVersionRule; -import org.springframework.data.redis.test.util.RedisClientRule; -import org.springframework.data.redis.test.util.RedisDriver; -import org.springframework.data.redis.test.util.WithRedisDriver; -import org.springframework.test.annotation.IfProfileValue; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; import org.springframework.util.ObjectUtils; /** @@ -47,15 +40,7 @@ import org.springframework.util.ObjectUtils; * @author Christoph Strobl * @author Thomas Darimont */ -public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTests { - - public @Rule RedisClientRule clientRule = new RedisClientRule() { - public RedisConnectionFactory getConnectionFactory() { - return template.getConnectionFactory(); - } - }; - - public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); +public abstract class AbstractRedisSetIntegrationTests extends AbstractRedisCollectionIntegrationTests { protected RedisSet set; @@ -66,12 +51,12 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe * @param template */ @SuppressWarnings("rawtypes") - public AbstractRedisSetTests(ObjectFactory factory, RedisTemplate template) { + AbstractRedisSetIntegrationTests(ObjectFactory factory, RedisTemplate template) { super(factory, template); } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); set = (RedisSet) collection; @@ -82,8 +67,8 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe return new DefaultRedisSet<>((BoundSetOperations) set.getOperations().boundSetOps(key)); } - @Test - public void testDiff() { + @ParameterizedRedisTest + void testDiff() { RedisSet diffSet1 = createSetFor("test:set:diff1"); RedisSet diffSet2 = createSetFor("test:set:diff2"); @@ -103,8 +88,8 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe assertThat(diff).contains(t1); } - @Test - public void testDiffAndStore() { + @ParameterizedRedisTest + void testDiffAndStore() { RedisSet diffSet1 = createSetFor("test:set:diff1"); RedisSet diffSet2 = createSetFor("test:set:diff2"); @@ -129,8 +114,8 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe assertThat(diff.getKey()).isEqualTo(resultName); } - @Test - public void testIntersect() { + @ParameterizedRedisTest + void testIntersect() { RedisSet intSet1 = createSetFor("test:set:int1"); RedisSet intSet2 = createSetFor("test:set:int2"); @@ -179,8 +164,8 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe } @SuppressWarnings("unchecked") - @Test - public void testUnion() { + @ParameterizedRedisTest + void testUnion() { RedisSet unionSet1 = createSetFor("test:set:union1"); RedisSet unionSet2 = createSetFor("test:set:union2"); @@ -202,8 +187,8 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe } @SuppressWarnings("unchecked") - @Test - public void testUnionAndStore() { + @ParameterizedRedisTest + void testUnionAndStore() { RedisSet unionSet1 = createSetFor("test:set:union1"); RedisSet unionSet2 = createSetFor("test:set:union2"); @@ -226,7 +211,7 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe assertThat(union.getKey()).isEqualTo(resultName); } - @Test + @ParameterizedRedisTest public void testIterator() { T t1 = getT(); T t2 = getT(); @@ -255,7 +240,7 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe } @SuppressWarnings("unchecked") - @Test + @ParameterizedRedisTest public void testToArray() { Object[] expectedArray = new Object[] { getT(), getT(), getT() }; List list = (List) Arrays.asList(expectedArray); @@ -280,7 +265,7 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe } @SuppressWarnings("unchecked") - @Test + @ParameterizedRedisTest public void testToArrayWithGenerics() { Object[] expectedArray = new Object[] { getT(), getT(), getT() }; List list = (List) Arrays.asList(expectedArray); @@ -305,10 +290,8 @@ public abstract class AbstractRedisSetTests extends AbstractRedisCollectionTe // DATAREDIS-314 @SuppressWarnings("unchecked") - @IfProfileValue(name = "redisVersion", value = "2.8+") - @Test - @WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE }) - public void testScanWorksCorrectly() throws IOException { + @ParameterizedRedisTest + void testScanWorksCorrectly() throws IOException { Object[] expectedArray = new Object[] { getT(), getT(), getT() }; collection.addAll((List) Arrays.asList(expectedArray)); diff --git a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTestIntegration.java similarity index 81% rename from src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java rename to src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTestIntegration.java index 44927ca90..1e3c10c1a 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTest.java +++ b/src/test/java/org/springframework/data/redis/support/collections/AbstractRedisZSetTestIntegration.java @@ -25,26 +25,19 @@ import java.util.NoSuchElementException; import java.util.Set; import org.assertj.core.data.Offset; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; import org.springframework.data.redis.DoubleAsStringObjectFactory; import org.springframework.data.redis.DoubleObjectFactory; import org.springframework.data.redis.LongAsStringObjectFactory; import org.springframework.data.redis.LongObjectFactory; import org.springframework.data.redis.ObjectFactory; -import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.connection.RedisZSetCommands; import org.springframework.data.redis.core.BoundZSetOperations; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.ZSetOperations.TypedTuple; -import org.springframework.data.redis.test.util.MinimumRedisVersionRule; -import org.springframework.data.redis.test.util.RedisClientRule; -import org.springframework.data.redis.test.util.RedisDriver; -import org.springframework.data.redis.test.util.WithRedisDriver; -import org.springframework.test.annotation.IfProfileValue; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; /** * Integration test for Redis ZSet. @@ -55,17 +48,9 @@ import org.springframework.test.annotation.IfProfileValue; * @author Mark Paluch * @author Andrey Shlykov */ -public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTests { +public abstract class AbstractRedisZSetTestIntegration extends AbstractRedisCollectionIntegrationTests { - public @Rule RedisClientRule clientRule = new RedisClientRule() { - public RedisConnectionFactory getConnectionFactory() { - return template.getConnectionFactory(); - } - }; - - public @Rule MinimumRedisVersionRule versionRule = new MinimumRedisVersionRule(); - - protected RedisZSet zSet; + private RedisZSet zSet; /** * Constructs a new AbstractRedisZSetTest instance. @@ -74,19 +59,19 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe * @param template */ @SuppressWarnings("rawtypes") - public AbstractRedisZSetTest(ObjectFactory factory, RedisTemplate template) { + AbstractRedisZSetTestIntegration(ObjectFactory factory, RedisTemplate template) { super(factory, template); } @SuppressWarnings("unchecked") - @Before + @BeforeEach public void setUp() throws Exception { super.setUp(); zSet = (RedisZSet) collection; } - @Test - public void testAddWithScore() { + @ParameterizedRedisTest + void testAddWithScore() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -102,7 +87,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(iterator.hasNext()).isFalse(); } - @Test + @ParameterizedRedisTest public void testAdd() { T t1 = getT(); T t2 = getT(); @@ -119,8 +104,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(zSet.score(t3)).isEqualTo(d); } - @Test - public void testFirst() { + @ParameterizedRedisTest + void testFirst() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -129,17 +114,17 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t2, 4); zSet.add(t3, 5); - assertThat(zSet.size()).isEqualTo(3); + assertThat(zSet).hasSize(3); assertThat(zSet.first()).isEqualTo(t1); } - @Test - public void testFirstException() { + @ParameterizedRedisTest + void testFirstException() { assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> zSet.first()); } - @Test - public void testLast() { + @ParameterizedRedisTest + void testLast() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -148,17 +133,17 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t2, 4); zSet.add(t3, 5); - assertThat(zSet.size()).isEqualTo(3); + assertThat(zSet).hasSize(3); assertThat(zSet.last()).isEqualTo(t3); } - @Test - public void testLastException() { + @ParameterizedRedisTest + void testLastException() { assertThatExceptionOfType(NoSuchElementException.class).isThrownBy(() -> zSet.last()); } - @Test - public void testRank() { + @ParameterizedRedisTest + void testRank() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -174,8 +159,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe // assertNull(); } - @Test - public void testReverseRank() { + @ParameterizedRedisTest + void testReverseRank() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -190,8 +175,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(zSet.rank(getT())).isNull(); } - @Test // DATAREDIS-729 - public void testLexCountUnbounded() { + @ParameterizedRedisTest // DATAREDIS-729 + void testLexCountUnbounded() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -207,8 +192,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(zSet.lexCount(RedisZSetCommands.Range.unbounded())).isEqualTo(Long.valueOf(3)); } - @Test // DATAREDIS-729 - public void testLexCountBounded() { + @ParameterizedRedisTest // DATAREDIS-729 + void testLexCountBounded() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -224,8 +209,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(zSet.lexCount(RedisZSetCommands.Range.range().gt(t1))).isEqualTo(Long.valueOf(2)); } - @Test - public void testScore() { + @ParameterizedRedisTest + void testScore() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -240,8 +225,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(zSet.score(t3)).isEqualTo(Double.valueOf(5)); } - @Test - public void testDefaultScore() { + @ParameterizedRedisTest + void testDefaultScore() { assertThat(zSet.getDefaultScore()).isCloseTo(1, Offset.offset(0d)); } @@ -250,9 +235,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe return new DefaultRedisZSet<>((BoundZSetOperations) zSet.getOperations().boundZSetOps(key)); } - @SuppressWarnings("unchecked") - @Test - public void testIntersectAndStore() { + @ParameterizedRedisTest + void testIntersectAndStore() { RedisZSet interSet1 = createZSetFor("test:zset:inter1"); RedisZSet interSet2 = createZSetFor("test:zset:inter"); @@ -274,14 +258,14 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe String resultName = "test:zset:inter:result:1"; RedisZSet inter = zSet.intersectAndStore(Arrays.asList(interSet1, interSet2), resultName); - assertThat(inter.size()).isEqualTo(1); + assertThat(inter).hasSize(1); assertThat(inter).contains(t2); assertThat(inter.score(t2)).isEqualTo(Double.valueOf(6)); assertThat(inter.getKey()).isEqualTo(resultName); } - @Test - public void testRange() { + @ParameterizedRedisTest + void testRange() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -291,14 +275,14 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set range = zSet.range(1, 2); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator iterator = range.iterator(); assertThat(iterator.next()).isEqualTo(t2); assertThat(iterator.next()).isEqualTo(t3); } - @Test - public void testRangeWithScores() { + @ParameterizedRedisTest + void testRangeWithScores() { T t1 = getT(); T t2 = getT(); @@ -309,7 +293,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set> range = zSet.rangeWithScores(1, 2); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator> iterator = range.iterator(); TypedTuple tuple1 = iterator.next(); @@ -321,8 +305,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(tuple2.getScore()).isEqualTo(Double.valueOf(3)); } - @Test - public void testReverseRange() { + @ParameterizedRedisTest + void testReverseRange() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -332,14 +316,14 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set range = zSet.reverseRange(1, 2); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator iterator = range.iterator(); assertThat(iterator.next()).isEqualTo(t2); assertThat(iterator.next()).isEqualTo(t1); } - @Test - public void testReverseRangeWithScores() { + @ParameterizedRedisTest + void testReverseRangeWithScores() { T t1 = getT(); T t2 = getT(); @@ -350,7 +334,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set> range = zSet.reverseRangeWithScores(1, 2); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator> iterator = range.iterator(); TypedTuple tuple1 = iterator.next(); @@ -362,8 +346,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(tuple2.getScore()).isEqualTo(Double.valueOf(1)); } - @Test // DATAREDIS-407 - public void testRangeByLexUnbounded() { + @ParameterizedRedisTest // DATAREDIS-407 + void testRangeByLexUnbounded() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -377,13 +361,13 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded()); - assertThat(tuples.size()).isEqualTo(3); + assertThat(tuples).hasSize(3); T tuple = tuples.iterator().next(); assertThat(tuple).isEqualTo(t1); } - @Test // DATAREDIS-407 - public void testRangeByLexBounded() { + @ParameterizedRedisTest // DATAREDIS-407 + void testRangeByLexBounded() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -397,13 +381,13 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.range().gt(t1).lt(t3)); - assertThat(tuples.size()).isEqualTo(1); + assertThat(tuples).hasSize(1); T tuple = tuples.iterator().next(); assertThat(tuple).isEqualTo(t2); } - @Test // DATAREDIS-407 - public void testRangeByLexUnboundedWithLimit() { + @ParameterizedRedisTest // DATAREDIS-407 + void testRangeByLexUnboundedWithLimit() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -418,13 +402,13 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe Set tuples = zSet.rangeByLex(RedisZSetCommands.Range.unbounded(), RedisZSetCommands.Limit.limit().count(1).offset(1)); - assertThat(tuples.size()).isEqualTo(1); + assertThat(tuples).hasSize(1); T tuple = tuples.iterator().next(); assertThat(tuple).isEqualTo(t2); } - @Test // DATAREDIS-407 - public void testRangeByLexBoundedWithLimit() { + @ParameterizedRedisTest // DATAREDIS-407 + void testRangeByLexBoundedWithLimit() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -442,8 +426,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(tuples).hasSize(2).containsSequence(t2, t3); } - @Test // DATAREDIS-729 - public void testReverseRangeByLexBoundedWithLimit() { + @ParameterizedRedisTest // DATAREDIS-729 + void testReverseRangeByLexBoundedWithLimit() { assumeThat(factory).isOfAnyClassIn(DoubleObjectFactory.class, DoubleAsStringObjectFactory.class, LongAsStringObjectFactory.class, LongObjectFactory.class); @@ -461,8 +445,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(tuples).hasSize(2).containsSequence(t2, t1); } - @Test // DATAREDIS-729 - public void testReverseRangeByScore() { + @ParameterizedRedisTest // DATAREDIS-729 + void testReverseRangeByScore() { T t1 = getT(); T t2 = getT(); @@ -473,14 +457,14 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set range = zSet.reverseRangeByScore(1.5, 3.5); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator iterator = range.iterator(); assertThat(iterator.next()).isEqualTo(t3); assertThat(iterator.next()).isEqualTo(t2); } - @Test - public void testReverseRangeByScoreWithScores() { + @ParameterizedRedisTest + void testReverseRangeByScoreWithScores() { T t1 = getT(); T t2 = getT(); @@ -491,7 +475,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set> range = zSet.reverseRangeByScoreWithScores(1.5, 3.5); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator> iterator = range.iterator(); TypedTuple tuple1 = iterator.next(); @@ -504,8 +488,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe } @SuppressWarnings("unchecked") - @Test - public void testRangeByScore() { + @ParameterizedRedisTest + void testRangeByScore() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -515,7 +499,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set range = zSet.rangeByScore(1.5, 3.5); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); assertThat(range).contains(t2, t3); Iterator iterator = range.iterator(); @@ -523,8 +507,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(iterator.next()).isEqualTo(t3); } - @Test - public void testRangeByScoreWithScores() { + @ParameterizedRedisTest + void testRangeByScoreWithScores() { T t1 = getT(); T t2 = getT(); @@ -535,7 +519,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.add(t3, 3); Set> range = zSet.rangeByScoreWithScores(1.5, 3.5); - assertThat(range.size()).isEqualTo(2); + assertThat(range).hasSize(2); Iterator> iterator = range.iterator(); TypedTuple tuple1 = iterator.next(); @@ -547,8 +531,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(tuple2.getScore()).isEqualTo(Double.valueOf(3)); } - @Test - public void testRemove() { + @ParameterizedRedisTest + void testRemove() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -561,14 +545,14 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.remove(1, 2); - assertThat(zSet.size()).isEqualTo(2); + assertThat(zSet).hasSize(2); Iterator iterator = zSet.iterator(); assertThat(iterator.next()).isEqualTo(t1); assertThat(iterator.next()).isEqualTo(t4); } - @Test - public void testRemoveByScore() { + @ParameterizedRedisTest + void testRemoveByScore() { T t1 = getT(); T t2 = getT(); T t3 = getT(); @@ -581,7 +565,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe zSet.removeByScore(1.5, 2.5); - assertThat(zSet.size()).isEqualTo(3); + assertThat(zSet).hasSize(3); Iterator iterator = zSet.iterator(); assertThat(iterator.next()).isEqualTo(t1); assertThat(iterator.next()).isEqualTo(t3); @@ -589,8 +573,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe } @SuppressWarnings("unchecked") - @Test - public void testUnionAndStore() { + @ParameterizedRedisTest + void testUnionAndStore() { RedisZSet unionSet1 = createZSetFor("test:zset:union1"); RedisZSet unionSet2 = createZSetFor("test:zset:union2"); @@ -609,7 +593,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe String resultName = "test:zset:union:result:1"; RedisZSet union = zSet.unionAndStore(Arrays.asList(unionSet1, unionSet2), resultName); - assertThat(union.size()).isEqualTo(4); + assertThat(union).hasSize(4); assertThat(union).contains(t1, t2, t3, t4); assertThat(union.getKey()).isEqualTo(resultName); @@ -619,7 +603,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(union.score(t4)).isEqualTo(Double.valueOf(5)); } - @Test + @ParameterizedRedisTest public void testIterator() { T t1 = getT(); T t2 = getT(); @@ -640,7 +624,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(iterator.hasNext()).isFalse(); } - @Test + @ParameterizedRedisTest public void testToArray() { T t1 = getT(); T t2 = getT(); @@ -656,7 +640,7 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(array).isEqualTo(new Object[] { t1, t2, t3, t4 }); } - @Test + @ParameterizedRedisTest public void testToArrayWithGenerics() { T t1 = getT(); T t2 = getT(); @@ -672,10 +656,8 @@ public abstract class AbstractRedisZSetTest extends AbstractRedisCollectionTe assertThat(array).isEqualTo(new Object[] { t1, t2, t3, t4 }); } - @IfProfileValue(name = "redisVersion", value = "2.8+") - @Test // DATAREDIS-314 - @WithRedisDriver({ RedisDriver.JEDIS, RedisDriver.LETTUCE }) - public void testScanWorksCorrectly() throws IOException { + @ParameterizedRedisTest // DATAREDIS-314 + void testScanWorksCorrectly() throws IOException { T t1 = getT(); T t2 = getT(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java index d3c26057c..6cbc6939a 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java +++ b/src/test/java/org/springframework/data/redis/support/collections/CollectionTestParams.java @@ -23,20 +23,18 @@ 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.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.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; 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; /** * @author Costin Leau @@ -48,14 +46,7 @@ public abstract class CollectionTestParams { public static Collection testParams() { - // 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 jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class); StringRedisSerializer stringSerializer = StringRedisSerializer.UTF_8; diff --git a/src/test/java/org/springframework/data/redis/support/collections/DefaultRedisMapUnitUnitTests.java b/src/test/java/org/springframework/data/redis/support/collections/DefaultRedisMapUnitUnitTests.java index 9deaa8fc2..8ebcec533 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/DefaultRedisMapUnitUnitTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/DefaultRedisMapUnitUnitTests.java @@ -22,11 +22,12 @@ import java.util.Collections; import java.util.Map.Entry; import java.util.Set; -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.core.BoundHashOperations; /** @@ -34,20 +35,20 @@ import org.springframework.data.redis.core.BoundHashOperations; * * @author Mark Paluch */ -@RunWith(MockitoJUnitRunner.class) -public class DefaultRedisMapUnitUnitTests { +@ExtendWith(MockitoExtension.class) +class DefaultRedisMapUnitUnitTests { @Mock BoundHashOperations operationsMock; - DefaultRedisMap map; + private DefaultRedisMap map; - @Before - public void before() { + @BeforeEach + void before() { map = new DefaultRedisMap<>(operationsMock); } @Test // DATAREDIS-803 - public void shouldGetEntrySet() { + void shouldGetEntrySet() { when(operationsMock.entries()).thenReturn(Collections.singletonMap("foo", "bar")); diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java index 3013afda8..9ec62757c 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisCollectionFactoryBeanTests.java @@ -17,11 +17,9 @@ package org.springframework.data.redis.support.collections; import static org.assertj.core.api.Assertions.*; -import org.junit.After; -import org.junit.AfterClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; -import org.springframework.data.redis.ConnectionFactoryTracker; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.StringObjectFactory; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; @@ -40,15 +38,15 @@ public class RedisCollectionFactoryBeanTests { protected StringRedisTemplate template; protected RedisStore col; - public RedisCollectionFactoryBeanTests() { + RedisCollectionFactoryBeanTests() { JedisConnectionFactory jedisConnFactory = JedisConnectionFactoryExtension .getConnectionFactory(RedisStanalone.class); this.template = new StringRedisTemplate(jedisConnFactory); } - @After - public void tearDown() throws Exception { + @AfterEach + void tearDown() throws Exception { // clean up the whole db template.execute((RedisCallback) connection -> { connection.flushDb(); @@ -71,7 +69,7 @@ public class RedisCollectionFactoryBeanTests { } @Test - public void testNone() throws Exception { + void testNone() throws Exception { RedisStore store = createCollection("nosrt", CollectionType.PROPERTIES); assertThat(store).isInstanceOf(RedisProperties.class); @@ -89,7 +87,7 @@ public class RedisCollectionFactoryBeanTests { } @Test - public void testExistingCol() throws Exception { + void testExistingCol() throws Exception { String key = "set"; String val = "value"; diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisListIntegrationTests.java similarity index 86% rename from src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java rename to src/test/java/org/springframework/data/redis/support/collections/RedisListIntegrationTests.java index eeb3497bb..342f4ba69 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisListTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisListIntegrationTests.java @@ -23,7 +23,7 @@ import org.springframework.data.redis.core.RedisTemplate; * * @author Costin Leau */ -public class RedisListTests extends AbstractRedisListTests { +public class RedisListIntegrationTests extends AbstractRedisListIntegrationTests { /** * Constructs a new RedisListTests instance. @@ -31,7 +31,7 @@ public class RedisListTests extends AbstractRedisListTests { * @param factory * @param connFactory */ - public RedisListTests(ObjectFactory factory, RedisTemplate template) { + public RedisListIntegrationTests(ObjectFactory factory, RedisTemplate template) { super(factory, template); } diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisMapIntegrationTests.java similarity index 88% rename from src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java rename to src/test/java/org/springframework/data/redis/support/collections/RedisMapIntegrationTests.java index 508dd694d..5e1b51608 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisMapTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisMapIntegrationTests.java @@ -18,28 +18,24 @@ package org.springframework.data.redis.support.collections; import java.util.Arrays; import java.util.Collection; -import org.junit.runners.Parameterized.Parameters; import org.springframework.data.redis.DoubleAsStringObjectFactory; import org.springframework.data.redis.LongAsStringObjectFactory; 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.PoolConfig; 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.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; 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; /** * Integration test for RedisMap. @@ -50,10 +46,11 @@ import org.springframework.oxm.xstream.XStreamMarshaller; * @author Christoph Strobl * @author Mark Paluch */ -public class RedisMapTests extends AbstractRedisMapTests { +public class RedisMapIntegrationTests extends AbstractRedisMapIntegrationTests { @SuppressWarnings("rawtypes") - public RedisMapTests(ObjectFactory keyFactory, ObjectFactory valueFactory, RedisTemplate template) { + public RedisMapIntegrationTests(ObjectFactory keyFactory, ObjectFactory valueFactory, + RedisTemplate template) { super(keyFactory, valueFactory, template); } @@ -65,25 +62,14 @@ public class RedisMapTests extends AbstractRedisMapTests { // DATAREDIS-241 @SuppressWarnings("rawtypes") - @Parameters public static Collection testParams() { - // 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 jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class); Jackson2JsonRedisSerializer jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<>( String.class); StringRedisSerializer stringSerializer = StringRedisSerializer.UTF_8; - PoolConfig defaultPoolConfig = new PoolConfig(); - defaultPoolConfig.setMaxActive(1000); - // create Jedis Factory ObjectFactory stringFactory = new StringObjectFactory(); ObjectFactory personFactory = new PersonObjectFactory(); diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java similarity index 87% rename from src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java rename to src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java index 35108a651..cf19bc5ea 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisPropertiesIntegrationTests.java @@ -27,9 +27,6 @@ import java.util.LinkedHashSet; import java.util.Properties; import java.util.Set; -import org.junit.Test; -import org.junit.runners.Parameterized.Parameters; - import org.springframework.data.redis.DoubleAsStringObjectFactory; import org.springframework.data.redis.LongAsStringObjectFactory; import org.springframework.data.redis.ObjectFactory; @@ -43,8 +40,9 @@ import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.serializer.Jackson2JsonRedisSerializer; import org.springframework.data.redis.serializer.OxmSerializer; +import org.springframework.data.redis.test.XstreamOxmSerializerSingleton; import org.springframework.data.redis.test.extension.RedisStanalone; -import org.springframework.oxm.xstream.XStreamMarshaller; +import org.springframework.data.redis.test.extension.parametrized.ParameterizedRedisTest; /** * @author Costin Leau @@ -52,10 +50,10 @@ import org.springframework.oxm.xstream.XStreamMarshaller; * @author Christoph Strobl * @author Mark Paluch */ -public class RedisPropertiesTests extends RedisMapTests { +public class RedisPropertiesIntegrationTests extends RedisMapIntegrationTests { - protected Properties defaults = new Properties(); - protected RedisProperties props; + private Properties defaults = new Properties(); + private RedisProperties props; /** * Constructs a new RedisPropertiesTests instance. @@ -64,7 +62,7 @@ public class RedisPropertiesTests extends RedisMapTests { * @param valueFactory * @param template */ - public RedisPropertiesTests(ObjectFactory keyFactory, ObjectFactory valueFactory, + public RedisPropertiesIntegrationTests(ObjectFactory keyFactory, ObjectFactory valueFactory, RedisTemplate template) { super(keyFactory, valueFactory, template); } @@ -79,13 +77,13 @@ public class RedisPropertiesTests extends RedisMapTests { return new RedisProperties(store.getKey(), store.getOperations()); } - @Test + @ParameterizedRedisTest public void testGetOperations() { assertThat(map.getOperations() instanceof StringRedisTemplate).isTrue(); } - @Test - public void testPropertiesLoad() throws Exception { + @ParameterizedRedisTest + void testPropertiesLoad() throws Exception { InputStream stream = getClass() .getResourceAsStream("/org/springframework/data/redis/support/collections/props.properties"); @@ -105,8 +103,8 @@ public class RedisPropertiesTests extends RedisMapTests { assertThat(props.size()).isEqualTo(size + 3); } - @Test - public void testPropertiesSave() throws Exception { + @ParameterizedRedisTest + void testPropertiesSave() throws Exception { props.setProperty("x", "y"); props.setProperty("a", "b"); @@ -114,36 +112,36 @@ public class RedisPropertiesTests extends RedisMapTests { props.store(writer, "no-comment"); } - @Test - public void testGetProperty() throws Exception { + @ParameterizedRedisTest + void testGetProperty() throws Exception { String property = props.getProperty("a"); assertThat(property).isNull(); defaults.put("a", "x"); assertThat(props.getProperty("a")).isEqualTo("x"); } - @Test - public void testGetPropertyDefault() throws Exception { + @ParameterizedRedisTest + void testGetPropertyDefault() throws Exception { assertThat(props.getProperty("a", "x")).isEqualTo("x"); } - @Test - public void testSetProperty() throws Exception { + @ParameterizedRedisTest + void testSetProperty() throws Exception { assertThat(props.getProperty("a")).isNull(); defaults.setProperty("a", "x"); assertThat(props.getProperty("a")).isEqualTo("x"); } - @Test - public void testPropertiesList() throws Exception { + @ParameterizedRedisTest + void testPropertiesList() throws Exception { defaults.setProperty("a", "b"); props.setProperty("x", "y"); StringWriter wr = new StringWriter(); props.list(new PrintWriter(wr)); } - @Test - public void testPropertyNames() throws Exception { + @ParameterizedRedisTest + void testPropertyNames() throws Exception { String key1 = "foo"; String key2 = "x"; String key3 = "d"; @@ -163,14 +161,14 @@ public class RedisPropertiesTests extends RedisMapTests { assertThat(names.hasMoreElements()).isFalse(); } - @Test - public void testDefaultInit() throws Exception { + @ParameterizedRedisTest + void testDefaultInit() throws Exception { RedisProperties redisProperties = new RedisProperties("foo", template); redisProperties.propertyNames(); } - @Test - public void testStringPropertyNames() throws Exception { + @ParameterizedRedisTest + void testStringPropertyNames() throws Exception { String key1 = "foo"; String key2 = "x"; String key3 = "d"; @@ -187,24 +185,16 @@ public class RedisPropertiesTests extends RedisMapTests { assertThat(keys.contains(key3)).isTrue(); } - @Test + @ParameterizedRedisTest @Override public void testScanWorksCorrectly() { assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> super.testScanWorksCorrectly()); } // DATAREDIS-241 - @Parameters public static Collection testParams() { - // 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 jackson2JsonSerializer = new Jackson2JsonRedisSerializer<>(Person.class); Jackson2JsonRedisSerializer jackson2JsonStringSerializer = new Jackson2JsonRedisSerializer<>( String.class); diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisSetIntegrationTests.java similarity index 87% rename from src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java rename to src/test/java/org/springframework/data/redis/support/collections/RedisSetIntegrationTests.java index 7ee0d05ce..80793d27f 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisSetIntegrationTests.java @@ -23,7 +23,7 @@ import org.springframework.data.redis.core.RedisTemplate; * * @author Costin Leau */ -public class RedisSetTests extends AbstractRedisSetTests { +public class RedisSetIntegrationTests extends AbstractRedisSetIntegrationTests { /** * Constructs a new RedisSetTests instance. @@ -31,7 +31,7 @@ public class RedisSetTests extends AbstractRedisSetTests { * @param factory * @param template */ - public RedisSetTests(ObjectFactory factory, RedisTemplate template) { + public RedisSetIntegrationTests(ObjectFactory factory, RedisTemplate template) { super(factory, template); } diff --git a/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java b/src/test/java/org/springframework/data/redis/support/collections/RedisZSetIntegrationTests.java similarity index 77% rename from src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java rename to src/test/java/org/springframework/data/redis/support/collections/RedisZSetIntegrationTests.java index 2414b8d11..cffd19a83 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/RedisZSetTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/RedisZSetIntegrationTests.java @@ -17,16 +17,13 @@ package org.springframework.data.redis.support.collections; import org.springframework.data.redis.ObjectFactory; import org.springframework.data.redis.core.RedisTemplate; -import org.springframework.data.redis.support.collections.AbstractRedisCollection; -import org.springframework.data.redis.support.collections.DefaultRedisZSet; -import org.springframework.data.redis.support.collections.RedisStore; /** * Parameterized instance of Redis sorted set tests. * * @author Costin Leau */ -public class RedisZSetTests extends AbstractRedisZSetTest { +public class RedisZSetIntegrationTests extends AbstractRedisZSetTestIntegration { /** * Constructs a new RedisZSetTests instance. @@ -34,7 +31,7 @@ public class RedisZSetTests extends AbstractRedisZSetTest { * @param factory * @param template */ - public RedisZSetTests(ObjectFactory factory, RedisTemplate template) { + public RedisZSetIntegrationTests(ObjectFactory factory, RedisTemplate template) { super(factory, template); } diff --git a/src/test/java/org/springframework/data/redis/support/collections/SupportXmlTests.java b/src/test/java/org/springframework/data/redis/support/collections/SupportXmlIntegrationTests.java similarity index 89% rename from src/test/java/org/springframework/data/redis/support/collections/SupportXmlTests.java rename to src/test/java/org/springframework/data/redis/support/collections/SupportXmlIntegrationTests.java index 747b51951..efc7d7e84 100644 --- a/src/test/java/org/springframework/data/redis/support/collections/SupportXmlTests.java +++ b/src/test/java/org/springframework/data/redis/support/collections/SupportXmlIntegrationTests.java @@ -17,21 +17,24 @@ package org.springframework.data.redis.support.collections; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; + import org.springframework.context.support.GenericXmlApplicationContext; /** * @author Costin Leau */ -public class SupportXmlTests { +class SupportXmlIntegrationTests { @Test - public void testContainerSetup() throws Exception { + void testContainerSetup() throws Exception { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext( "/org/springframework/data/redis/support/collections/container.xml"); RedisList list = ctx.getBean("non-existing", RedisList.class); RedisProperties props = ctx.getBean("props", RedisProperties.class); Map map = ctx.getBean("map", Map.class); + + ctx.close(); } } diff --git a/src/test/java/org/springframework/data/redis/test/XstreamOxmSerializerSingleton.java b/src/test/java/org/springframework/data/redis/test/XstreamOxmSerializerSingleton.java new file mode 100644 index 000000000..15dd688e0 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/XstreamOxmSerializerSingleton.java @@ -0,0 +1,47 @@ +/* + * Copyright 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.test; + +import org.springframework.data.redis.serializer.OxmSerializer; +import org.springframework.oxm.xstream.XStreamMarshaller; + +/** + * @author Mark Paluch + */ +public final class XstreamOxmSerializerSingleton { + + private final static XstreamOxmSerializerSingleton instance = new XstreamOxmSerializerSingleton(); + + private final OxmSerializer serializer; + + private XstreamOxmSerializerSingleton() { + + // XStream serializer + XStreamMarshaller xstream = new XStreamMarshaller(); + try { + xstream.afterPropertiesSet(); + } catch (Exception ex) { + throw new RuntimeException("Cannot init XStream", ex); + } + + serializer = new OxmSerializer(xstream, xstream); + serializer.afterPropertiesSet(); + } + + public static OxmSerializer getInstance() { + return instance.serializer; + } +} diff --git a/src/test/java/org/springframework/data/redis/test/condition/EnabledIfLongRunningTest.java b/src/test/java/org/springframework/data/redis/test/condition/EnabledIfLongRunningTest.java new file mode 100644 index 000000000..306089762 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/condition/EnabledIfLongRunningTest.java @@ -0,0 +1,43 @@ +/* + * Copyright 2018-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.test.condition; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; + +/** + * {@code @EnabledIfLongRunningTest} is used to signal that the annotated test method or test class is only + * enabled if long running tests are enabled. This is a meta-annotation for + * {@code @EnabledIfSystemProperty(named = "longRunningTest")}. + *

+ * When declared at the class level, the result will apply to all test methods within that class as well. + * + * @author Mark Paluch + */ +@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Inherited +@Documented +@EnabledIfSystemProperty(named = "runLongTests", matches = "true", disabledReason = "Long-running tests disabled") +public @interface EnabledIfLongRunningTest { + +} diff --git a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisClusterCondition.java b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisClusterCondition.java index 2f1791e26..533f48e25 100644 --- a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisClusterCondition.java +++ b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisClusterCondition.java @@ -17,9 +17,6 @@ package org.springframework.data.redis.test.condition; import static org.junit.jupiter.api.extension.ConditionEvaluationResult.*; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; import java.util.Optional; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -48,15 +45,13 @@ class EnabledOnRedisClusterCondition implements ExecutionCondition { if (optional.isPresent()) { - try (Socket socket = new Socket()) { - socket.connect(new InetSocketAddress(SettingsUtils.getHost(), SettingsUtils.getClusterPort()), 100); - + if (RedisDetector.isClusterAvailable()) { return enabled(String.format("Connection successful to Redis Cluster at %s:%d", SettingsUtils.getHost(), SettingsUtils.getClusterPort())); - } catch (IOException e) { - return disabled(String.format("Cannot connect to Redis Cluster at %s:%d (%s)", SettingsUtils.getHost(), - SettingsUtils.getClusterPort(), e)); } + + return disabled(String.format("Cannot connect to Redis Cluster at %s:%d", SettingsUtils.getHost(), + SettingsUtils.getClusterPort())); } return ENABLED_BY_DEFAULT; diff --git a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisDriver.java b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisDriver.java new file mode 100644 index 000000000..7e76ff879 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisDriver.java @@ -0,0 +1,60 @@ +/* + * Copyright 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.test.condition; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.extension.ExtendWith; + +/** + * {@code @EnabledOnRedisDriver} is used to signal that the annotated test class or test method is only enabled + * when one of the {@link #value() specified Redis Clients} is used. + *

+ * This annotation must be used in combination with {@link DriverQualifier @DriverQualifier} so the extension can + * identify the driver from a {@link org.springframework.data.redis.connection.RedisConnectionFactory}. + *

+ * If a test method is disabled via this annotation, that does not prevent the test class from being instantiated. + * Rather, it prevents the execution of the test method and method-level lifecycle callbacks such as {@code @BeforeEach} + * methods, {@code @AfterEach} methods, and corresponding extension APIs. + * + * @author Thomas Darimont + * @author Mark Paluch + * @see org.springframework.data.redis.connection.RedisConnectionFactory + */ +@Target({ ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(EnabledOnRedisDriverCondition.class) +public @interface EnabledOnRedisDriver { + + /** + * One or more Redis drivers that enable the condition. + */ + RedisDriver[] value() default {}; + + /** + * Annotation to identify the field that holds the + * {@link org.springframework.data.redis.connection.RedisConnectionFactory} to inspect. + */ + @Target(ElementType.FIELD) + @Retention(RetentionPolicy.RUNTIME) + @interface DriverQualifier { + + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisDriverCondition.java b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisDriverCondition.java new file mode 100644 index 000000000..161b942a8 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisDriverCondition.java @@ -0,0 +1,89 @@ +/* + * Copyright 2018-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.test.condition; + +import static org.junit.jupiter.api.extension.ConditionEvaluationResult.*; + +import java.lang.reflect.Field; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.platform.commons.function.Try; +import org.junit.platform.commons.util.AnnotationUtils; +import org.junit.platform.commons.util.ReflectionUtils; + +import org.springframework.data.redis.connection.RedisConnectionFactory; + +/** + * {@link ExecutionCondition} for {@link EnabledOnRedisDriverCondition @EnabledOnRedisDriver}. + * + * @author Mark Paluch + * @see EnabledOnRedisDriver + */ +class EnabledOnRedisDriverCondition implements ExecutionCondition { + + private static final ConditionEvaluationResult ENABLED_BY_DEFAULT = enabled("@WithRedisDriver is not present"); + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) { + + Optional optional = AnnotationUtils.findAnnotation(context.getElement(), + EnabledOnRedisDriver.class); + + if (optional.isPresent()) { + + EnabledOnRedisDriver annotation = optional.get(); + Class testClass = context.getRequiredTestClass(); + + List annotatedFields = AnnotationUtils.findAnnotatedFields(testClass, + EnabledOnRedisDriver.DriverQualifier.class, + it -> RedisConnectionFactory.class.isAssignableFrom(it.getType())); + + if (annotatedFields.isEmpty()) { + throw new IllegalStateException( + "@WithRedisDriver requires a field of type RedisConnectionFactory annotated with @DriverQualifier!"); + } + + for (Field field : annotatedFields) { + Try fieldValue = ReflectionUtils.tryToReadFieldValue(field, context.getRequiredTestInstance()); + + RedisConnectionFactory value = (RedisConnectionFactory) fieldValue + .getOrThrow(e -> new IllegalStateException("Cannot read field " + field, e)); + + boolean foundMatch = false; + for (RedisDriver redisDriver : annotation.value()) { + if (redisDriver.matches(value)) { + foundMatch = true; + } + } + + if (!foundMatch) { + return disabled(String.format("Driver %s not supported. Supported driver(s): %s", + value, Arrays.toString(annotation.value()))); + } + } + + return enabled("Found enabled driver(s): " + Arrays.toString(annotation.value())); + } + + return ENABLED_BY_DEFAULT; + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisSentinelCondition.java b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisSentinelCondition.java index 21ea1305f..c43af52d9 100644 --- a/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisSentinelCondition.java +++ b/src/test/java/org/springframework/data/redis/test/condition/EnabledOnRedisSentinelCondition.java @@ -17,9 +17,6 @@ package org.springframework.data.redis.test.condition; import static org.junit.jupiter.api.extension.ConditionEvaluationResult.*; -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.Socket; import java.util.Optional; import org.junit.jupiter.api.extension.ConditionEvaluationResult; @@ -50,15 +47,15 @@ class EnabledOnRedisSentinelCondition implements ExecutionCondition { if (optional.isPresent()) { EnabledOnRedisSentinelAvailable annotation = optional.get(); - try (Socket socket = new Socket()) { - socket.connect(new InetSocketAddress(SettingsUtils.getHost(), annotation.value()), 100); + + if (RedisDetector.canConnectToPort(annotation.value())) { return enabled(String.format("Connection successful to Redis Sentinel at %s:%d", SettingsUtils.getHost(), annotation.value())); - } catch (IOException e) { - return disabled(String.format("Cannot connect to Redis Sentinel at %s:%d (%s)", SettingsUtils.getHost(), - annotation.value(), e)); } + + return disabled( + String.format("Cannot connect to Redis Sentinel at %s:%d", SettingsUtils.getHost(), annotation.value())); } return ENABLED_BY_DEFAULT; diff --git a/src/test/java/org/springframework/data/redis/test/util/RequiresRedisSentinel.java b/src/test/java/org/springframework/data/redis/test/condition/LongRunningTest.java similarity index 61% rename from src/test/java/org/springframework/data/redis/test/util/RequiresRedisSentinel.java rename to src/test/java/org/springframework/data/redis/test/condition/LongRunningTest.java index 88fe684b3..306b91a78 100644 --- a/src/test/java/org/springframework/data/redis/test/util/RequiresRedisSentinel.java +++ b/src/test/java/org/springframework/data/redis/test/condition/LongRunningTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2020 the original author or authors. + * Copyright 2018-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. @@ -13,24 +13,30 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.redis.test.util; +package org.springframework.data.redis.test.condition; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; +import java.lang.annotation.Inherited; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; -import org.springframework.data.redis.test.util.RedisSentinelRule.SentinelsAvailable; +import org.junit.jupiter.api.Test; /** - * @author Christoph Strobl + * {@code @LongRunningTest} is used to signal that the annotated test method is only enabled if long running + * tests are enabled. This is a meta-annotation for {@code @Test} and + * {@code @EnabledIfSystemProperty(named = "runLongTests")}. + * + * @author Mark Paluch */ -@Documented @Target({ ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) -public @interface RequiresRedisSentinel { - - SentinelsAvailable value() default SentinelsAvailable.ALL_ACTIVE; +@Inherited +@Documented +@Test +@EnabledIfLongRunningTest +public @interface LongRunningTest { } diff --git a/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java b/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java new file mode 100644 index 000000000..0302314b0 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/condition/RedisDetector.java @@ -0,0 +1,62 @@ +/* + * Copyright 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.test.condition; + +import redis.clients.jedis.HostAndPort; +import redis.clients.jedis.JedisCluster; + +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.Socket; + +import org.springframework.data.redis.SettingsUtils; +import org.springframework.data.util.Lazy; + +/** + * Utility to detect Redis operation modes. + * + * @author Mark Paluch + */ +public class RedisDetector { + + private static final Lazy CLUSTER_AVAILABLE = Lazy.of(() -> { + + try (JedisCluster cluster = new JedisCluster( + new HostAndPort(SettingsUtils.getHost(), SettingsUtils.getClusterPort()))) { + cluster.getConnectionFromSlot(1).close(); + + return true; + } catch (Exception e) { + return false; + } + }); + + public static boolean isClusterAvailable() { + return CLUSTER_AVAILABLE.get(); + } + + public static boolean canConnectToPort(int port) { + + try (Socket socket = new Socket()) { + socket.connect(new InetSocketAddress(SettingsUtils.getHost(), port), 100); + + return true; + } catch (IOException e) { + return false; + } + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/util/RedisDriver.java b/src/test/java/org/springframework/data/redis/test/condition/RedisDriver.java similarity index 92% rename from src/test/java/org/springframework/data/redis/test/util/RedisDriver.java rename to src/test/java/org/springframework/data/redis/test/condition/RedisDriver.java index 083b5646f..3f79addbc 100644 --- a/src/test/java/org/springframework/data/redis/test/util/RedisDriver.java +++ b/src/test/java/org/springframework/data/redis/test/condition/RedisDriver.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2020 the original author or authors. + * Copyright 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.springframework.data.redis.test.util; +package org.springframework.data.redis.test.condition; import org.springframework.data.redis.connection.ConnectionUtils; import org.springframework.data.redis.connection.RedisConnectionFactory; diff --git a/src/test/java/org/springframework/data/redis/test/extension/LettuceExtension.java b/src/test/java/org/springframework/data/redis/test/extension/LettuceExtension.java index 3c4b6c951..d4cddce8c 100644 --- a/src/test/java/org/springframework/data/redis/test/extension/LettuceExtension.java +++ b/src/test/java/org/springframework/data/redis/test/extension/LettuceExtension.java @@ -51,7 +51,6 @@ import org.junit.jupiter.api.extension.ParameterResolver; import org.springframework.core.ResolvableType; import org.springframework.data.redis.SettingsUtils; -import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; import org.springframework.data.util.Lazy; /** @@ -188,6 +187,10 @@ public class LettuceExtension implements ParameterResolver, AfterAllCallback, Af return (Supplier) supplier; } + public T getInstance(Class resourceType) { + return (T) doGetInstance(resourceType); + } + private Object doGetInstance(Type parameterizedType) { Optional resourceFunction = findFunction(parameterizedType); diff --git a/src/test/java/org/springframework/data/redis/test/extension/ShutdownQueue.java b/src/test/java/org/springframework/data/redis/test/extension/ShutdownQueue.java index 092e2b3f3..5bb9713c8 100644 --- a/src/test/java/org/springframework/data/redis/test/extension/ShutdownQueue.java +++ b/src/test/java/org/springframework/data/redis/test/extension/ShutdownQueue.java @@ -18,8 +18,6 @@ package org.springframework.data.redis.test.extension; import java.io.Closeable; import java.util.LinkedList; -import org.springframework.beans.factory.DisposableBean; - /** * Shutdown queue allowing ordered resource shutdown (LIFO). * @@ -53,14 +51,4 @@ public enum ShutdownQueue { public static void register(Closeable closeable) { INSTANCE.closeables.add(closeable); } - - public static Closeable toCloseable(DisposableBean closeable) { - return () -> { - try { - closeable.destroy(); - } catch (Exception e) { - e.printStackTrace(); - } - }; - } } diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/MethodArgumentsProvider.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/MethodArgumentsProvider.java new file mode 100644 index 000000000..0d6d7fe27 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/MethodArgumentsProvider.java @@ -0,0 +1,108 @@ +/* + * Copyright 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.test.extension.parametrized; + +import static java.lang.String.*; +import static org.junit.jupiter.params.provider.Arguments.*; + +import java.lang.reflect.Method; +import java.util.Arrays; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.support.AnnotationConsumer; +import org.junit.platform.commons.JUnitException; +import org.junit.platform.commons.util.CollectionUtils; +import org.junit.platform.commons.util.Preconditions; +import org.junit.platform.commons.util.ReflectionUtils; +import org.junit.platform.commons.util.StringUtils; + +/** + * Copy of {@code org.junit.jupiter.params.provider.MethodArgumentsProvider}. + */ +class MethodArgumentsProvider implements ArgumentsProvider, AnnotationConsumer { + + private String[] methodNames = new String[0]; + + @Override + public void accept(MethodSource annotation) { + this.methodNames = annotation.value(); + } + + @Override + public Stream provideArguments(ExtensionContext context) { + Object testInstance = context.getTestInstance().orElse(null); + // @formatter:off + return Arrays.stream(this.methodNames).map(factoryMethodName -> getMethod(context, factoryMethodName)) + .map(method -> ReflectionUtils.invokeMethod(method, testInstance)).flatMap(CollectionUtils::toStream) + .map(MethodArgumentsProvider::toArguments); + // @formatter:on + } + + private Method getMethod(ExtensionContext context, String factoryMethodName) { + if (StringUtils.isNotBlank(factoryMethodName)) { + if (factoryMethodName.contains("#")) { + return getMethodByFullyQualifiedName(factoryMethodName); + } else { + return ReflectionUtils.getRequiredMethod(context.getRequiredTestClass(), factoryMethodName); + } + } + return ReflectionUtils.getRequiredMethod(context.getRequiredTestClass(), context.getRequiredTestMethod().getName()); + } + + private Method getMethodByFullyQualifiedName(String fullyQualifiedMethodName) { + String[] methodParts = ReflectionUtils.parseFullyQualifiedMethodName(fullyQualifiedMethodName); + String className = methodParts[0]; + String methodName = methodParts[1]; + String methodParameters = methodParts[2]; + + Preconditions.condition(StringUtils.isBlank(methodParameters), + () -> format("factory method [%s] must not declare formal parameters", fullyQualifiedMethodName)); + + return ReflectionUtils.getRequiredMethod(loadRequiredClass(className), methodName); + } + + private Class loadRequiredClass(String className) { + return ReflectionUtils.tryToLoadClass(className) + .getOrThrow(cause -> new JUnitException(format("Could not load class [%s]", className), cause)); + } + + private static Arguments toArguments(Object item) { + + // Nothing to do except cast. + if (item instanceof Arguments) { + return (Arguments) item; + } + + // Pass all multidimensional arrays "as is", in contrast to Object[]. + // See https://github.com/junit-team/junit5/issues/1665 + if (ReflectionUtils.isMultidimensionalArray(item)) { + return arguments(item); + } + + // Special treatment for one-dimensional reference arrays. + // See https://github.com/junit-team/junit5/issues/1665 + if (item instanceof Object[]) { + return arguments((Object[]) item); + } + + // Pass everything else "as is". + return arguments(item); + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/MethodSource.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/MethodSource.java new file mode 100644 index 000000000..eb8cf8cda --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/MethodSource.java @@ -0,0 +1,54 @@ +/* + * Copyright 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.test.extension.parametrized; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.params.provider.ArgumentsSource; + +/** + * {@code @MethodSource} is an {@link ArgumentsSource} which provides access to values returned from + * {@linkplain #value() factory methods} of the class in which this annotation is declared or from static factory + * methods in external classes referenced by fully qualified method name. + *

+ * This variant can be used only on type level. + *

+ * Copy of {@code org.junit.jupiter.params.provider.MethodSource}. + */ +@Target({ ElementType.ANNOTATION_TYPE, ElementType.TYPE }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@ArgumentsSource(MethodArgumentsProvider.class) +public @interface MethodSource { + + /** + * The names of factory methods within the test class or in external classes to use as sources for arguments. + *

+ * Factory methods in external classes must be referenced by fully qualified method name — for example, + * {@code com.example.StringsProviders#blankStrings}. + *

+ * If no factory method names are declared, a method within the test class that has the same name as the test method + * will be used as the factory method by default. + *

+ * For further information, see the {@linkplain MethodSource class-level Javadoc}. + */ + String[] value() default ""; + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTest.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTest.java new file mode 100644 index 000000000..92d3f90b0 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTest.java @@ -0,0 +1,145 @@ +/* + * Copyright 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.test.extension.parametrized; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import org.junit.jupiter.api.TestTemplate; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.extension.ExtensionContext; + +/** + * {@code @ParameterizedRedisTest} is used to signal that the annotated method is a parameterized test method + * within a potentially parametrized test class. + *

+ * Such methods must not be {@code private} or {@code static}. + *

Argument Providers and Sources

+ *

+ * Test classes defining {@code @ParameterizedRedisTest} methods must specify at least one + * {@link org.junit.jupiter.params.provider.ArgumentsProvider ArgumentsProvider} via + * {@link org.junit.jupiter.params.provider.ArgumentsSource @ArgumentsSource} or a corresponding composed annotation + * (e.g., {@code @ValueSource}, {@code @CsvSource}, etc.). The provider is responsible for providing a + * {@link java.util.stream.Stream Stream} of {@link org.junit.jupiter.params.provider.Arguments Arguments} that will be + * used to invoke the parameterized test method. + *

Method Parameter List

+ *

+ * A {@code @ParameterizedRedisTest} method may declare parameters that are resolved from the class-level + * {@link org.junit.jupiter.params.provider.ArgumentsSource}. Additional parameters that exceed the parameter index by + * the class argument source can be resolved by additional {@link org.junit.jupiter.api.extension.ParameterResolver + * ParameterResolvers} (e.g., {@code TestInfo}, {@code TestReporter}, etc). Specifically, a parameterized test method + * must declare formal parameters according to the following rules. + *

    + *
  1. Zero or more indexed arguments must be declared first.
  2. + *
  3. Zero or more aggregators must be declared next.
  4. + *
  5. Zero or more arguments supplied by other {@code ParameterResolver} implementations must be declared last.
  6. + *
+ *

+ * In this context, an indexed argument is an argument for a given index in the {@code Arguments} provided by + * an {@code ArgumentsProvider} that is passed as an argument to the parameterized method at the same index in the + * method's formal parameter list. An aggregator is any parameter of type + * {@link org.junit.jupiter.params.aggregator.ArgumentsAccessor ArgumentsAccessor} or any parameter annotated with + * {@link org.junit.jupiter.params.aggregator.AggregateWith @AggregateWith}. + *

+ *

Constructor Parameter List

+ *

+ * A class defining {@code @ParameterizedRedisTest} may declare a constructor accepting arguments. Constructor arguments + * are resolved from the same class-level {@link org.junit.jupiter.params.provider.ArgumentsSource} as method arguments. + * Therefore, constructor arguments follow the same index/aggregator semantics as method arguments. + *

Test Class Lifecycle

+ *

+ * Using parameterized tests requires instance creation per test method ({@code TestInstance(PER_METHOD)} to ensure that + * both, test method and test instance share the same arguments. This limitation is driven by the execution tree as test + * argument sources are activated per test method. See + * {@link org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider#provideTestTemplateInvocationContexts(ExtensionContext)}. + *

+ * Adaption of {@code org.junit.jupiter.params.ParameterizedTest}. + */ +@Target({ ElementType.ANNOTATION_TYPE, ElementType.METHOD }) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@TestTemplate +@ExtendWith(ParameterizedRedisTestExtension.class) +public @interface ParameterizedRedisTest { + + /** + * Placeholder for the {@linkplain org.junit.jupiter.api.TestInfo#getDisplayName display name} of a + * {@code @ParameterizedTest} method: {displayName} + * + * @see #name + */ + String DISPLAY_NAME_PLACEHOLDER = "{displayName}"; + + /** + * Placeholder for the current invocation index of a {@code @ParameterizedTest} method (1-based): {index} + * + * @see #name + */ + String INDEX_PLACEHOLDER = "{index}"; + + /** + * Placeholder for the complete, comma-separated arguments list of the current invocation of a + * {@code @ParameterizedTest} method: {arguments} + * + * @see #name + */ + String ARGUMENTS_PLACEHOLDER = "{arguments}"; + + /** + * Placeholder for the complete, comma-separated named arguments list of the current invocation of a + * {@code @ParameterizedTest} method: {argumentsWithNames} + * + * @see #name + */ + String ARGUMENTS_WITH_NAMES_PLACEHOLDER = "{argumentsWithNames}"; + + /** + * Default display name pattern for the current invocation of a {@code @ParameterizedTest} method: {@value} + *

+ * Note that the default pattern does not include the {@linkplain #DISPLAY_NAME_PLACEHOLDER display name} of + * the {@code @ParameterizedTest} method. + * + * @see #name + * @see #DISPLAY_NAME_PLACEHOLDER + * @see #INDEX_PLACEHOLDER + * @see #ARGUMENTS_WITH_NAMES_PLACEHOLDER + */ + String DEFAULT_DISPLAY_NAME = "[" + INDEX_PLACEHOLDER + "] " + ARGUMENTS_WITH_NAMES_PLACEHOLDER; + + /** + * The display name to be used for individual invocations of the parameterized test; never blank or consisting solely + * of whitespace. + *

+ * Defaults to {@link #DEFAULT_DISPLAY_NAME}. + *

Supported placeholders

+ *
    + *
  • {@link #DISPLAY_NAME_PLACEHOLDER}
  • + *
  • {@link #INDEX_PLACEHOLDER}
  • + *
  • {@link #ARGUMENTS_PLACEHOLDER}
  • + *
  • {0}, {1}, etc.: an individual argument (0-based)
  • + *
+ *

+ * For the latter, you may use {@link java.text.MessageFormat} patterns to customize formatting. Please note that the + * original arguments are passed when formatting, regardless of any implicit or explicit argument conversions. + * + * @see java.text.MessageFormat + */ + String name() default DEFAULT_DISPLAY_NAME; + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java new file mode 100644 index 000000000..c1af0f93c --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedRedisTestExtension.java @@ -0,0 +1,159 @@ +/* + * Copyright 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.test.extension.parametrized; + +import static org.junit.platform.commons.util.AnnotationUtils.*; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicLong; +import java.util.stream.Stream; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ExtensionContext.Namespace; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; +import org.junit.jupiter.api.extension.TestTemplateInvocationContextProvider; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.ArgumentsProvider; +import org.junit.jupiter.params.provider.ArgumentsSource; +import org.junit.jupiter.params.support.AnnotationConsumerInitializer; +import org.junit.platform.commons.JUnitException; +import org.junit.platform.commons.util.ExceptionUtils; +import org.junit.platform.commons.util.Preconditions; +import org.junit.platform.commons.util.ReflectionUtils; + +/** + * Copy of {@code org.junit.jupiter.params.ParameterizedTestExtension}. + */ +class ParameterizedRedisTestExtension implements TestTemplateInvocationContextProvider { + + private static final String METHOD_CONTEXT_KEY = "method-context"; + private static final String CONSTRUCTOR_CONTEXT_KEY = "constructor-context"; + static final String ARGUMENT_MAX_LENGTH_KEY = "junit.jupiter.params.displayname.argument.maxlength"; + + @Override + public boolean supportsTestTemplate(ExtensionContext context) { + if (!context.getTestMethod().isPresent()) { + return false; + } + + Method testMethod = context.getTestMethod().get(); + if (!isAnnotated(testMethod, ParameterizedRedisTest.class)) { + return false; + } + + Constructor declaredConstructor = ReflectionUtils.getDeclaredConstructor(context.getRequiredTestClass()); + ParameterizedTestContext methodContext = new ParameterizedTestContext(testMethod); + ParameterizedTestContext constructorContext = new ParameterizedTestContext(declaredConstructor); + + Preconditions.condition(methodContext.hasPotentiallyValidSignature(), + () -> String.format("@ParameterizedRedisTest method [%s] declares formal parameters in an invalid order: " + + "argument aggregators must be declared after any indexed arguments " + + "and before any arguments resolved by another ParameterResolver.", testMethod.toGenericString())); + + getStore(context).put(METHOD_CONTEXT_KEY, methodContext); + getStore(context).put(CONSTRUCTOR_CONTEXT_KEY, constructorContext); + + return true; + } + + @Override + public Stream provideTestTemplateInvocationContexts( + ExtensionContext extensionContext) { + + Method templateMethod = extensionContext.getRequiredTestMethod(); + String displayName = extensionContext.getDisplayName(); + ParameterizedTestContext methodContext = getStore(extensionContext)// + .get(METHOD_CONTEXT_KEY, ParameterizedTestContext.class); + + ParameterizedTestContext constructorContext = getStore(extensionContext)// + .get(CONSTRUCTOR_CONTEXT_KEY, ParameterizedTestContext.class); + int argumentMaxLength = extensionContext.getConfigurationParameter(ARGUMENT_MAX_LENGTH_KEY, Integer::parseInt) + .orElse(512); + ParameterizedTestNameFormatter formatter = createNameFormatter(templateMethod, methodContext, displayName, + argumentMaxLength); + AtomicLong invocationCount = new AtomicLong(0); + + List> hierarchy = new ArrayList<>(); + Class type = extensionContext.getRequiredTestClass(); + while (type != Object.class) { + hierarchy.add(type); + type = type.getSuperclass(); + } + + // @formatter:off + return hierarchy.stream().flatMap(it -> findRepeatableAnnotations(it, ArgumentsSource.class).stream() + .map(ArgumentsSource::value).map(this::instantiateArgumentsProvider) + .map(provider -> AnnotationConsumerInitializer.initialize(it, provider))) + .flatMap(provider -> arguments(provider, extensionContext)).map(Arguments::get) + .map(arguments -> consumedArguments(arguments, methodContext)) + .map(arguments -> createInvocationContext(formatter, constructorContext, methodContext, arguments)) + .peek(invocationContext -> invocationCount.incrementAndGet()) + .onClose(() -> Preconditions.condition(invocationCount.get() > 0, + "Configuration error: You must configure at least one set of arguments for this @ParameterizedRedisTest class")); + // @formatter:on + } + + @SuppressWarnings("ConstantConditions") + private ArgumentsProvider instantiateArgumentsProvider(Class clazz) { + try { + return ReflectionUtils.newInstance(clazz); + } catch (Exception ex) { + if (ex instanceof NoSuchMethodException) { + String message = String.format("Failed to find a no-argument constructor for ArgumentsProvider [%s]. " + + "Please ensure that a no-argument constructor exists and " + + "that the class is either a top-level class or a static nested class", clazz.getName()); + throw new JUnitException(message, ex); + } + throw ex; + } + } + + private ExtensionContext.Store getStore(ExtensionContext context) { + return context.getStore(Namespace.create(ParameterizedRedisTestExtension.class, context.getRequiredTestMethod())); + } + + private TestTemplateInvocationContext createInvocationContext(ParameterizedTestNameFormatter formatter, + ParameterizedTestContext constructorContext, ParameterizedTestContext methodContext, Object[] arguments) { + return new ParameterizedTestInvocationContext(formatter, constructorContext, methodContext, arguments); + } + + private ParameterizedTestNameFormatter createNameFormatter(Method templateMethod, + ParameterizedTestContext methodContext, String displayName, int argumentMaxLength) { + + ParameterizedRedisTest parameterizedTest = findAnnotation(templateMethod, ParameterizedRedisTest.class).get(); + String pattern = Preconditions.notBlank(parameterizedTest.name().trim(), + () -> String.format( + "Configuration error: @ParameterizedRedisTest on method [%s] must be declared with a non-empty name.", + templateMethod)); + return new ParameterizedTestNameFormatter(pattern, displayName, methodContext, argumentMaxLength); + } + + protected static Stream arguments(ArgumentsProvider provider, ExtensionContext context) { + try { + return provider.provideArguments(context); + } catch (Exception e) { + throw ExceptionUtils.throwAsUncheckedException(e); + } + } + + private Object[] consumedArguments(Object[] arguments, ParameterizedTestContext methodContext) { + return arguments; + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestContext.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestContext.java new file mode 100644 index 000000000..5b4a75881 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestContext.java @@ -0,0 +1,267 @@ +/* + * Copyright 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.test.extension.parametrized; + +import static org.junit.platform.commons.util.AnnotationUtils.*; +import static org.springframework.data.redis.test.extension.parametrized.ParameterizedTestContext.ResolverType.*; + +import java.lang.reflect.Executable; +import java.lang.reflect.Method; +import java.lang.reflect.Parameter; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import org.junit.jupiter.api.extension.ParameterContext; +import org.junit.jupiter.api.extension.ParameterResolutionException; +import org.junit.jupiter.params.aggregator.AggregateWith; +import org.junit.jupiter.params.aggregator.ArgumentsAccessor; +import org.junit.jupiter.params.aggregator.ArgumentsAggregator; +import org.junit.jupiter.params.aggregator.DefaultArgumentsAccessor; +import org.junit.jupiter.params.converter.ArgumentConverter; +import org.junit.jupiter.params.converter.ConvertWith; +import org.junit.jupiter.params.converter.DefaultArgumentConverter; +import org.junit.jupiter.params.support.AnnotationConsumerInitializer; +import org.junit.platform.commons.support.ReflectionSupport; +import org.junit.platform.commons.util.AnnotationUtils; +import org.junit.platform.commons.util.ReflectionUtils; +import org.junit.platform.commons.util.StringUtils; + +/** + * Encapsulates access to the parameters of a parameterized test method and caches the converters and aggregators used + * to resolve them. + *

+ * Copy of {@code org.junit.jupiter.params.ParameterizedTestContext}. + */ +class ParameterizedTestContext { + + private final Parameter[] parameters; + private final Resolver[] resolvers; + private final List resolverTypes; + + ParameterizedTestContext(Executable testMethod) { + this.parameters = testMethod.getParameters(); + this.resolvers = new Resolver[this.parameters.length]; + this.resolverTypes = new ArrayList<>(this.parameters.length); + for (Parameter parameter : this.parameters) { + this.resolverTypes.add(isAggregator(parameter) ? AGGREGATOR : CONVERTER); + } + } + + /** + * Determine if the supplied {@link Parameter} is an aggregator (i.e., of type {@link ArgumentsAccessor} or annotated + * with {@link AggregateWith}). + * + * @return {@code true} if the parameter is an aggregator + */ + private static boolean isAggregator(Parameter parameter) { + return ArgumentsAccessor.class.isAssignableFrom(parameter.getType()) || isAnnotated(parameter, AggregateWith.class); + } + + /** + * Determine if the {@link Method} represented by this context has a potentially valid signature (i.e., + * formal parameter declarations) with regard to aggregators. + *

+ * This method takes a best-effort approach at enforcing the following policy for parameterized test methods that + * accept aggregators as arguments. + *

    + *
  1. zero or more indexed arguments come first.
  2. + *
  3. zero or more aggregators come next.
  4. + *
  5. zero or more arguments supplied by other {@code ParameterResolver} implementations come last.
  6. + *
+ * + * @return {@code true} if the method has a potentially valid signature + */ + boolean hasPotentiallyValidSignature() { + int indexOfPreviousAggregator = -1; + for (int i = 0; i < getParameterCount(); i++) { + if (isAggregator(i)) { + if ((indexOfPreviousAggregator != -1) && (i != indexOfPreviousAggregator + 1)) { + return false; + } + indexOfPreviousAggregator = i; + } + } + return true; + } + + /** + * Get the number of parameters of the {@link Method} represented by this context. + */ + int getParameterCount() { + return parameters.length; + } + + /** + * Get the name of the {@link Parameter} with the supplied index, if it is present and declared before the + * aggregators. + * + * @return an {@code Optional} containing the name of the parameter + */ + Optional getParameterName(int parameterIndex) { + if (parameterIndex >= getParameterCount()) { + return Optional.empty(); + } + Parameter parameter = this.parameters[parameterIndex]; + if (!parameter.isNamePresent()) { + return Optional.empty(); + } + if (hasAggregator() && parameterIndex >= indexOfFirstAggregator()) { + return Optional.empty(); + } + return Optional.of(parameter.getName()); + } + + /** + * Determine if the {@link Method} represented by this context declares at least one {@link Parameter} that is an + * {@linkplain #isAggregator aggregator}. + * + * @return {@code true} if the method has an aggregator + */ + boolean hasAggregator() { + return resolverTypes.contains(AGGREGATOR); + } + + /** + * Determine if the {@link Parameter} with the supplied index is an aggregator (i.e., of type + * {@link ArgumentsAccessor} or annotated with {@link AggregateWith}). + * + * @return {@code true} if the parameter is an aggregator + */ + boolean isAggregator(int parameterIndex) { + return resolverTypes.size() > parameterIndex && resolverTypes.get(parameterIndex) == AGGREGATOR; + } + + /** + * Find the index of the first {@linkplain #isAggregator aggregator} {@link Parameter} in the {@link Method} + * represented by this context. + * + * @return the index of the first aggregator, or {@code -1} if not found + */ + int indexOfFirstAggregator() { + return resolverTypes.indexOf(AGGREGATOR); + } + + /** + * Resolve the parameter for the supplied context using the supplied arguments. + */ + Object resolve(ParameterContext parameterContext, Object[] arguments) { + return getResolver(parameterContext).resolve(parameterContext, arguments); + } + + private Resolver getResolver(ParameterContext parameterContext) { + int index = parameterContext.getIndex(); + if (resolvers[index] == null) { + resolvers[index] = resolverTypes.get(index).createResolver(parameterContext); + } + return resolvers[index]; + } + + enum ResolverType { + + CONVERTER { + @Override + Resolver createResolver(ParameterContext parameterContext) { + try { // @formatter:off + return AnnotationUtils.findAnnotation(parameterContext.getParameter(), ConvertWith.class) + .map(ConvertWith::value).map(clazz -> (ArgumentConverter) ReflectionUtils.newInstance(clazz)) + .map(converter -> AnnotationConsumerInitializer.initialize(parameterContext.getParameter(), converter)) + .map(Converter::new).orElse(Converter.DEFAULT); + } // @formatter:on + catch (Exception ex) { + throw parameterResolutionException("Error creating ArgumentConverter", ex, parameterContext); + } + } + }, + + AGGREGATOR { + @Override + Resolver createResolver(ParameterContext parameterContext) { + try { // @formatter:off + return AnnotationUtils.findAnnotation(parameterContext.getParameter(), AggregateWith.class) + .map(AggregateWith::value).map(clazz -> (ArgumentsAggregator) ReflectionSupport.newInstance(clazz)) + .map(Aggregator::new).orElse(Aggregator.DEFAULT); + } // @formatter:on + catch (Exception ex) { + throw parameterResolutionException("Error creating ArgumentsAggregator", ex, parameterContext); + } + } + }; + + abstract Resolver createResolver(ParameterContext parameterContext); + + } + + interface Resolver { + + Object resolve(ParameterContext parameterContext, Object[] arguments); + + } + + static class Converter implements Resolver { + + private static final Converter DEFAULT = new Converter(DefaultArgumentConverter.INSTANCE); + + private final ArgumentConverter argumentConverter; + + Converter(ArgumentConverter argumentConverter) { + this.argumentConverter = argumentConverter; + } + + @Override + public Object resolve(ParameterContext parameterContext, Object[] arguments) { + Object argument = arguments[parameterContext.getIndex()]; + try { + return this.argumentConverter.convert(argument, parameterContext); + } catch (Exception ex) { + throw parameterResolutionException("Error converting parameter", ex, parameterContext); + } + } + + } + + static class Aggregator implements Resolver { + + private static final Aggregator DEFAULT = new Aggregator((accessor, context) -> accessor); + + private final ArgumentsAggregator argumentsAggregator; + + Aggregator(ArgumentsAggregator argumentsAggregator) { + this.argumentsAggregator = argumentsAggregator; + } + + @Override + public Object resolve(ParameterContext parameterContext, Object[] arguments) { + ArgumentsAccessor accessor = new DefaultArgumentsAccessor(arguments); + try { + return this.argumentsAggregator.aggregateArguments(accessor, parameterContext); + } catch (Exception ex) { + throw parameterResolutionException("Error aggregating arguments for parameter", ex, parameterContext); + } + } + + } + + private static ParameterResolutionException parameterResolutionException(String message, Exception cause, + ParameterContext parameterContext) { + String fullMessage = message + " at index " + parameterContext.getIndex(); + if (StringUtils.isNotBlank(cause.getMessage())) { + fullMessage += ": " + cause.getMessage(); + } + return new ParameterResolutionException(fullMessage, cause); + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestInvocationContext.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestInvocationContext.java new file mode 100644 index 000000000..84ad85b6d --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestInvocationContext.java @@ -0,0 +1,53 @@ +/* + * Copyright 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.test.extension.parametrized; + +import java.util.Collections; +import java.util.List; + +import org.junit.jupiter.api.extension.Extension; +import org.junit.jupiter.api.extension.TestTemplateInvocationContext; + +/** + * Copy of {@code org.junit.jupiter.params.ParameterizedTestInvocationContext}. + */ +class ParameterizedTestInvocationContext implements TestTemplateInvocationContext { + + private final ParameterizedTestNameFormatter formatter; + private final ParameterizedTestContext constructorContext; + private final ParameterizedTestContext methodContext; + private final Object[] arguments; + + ParameterizedTestInvocationContext(ParameterizedTestNameFormatter formatter, + ParameterizedTestContext constructorContext, ParameterizedTestContext methodContext, Object[] arguments) { + this.formatter = formatter; + this.constructorContext = constructorContext; + this.methodContext = methodContext; + this.arguments = arguments; + } + + @Override + public String getDisplayName(int invocationIndex) { + return this.formatter.format(invocationIndex, this.arguments); + } + + @Override + public List getAdditionalExtensions() { + return Collections.singletonList( + new ParameterizedTestParameterResolver(this.constructorContext, this.methodContext, this.arguments)); + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestNameFormatter.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestNameFormatter.java new file mode 100644 index 000000000..03bdee891 --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestNameFormatter.java @@ -0,0 +1,115 @@ +/* + * Copyright 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.test.extension.parametrized; + +import static java.util.stream.Collectors.joining; +import static org.junit.jupiter.params.ParameterizedTest.ARGUMENTS_PLACEHOLDER; +import static org.junit.jupiter.params.ParameterizedTest.ARGUMENTS_WITH_NAMES_PLACEHOLDER; +import static org.junit.jupiter.params.ParameterizedTest.DISPLAY_NAME_PLACEHOLDER; +import static org.junit.jupiter.params.ParameterizedTest.INDEX_PLACEHOLDER; + +import java.text.Format; +import java.text.MessageFormat; +import java.util.Arrays; +import java.util.stream.IntStream; + +import org.junit.platform.commons.JUnitException; +import org.junit.platform.commons.util.StringUtils; + +/** + * Copy of {@code org.junit.jupiter.params.ParameterizedTestNameFormatter}. + */ +class ParameterizedTestNameFormatter { + + private static final char ELLIPSIS = '\u2026'; + + private final String pattern; + private final String displayName; + private final ParameterizedTestContext methodContext; + private final int argumentMaxLength; + + ParameterizedTestNameFormatter(String pattern, String displayName, ParameterizedTestContext methodContext, + int argumentMaxLength) { + this.pattern = pattern; + this.displayName = displayName; + this.methodContext = methodContext; + this.argumentMaxLength = argumentMaxLength; + } + + String format(int invocationIndex, Object... arguments) { + try { + return formatSafely(invocationIndex, arguments); + } catch (Exception ex) { + String message = "The display name pattern defined for the parameterized test is invalid. " + + "See nested exception for further details."; + throw new JUnitException(message, ex); + } + } + + private String formatSafely(int invocationIndex, Object[] arguments) { + String pattern = prepareMessageFormatPattern(invocationIndex, arguments); + MessageFormat format = new MessageFormat(pattern); + Object[] humanReadableArguments = makeReadable(format, arguments); + return format.format(humanReadableArguments); + } + + private String prepareMessageFormatPattern(int invocationIndex, Object[] arguments) { + String result = pattern// + .replace(DISPLAY_NAME_PLACEHOLDER, this.displayName)// + .replace(INDEX_PLACEHOLDER, String.valueOf(invocationIndex)); + + if (result.contains(ARGUMENTS_WITH_NAMES_PLACEHOLDER)) { + result = result.replace(ARGUMENTS_WITH_NAMES_PLACEHOLDER, argumentsWithNamesPattern(arguments)); + } + + if (result.contains(ARGUMENTS_PLACEHOLDER)) { + result = result.replace(ARGUMENTS_PLACEHOLDER, argumentsPattern(arguments)); + } + + return result; + } + + private String argumentsWithNamesPattern(Object[] arguments) { + return IntStream.range(0, arguments.length) // + .mapToObj(index -> methodContext.getParameterName(index).map(name -> name + "=").orElse("") + "{" + index + "}") // + .collect(joining(", ")); + } + + private String argumentsPattern(Object[] arguments) { + return IntStream.range(0, arguments.length) // + .mapToObj(index -> "{" + index + "}") // + .collect(joining(", ")); + } + + private Object[] makeReadable(MessageFormat format, Object[] arguments) { + Format[] formats = format.getFormatsByArgumentIndex(); + Object[] result = Arrays.copyOf(arguments, Math.min(arguments.length, formats.length), Object[].class); + for (int i = 0; i < result.length; i++) { + if (formats[i] == null) { + result[i] = truncateIfExceedsMaxLength(StringUtils.nullSafeToString(arguments[i])); + } + } + return result; + } + + private String truncateIfExceedsMaxLength(String argument) { + if (argument.length() > argumentMaxLength) { + return argument.substring(0, argumentMaxLength - 1) + ELLIPSIS; + } + return argument; + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestParameterResolver.java b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestParameterResolver.java new file mode 100644 index 000000000..61aeb549e --- /dev/null +++ b/src/test/java/org/springframework/data/redis/test/extension/parametrized/ParameterizedTestParameterResolver.java @@ -0,0 +1,89 @@ +/* + * Copyright 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.test.extension.parametrized; + +import java.lang.reflect.Constructor; +import java.lang.reflect.Executable; +import java.lang.reflect.Method; + +import org.junit.jupiter.api.extension.ExtensionContext; +import org.junit.jupiter.api.extension.ParameterContext; +import org.junit.jupiter.api.extension.ParameterResolutionException; +import org.junit.jupiter.api.extension.ParameterResolver; + +/** + * Copy of {@code org.junit.jupiter.params.ParameterizedTestParameterResolver}. + */ +class ParameterizedTestParameterResolver implements ParameterResolver { + + private final ParameterizedTestContext constructorContext; + private final ParameterizedTestContext methodContext; + private final Object[] arguments; + + ParameterizedTestParameterResolver(ParameterizedTestContext constructorContext, + ParameterizedTestContext methodContext, Object[] arguments) { + this.constructorContext = constructorContext; + this.methodContext = methodContext; + this.arguments = arguments; + } + + @Override + public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) { + + Executable declaringExecutable = parameterContext.getDeclaringExecutable(); + int parameterIndex = parameterContext.getIndex(); + ParameterizedTestContext testContext; + + if (declaringExecutable instanceof Constructor) { + testContext = this.constructorContext; + } else { + + Method testMethod = extensionContext.getTestMethod().orElse(null); + + // Not a parameterized method? + if (parameterContext.getDeclaringExecutable() instanceof Method && !declaringExecutable.equals(testMethod)) { + return false; + } + testContext = this.methodContext; + } + + // Current parameter is an aggregator? + if (testContext.isAggregator(parameterIndex)) { + return true; + } + + // Ensure that the current parameter is declared before aggregators. + // Otherwise, a different ParameterResolver should handle it. + if (testContext.hasAggregator()) { + return parameterIndex < testContext.indexOfFirstAggregator(); + } + + // Else fallback to behavior for parameterized test methods without aggregators. + return parameterIndex < this.arguments.length; + } + + @Override + public Object resolveParameter(ParameterContext parameterContext, ExtensionContext extensionContext) + throws ParameterResolutionException { + + if (parameterContext.getDeclaringExecutable() instanceof Constructor) { + return this.constructorContext.resolve(parameterContext, this.arguments); + } + + return this.methodContext.resolve(parameterContext, this.arguments); + } + +} diff --git a/src/test/java/org/springframework/data/redis/test/util/LettuceRedisClientProvider.java b/src/test/java/org/springframework/data/redis/test/util/LettuceRedisClientProvider.java deleted file mode 100644 index 666b1ec22..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/LettuceRedisClientProvider.java +++ /dev/null @@ -1,77 +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.test.util; - -import io.lettuce.core.ClientOptions; -import io.lettuce.core.RedisClient; -import io.lettuce.core.RedisURI; -import io.lettuce.core.protocol.ProtocolVersion; - -import org.junit.rules.ExternalResource; - -import org.springframework.data.redis.SettingsUtils; -import org.springframework.data.redis.test.extension.LettuceTestClientResources; - -/** - * @author Christoph Strobl - * @author Mark Paluch - */ -public class LettuceRedisClientProvider extends ExternalResource { - - String host = SettingsUtils.getHost(); - int port = SettingsUtils.getPort(); - - RedisClient client; - - @Override - protected void before() { - - try { - super.before(); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - - client = RedisClient.create(LettuceTestClientResources.getSharedClientResources(), - RedisURI.builder().withHost(host).withPort(port).build()); - client.setOptions( - ClientOptions.builder().protocolVersion(ProtocolVersion.RESP2).pingBeforeActivateConnection(false).build()); - } - - @Override - protected void after() { - super.after(); - client.shutdown(); - } - - public RedisClient getClient() { - if (client == null) { - before(); - } - return client; - } - - public void destroy() { - - if (client != null) { - after(); - } - } - - public static LettuceRedisClientProvider local() { - return new LettuceRedisClientProvider(); - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/LettuceRedisClusterClientProvider.java b/src/test/java/org/springframework/data/redis/test/util/LettuceRedisClusterClientProvider.java deleted file mode 100644 index b8f42b4f4..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/LettuceRedisClusterClientProvider.java +++ /dev/null @@ -1,91 +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.test.util; - -import io.lettuce.core.RedisURI; -import io.lettuce.core.cluster.ClusterClientOptions; -import io.lettuce.core.cluster.RedisClusterClient; -import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.protocol.ProtocolVersion; - -import org.junit.rules.ExternalResource; - -import org.springframework.data.redis.test.extension.LettuceTestClientResources; - -/** - * @author Christoph Strobl - * @author Mark Paluch - */ -public class LettuceRedisClusterClientProvider extends ExternalResource { - - String host = "127.0.0.1"; - int port = 7379; - - RedisClusterClient client; - - @Override - protected void before() { - - try { - super.before(); - } catch (Throwable throwable) { - throwable.printStackTrace(); - } - - client = RedisClusterClient.create(LettuceTestClientResources.getSharedClientResources(), - RedisURI.builder().withHost(host).withPort(port).build()); - client.setOptions(ClusterClientOptions.builder().protocolVersion(ProtocolVersion.RESP2) - .pingBeforeActivateConnection(false).build()); - } - - @Override - protected void after() { - - super.after(); - client.shutdown(); - } - - public RedisClusterClient getClient() { - - if (client == null) { - before(); - } - return client; - } - - public void destroy() { - - if (client != null) { - after(); - } - } - - public boolean test() { - - try { - StatefulRedisClusterConnection conn = getClient().connect(); - conn.close(); - } catch (Exception e) { - return false; - } - - return true; - } - - public static LettuceRedisClusterClientProvider local() { - return new LettuceRedisClusterClientProvider(); - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/MinimumRedisVersionRule.java b/src/test/java/org/springframework/data/redis/test/util/MinimumRedisVersionRule.java deleted file mode 100644 index 8f172b825..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/MinimumRedisVersionRule.java +++ /dev/null @@ -1,125 +0,0 @@ -/* - * Copyright 2014-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.test.util; - -import java.io.IOException; - -import org.junit.AssumptionViolatedException; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; -import org.springframework.data.redis.RedisVersionUtils; -import org.springframework.data.redis.SettingsUtils; -import org.springframework.data.redis.Version; -import org.springframework.data.redis.connection.jedis.JedisConverters; -import org.springframework.test.annotation.IfProfileValue; -import org.springframework.util.StringUtils; - -import redis.clients.jedis.Jedis; - -/** - * {@link MinimumRedisVersionRule} is a custom {@link TestRule} validating {@literal redisVersion} given in - * {@link IfProfileValue} against used redis server version. - * - * @author Christoph Strobl - * @since 1.4 - */ -public class MinimumRedisVersionRule implements TestRule { - - private static final String PROFILE_NAME = "redisVersion"; - private static final Version redisVersion; - - public MinimumRedisVersionRule() {} - - static { - redisVersion = readServerVersion(); - } - - private static synchronized Version readServerVersion() { - - Version version = Version.UNKNOWN; - - Jedis jedis = null; - try { - jedis = new Jedis(SettingsUtils.getHost(), SettingsUtils.getPort()); - String info = jedis.info(); - String versionString = (String) JedisConverters.stringToProps().convert(info).get("redis_version"); - - version = RedisVersionUtils.parseVersion(versionString); - } finally { - if (jedis != null) { - try { - - jedis.disconnect(); - if (jedis.getClient().getSocket().isConnected()) { - // force socket to be closed - jedis.getClient().getSocket().close(); - try { - // need to wait a bit - Thread.sleep(5); - } catch (InterruptedException e) { - Thread.interrupted(); - } - } - - } catch (IOException e1) { - // ignore as well - } - jedis.close(); - } - } - - return version; - } - - @Override - public Statement apply(final Statement base, Description description) { - - IfProfileValue profileValue = description.getAnnotation(IfProfileValue.class); - final String version = (profileValue != null && profileValue.name().equals(PROFILE_NAME)) ? profileValue.value() - : null; - - return new Statement() { - - @Override - public void evaluate() throws Throwable { - - verify(version); - base.evaluate(); - } - }; - } - - protected void verify(String version) throws Throwable { - - if (StringUtils.hasText(version)) { - - boolean sloppyMatch = version.endsWith("+"); - String cleanedVersionString = version.replace("+", ""); - Version expected = RedisVersionUtils.parseVersion(cleanedVersionString); - - if (sloppyMatch) { - if (redisVersion.compareTo(expected) < 0) { - throw new AssumptionViolatedException("Expected Redis version " + version + " but found " + redisVersion); - } - } else { - if (redisVersion.compareTo(expected) == 0) { - throw new AssumptionViolatedException("Expected Redis version " + version + " but found " + redisVersion); - } - } - } - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/RedisClientRule.java b/src/test/java/org/springframework/data/redis/test/util/RedisClientRule.java deleted file mode 100644 index ddd3b3efa..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/RedisClientRule.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2014-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.test.util; - -import org.junit.AssumptionViolatedException; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; -import org.springframework.data.redis.connection.RedisConnectionFactory; - -/** - * A JUnit {@link TestRule} that checks whether a given {@link RedisConnectionFactory} is from the required - * {@link RedisDriver}. - * - * @author Christoph Strobl - * @author Thomas Darimont - * @author Tugdual Grall - */ -public abstract class RedisClientRule implements TestRule { - - @Override - public Statement apply(final Statement base, final Description description) { - - return new Statement() { - - @Override - public void evaluate() throws Throwable { - - WithRedisDriver withRedisDriver = description.getAnnotation(WithRedisDriver.class); - RedisConnectionFactory redisConnectionFactory = getConnectionFactory(); - - if (withRedisDriver != null && redisConnectionFactory != null) { - - for (RedisDriver driver : withRedisDriver.value()) { - - if (driver.matches(redisConnectionFactory)) { - base.evaluate(); - return; - } - } - throw new AssumptionViolatedException("not a valid redis connection for driver: " + redisConnectionFactory); - } - - base.evaluate(); - } - }; - } - - public abstract RedisConnectionFactory getConnectionFactory(); -} diff --git a/src/test/java/org/springframework/data/redis/test/util/RedisClusterRule.java b/src/test/java/org/springframework/data/redis/test/util/RedisClusterRule.java deleted file mode 100644 index 7e47f1d4f..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/RedisClusterRule.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright 2015-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.test.util; - -import static org.assertj.core.api.Assumptions.*; - -import redis.clients.jedis.Jedis; - -import org.junit.rules.ExternalResource; -import org.junit.rules.TestRule; - -import org.springframework.data.redis.connection.RedisClusterConfiguration; -import org.springframework.data.redis.connection.RedisNode; -import org.springframework.data.redis.connection.jedis.JedisConverters; - -/** - * Simple {@link TestRule} implementation that check Redis is running in cluster mode. - * - * @author Christoph Strobl - * @author Mark Paluch - * @since 1.7 - */ -public class RedisClusterRule extends ExternalResource { - - private RedisClusterConfiguration clusterConfig; - private String mode; - - /** - * Create and init {@link RedisClusterRule} with default configuration ({@code host=127.0.0.1 port=7379}). - */ - public RedisClusterRule() { - this(new RedisClusterConfiguration().clusterNode("127.0.0.1", 7379)); - } - - /** - * Create and init {@link RedisClientRule} with given configuration. - * - * @param config - */ - public RedisClusterRule(RedisClusterConfiguration config) { - this.clusterConfig = config; - init(); - } - - /* - * (non-Javadoc) - * @see org.junit.rules.ExternalResource#before() - */ - @Override - public void before() { - assumeThat(mode).isEqualTo("cluster"); - } - - public RedisClusterConfiguration getConfiguration() { - return this.clusterConfig; - } - - /** - * @return {@literal true} if Redis Cluster is available. - */ - public boolean isAvailable() { - return "cluster".equals(mode); - } - - private void init() { - - if (clusterConfig == null) { - return; - } - - for (RedisNode node : clusterConfig.getClusterNodes()) { - - Jedis jedis = null; - try { - - jedis = new Jedis(node.getHost(), node.getPort()); - mode = JedisConverters.toProperties(jedis.info()).getProperty("redis_mode"); - return; - } catch (Exception e) { - // ignore and move on - } finally { - jedis.close(); - } - } - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/RedisSentinelRule.java b/src/test/java/org/springframework/data/redis/test/util/RedisSentinelRule.java deleted file mode 100644 index e359b74f8..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/RedisSentinelRule.java +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Copyright 2014-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.test.util; - -import redis.clients.jedis.Jedis; - -import java.util.HashMap; -import java.util.Map; - -import org.junit.AssumptionViolatedException; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; -import org.springframework.data.redis.connection.RedisNode; -import org.springframework.data.redis.connection.RedisSentinelConfiguration; - -/** - * @author Christoph Strobl - */ -public class RedisSentinelRule implements TestRule { - - public enum SentinelsAvailable { - ALL_ACTIVE, ONE_ACTIVE, NONE_ACTIVE - } - - private static final RedisSentinelConfiguration DEFAULT_SENTINEL_CONFIG = new RedisSentinelConfiguration() - .master("mymaster").sentinel("127.0.0.1", 26379).sentinel("127.0.0.1", 26380).sentinel("127.0.0.1", 26381); - - private RedisSentinelConfiguration sentinelConfig; - private SentinelsAvailable requiredSentinels; - - private Map cache = new HashMap<>(); - - protected RedisSentinelRule(RedisSentinelConfiguration config) { - this.sentinelConfig = config; - } - - /** - * Create new {@link RedisSentinelRule} for given {@link RedisSentinelConfiguration}. - * - * @param config - * @return - */ - public static RedisSentinelRule forConfig(RedisSentinelConfiguration config) { - return new RedisSentinelRule(config != null ? config : DEFAULT_SENTINEL_CONFIG); - } - - /** - * Create new {@link RedisSentinelRule} using default configuration. - * - * @return - */ - public static RedisSentinelRule withDefaultConfig() { - return new RedisSentinelRule(DEFAULT_SENTINEL_CONFIG); - } - - public RedisSentinelRule sentinelsDisabled() { - - this.requiredSentinels = SentinelsAvailable.NONE_ACTIVE; - return this; - } - - /** - * Verifies all {@literal Sentinel} nodes are available. - * - * @return - */ - public RedisSentinelRule allActive() { - - this.requiredSentinels = SentinelsAvailable.ALL_ACTIVE; - return this; - } - - /** - * Verifies at least one {@literal Sentinel} node is available. - * - * @return - */ - public RedisSentinelRule oneActive() { - - this.requiredSentinels = SentinelsAvailable.ONE_ACTIVE; - return this; - } - - /** - * Will only check {@link RedisSentinelConfiguration} configuration in case {@link RequiresRedisSentinel} is detected - * on test method. - * - * @return - */ - public RedisSentinelRule dynamicModeSelection() { - this.requiredSentinels = null; - return this; - } - - @Override - public Statement apply(final Statement base, final Description description) { - - return new Statement() { - - @Override - public void evaluate() throws Throwable { - - if (description.isTest()) { - RequiresRedisSentinel sentinels = description.getAnnotation(RequiresRedisSentinel.class); - if (RedisSentinelRule.this.requiredSentinels != null || sentinels != null) { - verify(sentinels != null ? sentinels.value() : RedisSentinelRule.this.requiredSentinels); - } - - } else { - verify(RedisSentinelRule.this.requiredSentinels); - } - - base.evaluate(); - } - }; - } - - private void verify(SentinelsAvailable verificationMode) { - - int failed = 0; - for (RedisNode node : sentinelConfig.getSentinels()) { - - if (cache.isEmpty() || !cache.containsKey(node.asString())) { - cache.put(node.asString(), isAvailable(node)); - } - - if (!cache.get(node.asString())) { - failed++; - } - } - - if (failed > 0) { - if (SentinelsAvailable.ALL_ACTIVE.equals(verificationMode)) { - throw new AssumptionViolatedException(String.format( - "Expected all Redis Sentinels to respone but %s of %s did not responde", failed, sentinelConfig - .getSentinels().size())); - } - - if (SentinelsAvailable.ONE_ACTIVE.equals(verificationMode) && sentinelConfig.getSentinels().size() - 1 < failed) { - throw new AssumptionViolatedException( - "Expected at least one sentinel to respond but it seems all are offline - Game Over!"); - } - } - - if (SentinelsAvailable.NONE_ACTIVE.equals(verificationMode) && failed != sentinelConfig.getSentinels().size()) { - throw new AssumptionViolatedException(String.format( - "Expected to have no sentinels online but found that %s are still alive.", (sentinelConfig.getSentinels() - .size() - failed))); - } - } - - private boolean isAvailable(RedisNode node) { - - Jedis jedis = null; - try { - - jedis = new Jedis(node.getHost(), node.getPort()); - jedis.ping(); - - return true; - } catch (Exception e) { - return false; - } finally { - - if (jedis != null) { - try { - - jedis.disconnect(); - if (jedis.getClient().getSocket().isConnected()) { - jedis.getClient().getSocket().close(); - Thread.sleep(5); - } - - jedis.close(); - } catch (Exception e) { - e.printStackTrace(); - } - } - } - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/RelaxedJUnit4ClassRunner.java b/src/test/java/org/springframework/data/redis/test/util/RelaxedJUnit4ClassRunner.java deleted file mode 100644 index 3f67d24a1..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/RelaxedJUnit4ClassRunner.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright 2014-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.test.util; - -import java.lang.reflect.AnnotatedElement; - -import org.junit.Ignore; -import org.junit.runners.model.FrameworkMethod; -import org.junit.runners.model.InitializationError; -import org.springframework.data.redis.Version; -import org.springframework.data.redis.VersionParser; -import org.springframework.test.annotation.IfProfileValue; -import org.springframework.test.annotation.ProfileValueSource; -import org.springframework.test.annotation.ProfileValueUtils; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.util.ObjectUtils; -import org.springframework.util.StringUtils; - -/** - * Extends the {@link SpringJUnit4ClassRunner} to accept {@code +} as wildcard for values tweaking comparison a litte so - * that tests marked {@code IfProfileValue(name="varName" value="2.6+"} will be executed in - * {@code 2.6, 2.6.1, 2.8, 3.0,... } environments. - * - * @author Christoph Strobl - */ -public class RelaxedJUnit4ClassRunner extends SpringJUnit4ClassRunner { - - public RelaxedJUnit4ClassRunner(Class clazz) throws InitializationError { - super(clazz); - } - - @Override - protected boolean isTestMethodIgnored(FrameworkMethod frameworkMethod) { - return isAnnotatedElementIgnored(frameworkMethod.getMethod()); - } - - private boolean isAnnotatedElementIgnored(AnnotatedElement annotatedElement) { - - if (annotatedElement.isAnnotationPresent(Ignore.class)) { - return true; - } - - IfProfileValue ifProfileValue = annotatedElement.getAnnotation(IfProfileValue.class); - if (ifProfileValue == null) { - return false; - } - - String environmentValue = extractEnvironmentValue(ifProfileValue); - return !isValidEnvironmentValue(environmentValue, ifProfileValue); - } - - private boolean isValidEnvironmentValue(String environmentValue, IfProfileValue ifProfileValue) { - - for (String value : extractProfileValues(ifProfileValue)) { - - if (value.endsWith("+")) { - - Version expected = VersionParser.parseVersion(value.replace("+", "")); - if (expected.compareTo(VersionParser.parseVersion(environmentValue)) <= 0) { - return true; - } - - } else { - if (ObjectUtils.nullSafeEquals(value, environmentValue)) { - return true; - } - } - } - return false; - } - - private String extractEnvironmentValue(IfProfileValue ifProfileValue) { - ProfileValueSource profileValueSource = ProfileValueUtils.retrieveProfileValueSource(getTestClass().getJavaClass()); - - String environmentValue = profileValueSource.get(ifProfileValue.name()); - return environmentValue; - } - - private String[] extractProfileValues(IfProfileValue ifProfileValue) { - String[] annotatedValues = ifProfileValue.values(); - - if (StringUtils.hasLength(ifProfileValue.value())) { - if (annotatedValues.length > 0) { - throw new IllegalArgumentException("Setting both the 'value' and 'values' attributes " - + "of @IfProfileValue is not allowed: choose one or the other."); - } - annotatedValues = new String[] { ifProfileValue.value() }; - } - return annotatedValues; - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/ServerAvailable.java b/src/test/java/org/springframework/data/redis/test/util/ServerAvailable.java deleted file mode 100644 index 460c7c90c..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/ServerAvailable.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * Copyright 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.test.util; - -import java.net.InetSocketAddress; -import java.net.Socket; - -import org.junit.AssumptionViolatedException; -import org.junit.rules.TestRule; -import org.junit.runner.Description; -import org.junit.runners.model.Statement; - -/** - * @author Christoph Strobl - */ -public class ServerAvailable implements TestRule { - - private final String host; - private final int port; - - ServerAvailable(String host, int port) { - - this.host = host; - this.port = port; - } - - public static ServerAvailable runningAtLocalhost() { - return runningAtLocalhost(6379); - } - - public static ServerAvailable runningAtLocalhost(int port) { - return runningAt("localhost", port); - } - - public static ServerAvailable runningAt(String host, int port) { - return new ServerAvailable(host, port); - } - - @Override - public Statement apply(Statement base, Description description) { - - return new Statement() { - - @Override - public void evaluate() throws Throwable { - - if (!isAvailable()) { - - throw new AssumptionViolatedException( - String.format("Redis Server (%s:%s) did not answer. Is it up and running?", host, port)); - } - - base.evaluate(); - } - }; - } - - public boolean isAvailable() { - - try (Socket socket = new Socket()) { - socket.connect(new InetSocketAddress(host, port), 100); - return true; - } catch (Exception e) { - return false; - } - - } -} diff --git a/src/test/java/org/springframework/data/redis/test/util/WithRedisDriver.java b/src/test/java/org/springframework/data/redis/test/util/WithRedisDriver.java deleted file mode 100644 index 45e01aca3..000000000 --- a/src/test/java/org/springframework/data/redis/test/util/WithRedisDriver.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2014-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.test.util; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * An annotation to declare the supported {@link RedisDriver} types. - * - * @author Thomas Darimont - */ -@Target(ElementType.METHOD) -@Retention(RetentionPolicy.RUNTIME) -public @interface WithRedisDriver { - - RedisDriver[] value() default {}; -}