From 0a977c94187027d7fac3dec8a3ea1eab06ca0b73 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Sat, 22 Sep 2018 19:05:33 -0400 Subject: [PATCH] Polishing #871 Align static final declarations, switch final static to static final. --- .../lettuce/core/PlainChannelInitializer.java | 2 +- src/main/java/io/lettuce/core/Range.java | 2 +- .../ClusterDistributionChannelWriter.java | 4 +- .../io/lettuce/core/dynamic/BatchTasks.java | 2 +- .../codec/AnnotationRedisCodecResolver.java | 6 +- .../core/dynamic/output/OutputRegistry.java | 2 +- .../internal/AbstractInvocationHandler.java | 2 +- .../internal/AsyncConnectionProvider.java | 2 +- .../lettuce/core/internal/DefaultMethods.java | 2 +- .../lettuce/core/output/ListSubscriber.java | 2 +- .../io/lettuce/core/protocol/Command.java | 6 +- .../lettuce/core/protocol/CommandWrapper.java | 4 +- .../io/lettuce/apigenerator/Constants.java | 6 +- ...=> ConnectionCommandIntegrationTests.java} | 6 +- .../core/PipeliningIntegrationTests.java | 8 ++ .../ReactiveConnectionIntegrationTests.java | 9 +- ...activeStreamingOutputIntegrationTests.java | 8 ++ .../core/RedisClientFactoryUnitTests.java | 4 +- .../core/ScanIteratorIntegrationTests.java | 10 +- ...t.java => ScanStreamIntegrationTests.java} | 12 +- ... => SyncAsyncApiConvergenceUnitTests.java} | 2 +- .../RedisClusterClientFactoryTests.java | 4 +- .../RedisClusterClientIntegrationTests.java | 14 +- ...erPasswordSecuredSslIntegrationTests.java} | 2 +- ...eactiveClusterClientIntegrationTests.java} | 8 +- .../cluster/ScanIteratorIntegrationTests.java | 7 + ...eactiveClusterClientIntegrationTests.java} | 7 +- ...CustomClusterCommandIntegrationTests.java} | 22 ++-- ...=> GeoClusterCommandIntegrationTests.java} | 48 +------ .../HashClusterCommandIntegrationTests.java | 33 +++++ .../commands/HashClusterCommandTest.java | 63 --------- ...=> KeyClusterCommandIntegrationTests.java} | 48 +++---- ...> ListClusterCommandIntegrationTests.java} | 44 ++----- ...StringClusterCommandIntegrationTests.java} | 44 ++----- ...lusterReactiveCommandIntegrationTests.java | 33 +++++ .../HashClusterReactiveCommandTest.java | 63 --------- .../KeyClusterReativeCommandTest.java | 62 --------- ...usterReactiveCommandIntegrationTests.java} | 44 ++----- ...usterReactiveCommandIntegrationTests.java} | 48 ++----- .../ClusterTopologyRefreshUnitTests.java | 2 +- ...t.java => BitCommandIntegrationTests.java} | 38 ++++-- ...ava => CustomCommandIntegrationTests.java} | 12 +- ...t.java => GeoCommandIntegrationTests.java} | 32 +++-- .../commands/HLLCommandIntegrationTests.java | 124 ++++++++++++++++++ .../lettuce/core/commands/HLLCommandTest.java | 105 --------------- ....java => HashCommandIntegrationTests.java} | 23 +++- ...t.java => KeyCommandIntegrationTests.java} | 23 +++- ....java => ListCommandIntegrationTests.java} | 30 ++++- ...va => NumericCommandIntegrationTests.java} | 26 +++- ... => ScriptingCommandIntegrationTests.java} | 28 +++- ...ava => ServerCommandIntegrationTests.java} | 35 +++-- ...t.java => SetCommandIntegrationTests.java} | 23 +++- ....java => SortCommandIntegrationTests.java} | 26 +++- ... => SortedSetCommandIntegrationTests.java} | 23 +++- ...ava => StreamCommandIntegrationTests.java} | 23 +++- ...ava => StringCommandIntegrationTests.java} | 25 +++- ...> TransactionCommandIntegrationTests.java} | 34 ++++- ...> BitReactiveCommandIntegrationTests.java} | 22 ++-- ...> GeoReactiveCommandIntegrationTests.java} | 19 ++- ...> HLLReactiveCommandIntegrationTests.java} | 14 +- ... HashReactiveCommandIntegrationTests.java} | 14 +- ...> KeyReactiveCommandIntegrationTests.java} | 14 +- .../ListReactiveCommandIntegrationTests.java | 33 +++++ ...umericReactiveCommandIntegrationTests.java | 33 +++++ .../reactive/NumericReactiveCommandTest.java | 31 ----- ...iptingReactiveCommandIntegrationTests.java | 34 +++++ .../ScriptingReactiveCommandTest.java | 31 ----- ...erverReactiveCommandIntegrationTests.java} | 23 ++-- ...> SetReactiveCommandIntegrationTests.java} | 14 +- .../reactive/SetReactiveCommandTest.java | 31 ----- .../SortReactiveCommandIntegrationTests.java | 33 +++++ .../reactive/SortReactiveCommandTest.java | 31 ----- ...tedSetReactiveCommandIntegrationTests.java | 33 +++++ .../SortedSetReactiveCommandTest.java | 31 ----- ...treamReactiveCommandIntegrationTests.java} | 14 +- ...tringReactiveCommandIntegrationTests.java} | 38 +++--- ...ctionReactiveCommandIntegrationTests.java} | 49 +++---- .../BitTxCommandIntegrationTests.java | 33 +++++ .../transactional/BitTxCommandTest.java | 32 ----- ...java => GeoTxCommandIntegrationTests.java} | 14 +- ...java => HLLTxCommandIntegrationTests.java} | 15 ++- ...ava => HashTxCommandIntegrationTests.java} | 14 +- ...java => KeyTxCommandIntegrationTests.java} | 14 +- ...ava => ListTxCommandIntegrationTests.java} | 14 +- ...java => SetTxCommandIntegrationTests.java} | 14 +- .../SortTxCommandIntegrationTests.java | 32 +++++ .../transactional/SortTxCommandTest.java | 30 ----- .../SortedSetTxCommandIntegrationTests.java | 32 +++++ .../transactional/SortedSetTxCommandTest.java | 30 ----- .../StringTxCommandIntegrationTests.java | 32 +++++ .../transactional/StringTxCommandTest.java | 30 ----- ...RedisCommandsBatchingIntegrationTests.java | 6 + ...ctionEventsTriggeredIntegrationTests.java} | 2 +- ...ava => CustomCommandIntegrationTests.java} | 4 +- ...=> ConnectionFailureIntegrationTests.java} | 21 ++- ...java => BraveTracingIntegrationTests.java} | 12 +- .../java/io/lettuce/test/KeysAndValues.java | 2 +- .../io/lettuce/test/LettuceExtension.java | 80 +++++++---- src/test/java/io/lettuce/test/Wait.java | 2 +- .../test/condition/EnabledOnCommand.java | 1 + .../test/resource/DefaultRedisClient.java | 2 +- .../resource/DefaultRedisClusterClient.java | 2 +- .../test/resource/TestClientResources.java | 2 +- .../partitions/RedisClusterNodeBenchmark.java | 6 +- .../lettuce/core/protocol/EmptyChannel.java | 2 +- .../lettuce/core/protocol/EmptyContext.java | 2 +- 106 files changed, 1251 insertions(+), 1100 deletions(-) rename src/test/java/io/lettuce/core/{ConnectionCommandTest.java => ConnectionCommandIntegrationTests.java} (95%) rename src/test/java/io/lettuce/core/{ScanStreamTest.java => ScanStreamIntegrationTests.java} (91%) rename src/test/java/io/lettuce/core/{SyncAsyncApiConvergenceTest.java => SyncAsyncApiConvergenceUnitTests.java} (98%) rename src/test/java/io/lettuce/core/cluster/{RedisClusterPasswordSecuredSslTest.java => RedisClusterPasswordSecuredSslIntegrationTests.java} (98%) rename src/test/java/io/lettuce/core/cluster/{RedisReactiveClusterClientTest.java => RedisReactiveClusterClientIntegrationTests.java} (94%) rename src/test/java/io/lettuce/core/cluster/{SingleThreadedReactiveClusterClientTest.java => SingleThreadedReactiveClusterClientIntegrationTests.java} (92%) rename src/test/java/io/lettuce/core/cluster/commands/{CustomClusterCommandTest.java => CustomClusterCommandIntegrationTests.java} (85%) rename src/test/java/io/lettuce/core/cluster/commands/{GeoClusterCommandTest.java => GeoClusterCommandIntegrationTests.java} (51%) create mode 100644 src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandTest.java rename src/test/java/io/lettuce/core/cluster/commands/{KeyClusterCommandTest.java => KeyClusterCommandIntegrationTests.java} (64%) rename src/test/java/io/lettuce/core/cluster/commands/{ListClusterCommandTest.java => ListClusterCommandIntegrationTests.java} (62%) rename src/test/java/io/lettuce/core/cluster/commands/{StringClusterCommandTest.java => StringClusterCommandIntegrationTests.java} (56%) create mode 100644 src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandTest.java delete mode 100644 src/test/java/io/lettuce/core/cluster/commands/reactive/KeyClusterReativeCommandTest.java rename src/test/java/io/lettuce/core/cluster/commands/reactive/{ListClusterReactiveCommandTest.java => ListClusterReactiveCommandIntegrationTests.java} (62%) rename src/test/java/io/lettuce/core/cluster/commands/reactive/{StringClusterReactiveCommandTest.java => StringClusterReactiveCommandIntegrationTests.java} (57%) rename src/test/java/io/lettuce/core/commands/{BitCommandTest.java => BitCommandIntegrationTests.java} (89%) rename src/test/java/io/lettuce/core/commands/{CustomCommandTest.java => CustomCommandIntegrationTests.java} (94%) rename src/test/java/io/lettuce/core/commands/{GeoCommandTest.java => GeoCommandIntegrationTests.java} (96%) create mode 100644 src/test/java/io/lettuce/core/commands/HLLCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/HLLCommandTest.java rename src/test/java/io/lettuce/core/commands/{HashCommandTest.java => HashCommandIntegrationTests.java} (94%) rename src/test/java/io/lettuce/core/commands/{KeyCommandTest.java => KeyCommandIntegrationTests.java} (95%) rename src/test/java/io/lettuce/core/commands/{ListCommandTest.java => ListCommandIntegrationTests.java} (91%) rename src/test/java/io/lettuce/core/commands/{NumericCommandTest.java => NumericCommandIntegrationTests.java} (70%) rename src/test/java/io/lettuce/core/commands/{ScriptingCommandTest.java => ScriptingCommandIntegrationTests.java} (86%) rename src/test/java/io/lettuce/core/commands/{ServerCommandTest.java => ServerCommandIntegrationTests.java} (93%) rename src/test/java/io/lettuce/core/commands/{SetCommandTest.java => SetCommandIntegrationTests.java} (94%) rename src/test/java/io/lettuce/core/commands/{SortCommandTest.java => SortCommandIntegrationTests.java} (80%) rename src/test/java/io/lettuce/core/commands/{SortedSetCommandTest.java => SortedSetCommandIntegrationTests.java} (98%) rename src/test/java/io/lettuce/core/commands/{StreamCommandTest.java => StreamCommandIntegrationTests.java} (95%) rename src/test/java/io/lettuce/core/commands/{StringCommandTest.java => StringCommandIntegrationTests.java} (90%) rename src/test/java/io/lettuce/core/commands/{TransactionCommandTest.java => TransactionCommandIntegrationTests.java} (77%) rename src/test/java/io/lettuce/core/commands/reactive/{BitReactiveCommandTest.java => BitReactiveCommandIntegrationTests.java} (86%) rename src/test/java/io/lettuce/core/commands/reactive/{GeoReactiveCommandTest.java => GeoReactiveCommandIntegrationTests.java} (74%) rename src/test/java/io/lettuce/core/commands/reactive/{KeyReactiveCommandTest.java => HLLReactiveCommandIntegrationTests.java} (66%) rename src/test/java/io/lettuce/core/commands/reactive/{ListReactiveCommandTest.java => HashReactiveCommandIntegrationTests.java} (66%) rename src/test/java/io/lettuce/core/commands/reactive/{HashReactiveCommandTest.java => KeyReactiveCommandIntegrationTests.java} (66%) create mode 100644 src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandIntegrationTests.java create mode 100644 src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandTest.java create mode 100644 src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandTest.java rename src/test/java/io/lettuce/core/commands/reactive/{ServerReactiveCommandTest.java => ServerReactiveCommandIntegrationTests.java} (78%) rename src/test/java/io/lettuce/core/commands/reactive/{HLLReactiveCommandTest.java => SetReactiveCommandIntegrationTests.java} (66%) delete mode 100644 src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandTest.java create mode 100644 src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandTest.java create mode 100644 src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandTest.java rename src/test/java/io/lettuce/core/commands/reactive/{StreamReactiveCommandTest.java => StreamReactiveCommandIntegrationTests.java} (65%) rename src/test/java/io/lettuce/core/commands/reactive/{StringReactiveCommandTest.java => StringReactiveCommandIntegrationTests.java} (58%) rename src/test/java/io/lettuce/core/commands/reactive/{TransactionReactiveCommandTest.java => TransactionReactiveCommandIntegrationTests.java} (81%) create mode 100644 src/test/java/io/lettuce/core/commands/transactional/BitTxCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/transactional/BitTxCommandTest.java rename src/test/java/io/lettuce/core/commands/transactional/{GeoTxCommandTest.java => GeoTxCommandIntegrationTests.java} (79%) rename src/test/java/io/lettuce/core/commands/transactional/{SetTxCommandTest.java => HLLTxCommandIntegrationTests.java} (65%) rename src/test/java/io/lettuce/core/commands/transactional/{HLLTxCommandTest.java => HashTxCommandIntegrationTests.java} (65%) rename src/test/java/io/lettuce/core/commands/transactional/{KeyTxCommandTest.java => KeyTxCommandIntegrationTests.java} (68%) rename src/test/java/io/lettuce/core/commands/transactional/{HashTxCommandTest.java => ListTxCommandIntegrationTests.java} (65%) rename src/test/java/io/lettuce/core/commands/transactional/{ListTxCommandTest.java => SetTxCommandIntegrationTests.java} (65%) create mode 100644 src/test/java/io/lettuce/core/commands/transactional/SortTxCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/transactional/SortTxCommandTest.java create mode 100644 src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandTest.java create mode 100644 src/test/java/io/lettuce/core/commands/transactional/StringTxCommandIntegrationTests.java delete mode 100644 src/test/java/io/lettuce/core/commands/transactional/StringTxCommandTest.java rename src/test/java/io/lettuce/core/event/{ConnectionEventsTriggeredTest.java => ConnectionEventsTriggeredIntegrationTests.java} (96%) rename src/test/java/io/lettuce/core/masterslave/{CustomCommandTest.java => CustomCommandIntegrationTests.java} (98%) rename src/test/java/io/lettuce/core/protocol/{ConnectionFailureTest.java => ConnectionFailureIntegrationTests.java} (94%) rename src/test/java/io/lettuce/core/tracing/{BraveTracingTest.java => BraveTracingIntegrationTests.java} (93%) diff --git a/src/main/java/io/lettuce/core/PlainChannelInitializer.java b/src/main/java/io/lettuce/core/PlainChannelInitializer.java index f27786b0f9..a1e42cd885 100644 --- a/src/main/java/io/lettuce/core/PlainChannelInitializer.java +++ b/src/main/java/io/lettuce/core/PlainChannelInitializer.java @@ -40,7 +40,7 @@ */ class PlainChannelInitializer extends io.netty.channel.ChannelInitializer implements RedisChannelInitializer { - final static Supplier> NO_PING = () -> null; + static final Supplier> NO_PING = () -> null; private final Supplier> handlers; private final Supplier> pingCommandSupplier; diff --git a/src/main/java/io/lettuce/core/Range.java b/src/main/java/io/lettuce/core/Range.java index 991545f522..9631a3a5ff 100644 --- a/src/main/java/io/lettuce/core/Range.java +++ b/src/main/java/io/lettuce/core/Range.java @@ -168,7 +168,7 @@ public String toString() { */ public static class Boundary { - private final static Boundary UNBOUNDED = new Boundary<>(null, true); + private static final Boundary UNBOUNDED = new Boundary<>(null, true); private final T value; private final boolean including; diff --git a/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java b/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java index 4fcc52e14c..b43fcbd9bf 100644 --- a/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java +++ b/src/main/java/io/lettuce/core/cluster/ClusterDistributionChannelWriter.java @@ -428,8 +428,8 @@ static class SlotIntent { final int slotHash; final Intent intent; - private final static SlotIntent[] READ; - private final static SlotIntent[] WRITE; + private static final SlotIntent[] READ; + private static final SlotIntent[] WRITE; static { READ = new SlotIntent[SlotHash.SLOT_COUNT]; diff --git a/src/main/java/io/lettuce/core/dynamic/BatchTasks.java b/src/main/java/io/lettuce/core/dynamic/BatchTasks.java index d1ef6cc91e..599b51bcc8 100644 --- a/src/main/java/io/lettuce/core/dynamic/BatchTasks.java +++ b/src/main/java/io/lettuce/core/dynamic/BatchTasks.java @@ -29,7 +29,7 @@ */ class BatchTasks implements Iterable> { - public final static BatchTasks EMPTY = new BatchTasks(Collections.emptyList()); + public static final BatchTasks EMPTY = new BatchTasks(Collections.emptyList()); private final List> futures; diff --git a/src/main/java/io/lettuce/core/dynamic/codec/AnnotationRedisCodecResolver.java b/src/main/java/io/lettuce/core/dynamic/codec/AnnotationRedisCodecResolver.java index 6c841d8356..c63775e0e4 100644 --- a/src/main/java/io/lettuce/core/dynamic/codec/AnnotationRedisCodecResolver.java +++ b/src/main/java/io/lettuce/core/dynamic/codec/AnnotationRedisCodecResolver.java @@ -226,9 +226,9 @@ public int compareTo(Voted o) { */ protected static class ParameterWrappers { - private final static Set> WRAPPERS = new HashSet<>(); - private final static Set> WITH_KEY_TYPE = new HashSet<>(); - private final static Set> WITH_VALUE_TYPE = new HashSet<>(); + private static final Set> WRAPPERS = new HashSet<>(); + private static final Set> WITH_KEY_TYPE = new HashSet<>(); + private static final Set> WITH_VALUE_TYPE = new HashSet<>(); static { diff --git a/src/main/java/io/lettuce/core/dynamic/output/OutputRegistry.java b/src/main/java/io/lettuce/core/dynamic/output/OutputRegistry.java index ebd08751cc..bcc7e92f0e 100644 --- a/src/main/java/io/lettuce/core/dynamic/output/OutputRegistry.java +++ b/src/main/java/io/lettuce/core/dynamic/output/OutputRegistry.java @@ -38,7 +38,7 @@ @SuppressWarnings("rawtypes") public class OutputRegistry { - private final static Map BUILTIN = new LinkedHashMap<>(); + private static final Map BUILTIN = new LinkedHashMap<>(); private final Map registry = new LinkedHashMap<>(); static { diff --git a/src/main/java/io/lettuce/core/internal/AbstractInvocationHandler.java b/src/main/java/io/lettuce/core/internal/AbstractInvocationHandler.java index bebad6844e..bf5fd2ec21 100644 --- a/src/main/java/io/lettuce/core/internal/AbstractInvocationHandler.java +++ b/src/main/java/io/lettuce/core/internal/AbstractInvocationHandler.java @@ -155,7 +155,7 @@ private static boolean isProxyOfSameInterfaces(Object arg, Class proxyClass) protected static class MethodTranslator { - private final static WeakHashMap, MethodTranslator> TRANSLATOR_MAP = new WeakHashMap<>(32); + private static final WeakHashMap, MethodTranslator> TRANSLATOR_MAP = new WeakHashMap<>(32); private final Map map; private MethodTranslator(Class delegate, Class... methodSources) { diff --git a/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java b/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java index d3790469ec..f2db9ebc0d 100644 --- a/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java +++ b/src/main/java/io/lettuce/core/internal/AsyncConnectionProvider.java @@ -207,7 +207,7 @@ static class Sync> { private static final int PHASE_CANCELED = 3; @SuppressWarnings({ "rawtypes", "unchecked" }) - private final static AtomicIntegerFieldUpdater PHASE = AtomicIntegerFieldUpdater.newUpdater(Sync.class, "phase"); + private static final AtomicIntegerFieldUpdater PHASE = AtomicIntegerFieldUpdater.newUpdater(Sync.class, "phase"); // Updated with AtomicIntegerFieldUpdater @SuppressWarnings("unused") diff --git a/src/main/java/io/lettuce/core/internal/DefaultMethods.java b/src/main/java/io/lettuce/core/internal/DefaultMethods.java index 1b4b3ed694..197ea5475b 100644 --- a/src/main/java/io/lettuce/core/internal/DefaultMethods.java +++ b/src/main/java/io/lettuce/core/internal/DefaultMethods.java @@ -33,7 +33,7 @@ */ public class DefaultMethods { - private final static MethodHandleLookup methodHandleLookup = MethodHandleLookup.getMethodHandleLookup(); + private static final MethodHandleLookup methodHandleLookup = MethodHandleLookup.getMethodHandleLookup(); /** * Lookup a {@link MethodHandle} for a default {@link Method}. diff --git a/src/main/java/io/lettuce/core/output/ListSubscriber.java b/src/main/java/io/lettuce/core/output/ListSubscriber.java index dd9ba689a5..f75b62df1e 100644 --- a/src/main/java/io/lettuce/core/output/ListSubscriber.java +++ b/src/main/java/io/lettuce/core/output/ListSubscriber.java @@ -27,7 +27,7 @@ */ class ListSubscriber extends Subscriber { - private final static ListSubscriber INSTANCE = new ListSubscriber<>(); + private static final ListSubscriber INSTANCE = new ListSubscriber<>(); private ListSubscriber() { } diff --git a/src/main/java/io/lettuce/core/protocol/Command.java b/src/main/java/io/lettuce/core/protocol/Command.java index 37de0909f5..bafa846b38 100644 --- a/src/main/java/io/lettuce/core/protocol/Command.java +++ b/src/main/java/io/lettuce/core/protocol/Command.java @@ -32,9 +32,9 @@ */ public class Command implements RedisCommand { - protected final static byte ST_INITIAL = 0; - protected final static byte ST_COMPLETED = 1; - protected final static byte ST_CANCELLED = 2; + protected static final byte ST_INITIAL = 0; + protected static final byte ST_COMPLETED = 1; + protected static final byte ST_CANCELLED = 2; private final ProtocolKeyword type; diff --git a/src/main/java/io/lettuce/core/protocol/CommandWrapper.java b/src/main/java/io/lettuce/core/protocol/CommandWrapper.java index c821b69e79..a813dc27db 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandWrapper.java +++ b/src/main/java/io/lettuce/core/protocol/CommandWrapper.java @@ -31,11 +31,11 @@ public class CommandWrapper implements RedisCommand, CompleteableCommand, DecoratedCommand { @SuppressWarnings({ "rawtypes", "unchecked" }) - private final static AtomicReferenceFieldUpdater ONCOMPLETE = AtomicReferenceFieldUpdater + private static final AtomicReferenceFieldUpdater ONCOMPLETE = AtomicReferenceFieldUpdater .newUpdater(CommandWrapper.class, Object[].class, "onComplete"); @SuppressWarnings({ "rawtypes", "unchecked" }) - private final static Object[] EMPTY = new Object[0]; + private static final Object[] EMPTY = new Object[0]; protected final RedisCommand command; diff --git a/src/test/java/io/lettuce/apigenerator/Constants.java b/src/test/java/io/lettuce/apigenerator/Constants.java index 9dbe29d9fb..4ddf288851 100644 --- a/src/test/java/io/lettuce/apigenerator/Constants.java +++ b/src/test/java/io/lettuce/apigenerator/Constants.java @@ -22,11 +22,11 @@ */ class Constants { - public final static String[] TEMPLATE_NAMES = { "BaseRedisCommands", "RedisGeoCommands", "RedisHashCommands", + public static final String[] TEMPLATE_NAMES = { "BaseRedisCommands", "RedisGeoCommands", "RedisHashCommands", "RedisHLLCommands", "RedisKeyCommands", "RedisListCommands", "RedisScriptingCommands", "RedisSentinelCommands", "RedisServerCommands", "RedisSetCommands", "RedisSortedSetCommands", "RedisStreamCommands", "RedisStringCommands", "RedisTransactionalCommands" }; - public final static File TEMPLATES = new File("src/main/templates"); - public final static File SOURCES = new File("src/main/java"); + public static final File TEMPLATES = new File("src/main/templates"); + public static final File SOURCES = new File("src/main/java"); } diff --git a/src/test/java/io/lettuce/core/ConnectionCommandTest.java b/src/test/java/io/lettuce/core/ConnectionCommandIntegrationTests.java similarity index 95% rename from src/test/java/io/lettuce/core/ConnectionCommandTest.java rename to src/test/java/io/lettuce/core/ConnectionCommandIntegrationTests.java index e20d5f2b9f..3e94cd0ae8 100644 --- a/src/test/java/io/lettuce/core/ConnectionCommandTest.java +++ b/src/test/java/io/lettuce/core/ConnectionCommandIntegrationTests.java @@ -40,16 +40,14 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) -class ConnectionCommandTest extends TestSupport { +class ConnectionCommandIntegrationTests extends TestSupport { private final RedisClient client; - private final StatefulRedisConnection connection; private final RedisCommands redis; @Inject - ConnectionCommandTest(RedisClient client, StatefulRedisConnection connection) { + ConnectionCommandIntegrationTests(RedisClient client, StatefulRedisConnection connection) { this.client = client; - this.connection = connection; this.redis = connection.sync(); } diff --git a/src/test/java/io/lettuce/core/PipeliningIntegrationTests.java b/src/test/java/io/lettuce/core/PipeliningIntegrationTests.java index 8977bb4ce4..8b61e88bba 100644 --- a/src/test/java/io/lettuce/core/PipeliningIntegrationTests.java +++ b/src/test/java/io/lettuce/core/PipeliningIntegrationTests.java @@ -23,7 +23,9 @@ import javax.inject.Inject; +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 io.lettuce.core.api.StatefulRedisConnection; @@ -35,6 +37,7 @@ */ @SuppressWarnings("rawtypes") @ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class PipeliningIntegrationTests extends TestSupport { private final RedisClient client; @@ -46,6 +49,11 @@ class PipeliningIntegrationTests extends TestSupport { this.connection = connection; } + @BeforeEach + void setUp() { + this.connection.async().flushall(); + } + @Test void basic() { diff --git a/src/test/java/io/lettuce/core/ReactiveConnectionIntegrationTests.java b/src/test/java/io/lettuce/core/ReactiveConnectionIntegrationTests.java index e360112bd0..9887df8a03 100644 --- a/src/test/java/io/lettuce/core/ReactiveConnectionIntegrationTests.java +++ b/src/test/java/io/lettuce/core/ReactiveConnectionIntegrationTests.java @@ -27,7 +27,9 @@ import javax.enterprise.inject.New; import javax.inject.Inject; +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.reactivestreams.Subscriber; import org.reactivestreams.Subscription; @@ -43,6 +45,7 @@ import io.lettuce.test.Wait; @ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class ReactiveConnectionIntegrationTests extends TestSupport { private final StatefulRedisConnection connection; @@ -54,7 +57,11 @@ class ReactiveConnectionIntegrationTests extends TestSupport { this.connection = connection; this.redis = connection.sync(); this.reactive = connection.reactive(); - this.redis.flushall(); + } + + @BeforeEach + void setUp() { + this.connection.async().flushall(); } @Test diff --git a/src/test/java/io/lettuce/core/ReactiveStreamingOutputIntegrationTests.java b/src/test/java/io/lettuce/core/ReactiveStreamingOutputIntegrationTests.java index 18d5abd2cb..80a9fad5e6 100644 --- a/src/test/java/io/lettuce/core/ReactiveStreamingOutputIntegrationTests.java +++ b/src/test/java/io/lettuce/core/ReactiveStreamingOutputIntegrationTests.java @@ -22,7 +22,9 @@ import javax.inject.Inject; +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 reactor.test.StepVerifier; @@ -38,6 +40,7 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class ReactiveStreamingOutputIntegrationTests extends TestSupport { private final RedisCommands redis; @@ -49,6 +52,11 @@ class ReactiveStreamingOutputIntegrationTests extends TestSupport { this.reactive = connection.reactive(); } + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void keyListCommandShouldReturnAllElements() { diff --git a/src/test/java/io/lettuce/core/RedisClientFactoryUnitTests.java b/src/test/java/io/lettuce/core/RedisClientFactoryUnitTests.java index b0d5a8ddc1..df88f4ab02 100644 --- a/src/test/java/io/lettuce/core/RedisClientFactoryUnitTests.java +++ b/src/test/java/io/lettuce/core/RedisClientFactoryUnitTests.java @@ -29,8 +29,8 @@ */ class RedisClientFactoryUnitTests { - private final static String URI = "redis://" + TestSettings.host() + ":" + TestSettings.port(); - private final static RedisURI REDIS_URI = RedisURI.create(URI); + private static final String URI = "redis://" + TestSettings.host() + ":" + TestSettings.port(); + private static final RedisURI REDIS_URI = RedisURI.create(URI); @Test void plain() { diff --git a/src/test/java/io/lettuce/core/ScanIteratorIntegrationTests.java b/src/test/java/io/lettuce/core/ScanIteratorIntegrationTests.java index 1e0834c03e..2df78e0573 100644 --- a/src/test/java/io/lettuce/core/ScanIteratorIntegrationTests.java +++ b/src/test/java/io/lettuce/core/ScanIteratorIntegrationTests.java @@ -25,7 +25,9 @@ import javax.inject.Inject; +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 io.lettuce.core.api.StatefulRedisConnection; @@ -37,17 +39,21 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class ScanIteratorIntegrationTests extends TestSupport { - private final StatefulRedisConnection connection; private final RedisCommands redis; @Inject ScanIteratorIntegrationTests(StatefulRedisConnection connection) { - this.connection = connection; this.redis = connection.sync(); } + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void scanShouldThrowNoSuchElementExceptionOnEmpty() { diff --git a/src/test/java/io/lettuce/core/ScanStreamTest.java b/src/test/java/io/lettuce/core/ScanStreamIntegrationTests.java similarity index 91% rename from src/test/java/io/lettuce/core/ScanStreamTest.java rename to src/test/java/io/lettuce/core/ScanStreamIntegrationTests.java index cdf9ac5053..36f15c5ae5 100644 --- a/src/test/java/io/lettuce/core/ScanStreamTest.java +++ b/src/test/java/io/lettuce/core/ScanStreamIntegrationTests.java @@ -20,7 +20,9 @@ import javax.inject.Inject; +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 reactor.core.publisher.Flux; @@ -34,17 +36,23 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) -class ScanStreamTest extends TestSupport { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class ScanStreamIntegrationTests extends TestSupport { private final StatefulRedisConnection connection; private final RedisCommands redis; @Inject - ScanStreamTest(StatefulRedisConnection connection) { + ScanStreamIntegrationTests(StatefulRedisConnection connection) { this.connection = connection; this.redis = connection.sync(); } + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void shouldScanIteratively() { diff --git a/src/test/java/io/lettuce/core/SyncAsyncApiConvergenceTest.java b/src/test/java/io/lettuce/core/SyncAsyncApiConvergenceUnitTests.java similarity index 98% rename from src/test/java/io/lettuce/core/SyncAsyncApiConvergenceTest.java rename to src/test/java/io/lettuce/core/SyncAsyncApiConvergenceUnitTests.java index ace8a313be..72dc3d34a6 100644 --- a/src/test/java/io/lettuce/core/SyncAsyncApiConvergenceTest.java +++ b/src/test/java/io/lettuce/core/SyncAsyncApiConvergenceUnitTests.java @@ -32,7 +32,7 @@ * @author Mark Paluch * @since 3.0 */ -class SyncAsyncApiConvergenceTest { +class SyncAsyncApiConvergenceUnitTests { @SuppressWarnings("rawtypes") private Class asyncClass = RedisAsyncCommands.class; diff --git a/src/test/java/io/lettuce/core/cluster/RedisClusterClientFactoryTests.java b/src/test/java/io/lettuce/core/cluster/RedisClusterClientFactoryTests.java index dfe68e2cab..18549090d1 100644 --- a/src/test/java/io/lettuce/core/cluster/RedisClusterClientFactoryTests.java +++ b/src/test/java/io/lettuce/core/cluster/RedisClusterClientFactoryTests.java @@ -33,8 +33,8 @@ */ class RedisClusterClientFactoryTests { - private final static String URI = "redis://" + TestSettings.host() + ":" + TestSettings.port(); - private final static RedisURI REDIS_URI = RedisURI.create(URI); + private static final String URI = "redis://" + TestSettings.host() + ":" + TestSettings.port(); + private static final RedisURI REDIS_URI = RedisURI.create(URI); private static final List REDIS_URIS = LettuceLists.newList(REDIS_URI); @Test diff --git a/src/test/java/io/lettuce/core/cluster/RedisClusterClientIntegrationTests.java b/src/test/java/io/lettuce/core/cluster/RedisClusterClientIntegrationTests.java index 8aec366496..486c03e4c5 100644 --- a/src/test/java/io/lettuce/core/cluster/RedisClusterClientIntegrationTests.java +++ b/src/test/java/io/lettuce/core/cluster/RedisClusterClientIntegrationTests.java @@ -135,8 +135,6 @@ void statefulConnectionFromAsync() { @Test void shouldApplyTimeoutOnRegularConnection() { - clusterClient.setDefaultTimeout(1, TimeUnit.MINUTES); - StatefulRedisClusterConnection connection = clusterClient.connect(); assertThat(connection.getTimeout()).isEqualTo(Duration.ofMinutes(1)); @@ -148,12 +146,12 @@ void shouldApplyTimeoutOnRegularConnection() { @Test void shouldApplyTimeoutOnRegularConnectionUsingCodec() { - clusterClient.setDefaultTimeout(1, TimeUnit.MINUTES); + clusterClient.setDefaultTimeout(2, TimeUnit.MINUTES); StatefulRedisClusterConnection connection = clusterClient.connect(Utf8StringCodec.UTF8); - assertThat(connection.getTimeout()).isEqualTo(Duration.ofMinutes(1)); - assertThat(connection.getConnection(host, ClusterTestSettings.port1).getTimeout()).isEqualTo(Duration.ofMinutes(1)); + assertThat(connection.getTimeout()).isEqualTo(Duration.ofMinutes(2)); + assertThat(connection.getConnection(host, ClusterTestSettings.port1).getTimeout()).isEqualTo(Duration.ofMinutes(2)); connection.close(); } @@ -161,7 +159,7 @@ void shouldApplyTimeoutOnRegularConnectionUsingCodec() { @Test void shouldApplyTimeoutOnPubSubConnection() { - clusterClient.setDefaultTimeout(1, TimeUnit.MINUTES); + clusterClient.setDefaultTimeout(Duration.ofMinutes(1)); StatefulRedisPubSubConnection connection = clusterClient.connectPubSub(); @@ -172,8 +170,7 @@ void shouldApplyTimeoutOnPubSubConnection() { @Test void shouldApplyTimeoutOnPubSubConnectionUsingCodec() { - clusterClient.setDefaultTimeout(1, TimeUnit.MINUTES); - + clusterClient.setDefaultTimeout(Duration.ofMinutes(1)); StatefulRedisPubSubConnection connection = clusterClient.connectPubSub(Utf8StringCodec.UTF8); assertThat(connection.getTimeout()).isEqualTo(Duration.ofMinutes(1)); @@ -262,7 +259,6 @@ void testClusteredOperations() { assertThat(connection.set(ClusterTestSettings.KEY_D, "myValue2")).isEqualTo("OK"); connection.getStatefulConnection().close(); - } @Test diff --git a/src/test/java/io/lettuce/core/cluster/RedisClusterPasswordSecuredSslTest.java b/src/test/java/io/lettuce/core/cluster/RedisClusterPasswordSecuredSslIntegrationTests.java similarity index 98% rename from src/test/java/io/lettuce/core/cluster/RedisClusterPasswordSecuredSslTest.java rename to src/test/java/io/lettuce/core/cluster/RedisClusterPasswordSecuredSslIntegrationTests.java index f1c46ac966..51420fedb2 100644 --- a/src/test/java/io/lettuce/core/cluster/RedisClusterPasswordSecuredSslTest.java +++ b/src/test/java/io/lettuce/core/cluster/RedisClusterPasswordSecuredSslIntegrationTests.java @@ -42,7 +42,7 @@ /** * @author Mark Paluch */ -class RedisClusterPasswordSecuredSslTest extends TestSupport { +class RedisClusterPasswordSecuredSslIntegrationTests extends TestSupport { private static final int CLUSTER_PORT_SSL_1 = 7443; private static final int CLUSTER_PORT_SSL_2 = 7444; diff --git a/src/test/java/io/lettuce/core/cluster/RedisReactiveClusterClientTest.java b/src/test/java/io/lettuce/core/cluster/RedisReactiveClusterClientIntegrationTests.java similarity index 94% rename from src/test/java/io/lettuce/core/cluster/RedisReactiveClusterClientTest.java rename to src/test/java/io/lettuce/core/cluster/RedisReactiveClusterClientIntegrationTests.java index b3d3efcfcf..2ff7bb19e5 100644 --- a/src/test/java/io/lettuce/core/cluster/RedisReactiveClusterClientTest.java +++ b/src/test/java/io/lettuce/core/cluster/RedisReactiveClusterClientIntegrationTests.java @@ -36,13 +36,13 @@ */ @SuppressWarnings("unchecked") @ExtendWith(LettuceExtension.class) -class RedisReactiveClusterClientTest extends TestSupport { +class RedisReactiveClusterClientIntegrationTests extends TestSupport { private final RedisAdvancedClusterCommands sync; private final RedisAdvancedClusterReactiveCommands reactive; @Inject - RedisReactiveClusterClientTest(StatefulRedisClusterConnection connection) { + RedisReactiveClusterClientIntegrationTests(StatefulRedisClusterConnection connection) { this.sync = connection.sync(); this.reactive = connection.reactive(); } @@ -60,6 +60,8 @@ void testClusterCommandRedirection() { @Test void getKeysInSlot() { + sync.flushall(); + sync.set(ClusterTestSettings.KEY_A, value); sync.set(ClusterTestSettings.KEY_B, value); @@ -72,6 +74,8 @@ void getKeysInSlot() { @Test void countKeysInSlot() { + sync.flushall(); + sync.set(ClusterTestSettings.KEY_A, value); sync.set(ClusterTestSettings.KEY_B, value); diff --git a/src/test/java/io/lettuce/core/cluster/ScanIteratorIntegrationTests.java b/src/test/java/io/lettuce/core/cluster/ScanIteratorIntegrationTests.java index ff29bfca64..04fd0ac424 100644 --- a/src/test/java/io/lettuce/core/cluster/ScanIteratorIntegrationTests.java +++ b/src/test/java/io/lettuce/core/cluster/ScanIteratorIntegrationTests.java @@ -25,7 +25,9 @@ import javax.inject.Inject; +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 io.lettuce.core.*; @@ -38,6 +40,7 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) class ScanIteratorIntegrationTests extends TestSupport { private final StatefulRedisClusterConnection connection; @@ -47,6 +50,10 @@ class ScanIteratorIntegrationTests extends TestSupport { ScanIteratorIntegrationTests(StatefulRedisClusterConnection connection) { this.connection = connection; this.redis = connection.sync(); + } + + @BeforeEach + void setUp() { this.redis.flushall(); } diff --git a/src/test/java/io/lettuce/core/cluster/SingleThreadedReactiveClusterClientTest.java b/src/test/java/io/lettuce/core/cluster/SingleThreadedReactiveClusterClientIntegrationTests.java similarity index 92% rename from src/test/java/io/lettuce/core/cluster/SingleThreadedReactiveClusterClientTest.java rename to src/test/java/io/lettuce/core/cluster/SingleThreadedReactiveClusterClientIntegrationTests.java index e51006695e..11330b1ca1 100644 --- a/src/test/java/io/lettuce/core/cluster/SingleThreadedReactiveClusterClientTest.java +++ b/src/test/java/io/lettuce/core/cluster/SingleThreadedReactiveClusterClientIntegrationTests.java @@ -28,12 +28,13 @@ import io.lettuce.core.metrics.DefaultCommandLatencyCollectorOptions; import io.lettuce.core.resource.DefaultClientResources; import io.lettuce.core.resource.DefaultEventLoopGroupProvider; +import io.lettuce.test.resource.FastShutdown; import io.netty.util.concurrent.ImmediateEventExecutor; /** * @author Mark Paluch */ -class SingleThreadedReactiveClusterClientTest { +class SingleThreadedReactiveClusterClientIntegrationTests { private RedisClusterClient client; @@ -51,8 +52,8 @@ void before() { @AfterEach void tearDown() { - client.shutdown(); - client.getResources().shutdown(); + FastShutdown.shutdown(client); + FastShutdown.shutdown(client.getResources()); } @Test diff --git a/src/test/java/io/lettuce/core/cluster/commands/CustomClusterCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/CustomClusterCommandIntegrationTests.java similarity index 85% rename from src/test/java/io/lettuce/core/cluster/commands/CustomClusterCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/CustomClusterCommandIntegrationTests.java index 49cf7fff56..b79ebbe060 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/CustomClusterCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/CustomClusterCommandIntegrationTests.java @@ -31,7 +31,7 @@ import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; import io.lettuce.core.cluster.api.sync.RedisAdvancedClusterCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.commands.CustomCommandTest; +import io.lettuce.core.commands.CustomCommandIntegrationTests; import io.lettuce.core.output.StatusOutput; import io.lettuce.core.protocol.*; import io.lettuce.test.Futures; @@ -41,13 +41,13 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) -class CustomClusterCommandTest extends TestSupport { +class CustomClusterCommandIntegrationTests extends TestSupport { private final StatefulRedisClusterConnection connection; private RedisAdvancedClusterCommands redis; @Inject - CustomClusterCommandTest(StatefulRedisClusterConnection connection) { + CustomClusterCommandIntegrationTests(StatefulRedisClusterConnection connection) { this.connection = connection; this.redis = connection.sync(); this.redis.flushall(); @@ -56,7 +56,7 @@ class CustomClusterCommandTest extends TestSupport { @Test void dispatchSet() { - String response = redis.dispatch(CustomCommandTest.MyCommands.SET, new StatusOutput<>(StringCodec.UTF8), + String response = redis.dispatch(CustomCommandIntegrationTests.MyCommands.SET, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>(StringCodec.UTF8).addKey(key).addValue(value)); assertThat(response).isEqualTo("OK"); @@ -65,7 +65,7 @@ void dispatchSet() { @Test void dispatchWithoutArgs() { - String response = redis.dispatch(CustomCommandTest.MyCommands.INFO, new StatusOutput<>(StringCodec.UTF8)); + String response = redis.dispatch(CustomCommandIntegrationTests.MyCommands.INFO, new StatusOutput<>(StringCodec.UTF8)); assertThat(response).contains("connected_clients"); } @@ -82,7 +82,8 @@ void dispatchShouldFailForWrongDataType() { @Test void clusterAsyncPing() { - RedisCommand command = new Command<>(CustomCommandTest.MyCommands.PING, new StatusOutput<>( + RedisCommand command = new Command<>(CustomCommandIntegrationTests.MyCommands.PING, + new StatusOutput<>( StringCodec.UTF8), null); AsyncCommand async = new AsyncCommand<>(command); @@ -94,10 +95,12 @@ void clusterAsyncPing() { @Test void clusterAsyncBatchPing() { - RedisCommand command1 = new Command<>(CustomCommandTest.MyCommands.PING, new StatusOutput<>( + RedisCommand command1 = new Command<>(CustomCommandIntegrationTests.MyCommands.PING, + new StatusOutput<>( StringCodec.UTF8), null); - RedisCommand command2 = new Command<>(CustomCommandTest.MyCommands.PING, new StatusOutput<>( + RedisCommand command2 = new Command<>(CustomCommandIntegrationTests.MyCommands.PING, + new StatusOutput<>( StringCodec.UTF8), null); AsyncCommand async1 = new AsyncCommand<>(command1); @@ -133,7 +136,8 @@ void clusterAsyncBatchSet() { @Test void clusterFireAndForget() { - RedisCommand command = new Command<>(CustomCommandTest.MyCommands.PING, new StatusOutput<>( + RedisCommand command = new Command<>(CustomCommandIntegrationTests.MyCommands.PING, + new StatusOutput<>( StringCodec.UTF8), null); connection.dispatch(command); assertThat(command.isCancelled()).isFalse(); diff --git a/src/test/java/io/lettuce/core/cluster/commands/GeoClusterCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/GeoClusterCommandIntegrationTests.java similarity index 51% rename from src/test/java/io/lettuce/core/cluster/commands/GeoClusterCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/GeoClusterCommandIntegrationTests.java index e15094fbe0..be59dad6f2 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/GeoClusterCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/GeoClusterCommandIntegrationTests.java @@ -15,58 +15,22 @@ */ package io.lettuce.core.cluster.commands; -import static io.lettuce.core.cluster.ClusterTestUtil.flushDatabaseOfAllNodes; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import javax.inject.Inject; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.commands.GeoCommandTest; -import io.lettuce.test.condition.RedisConditions; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; +import io.lettuce.core.commands.GeoCommandIntegrationTests; /** * @author Mark Paluch */ -public class GeoClusterCommandTest extends GeoCommandTest { - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; +class GeoClusterCommandIntegrationTests extends GeoCommandIntegrationTests { - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create(TestClientResources.get(), - RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - - try (StatefulRedisClusterConnection connection = redisClusterClient.connect()) { - assumeTrue(RedisConditions.of(connection).hasCommand("GEOADD")); - } - } - - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - flushDatabaseOfAllNodes(clusterConnection); - } - - @Override - @SuppressWarnings("unchecked") - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ClusterTestUtil.redisCommandsOverCluster(clusterConnection); + @Inject + GeoClusterCommandIntegrationTests(StatefulRedisClusterConnection clusterConnection) { + super(ClusterTestUtil.redisCommandsOverCluster(clusterConnection)); } @Disabled("MULTI not available on Redis Cluster") diff --git a/src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandIntegrationTests.java b/src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandIntegrationTests.java new file mode 100644 index 0000000000..b4360c30d0 --- /dev/null +++ b/src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.cluster.commands; + +import javax.inject.Inject; + +import io.lettuce.core.cluster.ClusterTestUtil; +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.core.commands.HashCommandIntegrationTests; + +/** + * @author Mark Paluch + */ +public class HashClusterCommandIntegrationTests extends HashCommandIntegrationTests { + + @Inject + public HashClusterCommandIntegrationTests(StatefulRedisClusterConnection connection) { + super(ClusterTestUtil.redisCommandsOverCluster(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandTest.java deleted file mode 100644 index 6bde123a33..0000000000 --- a/src/test/java/io/lettuce/core/cluster/commands/HashClusterCommandTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.cluster.commands; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; - -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; -import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.commands.HashCommandTest; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; - -/** - * @author Mark Paluch - */ -public class HashClusterCommandTest extends HashCommandTest { - - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create( - TestClientResources.get(), RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } - - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } - - @Override - @SuppressWarnings("unchecked") - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ClusterTestUtil.redisCommandsOverCluster(clusterConnection); - } -} diff --git a/src/test/java/io/lettuce/core/cluster/commands/KeyClusterCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/KeyClusterCommandIntegrationTests.java similarity index 64% rename from src/test/java/io/lettuce/core/cluster/commands/KeyClusterCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/KeyClusterCommandIntegrationTests.java index f5c2db7044..3b75233664 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/KeyClusterCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/KeyClusterCommandIntegrationTests.java @@ -17,52 +17,39 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; +import javax.inject.Inject; + 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 io.lettuce.core.AbstractRedisClientTest; -import io.lettuce.core.RedisURI; +import io.lettuce.core.TestSupport; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.condition.EnabledOnCommand; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; /** * @author Mark Paluch */ -public class KeyClusterCommandTest extends AbstractRedisClientTest { - - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class KeyClusterCommandIntegrationTests extends TestSupport { - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create(TestClientResources.get(), - RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } + private final StatefulRedisClusterConnection clusterConnection; + private final RedisCommands redis; - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); + @Inject + KeyClusterCommandIntegrationTests(StatefulRedisClusterConnection clusterConnection) { + this.clusterConnection = clusterConnection; + this.redis = ClusterTestUtil.redisCommandsOverCluster(clusterConnection); } @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } - - @Override - @SuppressWarnings("unchecked") - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ClusterTestUtil.redisCommandsOverCluster(clusterConnection); + void setUp() { + this.redis.flushall(); } @Test @@ -113,5 +100,4 @@ void unlink() { assertThat(redis.unlink(key, "a", "b")).isEqualTo(3); assertThat(redis.exists(key)).isEqualTo(0); } - } diff --git a/src/test/java/io/lettuce/core/cluster/commands/ListClusterCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/ListClusterCommandIntegrationTests.java similarity index 62% rename from src/test/java/io/lettuce/core/cluster/commands/ListClusterCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/ListClusterCommandIntegrationTests.java index f7c84838ae..ffeb4b115e 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/ListClusterCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/ListClusterCommandIntegrationTests.java @@ -17,51 +17,28 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.commands.ListCommandTest; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; +import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.commands.ListCommandIntegrationTests; /** * @author Mark Paluch */ -public class ListClusterCommandTest extends ListCommandTest { - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create( - TestClientResources.get(), RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } +class ListClusterCommandIntegrationTests extends ListCommandIntegrationTests { - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } + private final RedisClusterCommands redis; - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); + @Inject + ListClusterCommandIntegrationTests(StatefulRedisClusterConnection connection) { + super(ClusterTestUtil.redisCommandsOverCluster(connection)); + this.redis = connection.sync(); } - @Override - @SuppressWarnings("unchecked") - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ClusterTestUtil.redisCommandsOverCluster(clusterConnection); - } // re-implementation because keys have to be on the same slot @Test @@ -100,5 +77,4 @@ void rpoplpush() { assertThat(redis.lrange("UKPDHs8Zlp", 0, -1)).isEqualTo(list("1")); assertThat(redis.lrange("br7EPz9bbj", 0, -1)).isEqualTo(list("2", "3", "4")); } - } diff --git a/src/test/java/io/lettuce/core/cluster/commands/StringClusterCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/StringClusterCommandIntegrationTests.java similarity index 56% rename from src/test/java/io/lettuce/core/cluster/commands/StringClusterCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/StringClusterCommandIntegrationTests.java index dbcbd74917..19dfeee11a 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/StringClusterCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/StringClusterCommandIntegrationTests.java @@ -20,51 +20,27 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.commands.StringCommandTest; +import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.commands.StringCommandIntegrationTests; import io.lettuce.test.KeyValueStreamingAdapter; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; /** * @author Mark Paluch */ -public class StringClusterCommandTest extends StringCommandTest { - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create( - TestClientResources.get(), RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } +class StringClusterCommandIntegrationTests extends StringCommandIntegrationTests { - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } + private final RedisClusterCommands redis; - @Override - @SuppressWarnings("unchecked") - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ClusterTestUtil.redisCommandsOverCluster(clusterConnection); + @Inject + StringClusterCommandIntegrationTests(StatefulRedisClusterConnection connection) { + super(ClusterTestUtil.redisCommandsOverCluster(connection)); + this.redis = connection.sync(); } @Test diff --git a/src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandIntegrationTests.java b/src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandIntegrationTests.java new file mode 100644 index 0000000000..c6031bb283 --- /dev/null +++ b/src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.cluster.commands.reactive; + +import javax.inject.Inject; + +import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; +import io.lettuce.core.commands.HashCommandIntegrationTests; +import io.lettuce.test.ReactiveSyncInvocationHandler; + +/** + * @author Mark Paluch + */ +class HashClusterReactiveCommandIntegrationTests extends HashCommandIntegrationTests { + + @Inject + HashClusterReactiveCommandIntegrationTests(StatefulRedisClusterConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandTest.java deleted file mode 100644 index 2ac1bc07c7..0000000000 --- a/src/test/java/io/lettuce/core/cluster/commands/reactive/HashClusterReactiveCommandTest.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.cluster.commands.reactive; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; - -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; -import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.commands.HashCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; - -/** - * @author Mark Paluch - */ -public class HashClusterReactiveCommandTest extends HashCommandTest { - - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create(TestClientResources.get(), - RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } - - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } - - @Override - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ReactiveSyncInvocationHandler.sync(redisClusterClient.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/cluster/commands/reactive/KeyClusterReativeCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/reactive/KeyClusterReativeCommandTest.java deleted file mode 100644 index d2be833cc1..0000000000 --- a/src/test/java/io/lettuce/core/cluster/commands/reactive/KeyClusterReativeCommandTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.cluster.commands.reactive; - -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; - -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; -import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.cluster.commands.KeyClusterCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; - -/** - * @author Mark Paluch - */ -public class KeyClusterReativeCommandTest extends KeyClusterCommandTest { - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create(TestClientResources.get(), - RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } - - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } - - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ReactiveSyncInvocationHandler.sync(redisClusterClient.connect()); - } - -} diff --git a/src/test/java/io/lettuce/core/cluster/commands/reactive/ListClusterReactiveCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/reactive/ListClusterReactiveCommandIntegrationTests.java similarity index 62% rename from src/test/java/io/lettuce/core/cluster/commands/reactive/ListClusterReactiveCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/reactive/ListClusterReactiveCommandIntegrationTests.java index 8b0e2cae5e..e0638c587b 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/reactive/ListClusterReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/reactive/ListClusterReactiveCommandIntegrationTests.java @@ -17,50 +17,26 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; -import io.lettuce.core.commands.ListCommandTest; +import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.commands.ListCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; /** * @author Mark Paluch */ -public class ListClusterReactiveCommandTest extends ListCommandTest { - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create(TestClientResources.get(), - RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } +class ListClusterReactiveCommandIntegrationTests extends ListCommandIntegrationTests { - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } + private final RedisClusterCommands redis; - @Override - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ReactiveSyncInvocationHandler.sync(redisClusterClient.connect()); + @Inject + ListClusterReactiveCommandIntegrationTests(StatefulRedisClusterConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + this.redis = ReactiveSyncInvocationHandler.sync(connection); } // re-implementation because keys have to be on the same slot diff --git a/src/test/java/io/lettuce/core/cluster/commands/reactive/StringClusterReactiveCommandTest.java b/src/test/java/io/lettuce/core/cluster/commands/reactive/StringClusterReactiveCommandIntegrationTests.java similarity index 57% rename from src/test/java/io/lettuce/core/cluster/commands/reactive/StringClusterReactiveCommandTest.java rename to src/test/java/io/lettuce/core/cluster/commands/reactive/StringClusterReactiveCommandIntegrationTests.java index c0860a9fc2..800d3b9a2c 100644 --- a/src/test/java/io/lettuce/core/cluster/commands/reactive/StringClusterReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/cluster/commands/reactive/StringClusterReactiveCommandIntegrationTests.java @@ -20,54 +20,32 @@ import java.util.LinkedHashMap; import java.util.Map; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.BeforeEach; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; import io.lettuce.core.KeyValue; -import io.lettuce.core.RedisURI; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.cluster.ClusterTestUtil; -import io.lettuce.core.cluster.RedisClusterClient; import io.lettuce.core.cluster.api.StatefulRedisClusterConnection; import io.lettuce.core.cluster.api.reactive.RedisAdvancedClusterReactiveCommands; -import io.lettuce.core.commands.StringCommandTest; +import io.lettuce.core.cluster.api.sync.RedisClusterCommands; +import io.lettuce.core.commands.StringCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; -import io.lettuce.test.resource.FastShutdown; -import io.lettuce.test.resource.TestClientResources; -import io.lettuce.test.settings.TestSettings; /** * @author Mark Paluch */ -public class StringClusterReactiveCommandTest extends StringCommandTest { - private static RedisClusterClient redisClusterClient; - private StatefulRedisClusterConnection clusterConnection; - - @BeforeAll - public static void setupClient() { - redisClusterClient = RedisClusterClient.create(TestClientResources.get(), - RedisURI.Builder.redis(TestSettings.host(), TestSettings.port(900)).build()); - } +class StringClusterReactiveCommandIntegrationTests extends StringCommandIntegrationTests { - @AfterAll - static void closeClient() { - FastShutdown.shutdown(redisClusterClient); - } - - @BeforeEach - public void openConnection() { - redis = connect(); - ClusterTestUtil.flushDatabaseOfAllNodes(clusterConnection); - } + private final StatefulRedisClusterConnection connection; + private final RedisClusterCommands redis; - @Override - protected RedisCommands connect() { - clusterConnection = redisClusterClient.connect(); - return ReactiveSyncInvocationHandler.sync(redisClusterClient.connect()); + @Inject + StringClusterReactiveCommandIntegrationTests(StatefulRedisClusterConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + this.connection = connection; + this.redis = connection.sync(); } @Test @@ -90,7 +68,7 @@ void mget() { redis.set("key1", value); redis.set("key2", value); - RedisAdvancedClusterReactiveCommands reactive = clusterConnection.reactive(); + RedisAdvancedClusterReactiveCommands reactive = connection.reactive(); Flux> mget = reactive.mget(key, "key1", "key2"); StepVerifier.create(mget.next()).expectNext(KeyValue.just(key, value)).verifyComplete(); diff --git a/src/test/java/io/lettuce/core/cluster/topology/ClusterTopologyRefreshUnitTests.java b/src/test/java/io/lettuce/core/cluster/topology/ClusterTopologyRefreshUnitTests.java index 96af83ba75..e992868ef5 100644 --- a/src/test/java/io/lettuce/core/cluster/topology/ClusterTopologyRefreshUnitTests.java +++ b/src/test/java/io/lettuce/core/cluster/topology/ClusterTopologyRefreshUnitTests.java @@ -62,7 +62,7 @@ @MockitoSettings(strictness = Strictness.LENIENT) class ClusterTopologyRefreshUnitTests { - private final static long COMMAND_TIMEOUT_NS = TimeUnit.MILLISECONDS.toNanos(10); + private static final long COMMAND_TIMEOUT_NS = TimeUnit.MILLISECONDS.toNanos(10); private static final String NODE_1_VIEW = "1 127.0.0.1:7380 master,myself - 0 1401258245007 2 disconnected 8000-11999\n" + "2 127.0.0.1:7381 master - 111 1401258245007 222 connected 7000 12000 12002-16383\n"; diff --git a/src/test/java/io/lettuce/core/commands/BitCommandTest.java b/src/test/java/io/lettuce/core/commands/BitCommandIntegrationTests.java similarity index 89% rename from src/test/java/io/lettuce/core/commands/BitCommandTest.java rename to src/test/java/io/lettuce/core/commands/BitCommandIntegrationTests.java index 03583056eb..2c2d955b9c 100644 --- a/src/test/java/io/lettuce/core/commands/BitCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/BitCommandIntegrationTests.java @@ -25,35 +25,49 @@ import java.util.List; +import javax.inject.Inject; + +import org.junit.jupiter.api.AfterEach; +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 io.lettuce.core.AbstractRedisClientTest; import io.lettuce.core.BitFieldArgs; +import io.lettuce.core.RedisClient; +import io.lettuce.core.TestSupport; import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.condition.EnabledOnCommand; /** * @author Will Glozer * @author Mark Paluch */ -public class BitCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class BitCommandIntegrationTests extends TestSupport { + + private final RedisClient client; + private final RedisCommands redis; protected RedisCommands bitstring; - @Override - public RedisCommands connect() { - connectBitString(); - return super.connect(); + @Inject + protected BitCommandIntegrationTests(RedisClient client, RedisCommands redis) { + this.client = client; + this.redis = redis; } - void connectBitString() { - bitstring = client.connect(new BitStringCodec()).sync(); + @BeforeEach + void setUp() { + this.redis.flushall(); + this.bitstring = client.connect(new BitStringCodec()).sync(); } - @Override - public void closeConnection() throws Exception { - bitstring.getStatefulConnection().close(); - super.closeConnection(); + @AfterEach + void tearDown() { + this.bitstring.getStatefulConnection().close(); } @Test diff --git a/src/test/java/io/lettuce/core/commands/CustomCommandTest.java b/src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java similarity index 94% rename from src/test/java/io/lettuce/core/commands/CustomCommandTest.java rename to src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java index f22fd2f7b1..51a25b7084 100644 --- a/src/test/java/io/lettuce/core/commands/CustomCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/CustomCommandIntegrationTests.java @@ -23,7 +23,9 @@ import javax.inject.Inject; +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 io.lettuce.core.RedisCommandExecutionException; @@ -41,15 +43,21 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) -public class CustomCommandTest extends TestSupport { +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class CustomCommandIntegrationTests extends TestSupport { private final RedisCommands redis; @Inject - CustomCommandTest(StatefulRedisConnection connection) { + CustomCommandIntegrationTests(StatefulRedisConnection connection) { this.redis = connection.sync(); } + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void dispatchSet() { diff --git a/src/test/java/io/lettuce/core/commands/GeoCommandTest.java b/src/test/java/io/lettuce/core/commands/GeoCommandIntegrationTests.java similarity index 96% rename from src/test/java/io/lettuce/core/commands/GeoCommandTest.java rename to src/test/java/io/lettuce/core/commands/GeoCommandIntegrationTests.java index 68a3765317..66e7d64a96 100644 --- a/src/test/java/io/lettuce/core/commands/GeoCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/GeoCommandIntegrationTests.java @@ -23,27 +23,37 @@ import java.util.List; import java.util.Set; -import org.junit.jupiter.api.BeforeAll; +import javax.inject.Inject; + +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 io.lettuce.core.*; -import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; +import io.lettuce.test.condition.EnabledOnCommand; import io.lettuce.test.condition.RedisConditions; -import io.lettuce.test.resource.DefaultRedisClient; /** * @author Mark Paluch */ -public class GeoCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@EnabledOnCommand("GEOADD") +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class GeoCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; - @BeforeAll - public static void setupClient() { - client = DefaultRedisClient.get(); - client.setOptions(ClientOptions.create()); + @Inject + protected GeoCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } - try (StatefulRedisConnection connection = client.connect()) { - assumeTrue(RedisConditions.of(connection).hasCommand("GEOADD")); - } + @BeforeEach + void setUp() { + this.redis.flushall(); } @Test diff --git a/src/test/java/io/lettuce/core/commands/HLLCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/HLLCommandIntegrationTests.java new file mode 100644 index 0000000000..78072d7ec5 --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/HLLCommandIntegrationTests.java @@ -0,0 +1,124 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Fail.fail; + +import javax.inject.Inject; + +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 io.lettuce.core.TestSupport; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; + +/** + * @author Mark Paluch + */ +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class HLLCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected HLLCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } + + @Test + void pfadd() { + + assertThat(redis.pfadd(key, value, value)).isEqualTo(1); + assertThat(redis.pfadd(key, value, value)).isEqualTo(0); + assertThat(redis.pfadd(key, value)).isEqualTo(0); + } + + @Test + void pfaddNoValues() { + assertThatThrownBy(() -> redis.pfadd(key)).isInstanceOf(IllegalArgumentException.class); + } + + @Test + void pfaddNullValues() { + try { + redis.pfadd(key, null); + fail("Missing IllegalArgumentException"); + } catch (IllegalArgumentException e) { + } + try { + redis.pfadd(key, value, null); + fail("Missing IllegalArgumentException"); + } catch (IllegalArgumentException e) { + } + } + + @Test + void pfmerge() { + redis.pfadd(key, value); + redis.pfadd("key2", "value2"); + redis.pfadd("key3", "value3"); + + assertThat(redis.pfmerge(key, "key2", "key3")).isEqualTo("OK"); + assertThat(redis.pfcount(key)).isEqualTo(3); + + redis.pfadd("key2660", "rand", "mat"); + redis.pfadd("key7112", "mat", "perrin"); + + redis.pfmerge("key8885", "key2660", "key7112"); + + assertThat(redis.pfcount("key8885")).isEqualTo(3); + } + + @Test + void pfmergeNoKeys() { + assertThatThrownBy(() -> redis.pfmerge(key)).isInstanceOf(IllegalArgumentException.class); + } + + @Test + void pfcount() { + redis.pfadd(key, value); + redis.pfadd("key2", "value2"); + assertThat(redis.pfcount(key)).isEqualTo(1); + assertThat(redis.pfcount(key, "key2")).isEqualTo(2); + } + + @Test + void pfcountNoKeys() { + assertThatThrownBy(() -> redis.pfcount()).isInstanceOf(IllegalArgumentException.class); + } + + @Test + void pfaddPfmergePfCount() { + + redis.pfadd("key2660", "rand", "mat"); + redis.pfadd("key7112", "mat", "perrin"); + + redis.pfmerge("key8885", "key2660", "key7112"); + + assertThat(redis.pfcount("key8885")).isEqualTo(3); + } +} diff --git a/src/test/java/io/lettuce/core/commands/HLLCommandTest.java b/src/test/java/io/lettuce/core/commands/HLLCommandTest.java deleted file mode 100644 index 1ca6da85a5..0000000000 --- a/src/test/java/io/lettuce/core/commands/HLLCommandTest.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.assertj.core.api.Fail.fail; - -import org.junit.jupiter.api.Test; - -import io.lettuce.core.AbstractRedisClientTest; -import io.lettuce.core.api.sync.RedisHLLCommands; - -public class HLLCommandTest extends AbstractRedisClientTest { - - private RedisHLLCommands commands() { - return redis; - } - - @Test - void pfadd() { - - assertThat(commands().pfadd(key, value, value)).isEqualTo(1); - assertThat(commands().pfadd(key, value, value)).isEqualTo(0); - assertThat(commands().pfadd(key, value)).isEqualTo(0); - } - - @Test - void pfaddNoValues() { - assertThatThrownBy(() -> commands().pfadd(key)).isInstanceOf(IllegalArgumentException.class); - } - - @Test - void pfaddNullValues() { - try { - commands().pfadd(key, null); - fail("Missing IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - try { - commands().pfadd(key, value, null); - fail("Missing IllegalArgumentException"); - } catch (IllegalArgumentException e) { - } - } - - @Test - void pfmerge() { - commands().pfadd(key, value); - commands().pfadd("key2", "value2"); - commands().pfadd("key3", "value3"); - - assertThat(commands().pfmerge(key, "key2", "key3")).isEqualTo("OK"); - assertThat(commands().pfcount(key)).isEqualTo(3); - - commands().pfadd("key2660", "rand", "mat"); - commands().pfadd("key7112", "mat", "perrin"); - - commands().pfmerge("key8885", "key2660", "key7112"); - - assertThat(commands().pfcount("key8885")).isEqualTo(3); - } - - @Test - void pfmergeNoKeys() { - assertThatThrownBy(() -> commands().pfmerge(key)).isInstanceOf(IllegalArgumentException.class); - } - - @Test - void pfcount() { - commands().pfadd(key, value); - commands().pfadd("key2", "value2"); - assertThat(commands().pfcount(key)).isEqualTo(1); - assertThat(commands().pfcount(key, "key2")).isEqualTo(2); - } - - @Test - void pfcountNoKeys() { - assertThatThrownBy(() -> commands().pfcount()).isInstanceOf(IllegalArgumentException.class); - } - - @Test - void pfaddPfmergePfCount() { - - commands().pfadd("key2660", "rand", "mat"); - commands().pfadd("key7112", "mat", "perrin"); - - commands().pfmerge("key8885", "key2660", "key7112"); - - assertThat(commands().pfcount("key8885")).isEqualTo(3); - } -} diff --git a/src/test/java/io/lettuce/core/commands/HashCommandTest.java b/src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java similarity index 94% rename from src/test/java/io/lettuce/core/commands/HashCommandTest.java rename to src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java index b60515d241..f51bb5a1ad 100644 --- a/src/test/java/io/lettuce/core/commands/HashCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/HashCommandIntegrationTests.java @@ -23,10 +23,17 @@ import java.util.List; import java.util.Map; +import javax.inject.Inject; + +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 io.lettuce.core.*; +import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.test.KeyValueStreamingAdapter; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; import io.lettuce.test.condition.EnabledOnCommand; @@ -34,7 +41,21 @@ * @author Will Glozer * @author Mark Paluch */ -public class HashCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class HashCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected HashCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void hdel() { diff --git a/src/test/java/io/lettuce/core/commands/KeyCommandTest.java b/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java similarity index 95% rename from src/test/java/io/lettuce/core/commands/KeyCommandTest.java rename to src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java index 6e40de3375..925174696f 100644 --- a/src/test/java/io/lettuce/core/commands/KeyCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/KeyCommandIntegrationTests.java @@ -22,9 +22,16 @@ import java.time.Duration; import java.util.*; +import javax.inject.Inject; + +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 io.lettuce.core.*; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; import io.lettuce.test.condition.EnabledOnCommand; @@ -32,7 +39,21 @@ * @author Will Glozer * @author Mark Paluch */ -public class KeyCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class KeyCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected KeyCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void del() { diff --git a/src/test/java/io/lettuce/core/commands/ListCommandTest.java b/src/test/java/io/lettuce/core/commands/ListCommandIntegrationTests.java similarity index 91% rename from src/test/java/io/lettuce/core/commands/ListCommandTest.java rename to src/test/java/io/lettuce/core/commands/ListCommandIntegrationTests.java index 75d5eb82e2..57259c42f9 100644 --- a/src/test/java/io/lettuce/core/commands/ListCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/ListCommandIntegrationTests.java @@ -21,9 +21,16 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import javax.inject.Inject; + +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 io.lettuce.core.AbstractRedisClientTest; +import io.lettuce.core.TestSupport; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; import io.lettuce.test.condition.RedisConditions; @@ -31,7 +38,21 @@ * @author Will Glozer * @author Mark Paluch */ -public class ListCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ListCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected ListCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void blpop() { @@ -60,11 +81,6 @@ void brpoplpush() { assertThat(redis.lrange("two", 0, -1)).isEqualTo(list("2", "3", "4")); } - @Test - void brpoplpushTimeout() { - assertThat(redis.brpoplpush(1, "one", "two")).isNull(); - } - @Test void lindex() { assertThat(redis.lindex(key, 0)).isNull(); diff --git a/src/test/java/io/lettuce/core/commands/NumericCommandTest.java b/src/test/java/io/lettuce/core/commands/NumericCommandIntegrationTests.java similarity index 70% rename from src/test/java/io/lettuce/core/commands/NumericCommandTest.java rename to src/test/java/io/lettuce/core/commands/NumericCommandIntegrationTests.java index 7cfbc0f038..25dd26bf7b 100644 --- a/src/test/java/io/lettuce/core/commands/NumericCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/NumericCommandIntegrationTests.java @@ -18,15 +18,37 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.offset; +import javax.inject.Inject; + +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 io.lettuce.core.AbstractRedisClientTest; +import io.lettuce.core.TestSupport; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; /** * @author Will Glozer * @author Mark Paluch */ -public class NumericCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class NumericCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected NumericCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void decr() { assertThat((long) redis.decr(key)).isEqualTo(-1); diff --git a/src/test/java/io/lettuce/core/commands/ScriptingCommandTest.java b/src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java similarity index 86% rename from src/test/java/io/lettuce/core/commands/ScriptingCommandTest.java rename to src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java index f69623a97f..a2c8055d2d 100644 --- a/src/test/java/io/lettuce/core/commands/ScriptingCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/ScriptingCommandIntegrationTests.java @@ -23,20 +23,44 @@ import java.util.List; import java.util.concurrent.TimeUnit; +import javax.inject.Inject; + import org.junit.jupiter.api.AfterEach; +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 io.lettuce.core.AbstractRedisClientTest; +import io.lettuce.core.RedisClient; import io.lettuce.core.RedisException; import io.lettuce.core.RedisNoScriptException; +import io.lettuce.core.TestSupport; import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.Wait; /** * @author Will Glozer * @author Mark Paluch */ -public class ScriptingCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ScriptingCommandIntegrationTests extends TestSupport { + + private final RedisClient client; + private final RedisCommands redis; + + @Inject + protected ScriptingCommandIntegrationTests(RedisClient client, RedisCommands redis) { + this.client = client; + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @AfterEach void tearDown() { diff --git a/src/test/java/io/lettuce/core/commands/ServerCommandTest.java b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java similarity index 93% rename from src/test/java/io/lettuce/core/commands/ServerCommandTest.java rename to src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java index 8cffc6ef99..eed95d86d9 100644 --- a/src/test/java/io/lettuce/core/commands/ServerCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/ServerCommandIntegrationTests.java @@ -28,8 +28,13 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.inject.Inject; + +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import io.lettuce.core.*; import io.lettuce.core.api.StatefulRedisConnection; @@ -39,6 +44,7 @@ import io.lettuce.core.models.role.RedisInstance; import io.lettuce.core.models.role.RoleParser; import io.lettuce.core.protocol.CommandType; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.Wait; import io.lettuce.test.condition.EnabledOnCommand; import io.lettuce.test.condition.RedisConditions; @@ -48,7 +54,23 @@ * @author Will Glozer * @author Mark Paluch */ -public class ServerCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class ServerCommandIntegrationTests extends TestSupport { + + private final RedisClient client; + private final RedisCommands redis; + + @Inject + protected ServerCommandIntegrationTests(RedisClient client, RedisCommands redis) { + this.client = client; + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void bgrewriteaof() { @@ -224,7 +246,7 @@ void debugCrashAndRecover() { void debugHtstats() { redis.set(key, value); String result = redis.debugHtstats(0); - assertThat(result).contains("table size"); + assertThat(result).contains("Dictionary"); } @Test @@ -255,11 +277,6 @@ void debugSdslen() { assertThat(result).contains("key_sds_len"); } - /** - * this test causes a stop of the redis. This means, you cannot repeat the test without restarting your redis. - * - * @ - */ @Test void flushall() { redis.set(key, value); @@ -280,12 +297,8 @@ void flushallAsync() { @Test void flushdb() { redis.set(key, value); - redis.select(1); - redis.set(key, value + "X"); assertThat(redis.flushdb()).isEqualTo("OK"); assertThat(redis.get(key)).isNull(); - redis.select(0); - assertThat(redis.get(key)).isEqualTo(value); } @Test diff --git a/src/test/java/io/lettuce/core/commands/SetCommandTest.java b/src/test/java/io/lettuce/core/commands/SetCommandIntegrationTests.java similarity index 94% rename from src/test/java/io/lettuce/core/commands/SetCommandTest.java rename to src/test/java/io/lettuce/core/commands/SetCommandIntegrationTests.java index 78d3741ba4..71dc8efd8c 100644 --- a/src/test/java/io/lettuce/core/commands/SetCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/SetCommandIntegrationTests.java @@ -24,9 +24,16 @@ import java.util.Set; import java.util.TreeSet; +import javax.inject.Inject; + +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 io.lettuce.core.*; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; import io.lettuce.test.condition.RedisConditions; @@ -34,7 +41,21 @@ * @author Will Glozer * @author Mark Paluch */ -public class SetCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class SetCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected SetCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void sadd() { diff --git a/src/test/java/io/lettuce/core/commands/SortCommandTest.java b/src/test/java/io/lettuce/core/commands/SortCommandIntegrationTests.java similarity index 80% rename from src/test/java/io/lettuce/core/commands/SortCommandTest.java rename to src/test/java/io/lettuce/core/commands/SortCommandIntegrationTests.java index ca285baf96..20e351c06d 100644 --- a/src/test/java/io/lettuce/core/commands/SortCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/SortCommandIntegrationTests.java @@ -18,16 +18,38 @@ import static io.lettuce.core.SortArgs.Builder.*; import static org.assertj.core.api.Assertions.assertThat; +import javax.inject.Inject; + +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 io.lettuce.core.AbstractRedisClientTest; +import io.lettuce.core.TestSupport; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; /** * @author Will Glozer * @author Mark Paluch */ -public class SortCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class SortCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected SortCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void sort() { redis.rpush(key, "3", "2", "1"); diff --git a/src/test/java/io/lettuce/core/commands/SortedSetCommandTest.java b/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java similarity index 98% rename from src/test/java/io/lettuce/core/commands/SortedSetCommandTest.java rename to src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java index b5fa9e9d28..f0e1a2183d 100644 --- a/src/test/java/io/lettuce/core/commands/SortedSetCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/SortedSetCommandIntegrationTests.java @@ -29,10 +29,17 @@ import java.util.HashSet; import java.util.Set; +import javax.inject.Inject; + +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 io.lettuce.core.*; import io.lettuce.core.Range.Boundary; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.ListStreamingAdapter; import io.lettuce.test.condition.EnabledOnCommand; @@ -40,7 +47,21 @@ * @author Will Glozer * @author Mark Paluch */ -public class SortedSetCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class SortedSetCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected SortedSetCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void zadd() { diff --git a/src/test/java/io/lettuce/core/commands/StreamCommandTest.java b/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java similarity index 95% rename from src/test/java/io/lettuce/core/commands/StreamCommandTest.java rename to src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java index 6122a7e833..689970cef1 100644 --- a/src/test/java/io/lettuce/core/commands/StreamCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/StreamCommandIntegrationTests.java @@ -21,22 +21,43 @@ import java.time.Instant; import java.util.*; +import javax.inject.Inject; + +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 io.lettuce.core.*; import io.lettuce.core.XReadArgs.StreamOffset; +import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; import io.lettuce.core.models.stream.PendingMessage; import io.lettuce.core.models.stream.PendingParser; import io.lettuce.core.output.NestedMultiOutput; import io.lettuce.core.protocol.CommandArgs; +import io.lettuce.test.LettuceExtension; import io.lettuce.test.condition.EnabledOnCommand; /** * @author Mark Paluch */ +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) @EnabledOnCommand("XADD") -public class StreamCommandTest extends AbstractRedisClientTest { +public class StreamCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected StreamCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void xadd() { diff --git a/src/test/java/io/lettuce/core/commands/StringCommandTest.java b/src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java similarity index 90% rename from src/test/java/io/lettuce/core/commands/StringCommandTest.java rename to src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java index 65e9c5f7d8..1f980d119a 100644 --- a/src/test/java/io/lettuce/core/commands/StringCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/StringCommandIntegrationTests.java @@ -26,18 +26,39 @@ import java.util.List; import java.util.Map; +import javax.inject.Inject; + +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 io.lettuce.core.AbstractRedisClientTest; import io.lettuce.core.KeyValue; import io.lettuce.core.RedisException; +import io.lettuce.core.TestSupport; +import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.test.KeyValueStreamingAdapter; +import io.lettuce.test.LettuceExtension; /** * @author Will Glozer * @author Mark Paluch */ -public class StringCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class StringCommandIntegrationTests extends TestSupport { + + private final RedisCommands redis; + + @Inject + protected StringCommandIntegrationTests(RedisCommands redis) { + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void append() { diff --git a/src/test/java/io/lettuce/core/commands/TransactionCommandTest.java b/src/test/java/io/lettuce/core/commands/TransactionCommandIntegrationTests.java similarity index 77% rename from src/test/java/io/lettuce/core/commands/TransactionCommandTest.java rename to src/test/java/io/lettuce/core/commands/TransactionCommandIntegrationTests.java index de1e89ed12..d7adba8d6e 100644 --- a/src/test/java/io/lettuce/core/commands/TransactionCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/TransactionCommandIntegrationTests.java @@ -18,19 +18,38 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import javax.inject.Inject; + +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 io.lettuce.core.AbstractRedisClientTest; -import io.lettuce.core.RedisCommandExecutionException; -import io.lettuce.core.RedisException; -import io.lettuce.core.TransactionResult; +import io.lettuce.core.*; import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.test.LettuceExtension; /** * @author Will Glozer * @author Mark Paluch */ -public class TransactionCommandTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +public class TransactionCommandIntegrationTests extends TestSupport { + + private final RedisClient client; + private final RedisCommands redis; + + @Inject + protected TransactionCommandIntegrationTests(RedisClient client, RedisCommands redis) { + this.client = client; + this.redis = redis; + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } @Test void discard() { @@ -118,7 +137,7 @@ void errorInMulti() { @Test void execWithoutMulti() { - assertThatThrownBy(() -> redis.exec()).isInstanceOf(RedisCommandExecutionException.class).hasMessageContaining( + assertThatThrownBy(redis::exec).isInstanceOf(RedisCommandExecutionException.class).hasMessageContaining( "ERR EXEC without MULTI"); } @@ -126,7 +145,8 @@ void execWithoutMulti() { void multiCalledTwiceShouldFail() { redis.multi(); - assertThatThrownBy(() -> redis.multi()).isInstanceOf(RedisCommandExecutionException.class).hasMessageContaining( + assertThatThrownBy(redis::multi).isInstanceOf(RedisCommandExecutionException.class).hasMessageContaining( "ERR MULTI calls can not be nested"); + redis.discard(); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/BitReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/BitReactiveCommandIntegrationTests.java similarity index 86% rename from src/test/java/io/lettuce/core/commands/reactive/BitReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/BitReactiveCommandIntegrationTests.java index abb22b8975..ef9facc8f4 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/BitReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/BitReactiveCommandIntegrationTests.java @@ -21,32 +21,30 @@ import static io.lettuce.core.BitFieldArgs.OverflowType.FAIL; import static org.assertj.core.api.Assertions.assertThat; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; import reactor.test.StepVerifier; import io.lettuce.core.BitFieldArgs; +import io.lettuce.core.RedisClient; import io.lettuce.core.Value; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.reactive.RedisStringReactiveCommands; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.BitCommandTest; -import io.lettuce.core.commands.BitStringCodec; +import io.lettuce.core.commands.BitCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class BitReactiveCommandTest extends BitCommandTest { +class BitReactiveCommandIntegrationTests extends BitCommandIntegrationTests { private RedisStringReactiveCommands reactive; - @Override - public RedisCommands connect() { - bitstring = ReactiveSyncInvocationHandler.sync(client.connect(new BitStringCodec())); - - StatefulRedisConnection connection = client.connect(); - reactive = connection.reactive(); - return ReactiveSyncInvocationHandler.sync(connection); + @Inject + BitReactiveCommandIntegrationTests(RedisClient client, StatefulRedisConnection connection) { + super(client, ReactiveSyncInvocationHandler.sync(connection)); + this.reactive = connection.reactive(); } @Test @@ -88,7 +86,7 @@ void bitfieldWithOffsetSet() { assertThat(bitstring.get(key)).isEqualTo("000000000000000010100000"); - redis.del(key); + bitstring.del(key); StepVerifier.create(reactive.bitfield(key, BitFieldArgs.Builder.set(signed(8), offset(2), 5))).expectNextCount(1) .verifyComplete(); assertThat(bitstring.get(key)).isEqualTo("1000000000000010"); diff --git a/src/test/java/io/lettuce/core/commands/reactive/GeoReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/GeoReactiveCommandIntegrationTests.java similarity index 74% rename from src/test/java/io/lettuce/core/commands/reactive/GeoReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/GeoReactiveCommandIntegrationTests.java index 127cc19771..e07ae03dc3 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/GeoReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/GeoReactiveCommandIntegrationTests.java @@ -18,30 +18,35 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.offset; +import javax.inject.Inject; + import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import reactor.test.StepVerifier; +import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.reactive.RedisReactiveCommands; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.GeoCommandTest; +import io.lettuce.core.commands.GeoCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class GeoReactiveCommandTest extends GeoCommandTest { +class GeoReactiveCommandIntegrationTests extends GeoCommandIntegrationTests { - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + private final StatefulRedisConnection connection; + + @Inject + GeoReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + this.connection = connection; } @Test @Override public void geopos() { - RedisReactiveCommands reactive = client.connect().reactive(); + RedisReactiveCommands reactive = connection.reactive(); prepareGeo(); diff --git a/src/test/java/io/lettuce/core/commands/reactive/KeyReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/HLLReactiveCommandIntegrationTests.java similarity index 66% rename from src/test/java/io/lettuce/core/commands/reactive/KeyReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/HLLReactiveCommandIntegrationTests.java index 88f5dfebb3..2556582c59 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/KeyReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/HLLReactiveCommandIntegrationTests.java @@ -15,17 +15,19 @@ */ package io.lettuce.core.commands.reactive; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.KeyCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.HLLCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class KeyReactiveCommandTest extends KeyCommandTest { +class HLLReactiveCommandIntegrationTests extends HLLCommandIntegrationTests { - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + HLLReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/HashReactiveCommandIntegrationTests.java similarity index 66% rename from src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/HashReactiveCommandIntegrationTests.java index 57760d4015..41468d1c0c 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/HashReactiveCommandIntegrationTests.java @@ -15,17 +15,19 @@ */ package io.lettuce.core.commands.reactive; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.ListCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.HashCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class ListReactiveCommandTest extends ListCommandTest { +class HashReactiveCommandIntegrationTests extends HashCommandIntegrationTests { - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + HashReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/HashReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/KeyReactiveCommandIntegrationTests.java similarity index 66% rename from src/test/java/io/lettuce/core/commands/reactive/HashReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/KeyReactiveCommandIntegrationTests.java index 4e936bd14b..73b376f835 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/HashReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/KeyReactiveCommandIntegrationTests.java @@ -15,17 +15,19 @@ */ package io.lettuce.core.commands.reactive; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.HashCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.KeyCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class HashReactiveCommandTest extends HashCommandTest { +class KeyReactiveCommandIntegrationTests extends KeyCommandIntegrationTests { - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + KeyReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandIntegrationTests.java new file mode 100644 index 0000000000..ecc317327b --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/reactive/ListReactiveCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.reactive; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.ListCommandIntegrationTests; +import io.lettuce.test.ReactiveSyncInvocationHandler; + +/** + * @author Mark Paluch + */ +class ListReactiveCommandIntegrationTests extends ListCommandIntegrationTests { + + @Inject + ListReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandIntegrationTests.java new file mode 100644 index 0000000000..41da7b6098 --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.reactive; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.NumericCommandIntegrationTests; +import io.lettuce.test.ReactiveSyncInvocationHandler; + +/** + * @author Mark Paluch + */ +class NumericReactiveCommandIntegrationTests extends NumericCommandIntegrationTests { + + @Inject + NumericReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandTest.java deleted file mode 100644 index b58593cc58..0000000000 --- a/src/test/java/io/lettuce/core/commands/reactive/NumericReactiveCommandTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.reactive; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.NumericCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; - -/** - * @author Mark Paluch - */ -public class NumericReactiveCommandTest extends NumericCommandTest { - - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandIntegrationTests.java new file mode 100644 index 0000000000..8795fe2fe6 --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandIntegrationTests.java @@ -0,0 +1,34 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.reactive; + +import javax.inject.Inject; + +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.ScriptingCommandIntegrationTests; +import io.lettuce.test.ReactiveSyncInvocationHandler; + +/** + * @author Mark Paluch + */ +class ScriptingReactiveCommandIntegrationTests extends ScriptingCommandIntegrationTests { + + @Inject + ScriptingReactiveCommandIntegrationTests(RedisClient client, StatefulRedisConnection connection) { + super(client, ReactiveSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandTest.java deleted file mode 100644 index 5f813a0fbe..0000000000 --- a/src/test/java/io/lettuce/core/commands/reactive/ScriptingReactiveCommandTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.reactive; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.ScriptingCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; - -/** - * @author Mark Paluch - */ -public class ScriptingReactiveCommandTest extends ScriptingCommandTest { - - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/reactive/ServerReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/ServerReactiveCommandIntegrationTests.java similarity index 78% rename from src/test/java/io/lettuce/core/commands/reactive/ServerReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/ServerReactiveCommandIntegrationTests.java index 3795577ce0..f84f1b2aaf 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/ServerReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/ServerReactiveCommandIntegrationTests.java @@ -17,30 +17,27 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.BeforeEach; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.reactive.RedisReactiveCommands; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.ServerCommandTest; +import io.lettuce.core.commands.ServerCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class ServerReactiveCommandTest extends ServerCommandTest { +class ServerReactiveCommandIntegrationTests extends ServerCommandIntegrationTests { private RedisReactiveCommands reactive; - @BeforeEach - public void openConnection() throws Exception { - super.openConnection(); - reactive = redis.getStatefulConnection().reactive(); - } - - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + ServerReactiveCommandIntegrationTests(RedisClient client, StatefulRedisConnection connection) { + super(client, ReactiveSyncInvocationHandler.sync(connection)); + this.reactive = connection.reactive(); } /** diff --git a/src/test/java/io/lettuce/core/commands/reactive/HLLReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandIntegrationTests.java similarity index 66% rename from src/test/java/io/lettuce/core/commands/reactive/HLLReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandIntegrationTests.java index 9097deb5b4..66429071b2 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/HLLReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandIntegrationTests.java @@ -15,17 +15,19 @@ */ package io.lettuce.core.commands.reactive; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.HLLCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.SetCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class HLLReactiveCommandTest extends HLLCommandTest { +class SetReactiveCommandIntegrationTests extends SetCommandIntegrationTests { - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + SetReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandTest.java deleted file mode 100644 index f72b4fc85e..0000000000 --- a/src/test/java/io/lettuce/core/commands/reactive/SetReactiveCommandTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.reactive; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.SetCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; - -/** - * @author Mark Paluch - */ -public class SetReactiveCommandTest extends SetCommandTest { - - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandIntegrationTests.java new file mode 100644 index 0000000000..f554e2b23c --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.reactive; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.SortCommandIntegrationTests; +import io.lettuce.test.ReactiveSyncInvocationHandler; + +/** + * @author Mark Paluch + */ +class SortReactiveCommandIntegrationTests extends SortCommandIntegrationTests { + + @Inject + SortReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandTest.java deleted file mode 100644 index ec8ed19cc0..0000000000 --- a/src/test/java/io/lettuce/core/commands/reactive/SortReactiveCommandTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.reactive; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.SortCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; - -/** - * @author Mark Paluch - */ -public class SortReactiveCommandTest extends SortCommandTest { - - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandIntegrationTests.java new file mode 100644 index 0000000000..9a00eb0daf --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.reactive; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.SortedSetCommandIntegrationTests; +import io.lettuce.test.ReactiveSyncInvocationHandler; + +/** + * @author Mark Paluch + */ +class SortedSetReactiveCommandIntegrationTests extends SortedSetCommandIntegrationTests { + + @Inject + SortedSetReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandTest.java deleted file mode 100644 index 338091d814..0000000000 --- a/src/test/java/io/lettuce/core/commands/reactive/SortedSetReactiveCommandTest.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.reactive; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.SortedSetCommandTest; -import io.lettuce.test.ReactiveSyncInvocationHandler; - -/** - * @author Mark Paluch - */ -public class SortedSetReactiveCommandTest extends SortedSetCommandTest { - - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/reactive/StreamReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/StreamReactiveCommandIntegrationTests.java similarity index 65% rename from src/test/java/io/lettuce/core/commands/reactive/StreamReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/StreamReactiveCommandIntegrationTests.java index 1b28fce9bf..28ee9c6bf8 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/StreamReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/StreamReactiveCommandIntegrationTests.java @@ -15,17 +15,19 @@ */ package io.lettuce.core.commands.reactive; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.StreamCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.StreamCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class StreamReactiveCommandTest extends StreamCommandTest { +class StreamReactiveCommandIntegrationTests extends StreamCommandIntegrationTests { - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + StreamReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/StringReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/StringReactiveCommandIntegrationTests.java similarity index 58% rename from src/test/java/io/lettuce/core/commands/reactive/StringReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/StringReactiveCommandIntegrationTests.java index 59eb6b49be..205169f796 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/StringReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/StringReactiveCommandIntegrationTests.java @@ -15,51 +15,51 @@ */ package io.lettuce.core.commands.reactive; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; import reactor.core.publisher.Flux; import reactor.test.StepVerifier; import io.lettuce.core.KeyValue; import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.reactive.RedisReactiveCommands; import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.StringCommandTest; +import io.lettuce.core.commands.StringCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class StringReactiveCommandTest extends StringCommandTest { +class StringReactiveCommandIntegrationTests extends StringCommandIntegrationTests { + + private final RedisCommands redis; + private final RedisReactiveCommands reactive; - @Override - public RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); + @Inject + StringReactiveCommandIntegrationTests(StatefulRedisConnection connection) { + super(ReactiveSyncInvocationHandler.sync(connection)); + this.redis = connection.sync(); + this.reactive = connection.reactive(); } @Test void mget() { - StatefulRedisConnection connection = client.connect(); - - connection.sync().set(key, value); - connection.sync().set("key1", value); - connection.sync().set("key2", value); + redis.set(key, value); + redis.set("key1", value); + redis.set("key2", value); - Flux> mget = connection.reactive().mget(key, "key1", "key2"); + Flux> mget = reactive.mget(key, "key1", "key2"); StepVerifier.create(mget.next()).expectNext(KeyValue.just(key, value)).verifyComplete(); - - connection.close(); } @Test void mgetEmpty() { - StatefulRedisConnection connection = client.connect(); - - connection.sync().set(key, value); + redis.set(key, value); - Flux> mget = connection.reactive().mget("unknown"); + Flux> mget = reactive.mget("unknown"); StepVerifier.create(mget.next()).expectNext(KeyValue.empty("unknown")).verifyComplete(); - - connection.close(); } } diff --git a/src/test/java/io/lettuce/core/commands/reactive/TransactionReactiveCommandTest.java b/src/test/java/io/lettuce/core/commands/reactive/TransactionReactiveCommandIntegrationTests.java similarity index 81% rename from src/test/java/io/lettuce/core/commands/reactive/TransactionReactiveCommandTest.java rename to src/test/java/io/lettuce/core/commands/reactive/TransactionReactiveCommandIntegrationTests.java index 321f27e411..8a1fad612c 100644 --- a/src/test/java/io/lettuce/core/commands/reactive/TransactionReactiveCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/reactive/TransactionReactiveCommandIntegrationTests.java @@ -17,45 +17,34 @@ import static org.assertj.core.api.Assertions.assertThat; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; import reactor.test.StepVerifier; -import io.lettuce.core.ClientOptions; import io.lettuce.core.KeyValue; +import io.lettuce.core.RedisClient; import io.lettuce.core.RedisException; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.reactive.RedisReactiveCommands; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.TransactionCommandTest; +import io.lettuce.core.commands.TransactionCommandIntegrationTests; import io.lettuce.test.ReactiveSyncInvocationHandler; /** * @author Mark Paluch */ -public class TransactionReactiveCommandTest extends TransactionCommandTest { - - private RedisReactiveCommands commands; - - @Override - protected RedisCommands connect() { - return ReactiveSyncInvocationHandler.sync(client.connect()); - } - - @BeforeEach - public void openConnection() { - client.setOptions(ClientOptions.builder().build()); - redis = connect(); - redis.flushall(); - redis.flushdb(); - - commands = redis.getStatefulConnection().reactive(); - } - - @AfterEach - public void closeConnection() { - redis.getStatefulConnection().close(); +public class TransactionReactiveCommandIntegrationTests extends TransactionCommandIntegrationTests { + + private final RedisClient client; + private final RedisReactiveCommands commands; + private final StatefulRedisConnection connection; + + @Inject + public TransactionReactiveCommandIntegrationTests(RedisClient client, StatefulRedisConnection connection) { + super(client, ReactiveSyncInvocationHandler.sync(connection)); + this.client = client; + this.commands = connection.reactive(); + this.connection = connection; } @Test @@ -87,6 +76,8 @@ void watchRollback() { assertThat(actual).isNotNull(); assertThat(actual.wasDiscarded()).isTrue(); }); + + otherConnection.close(); } @Test @@ -94,7 +85,7 @@ void execSingular() { StepVerifier.create(commands.multi()).expectNext("OK").verifyComplete(); - redis.set(key, value); + connection.sync().set(key, value); StepVerifier.create(commands.exec()).consumeNextWith(actual -> assertThat(actual).contains("OK")).verifyComplete(); StepVerifier.create(commands.get(key)).expectNext(value).verifyComplete(); @@ -111,7 +102,7 @@ void errorInMulti() { StepVerifier.create(commands.exec()).consumeNextWith(actual -> { assertThat((String) actual.get(0)).isEqualTo("OK"); - assertThat(actual.get(1) instanceof RedisException).isTrue(); + assertThat((Object) actual.get(1)).isInstanceOf(RedisException.class); assertThat((String) actual.get(2)).isEqualTo(value); }).verifyComplete(); } diff --git a/src/test/java/io/lettuce/core/commands/transactional/BitTxCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/transactional/BitTxCommandIntegrationTests.java new file mode 100644 index 0000000000..6c173b00c1 --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/transactional/BitTxCommandIntegrationTests.java @@ -0,0 +1,33 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.transactional; + +import javax.inject.Inject; + +import io.lettuce.core.RedisClient; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.BitCommandIntegrationTests; + +/** + * @author Mark Paluch + */ +class BitTxCommandIntegrationTests extends BitCommandIntegrationTests { + + @Inject + BitTxCommandIntegrationTests(RedisClient client, StatefulRedisConnection connection) { + super(client, TxSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/transactional/BitTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/BitTxCommandTest.java deleted file mode 100644 index 0052294565..0000000000 --- a/src/test/java/io/lettuce/core/commands/transactional/BitTxCommandTest.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.transactional; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.BitCommandTest; -import io.lettuce.core.commands.BitStringCodec; - -/** - * @author Mark Paluch - */ -public class BitTxCommandTest extends BitCommandTest { - - @Override - public RedisCommands connect() { - bitstring = TxSyncInvocationHandler.sync(client.connect(new BitStringCodec())); - return TxSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/transactional/GeoTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/GeoTxCommandIntegrationTests.java similarity index 79% rename from src/test/java/io/lettuce/core/commands/transactional/GeoTxCommandTest.java rename to src/test/java/io/lettuce/core/commands/transactional/GeoTxCommandIntegrationTests.java index 1bc26d9b52..4f5e87a10e 100644 --- a/src/test/java/io/lettuce/core/commands/transactional/GeoTxCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/transactional/GeoTxCommandIntegrationTests.java @@ -15,19 +15,21 @@ */ package io.lettuce.core.commands.transactional; +import javax.inject.Inject; + import org.junit.jupiter.api.Disabled; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.GeoCommandTest; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.GeoCommandIntegrationTests; /** * @author Mark Paluch */ -public class GeoTxCommandTest extends GeoCommandTest { +class GeoTxCommandIntegrationTests extends GeoCommandIntegrationTests { - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); + @Inject + GeoTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); } @Disabled diff --git a/src/test/java/io/lettuce/core/commands/transactional/SetTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/HLLTxCommandIntegrationTests.java similarity index 65% rename from src/test/java/io/lettuce/core/commands/transactional/SetTxCommandTest.java rename to src/test/java/io/lettuce/core/commands/transactional/HLLTxCommandIntegrationTests.java index e55ffc2571..26d162ab3b 100644 --- a/src/test/java/io/lettuce/core/commands/transactional/SetTxCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/transactional/HLLTxCommandIntegrationTests.java @@ -15,17 +15,18 @@ */ package io.lettuce.core.commands.transactional; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.SetCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.HLLCommandIntegrationTests; /** * @author Mark Paluch */ -public class SetTxCommandTest extends SetCommandTest { +class HLLTxCommandIntegrationTests extends HLLCommandIntegrationTests { - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); + @Inject + HLLTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); } - } diff --git a/src/test/java/io/lettuce/core/commands/transactional/HLLTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/HashTxCommandIntegrationTests.java similarity index 65% rename from src/test/java/io/lettuce/core/commands/transactional/HLLTxCommandTest.java rename to src/test/java/io/lettuce/core/commands/transactional/HashTxCommandIntegrationTests.java index d3c51a6ef6..4080daaee0 100644 --- a/src/test/java/io/lettuce/core/commands/transactional/HLLTxCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/transactional/HashTxCommandIntegrationTests.java @@ -15,16 +15,18 @@ */ package io.lettuce.core.commands.transactional; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.HLLCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.HashCommandIntegrationTests; /** * @author Mark Paluch */ -public class HLLTxCommandTest extends HLLCommandTest { +class HashTxCommandIntegrationTests extends HashCommandIntegrationTests { - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); + @Inject + HashTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/transactional/KeyTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/KeyTxCommandIntegrationTests.java similarity index 68% rename from src/test/java/io/lettuce/core/commands/transactional/KeyTxCommandTest.java rename to src/test/java/io/lettuce/core/commands/transactional/KeyTxCommandIntegrationTests.java index 1c6824af70..404f8b02cf 100644 --- a/src/test/java/io/lettuce/core/commands/transactional/KeyTxCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/transactional/KeyTxCommandIntegrationTests.java @@ -15,19 +15,21 @@ */ package io.lettuce.core.commands.transactional; +import javax.inject.Inject; + import org.junit.jupiter.api.Disabled; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.KeyCommandTest; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.KeyCommandIntegrationTests; /** * @author Mark Paluch */ -public class KeyTxCommandTest extends KeyCommandTest { +public class KeyTxCommandIntegrationTests extends KeyCommandIntegrationTests { - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); + @Inject + KeyTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); } @Disabled diff --git a/src/test/java/io/lettuce/core/commands/transactional/HashTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/ListTxCommandIntegrationTests.java similarity index 65% rename from src/test/java/io/lettuce/core/commands/transactional/HashTxCommandTest.java rename to src/test/java/io/lettuce/core/commands/transactional/ListTxCommandIntegrationTests.java index 568968bc2f..e1ab52159c 100644 --- a/src/test/java/io/lettuce/core/commands/transactional/HashTxCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/transactional/ListTxCommandIntegrationTests.java @@ -15,16 +15,18 @@ */ package io.lettuce.core.commands.transactional; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.HashCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.ListCommandIntegrationTests; /** * @author Mark Paluch */ -public class HashTxCommandTest extends HashCommandTest { +class ListTxCommandIntegrationTests extends ListCommandIntegrationTests { - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); + @Inject + ListTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/transactional/ListTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/SetTxCommandIntegrationTests.java similarity index 65% rename from src/test/java/io/lettuce/core/commands/transactional/ListTxCommandTest.java rename to src/test/java/io/lettuce/core/commands/transactional/SetTxCommandIntegrationTests.java index dc99b1f90d..0c3fd1cbfa 100644 --- a/src/test/java/io/lettuce/core/commands/transactional/ListTxCommandTest.java +++ b/src/test/java/io/lettuce/core/commands/transactional/SetTxCommandIntegrationTests.java @@ -15,16 +15,18 @@ */ package io.lettuce.core.commands.transactional; -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.ListCommandTest; +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.SetCommandIntegrationTests; /** * @author Mark Paluch */ -public class ListTxCommandTest extends ListCommandTest { +class SetTxCommandIntegrationTests extends SetCommandIntegrationTests { - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); + @Inject + SetTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); } } diff --git a/src/test/java/io/lettuce/core/commands/transactional/SortTxCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/transactional/SortTxCommandIntegrationTests.java new file mode 100644 index 0000000000..ad11ebf15d --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/transactional/SortTxCommandIntegrationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.transactional; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.SortCommandIntegrationTests; + +/** + * @author Mark Paluch + */ +class SortTxCommandIntegrationTests extends SortCommandIntegrationTests { + + @Inject + SortTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/transactional/SortTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/SortTxCommandTest.java deleted file mode 100644 index 9ea67e5631..0000000000 --- a/src/test/java/io/lettuce/core/commands/transactional/SortTxCommandTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.transactional; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.SortCommandTest; - -/** - * @author Mark Paluch - */ -public class SortTxCommandTest extends SortCommandTest { - - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandIntegrationTests.java new file mode 100644 index 0000000000..1ea88c364c --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandIntegrationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.transactional; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.SortedSetCommandIntegrationTests; + +/** + * @author Mark Paluch + */ +class SortedSetTxCommandIntegrationTests extends SortedSetCommandIntegrationTests { + + @Inject + SortedSetTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandTest.java deleted file mode 100644 index caa7f54044..0000000000 --- a/src/test/java/io/lettuce/core/commands/transactional/SortedSetTxCommandTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.transactional; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.SortedSetCommandTest; - -/** - * @author Mark Paluch - */ -public class SortedSetTxCommandTest extends SortedSetCommandTest { - - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/commands/transactional/StringTxCommandIntegrationTests.java b/src/test/java/io/lettuce/core/commands/transactional/StringTxCommandIntegrationTests.java new file mode 100644 index 0000000000..8e359295e5 --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/transactional/StringTxCommandIntegrationTests.java @@ -0,0 +1,32 @@ +/* + * Copyright 2011-2018 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 + * + * http://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 io.lettuce.core.commands.transactional; + +import javax.inject.Inject; + +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.commands.StringCommandIntegrationTests; + +/** + * @author Mark Paluch + */ +class StringTxCommandIntegrationTests extends StringCommandIntegrationTests { + + @Inject + StringTxCommandIntegrationTests(StatefulRedisConnection connection) { + super(TxSyncInvocationHandler.sync(connection)); + } +} diff --git a/src/test/java/io/lettuce/core/commands/transactional/StringTxCommandTest.java b/src/test/java/io/lettuce/core/commands/transactional/StringTxCommandTest.java deleted file mode 100644 index f60c2fac0d..0000000000 --- a/src/test/java/io/lettuce/core/commands/transactional/StringTxCommandTest.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2011-2018 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 - * - * http://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 io.lettuce.core.commands.transactional; - -import io.lettuce.core.api.sync.RedisCommands; -import io.lettuce.core.commands.StringCommandTest; - -/** - * @author Mark Paluch - */ -public class StringTxCommandTest extends StringCommandTest { - - @Override - public RedisCommands connect() { - return TxSyncInvocationHandler.sync(client.connect()); - } -} diff --git a/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java b/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java index e268149370..bbddf41d83 100644 --- a/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java +++ b/src/test/java/io/lettuce/core/dynamic/RedisCommandsBatchingIntegrationTests.java @@ -22,6 +22,7 @@ import javax.inject.Inject; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -52,6 +53,11 @@ class RedisCommandsBatchingIntegrationTests extends TestSupport { this.redis = connection.sync(); } + @BeforeEach + void setUp() { + this.redis.flushall(); + } + @Test void selectiveBatching() { diff --git a/src/test/java/io/lettuce/core/event/ConnectionEventsTriggeredTest.java b/src/test/java/io/lettuce/core/event/ConnectionEventsTriggeredIntegrationTests.java similarity index 96% rename from src/test/java/io/lettuce/core/event/ConnectionEventsTriggeredTest.java rename to src/test/java/io/lettuce/core/event/ConnectionEventsTriggeredIntegrationTests.java index fed5cacb26..3c2cd6e8e8 100644 --- a/src/test/java/io/lettuce/core/event/ConnectionEventsTriggeredTest.java +++ b/src/test/java/io/lettuce/core/event/ConnectionEventsTriggeredIntegrationTests.java @@ -33,7 +33,7 @@ /** * @author Mark Paluch */ -class ConnectionEventsTriggeredTest extends TestSupport { +class ConnectionEventsTriggeredIntegrationTests extends TestSupport { @Test void testConnectionEvents() { diff --git a/src/test/java/io/lettuce/core/masterslave/CustomCommandTest.java b/src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java similarity index 98% rename from src/test/java/io/lettuce/core/masterslave/CustomCommandTest.java rename to src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java index 843c3077d8..535cbe303e 100644 --- a/src/test/java/io/lettuce/core/masterslave/CustomCommandTest.java +++ b/src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java @@ -42,7 +42,7 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) -public class CustomCommandTest extends TestSupport { +class CustomCommandIntegrationTests extends TestSupport { private final RedisClient redisClient; @@ -50,7 +50,7 @@ public class CustomCommandTest extends TestSupport { private RedisCommands redis; @Inject - CustomCommandTest(RedisClient redisClient) { + CustomCommandIntegrationTests(RedisClient redisClient) { this.redisClient = redisClient; } diff --git a/src/test/java/io/lettuce/core/protocol/ConnectionFailureTest.java b/src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java similarity index 94% rename from src/test/java/io/lettuce/core/protocol/ConnectionFailureTest.java rename to src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java index 71e608e935..dcf89a3128 100644 --- a/src/test/java/io/lettuce/core/protocol/ConnectionFailureTest.java +++ b/src/test/java/io/lettuce/core/protocol/ConnectionFailureIntegrationTests.java @@ -24,25 +24,34 @@ import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; +import javax.inject.Inject; + import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.test.util.ReflectionTestUtils; import io.lettuce.core.*; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.async.RedisAsyncCommands; -import io.lettuce.test.ConnectionTestUtil; -import io.lettuce.test.Delay; -import io.lettuce.test.Futures; -import io.lettuce.test.Wait; +import io.lettuce.test.*; import io.lettuce.test.server.RandomResponseServer; import io.lettuce.test.settings.TestSettings; /** * @author Mark Paluch */ -class ConnectionFailureTest extends AbstractRedisClientTest { +@ExtendWith(LettuceExtension.class) +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class ConnectionFailureIntegrationTests extends TestSupport { + + private final RedisClient client; + private final RedisURI defaultRedisUri = RedisURI.Builder.redis(TestSettings.host(), TestSettings.port()).build(); - private RedisURI defaultRedisUri = RedisURI.Builder.redis(TestSettings.host(), TestSettings.port()).build(); + @Inject + ConnectionFailureIntegrationTests(RedisClient client) { + this.client = client; + } /** * Expect to run into Invalid first byte exception instead of timeout. diff --git a/src/test/java/io/lettuce/core/tracing/BraveTracingTest.java b/src/test/java/io/lettuce/core/tracing/BraveTracingIntegrationTests.java similarity index 93% rename from src/test/java/io/lettuce/core/tracing/BraveTracingTest.java rename to src/test/java/io/lettuce/core/tracing/BraveTracingIntegrationTests.java index 06c29a90d8..d3def21ae7 100644 --- a/src/test/java/io/lettuce/core/tracing/BraveTracingTest.java +++ b/src/test/java/io/lettuce/core/tracing/BraveTracingIntegrationTests.java @@ -47,7 +47,7 @@ /** * @author Mark Paluch */ -class BraveTracingTest extends TestSupport { +class BraveTracingIntegrationTests extends TestSupport { private static ClientResources clientResources; private static RedisClient client; @@ -93,7 +93,7 @@ void pingWithTrace() { foo.finish(); - List spans = new ArrayList<>(BraveTracingTest.spans); + List spans = new ArrayList<>(BraveTracingIntegrationTests.spans); assertThat(spans.get(0).name()).isEqualTo("ping"); assertThat(spans.get(1).name()).isEqualTo("foo"); @@ -115,7 +115,7 @@ void pingWithTraceShouldCatchErrors() { foo.finish(); - List spans = new ArrayList<>(BraveTracingTest.spans); + List spans = new ArrayList<>(BraveTracingIntegrationTests.spans); assertThat(spans.get(0).name()).isEqualTo("set"); assertThat(spans.get(1).name()).isEqualTo("hgetall"); @@ -149,7 +149,7 @@ void reactivePingWithTrace() { trace.finish(); - List spans = new ArrayList<>(BraveTracingTest.spans); + List spans = new ArrayList<>(BraveTracingIntegrationTests.spans); assertThat(spans.get(0).name()).isEqualTo("ping"); assertThat(spans.get(1).name()).isEqualTo("foo"); @@ -171,7 +171,7 @@ void reactiveGetAndSetWithTrace() { trace.finish(); - List spans = new ArrayList<>(BraveTracingTest.spans); + List spans = new ArrayList<>(BraveTracingIntegrationTests.spans); assertThat(spans.get(0).name()).isEqualTo("set"); assertThat(spans.get(1).name()).isEqualTo("get"); @@ -197,7 +197,7 @@ void reactiveGetAndSetWithTraceProvider() { trace.finish(); - List spans = new ArrayList<>(BraveTracingTest.spans); + List spans = new ArrayList<>(BraveTracingIntegrationTests.spans); assertThat(spans.get(0).name()).isEqualTo("set"); assertThat(spans.get(1).name()).isEqualTo("get"); diff --git a/src/test/java/io/lettuce/test/KeysAndValues.java b/src/test/java/io/lettuce/test/KeysAndValues.java index 08408dd00b..2b024d139b 100644 --- a/src/test/java/io/lettuce/test/KeysAndValues.java +++ b/src/test/java/io/lettuce/test/KeysAndValues.java @@ -42,7 +42,7 @@ public class KeysAndValues { /** * Number of entries. */ - public final static int COUNT = 500; + public static final int COUNT = 500; static { diff --git a/src/test/java/io/lettuce/test/LettuceExtension.java b/src/test/java/io/lettuce/test/LettuceExtension.java index 16eee62894..fbd0d66cc6 100644 --- a/src/test/java/io/lettuce/test/LettuceExtension.java +++ b/src/test/java/io/lettuce/test/LettuceExtension.java @@ -24,6 +24,7 @@ import java.lang.reflect.Type; import java.time.Duration; import java.util.*; +import java.util.function.Function; import java.util.function.Supplier; import javax.enterprise.inject.New; @@ -35,6 +36,7 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.api.StatefulConnection; 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.dynamic.support.ResolvableType; @@ -94,23 +96,25 @@ * @see AfterEachCallback * @see AfterAllCallback */ -public class LettuceExtension implements ParameterResolver, BeforeEachCallback, AfterAllCallback, AfterEachCallback { +public class LettuceExtension implements ParameterResolver, AfterAllCallback, AfterEachCallback { - private final static InternalLogger LOGGER = InternalLoggerFactory.getInstance(LettuceExtension.class); + private static final InternalLogger LOGGER = InternalLoggerFactory.getInstance(LettuceExtension.class); private final ExtensionContext.Namespace LETTUCE = ExtensionContext.Namespace.create("lettuce.parameters"); - private final static Set> SUPPORTED_INJECTABLE_TYPES = new HashSet<>(Arrays.asList(StatefulRedisConnection.class, - StatefulRedisPubSubConnection.class, RedisClient.class, ClientResources.class, + private static final Set> SUPPORTED_INJECTABLE_TYPES = new HashSet<>(Arrays.asList(StatefulRedisConnection.class, + StatefulRedisPubSubConnection.class, RedisCommands.class, RedisClient.class, ClientResources.class, StatefulRedisClusterConnection.class, RedisClusterClient.class)); - private final static Set> CLOSE_AFTER_EACH = new HashSet<>(Arrays.asList(StatefulRedisConnection.class, + private static final Set> CLOSE_AFTER_EACH = new HashSet<>(Arrays.asList(StatefulRedisConnection.class, StatefulRedisPubSubConnection.class, StatefulRedisClusterConnection.class)); - private final static List> SUPPLIERS = Arrays.asList(ClientResourcesSupplier.INSTANCE, + private static final List> SUPPLIERS = Arrays.asList(ClientResourcesSupplier.INSTANCE, RedisClusterClientSupplier.INSTANCE, RedisClientSupplier.INSTANCE, StatefulRedisConnectionSupplier.INSTANCE, StatefulRedisPubSubConnectionSupplier.INSTANCE, StatefulRedisClusterConnectionSupplier.INSTANCE); + private static final List> RESOURCE_FUNCTIONS = Arrays.asList(RedisCommandsFunction.INSTANCE); + @Override public boolean supportsParameter(ParameterContext parameterContext, ExtensionContext extensionContext) throws ParameterResolutionException { @@ -137,9 +141,10 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte Parameter parameter = parameterContext.getParameter(); + Type parameterizedType = parameter.getParameterizedType(); if (parameterContext.isAnnotated(New.class)) { - Object instance = findSupplier(parameter.getParameterizedType()).get(); + Object instance = doGetInstance(parameterizedType); if (instance instanceof Closeable || instance instanceof AutoCloseable) { @@ -152,7 +157,14 @@ public Object resolveParameter(ParameterContext parameterContext, ExtensionConte return instance; } - return store.getOrComputeIfAbsent(parameter.getType(), it -> findSupplier(parameter.getParameterizedType()).get()); + return store.getOrComputeIfAbsent(parameter.getType(), it -> doGetInstance(parameterizedType)); + } + + private Object doGetInstance(Type parameterizedType) { + + Optional resourceFunction = findFunction(parameterizedType); + return resourceFunction.map(it -> it.function.apply(findSupplier(it.dependsOn.getType()).get())).orElseGet( + () -> findSupplier(parameterizedType).get()); } /** @@ -190,23 +202,6 @@ public void afterAll(ExtensionContext context) { }); } - @Override - public void beforeEach(ExtensionContext context) { - - ExtensionContext.Store store = getStore(context); - StatefulRedisConnection connection = store.get(StatefulRedisConnection.class, StatefulRedisConnection.class); - StatefulRedisPubSubConnection pubsub = store.get(StatefulRedisPubSubConnection.class, - StatefulRedisPubSubConnection.class); - - if (connection != null || pubsub != null) { - if (connection != null) { - connection.sync().flushall(); - } else if (pubsub != null) { - pubsub.sync().flushall(); - } - } - } - @Override public void afterEach(ExtensionContext context) { @@ -254,6 +249,19 @@ private static Supplier findSupplier(Type type) { return (Supplier) supplier; } + private static Optional findFunction(Type type) { + + ResolvableType requested = ResolvableType.forType(type); + + return RESOURCE_FUNCTIONS.stream().map(it -> { + + ResolvableType dependsOn = ResolvableType.forType(it.getClass()).as(Function.class).getGeneric(0); + ResolvableType providedType = ResolvableType.forType(it.getClass()).as(Function.class).getGeneric(1); + + return new ResourceFunction(dependsOn, providedType, it); + }).filter(it -> requested.isAssignableFrom(it.provides)).findFirst(); + } + @Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface Connection { @@ -263,6 +271,19 @@ private static Supplier findSupplier(Type type) { static class CloseAfterTest extends ArrayList { } + static class ResourceFunction { + + final ResolvableType dependsOn; + final ResolvableType provides; + final Function function; + + public ResourceFunction(ResolvableType dependsOn, ResolvableType provides, Function function) { + this.dependsOn = dependsOn; + this.provides = provides; + this.function = (Function) function; + } + } + enum ClientResourcesSupplier implements Supplier { INSTANCE; @@ -322,4 +343,13 @@ public StatefulRedisClusterConnection get() { return RedisClusterClientSupplier.INSTANCE.get().connect(); } } + + enum RedisCommandsFunction implements Function, RedisCommands> { + INSTANCE; + + @Override + public RedisCommands apply(StatefulRedisConnection connection) { + return connection.sync(); + } + } } diff --git a/src/test/java/io/lettuce/test/Wait.java b/src/test/java/io/lettuce/test/Wait.java index 337940cfe1..5d97f28e44 100644 --- a/src/test/java/io/lettuce/test/Wait.java +++ b/src/test/java/io/lettuce/test/Wait.java @@ -290,7 +290,7 @@ private boolean success(WaitCondition condition, Timeout timeout) throws Excepti static class Timeout { - private final static Clock clock = Clock.systemDefaultZone(); + private static final Clock clock = Clock.systemDefaultZone(); private final Instant timeout; private Timeout(Instant timeout) { diff --git a/src/test/java/io/lettuce/test/condition/EnabledOnCommand.java b/src/test/java/io/lettuce/test/condition/EnabledOnCommand.java index 888b4f96ab..f99021824f 100644 --- a/src/test/java/io/lettuce/test/condition/EnabledOnCommand.java +++ b/src/test/java/io/lettuce/test/condition/EnabledOnCommand.java @@ -28,6 +28,7 @@ */ @Target({ ElementType.TYPE, ElementType.METHOD }) @Retention(RetentionPolicy.RUNTIME) +@Inherited @Documented @ExtendWith(EnabledOnCommandCondition.class) public @interface EnabledOnCommand { diff --git a/src/test/java/io/lettuce/test/resource/DefaultRedisClient.java b/src/test/java/io/lettuce/test/resource/DefaultRedisClient.java index b926c4ec96..1ad36a6b3d 100644 --- a/src/test/java/io/lettuce/test/resource/DefaultRedisClient.java +++ b/src/test/java/io/lettuce/test/resource/DefaultRedisClient.java @@ -26,7 +26,7 @@ */ public class DefaultRedisClient { - private final static DefaultRedisClient instance = new DefaultRedisClient(); + private static final DefaultRedisClient instance = new DefaultRedisClient(); private RedisClient redisClient; diff --git a/src/test/java/io/lettuce/test/resource/DefaultRedisClusterClient.java b/src/test/java/io/lettuce/test/resource/DefaultRedisClusterClient.java index 20a23de222..37a38513f4 100644 --- a/src/test/java/io/lettuce/test/resource/DefaultRedisClusterClient.java +++ b/src/test/java/io/lettuce/test/resource/DefaultRedisClusterClient.java @@ -25,7 +25,7 @@ */ public class DefaultRedisClusterClient { - private final static DefaultRedisClusterClient instance = new DefaultRedisClusterClient(); + private static final DefaultRedisClusterClient instance = new DefaultRedisClusterClient(); private RedisClusterClient redisClient; diff --git a/src/test/java/io/lettuce/test/resource/TestClientResources.java b/src/test/java/io/lettuce/test/resource/TestClientResources.java index 678a6816a6..2d81df2a99 100644 --- a/src/test/java/io/lettuce/test/resource/TestClientResources.java +++ b/src/test/java/io/lettuce/test/resource/TestClientResources.java @@ -29,7 +29,7 @@ */ public class TestClientResources { - private final static TestClientResources instance = new TestClientResources(); + private static final TestClientResources instance = new TestClientResources(); private ClientResources clientResources = create(); /** diff --git a/src/test/jmh/io/lettuce/core/cluster/models/partitions/RedisClusterNodeBenchmark.java b/src/test/jmh/io/lettuce/core/cluster/models/partitions/RedisClusterNodeBenchmark.java index aea94f9a0f..7e6f7c6509 100644 --- a/src/test/jmh/io/lettuce/core/cluster/models/partitions/RedisClusterNodeBenchmark.java +++ b/src/test/jmh/io/lettuce/core/cluster/models/partitions/RedisClusterNodeBenchmark.java @@ -32,10 +32,10 @@ @State(Scope.Benchmark) public class RedisClusterNodeBenchmark { - private final static List ALL_SLOTS = IntStream.range(0, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()); - private final static List LOWER_SLOTS = IntStream.range(0, 8192).boxed().collect(Collectors.toList()); + private static final List ALL_SLOTS = IntStream.range(0, SlotHash.SLOT_COUNT).boxed().collect(Collectors.toList()); + private static final List LOWER_SLOTS = IntStream.range(0, 8192).boxed().collect(Collectors.toList()); - private final static RedisClusterNode NODE = new RedisClusterNode(null, null, true, null, 0, 0, 0, ALL_SLOTS, + private static final RedisClusterNode NODE = new RedisClusterNode(null, null, true, null, 0, 0, 0, ALL_SLOTS, Collections.emptySet()); @Benchmark diff --git a/src/test/jmh/io/lettuce/core/protocol/EmptyChannel.java b/src/test/jmh/io/lettuce/core/protocol/EmptyChannel.java index 5e98216f7a..8497ab25d0 100644 --- a/src/test/jmh/io/lettuce/core/protocol/EmptyChannel.java +++ b/src/test/jmh/io/lettuce/core/protocol/EmptyChannel.java @@ -12,7 +12,7 @@ */ class EmptyChannel implements Channel { - private final static ChannelConfig CONFIG = new EmptyConfig(); + private static final ChannelConfig CONFIG = new EmptyConfig(); @Override public ChannelId id() { diff --git a/src/test/jmh/io/lettuce/core/protocol/EmptyContext.java b/src/test/jmh/io/lettuce/core/protocol/EmptyContext.java index e715171e0f..7034aa1c16 100644 --- a/src/test/jmh/io/lettuce/core/protocol/EmptyContext.java +++ b/src/test/jmh/io/lettuce/core/protocol/EmptyContext.java @@ -30,7 +30,7 @@ */ class EmptyContext implements ChannelHandlerContext { - private final static Channel CHANNEL = new EmptyChannel(); + private static final Channel CHANNEL = new EmptyChannel(); @Override public Channel channel() {