diff --git a/src/main/java/io/lettuce/core/BitFieldArgs.java b/src/main/java/io/lettuce/core/BitFieldArgs.java index d63479e08e..df9927e8a7 100644 --- a/src/main/java/io/lettuce/core/BitFieldArgs.java +++ b/src/main/java/io/lettuce/core/BitFieldArgs.java @@ -15,6 +15,7 @@ */ package io.lettuce.core; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -22,7 +23,6 @@ import io.lettuce.core.internal.LettuceAssert; import io.lettuce.core.protocol.CommandArgs; import io.lettuce.core.protocol.CommandType; -import io.lettuce.core.protocol.LettuceCharsets; import io.lettuce.core.protocol.ProtocolKeyword; /** @@ -566,7 +566,7 @@ public enum OverflowType implements ProtocolKeyword { public final byte[] bytes; OverflowType() { - bytes = name().getBytes(LettuceCharsets.ASCII); + bytes = name().getBytes(StandardCharsets.US_ASCII); } @Override diff --git a/src/main/java/io/lettuce/core/LettuceStrings.java b/src/main/java/io/lettuce/core/LettuceStrings.java index 64e5fa01d7..55be46e047 100644 --- a/src/main/java/io/lettuce/core/LettuceStrings.java +++ b/src/main/java/io/lettuce/core/LettuceStrings.java @@ -16,6 +16,8 @@ package io.lettuce.core; import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.Collection; diff --git a/src/main/java/io/lettuce/core/RedisURI.java b/src/main/java/io/lettuce/core/RedisURI.java index 714fa66d44..2db323d8f4 100644 --- a/src/main/java/io/lettuce/core/RedisURI.java +++ b/src/main/java/io/lettuce/core/RedisURI.java @@ -24,6 +24,7 @@ import java.net.SocketAddress; import java.net.URI; import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.*; import java.util.function.LongFunction; @@ -32,7 +33,6 @@ import io.lettuce.core.internal.HostAndPort; import io.lettuce.core.internal.LettuceAssert; import io.lettuce.core.internal.LettuceSets; -import io.lettuce.core.protocol.LettuceCharsets; /** * Redis URI. Contains connection details for the Redis/Sentinel connections. You can provide the database, client name, @@ -706,7 +706,7 @@ private String getScheme() { */ private static String urlEncode(String str) { try { - return URLEncoder.encode(str, LettuceCharsets.UTF8.name()).replaceAll("%2F", "/"); + return URLEncoder.encode(str, StandardCharsets.UTF_8.name()).replaceAll("%2F", "/"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } diff --git a/src/main/java/io/lettuce/core/UnblockType.java b/src/main/java/io/lettuce/core/UnblockType.java index 07cdfd18a2..cf21909e22 100644 --- a/src/main/java/io/lettuce/core/UnblockType.java +++ b/src/main/java/io/lettuce/core/UnblockType.java @@ -15,7 +15,8 @@ */ package io.lettuce.core; -import io.lettuce.core.protocol.LettuceCharsets; +import java.nio.charset.StandardCharsets; + import io.lettuce.core.protocol.ProtocolKeyword; /** @@ -31,7 +32,7 @@ public enum UnblockType implements ProtocolKeyword { private final byte[] bytes; UnblockType() { - bytes = name().getBytes(LettuceCharsets.ASCII); + bytes = name().getBytes(StandardCharsets.US_ASCII); } @Override diff --git a/src/main/java/io/lettuce/core/codec/StringCodec.java b/src/main/java/io/lettuce/core/codec/StringCodec.java index 209f6c7d76..79707b54d0 100644 --- a/src/main/java/io/lettuce/core/codec/StringCodec.java +++ b/src/main/java/io/lettuce/core/codec/StringCodec.java @@ -17,13 +17,9 @@ import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.CharacterCodingException; -import java.nio.charset.Charset; -import java.nio.charset.CharsetEncoder; -import java.nio.charset.CoderResult; +import java.nio.charset.*; import io.lettuce.core.internal.LettuceAssert; -import io.lettuce.core.protocol.LettuceCharsets; import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufUtil; import io.netty.buffer.Unpooled; @@ -38,8 +34,8 @@ */ public class StringCodec implements RedisCodec, ToByteBufEncoder { - public static final StringCodec UTF8 = new StringCodec(LettuceCharsets.UTF8); - public static final StringCodec ASCII = new StringCodec(LettuceCharsets.ASCII); + public static final StringCodec UTF8 = new StringCodec(StandardCharsets.UTF_8); + public static final StringCodec ASCII = new StringCodec(StandardCharsets.US_ASCII); private static final byte[] EMPTY = new byte[0]; diff --git a/src/main/java/io/lettuce/core/codec/Utf8StringCodec.java b/src/main/java/io/lettuce/core/codec/Utf8StringCodec.java index cdd49e7921..42d19e96f4 100644 --- a/src/main/java/io/lettuce/core/codec/Utf8StringCodec.java +++ b/src/main/java/io/lettuce/core/codec/Utf8StringCodec.java @@ -15,7 +15,7 @@ */ package io.lettuce.core.codec; -import io.lettuce.core.protocol.LettuceCharsets; +import java.nio.charset.StandardCharsets; /** * A {@link RedisCodec} that handles UTF-8 encoded keys and values. @@ -23,7 +23,7 @@ * @author Will Glozer * @author Mark Paluch * @see StringCodec - * @see LettuceCharsets#UTF8 + * @see StandardCharsets#UTF_8 * @deprecated since 5.2, use {@link StringCodec#UTF8} instead. */ @Deprecated @@ -33,6 +33,6 @@ public class Utf8StringCodec extends StringCodec implements RedisCodec connection) { - this(connection, LettuceLists.newList(new ByteArrayCodec(), new StringCodec(LettuceCharsets.UTF8))); + this(connection, LettuceLists.newList(new ByteArrayCodec(), new StringCodec(StandardCharsets.UTF_8))); } /** diff --git a/src/main/java/io/lettuce/core/masterslave/SentinelTopologyRefresh.java b/src/main/java/io/lettuce/core/masterslave/SentinelTopologyRefresh.java index 6309c5eaaf..3cbeece3b7 100644 --- a/src/main/java/io/lettuce/core/masterslave/SentinelTopologyRefresh.java +++ b/src/main/java/io/lettuce/core/masterslave/SentinelTopologyRefresh.java @@ -16,6 +16,7 @@ package io.lettuce.core.masterslave; import java.io.Closeable; +import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.*; import java.util.concurrent.*; @@ -31,7 +32,6 @@ import io.lettuce.core.internal.AsyncCloseable; import io.lettuce.core.internal.Futures; import io.lettuce.core.internal.LettuceLists; -import io.lettuce.core.protocol.LettuceCharsets; import io.lettuce.core.pubsub.RedisPubSubAdapter; import io.lettuce.core.pubsub.StatefulRedisPubSubConnection; import io.netty.util.concurrent.EventExecutorGroup; @@ -48,7 +48,7 @@ class SentinelTopologyRefresh implements AsyncCloseable, Closeable { private static final InternalLogger LOG = InternalLoggerFactory.getInstance(SentinelTopologyRefresh.class); - private static final StringCodec CODEC = new StringCodec(LettuceCharsets.ASCII); + private static final StringCodec CODEC = new StringCodec(StandardCharsets.US_ASCII); private static final Set PROCESSING_CHANNELS = new HashSet<>( Arrays.asList("failover-end", "failover-end-for-timeout")); @@ -155,8 +155,8 @@ private CompletionStage initializeSentinels() { SentinelTopologyRefreshConnections collector = collectConnections(connectionFutures); - CompletionStage completionStage = collector.getOrTimeout(timeout, redisClient - .getResources().eventExecutorGroup()); + CompletionStage completionStage = collector.getOrTimeout(timeout, + redisClient.getResources().eventExecutorGroup()); return completionStage.whenComplete((aVoid, throwable) -> { @@ -359,8 +359,8 @@ interface MessagePredicate extends BiPredicate { private static class TopologyRefreshMessagePredicate implements MessagePredicate { private final String masterId; - private Set TOPOLOGY_CHANGE_CHANNELS = new HashSet<>(Arrays.asList("+slave", "+sdown", "-sdown", - "fix-slave-config", "+convert-to-slave", "+role-change")); + private Set TOPOLOGY_CHANGE_CHANNELS = new HashSet<>( + Arrays.asList("+slave", "+sdown", "-sdown", "fix-slave-config", "+convert-to-slave", "+role-change")); TopologyRefreshMessagePredicate(String masterId) { this.masterId = masterId; diff --git a/src/main/java/io/lettuce/core/output/StatusOutput.java b/src/main/java/io/lettuce/core/output/StatusOutput.java index bbe5b1503a..7889834d5e 100644 --- a/src/main/java/io/lettuce/core/output/StatusOutput.java +++ b/src/main/java/io/lettuce/core/output/StatusOutput.java @@ -15,9 +15,8 @@ */ package io.lettuce.core.output; -import static io.lettuce.core.protocol.LettuceCharsets.buffer; - import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import io.lettuce.core.codec.RedisCodec; @@ -30,7 +29,7 @@ */ public class StatusOutput extends CommandOutput { - private static final ByteBuffer OK = buffer("OK"); + private static final ByteBuffer OK = StandardCharsets.US_ASCII.encode("OK"); public StatusOutput(RedisCodec codec) { super(codec, null); diff --git a/src/main/java/io/lettuce/core/protocol/CommandArgs.java b/src/main/java/io/lettuce/core/protocol/CommandArgs.java index 876a616ee2..24402e73aa 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandArgs.java +++ b/src/main/java/io/lettuce/core/protocol/CommandArgs.java @@ -16,6 +16,7 @@ package io.lettuce.core.protocol; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Base64; import java.util.List; @@ -47,7 +48,7 @@ */ public class CommandArgs { - static final byte[] CRLF = "\r\n".getBytes(LettuceCharsets.ASCII); + static final byte[] CRLF = "\r\n".getBytes(StandardCharsets.US_ASCII); protected final RedisCodec codec; diff --git a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java index a30fd7140c..3dfc82b84f 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandKeyword.java +++ b/src/main/java/io/lettuce/core/protocol/CommandKeyword.java @@ -15,6 +15,8 @@ */ package io.lettuce.core.protocol; +import java.nio.charset.StandardCharsets; + /** * Keyword modifiers for redis commands. * @@ -45,7 +47,7 @@ public enum CommandKeyword implements ProtocolKeyword { public final byte[] bytes; private CommandKeyword() { - bytes = name().getBytes(LettuceCharsets.ASCII); + bytes = name().getBytes(StandardCharsets.US_ASCII); } @Override diff --git a/src/main/java/io/lettuce/core/protocol/CommandType.java b/src/main/java/io/lettuce/core/protocol/CommandType.java index 5be32d7ca7..d788993fdd 100644 --- a/src/main/java/io/lettuce/core/protocol/CommandType.java +++ b/src/main/java/io/lettuce/core/protocol/CommandType.java @@ -15,6 +15,8 @@ */ package io.lettuce.core.protocol; +import java.nio.charset.StandardCharsets; + /** * Redis commands. * @@ -102,7 +104,7 @@ public enum CommandType implements ProtocolKeyword { public final byte[] bytes; CommandType() { - bytes = name().getBytes(LettuceCharsets.ASCII); + bytes = name().getBytes(StandardCharsets.US_ASCII); } @Override diff --git a/src/main/java/io/lettuce/core/protocol/LettuceCharsets.java b/src/main/java/io/lettuce/core/protocol/LettuceCharsets.java deleted file mode 100644 index 245b62c483..0000000000 --- a/src/main/java/io/lettuce/core/protocol/LettuceCharsets.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2011-2019 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.protocol; - -import java.nio.ByteBuffer; -import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; - -/** - * {@link Charset}-related utilities. - * - * @author Will Glozer - */ -public class LettuceCharsets { - - /** - * US-ASCII charset. - */ - public static final Charset ASCII = StandardCharsets.US_ASCII; - - /** - * UTF-8 charset. - */ - public static final Charset UTF8 = StandardCharsets.UTF_8; - - /** - * Utility constructor. - */ - private LettuceCharsets() { - - } - - /** - * Create a ByteBuffer from a string using ASCII encoding. - * - * @param s the string - * @return ByteBuffer - */ - public static ByteBuffer buffer(String s) { - return ByteBuffer.wrap(s.getBytes(ASCII)); - } - -} diff --git a/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java b/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java index 9d017dc7f1..f30e9a9f64 100644 --- a/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java +++ b/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java @@ -15,10 +15,10 @@ */ package io.lettuce.core.protocol; -import static io.lettuce.core.protocol.LettuceCharsets.buffer; import static io.lettuce.core.protocol.RedisStateMachine.State.Type.*; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.concurrent.atomic.AtomicBoolean; @@ -41,7 +41,7 @@ public class RedisStateMachine { private static final InternalLogger logger = InternalLoggerFactory.getInstance(RedisStateMachine.class); - private static final ByteBuffer QUEUED = buffer("QUEUED"); + private static final ByteBuffer QUEUED = StandardCharsets.US_ASCII.encode("QUEUED"); static class State { enum Type { diff --git a/src/test/java/io/lettuce/core/cluster/ClusterCommandUnitTests.java b/src/test/java/io/lettuce/core/cluster/ClusterCommandUnitTests.java index faf758c347..e3d7f9aa91 100644 --- a/src/test/java/io/lettuce/core/cluster/ClusterCommandUnitTests.java +++ b/src/test/java/io/lettuce/core/cluster/ClusterCommandUnitTests.java @@ -30,7 +30,6 @@ import io.lettuce.core.RedisChannelWriter; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.output.StatusOutput; import io.lettuce.core.protocol.AsyncCommand; import io.lettuce.core.protocol.Command; @@ -46,8 +45,8 @@ class ClusterCommandUnitTests { private RedisChannelWriter writerMock; private ClusterCommand sut; - private Command command = new Command<>(CommandType.TYPE, - new StatusOutput<>(StringCodec.UTF8), null); + private Command command = new Command<>(CommandType.TYPE, new StatusOutput<>(StringCodec.UTF8), + null); @BeforeEach void before() { diff --git a/src/test/java/io/lettuce/core/cluster/ClusterNodeEndpointUnitTests.java b/src/test/java/io/lettuce/core/cluster/ClusterNodeEndpointUnitTests.java index 530525b724..7760a4e8f1 100644 --- a/src/test/java/io/lettuce/core/cluster/ClusterNodeEndpointUnitTests.java +++ b/src/test/java/io/lettuce/core/cluster/ClusterNodeEndpointUnitTests.java @@ -34,7 +34,6 @@ import io.lettuce.core.RedisChannelWriter; import io.lettuce.core.RedisException; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.output.StatusOutput; import io.lettuce.core.protocol.AsyncCommand; import io.lettuce.core.protocol.Command; @@ -49,8 +48,8 @@ @ExtendWith(MockitoExtension.class) class ClusterNodeEndpointUnitTests { - private AsyncCommand command = new AsyncCommand<>(new Command<>(CommandType.APPEND, - new StatusOutput<>(StringCodec.UTF8), null)); + private AsyncCommand command = new AsyncCommand<>( + new Command<>(CommandType.APPEND, new StatusOutput<>(StringCodec.UTF8), null)); private Queue> disconnectedBuffer; diff --git a/src/test/java/io/lettuce/core/codec/StringCodecUnitTests.java b/src/test/java/io/lettuce/core/codec/StringCodecUnitTests.java index b8ee1d7edb..152675045e 100644 --- a/src/test/java/io/lettuce/core/codec/StringCodecUnitTests.java +++ b/src/test/java/io/lettuce/core/codec/StringCodecUnitTests.java @@ -22,7 +22,6 @@ import org.junit.jupiter.api.Test; -import io.lettuce.core.protocol.LettuceCharsets; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -37,7 +36,7 @@ class StringCodecUnitTests { @Test void encodeUtf8Buf() { - StringCodec codec = new StringCodec(LettuceCharsets.UTF8); + StringCodec codec = new StringCodec(StandardCharsets.UTF_8); ByteBuf buffer = Unpooled.buffer(1234); codec.encode(teststring, buffer); @@ -48,12 +47,12 @@ void encodeUtf8Buf() { @Test void encodeAsciiBuf() { - StringCodec codec = new StringCodec(LettuceCharsets.ASCII); + StringCodec codec = new StringCodec(StandardCharsets.US_ASCII); ByteBuf buffer = Unpooled.buffer(1234); codec.encode(teststringPlain, buffer); - assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(teststringPlain); + assertThat(buffer.toString(StandardCharsets.US_ASCII)).isEqualTo(teststringPlain); } @Test @@ -70,7 +69,7 @@ void encodeIso88591Buf() { @Test void encodeAndDecodeUtf8Buf() { - StringCodec codec = new StringCodec(LettuceCharsets.UTF8); + StringCodec codec = new StringCodec(StandardCharsets.UTF_8); ByteBuf buffer = Unpooled.buffer(1234); codec.encodeKey(teststring, buffer); @@ -81,7 +80,7 @@ void encodeAndDecodeUtf8Buf() { @Test void encodeAndDecodeUtf8() { - StringCodec codec = new StringCodec(LettuceCharsets.UTF8); + StringCodec codec = new StringCodec(StandardCharsets.UTF_8); ByteBuffer byteBuffer = codec.encodeKey(teststring); assertThat(codec.decodeKey(byteBuffer)).isEqualTo(teststring); @@ -90,7 +89,7 @@ void encodeAndDecodeUtf8() { @Test void encodeAndDecodeAsciiBuf() { - StringCodec codec = new StringCodec(LettuceCharsets.ASCII); + StringCodec codec = new StringCodec(StandardCharsets.US_ASCII); ByteBuf buffer = Unpooled.buffer(1234); codec.encode(teststringPlain, buffer); @@ -112,8 +111,9 @@ void encodeAndDecodeIso88591Buf() { @Test void estimateSize() { - assertThat(new StringCodec(LettuceCharsets.UTF8).estimateSize(teststring)).isEqualTo((int) (teststring.length() * 1.1)); - assertThat(new StringCodec(LettuceCharsets.ASCII).estimateSize(teststring)).isEqualTo(teststring.length()); + assertThat(new StringCodec(StandardCharsets.UTF_8).estimateSize(teststring)) + .isEqualTo((int) (teststring.length() * 1.1)); + assertThat(new StringCodec(StandardCharsets.US_ASCII).estimateSize(teststring)).isEqualTo(teststring.length()); assertThat(new StringCodec(StandardCharsets.ISO_8859_1).estimateSize(teststring)).isEqualTo(teststring.length()); } } diff --git a/src/test/java/io/lettuce/core/commands/BitStringCodec.java b/src/test/java/io/lettuce/core/commands/BitStringCodec.java index e919d6eae6..06cc58bc3e 100644 --- a/src/test/java/io/lettuce/core/commands/BitStringCodec.java +++ b/src/test/java/io/lettuce/core/commands/BitStringCodec.java @@ -17,12 +17,12 @@ import java.nio.ByteBuffer; -import io.lettuce.core.codec.Utf8StringCodec; +import io.lettuce.core.codec.StringCodec; /** * @author Mark Paluch */ -public class BitStringCodec extends Utf8StringCodec { +public class BitStringCodec extends StringCodec { @Override public String decodeValue(ByteBuffer bytes) { diff --git a/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java index 30db6bfa0a..bf8673bd88 100644 --- a/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java @@ -36,7 +36,6 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.models.role.RedisInstance; import io.lettuce.core.models.role.RedisNodeDescription; import io.lettuce.core.models.role.RoleParser; @@ -73,13 +72,14 @@ void before() throws Exception { if (node1Instance.getRole() == RedisInstance.Role.MASTER && node2Instance.getRole() == RedisInstance.Role.SLAVE) { master = node1; replica = node2; - } else if (node2Instance.getRole() == RedisInstance.Role.MASTER && node1Instance.getRole() == RedisInstance.Role.SLAVE) { + } else if (node2Instance.getRole() == RedisInstance.Role.MASTER + && node1Instance.getRole() == RedisInstance.Role.SLAVE) { master = node2; replica = node1; } else { - assumeTrue(false, String.format( - "Cannot run the test because I don't have a distinct master and replica but %s and %s", node1Instance, - node2Instance)); + assumeTrue(false, + String.format("Cannot run the test because I don't have a distinct master and replica but %s and %s", + node1Instance, node2Instance)); } connectionToNode1.configSet("requirepass", passwd); diff --git a/src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java b/src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java index cef8066885..ea4c0db027 100644 --- a/src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java +++ b/src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java @@ -35,7 +35,6 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.models.role.RedisInstance; import io.lettuce.core.models.role.RoleParser; import io.lettuce.test.settings.TestSettings; @@ -68,13 +67,14 @@ void before() throws Exception { if (node1Instance.getRole() == RedisInstance.Role.MASTER && node2Instance.getRole() == RedisInstance.Role.SLAVE) { master = node1; slave = node2; - } else if (node2Instance.getRole() == RedisInstance.Role.MASTER && node1Instance.getRole() == RedisInstance.Role.SLAVE) { + } else if (node2Instance.getRole() == RedisInstance.Role.MASTER + && node1Instance.getRole() == RedisInstance.Role.SLAVE) { master = node2; slave = node1; } else { - assumeTrue(false, String.format( - "Cannot run the test because I don't have a distinct master and slave but %s and %s", node1Instance, - node2Instance)); + assumeTrue(false, + String.format("Cannot run the test because I don't have a distinct master and slave but %s and %s", + node1Instance, node2Instance)); } connectionToNode1.configSet("requirepass", passwd); diff --git a/src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java b/src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java index 772e97a19e..dae1476d88 100644 --- a/src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java +++ b/src/test/java/io/lettuce/core/masterslave/CustomCommandIntegrationTests.java @@ -32,7 +32,6 @@ import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.output.StatusOutput; import io.lettuce.core.protocol.*; import io.lettuce.test.Futures; @@ -71,8 +70,8 @@ void after() { @Test void dispatchSet() { - String response = redis.dispatch(MyCommands.SET, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>( - StringCodec.UTF8).addKey(key).addValue(value)); + String response = redis.dispatch(MyCommands.SET, new StatusOutput<>(StringCodec.UTF8), + new CommandArgs<>(StringCodec.UTF8).addKey(key).addValue(value)); assertThat(response).isEqualTo("OK"); } @@ -89,17 +88,16 @@ void dispatchWithoutArgs() { void dispatchShouldFailForWrongDataType() { redis.hset(key, key, value); - assertThatThrownBy( - () -> redis.dispatch(CommandType.GET, new StatusOutput<>(StringCodec.UTF8), - new CommandArgs<>(StringCodec.UTF8).addKey(key))).isInstanceOf(RedisCommandExecutionException.class); + assertThatThrownBy(() -> redis.dispatch(CommandType.GET, new StatusOutput<>(StringCodec.UTF8), + new CommandArgs<>(StringCodec.UTF8).addKey(key))).isInstanceOf(RedisCommandExecutionException.class); } @Test void dispatchTransactions() { redis.multi(); - String response = redis.dispatch(CommandType.SET, new StatusOutput<>(StringCodec.UTF8), new CommandArgs<>( - StringCodec.UTF8).addKey(key).addValue(value)); + String response = redis.dispatch(CommandType.SET, new StatusOutput<>(StringCodec.UTF8), + new CommandArgs<>(StringCodec.UTF8).addKey(key).addValue(value)); TransactionResult exec = redis.exec(); @@ -110,8 +108,8 @@ void dispatchTransactions() { @Test void masterSlaveAsyncPing() { - RedisCommand command = new Command<>(MyCommands.PING, - new StatusOutput<>(StringCodec.UTF8), null); + RedisCommand command = new Command<>(MyCommands.PING, new StatusOutput<>(StringCodec.UTF8), + null); AsyncCommand async = new AsyncCommand<>(command); getStandaloneConnection().dispatch(async); @@ -144,8 +142,8 @@ void masterSlaveAsyncBatchPing() { @Test void masterSlaveFireAndForget() { - RedisCommand command = new Command<>(MyCommands.PING, - new StatusOutput<>(StringCodec.UTF8), null); + RedisCommand command = new Command<>(MyCommands.PING, new StatusOutput<>(StringCodec.UTF8), + null); getStandaloneConnection().dispatch(command); assertThat(command.isCancelled()).isFalse(); diff --git a/src/test/java/io/lettuce/core/masterslave/MasterSlaveSentinelIntegrationTests.java b/src/test/java/io/lettuce/core/masterslave/MasterSlaveSentinelIntegrationTests.java index 97ea9c5175..a1ef370e2c 100644 --- a/src/test/java/io/lettuce/core/masterslave/MasterSlaveSentinelIntegrationTests.java +++ b/src/test/java/io/lettuce/core/masterslave/MasterSlaveSentinelIntegrationTests.java @@ -31,7 +31,6 @@ import io.lettuce.core.*; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.sentinel.SentinelTestSettings; import io.lettuce.test.LettuceExtension; import io.lettuce.test.settings.TestSettings; @@ -54,10 +53,9 @@ class MasterSlaveSentinelIntegrationTests extends TestSupport { @Test void testMasterSlaveSentinelBasic() { - RedisURI uri = RedisURI - .create("redis-sentinel://127.0.0.1:21379,127.0.0.1:22379,127.0.0.1:26379?sentinelMasterId=mymaster&timeout=5s"); - StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, - StringCodec.UTF8, uri); + RedisURI uri = RedisURI.create( + "redis-sentinel://127.0.0.1:21379,127.0.0.1:22379,127.0.0.1:26379?sentinelMasterId=mymaster&timeout=5s"); + StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, StringCodec.UTF8, uri); connection.setReadFrom(ReadFrom.MASTER); String server = slaveCall(connection); @@ -72,8 +70,8 @@ void masterSlaveConnectionShouldSetClientName() { RedisURI redisURI = RedisURI.Builder.sentinel(TestSettings.host(), SentinelTestSettings.MASTER_ID) .withClientName("my-client").build(); - StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, - StringCodec.UTF8, redisURI); + StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, StringCodec.UTF8, + redisURI); assertThat(connection.sync().clientGetname()).isEqualTo(redisURI.getClientName()); connection.sync().quit(); @@ -85,10 +83,9 @@ void masterSlaveConnectionShouldSetClientName() { @Test void testMasterSlaveSentinelWithTwoUnavailableSentinels() { - RedisURI uri = RedisURI - .create("redis-sentinel://127.0.0.1:21379,127.0.0.1:22379,127.0.0.1:26379?sentinelMasterId=mymaster&timeout=5s"); - StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, - StringCodec.UTF8, uri); + RedisURI uri = RedisURI.create( + "redis-sentinel://127.0.0.1:21379,127.0.0.1:22379,127.0.0.1:26379?sentinelMasterId=mymaster&timeout=5s"); + StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, StringCodec.UTF8, uri); connection.setReadFrom(ReadFrom.MASTER); String server = connection.sync().info("replication"); @@ -123,7 +120,7 @@ void testMasterSlaveSentinelConnectionCount() { connection.setReadFrom(ReadFrom.REPLICA); slaveCall(connection); - assertThat(channels.size()).isEqualTo(count + 2 /* connections */+ 1 /* sentinel connections */); + assertThat(channels.size()).isEqualTo(count + 2 /* connections */ + 1 /* sentinel connections */); connection.close(); } diff --git a/src/test/java/io/lettuce/core/masterslave/MasterSlaveTest.java b/src/test/java/io/lettuce/core/masterslave/MasterSlaveTest.java index 2e48833c50..28a592cbf3 100644 --- a/src/test/java/io/lettuce/core/masterslave/MasterSlaveTest.java +++ b/src/test/java/io/lettuce/core/masterslave/MasterSlaveTest.java @@ -36,7 +36,6 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.models.role.RedisInstance; import io.lettuce.core.models.role.RedisNodeDescription; import io.lettuce.core.models.role.RoleParser; @@ -78,9 +77,9 @@ void before() throws Exception { master = node2; replica = node1; } else { - assumeTrue(false, String.format( - "Cannot run the test because I don't have a distinct master and replica but %s and %s", node1Instance, - node2Instance)); + assumeTrue(false, + String.format("Cannot run the test because I don't have a distinct master and replica but %s and %s", + node1Instance, node2Instance)); } connectionToNode1.configSet("requirepass", passwd); diff --git a/src/test/java/io/lettuce/core/masterslave/StaticMasterSlaveTest.java b/src/test/java/io/lettuce/core/masterslave/StaticMasterSlaveTest.java index 5de40d3c74..595f674f03 100644 --- a/src/test/java/io/lettuce/core/masterslave/StaticMasterSlaveTest.java +++ b/src/test/java/io/lettuce/core/masterslave/StaticMasterSlaveTest.java @@ -36,7 +36,6 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.models.role.RedisInstance; import io.lettuce.core.models.role.RoleParser; import io.lettuce.test.settings.TestSettings; @@ -74,9 +73,9 @@ void before() throws Exception { master = node2; replica = node1; } else { - assumeTrue(false, String.format( - "Cannot run the test because I don't have a distinct master and replica but %s and %s", node1Instance, - node2Instance)); + assumeTrue(false, + String.format("Cannot run the test because I don't have a distinct master and replica but %s and %s", + node1Instance, node2Instance)); } connectionToNode1.configSet("requirepass", passwd); diff --git a/src/test/java/io/lettuce/core/output/BooleanListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/BooleanListOutputUnitTests.java index 9ebd924570..8b3e9245fc 100644 --- a/src/test/java/io/lettuce/core/output/BooleanListOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/BooleanListOutputUnitTests.java @@ -23,7 +23,6 @@ import org.junit.jupiter.api.Test; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; /** * @author Mark Paluch diff --git a/src/test/java/io/lettuce/core/output/GeoCoordinatesListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/GeoCoordinatesListOutputUnitTests.java index d346c7a7c7..002285e7cd 100644 --- a/src/test/java/io/lettuce/core/output/GeoCoordinatesListOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/GeoCoordinatesListOutputUnitTests.java @@ -24,7 +24,6 @@ import io.lettuce.core.GeoCoordinates; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; /** * @author Mark Paluch @@ -35,7 +34,7 @@ class GeoCoordinatesListOutputUnitTests { @Test void setIntegerShouldFail() { - assertThatThrownBy(() -> sut.set(123L)).isInstanceOf(IllegalStateException. class); + assertThatThrownBy(() -> sut.set(123L)).isInstanceOf(IllegalStateException.class); } @Test diff --git a/src/test/java/io/lettuce/core/output/GeoCoordinatesValueListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/GeoCoordinatesValueListOutputUnitTests.java index 2369dfde62..ee4117a556 100644 --- a/src/test/java/io/lettuce/core/output/GeoCoordinatesValueListOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/GeoCoordinatesValueListOutputUnitTests.java @@ -25,7 +25,6 @@ import io.lettuce.core.GeoCoordinates; import io.lettuce.core.Value; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; /** * @author Mark Paluch diff --git a/src/test/java/io/lettuce/core/output/GeoWithinListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/GeoWithinListOutputUnitTests.java index b47dd4fa9f..18670fef04 100644 --- a/src/test/java/io/lettuce/core/output/GeoWithinListOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/GeoWithinListOutputUnitTests.java @@ -25,7 +25,6 @@ import io.lettuce.core.GeoWithin; import io.lettuce.core.codec.RedisCodec; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; /** * @author Mark Paluch diff --git a/src/test/java/io/lettuce/core/output/ListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/ListOutputUnitTests.java index a93b87b7e4..20d4f4bb3c 100644 --- a/src/test/java/io/lettuce/core/output/ListOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/ListOutputUnitTests.java @@ -27,7 +27,6 @@ import org.junit.jupiter.params.provider.MethodSource; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; /** * @author Mark Paluch diff --git a/src/test/java/io/lettuce/core/output/NestedMultiOutputUnitTests.java b/src/test/java/io/lettuce/core/output/NestedMultiOutputUnitTests.java index 00a116857c..e65fbb5138 100644 --- a/src/test/java/io/lettuce/core/output/NestedMultiOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/NestedMultiOutputUnitTests.java @@ -15,9 +15,10 @@ */ package io.lettuce.core.output; -import static io.lettuce.core.protocol.LettuceCharsets.buffer; import static org.assertj.core.api.Assertions.assertThat; +import java.nio.charset.StandardCharsets; + import org.junit.jupiter.api.Test; import io.lettuce.core.codec.StringCodec; @@ -31,7 +32,7 @@ class NestedMultiOutputUnitTests { void nestedMultiError() { NestedMultiOutput output = new NestedMultiOutput<>(StringCodec.UTF8); - output.setError(buffer("Oops!")); + output.setError(StandardCharsets.US_ASCII.encode("Oops!")); assertThat(output.getError()).isNotNull(); } } diff --git a/src/test/java/io/lettuce/core/output/ScoredValueListOutputUnitTests.java b/src/test/java/io/lettuce/core/output/ScoredValueListOutputUnitTests.java index 61d768660c..f605767355 100644 --- a/src/test/java/io/lettuce/core/output/ScoredValueListOutputUnitTests.java +++ b/src/test/java/io/lettuce/core/output/ScoredValueListOutputUnitTests.java @@ -24,7 +24,6 @@ import io.lettuce.core.ScoredValue; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; /** * @author Mark Paluch diff --git a/src/test/java/io/lettuce/core/protocol/AsyncCommandUnitTests.java b/src/test/java/io/lettuce/core/protocol/AsyncCommandUnitTests.java index f17472fffc..cebf0a1a00 100644 --- a/src/test/java/io/lettuce/core/protocol/AsyncCommandUnitTests.java +++ b/src/test/java/io/lettuce/core/protocol/AsyncCommandUnitTests.java @@ -15,10 +15,10 @@ */ package io.lettuce.core.protocol; -import static io.lettuce.core.protocol.LettuceCharsets.buffer; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.nio.charset.StandardCharsets; import java.util.concurrent.CancellationException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; @@ -29,7 +29,6 @@ import io.lettuce.core.*; import io.lettuce.core.codec.RedisCodec; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.output.CommandOutput; import io.lettuce.core.output.StatusOutput; import io.lettuce.test.Futures; @@ -78,8 +77,8 @@ void awaitAll() { @Test void awaitNotCompleted() { - assertThatThrownBy(() -> LettuceFutures.awaitOrCancel(sut, 0, TimeUnit.NANOSECONDS)).isInstanceOf( - RedisCommandTimeoutException.class); + assertThatThrownBy(() -> LettuceFutures.awaitOrCancel(sut, 0, TimeUnit.NANOSECONDS)) + .isInstanceOf(RedisCommandTimeoutException.class); } @Test @@ -91,8 +90,8 @@ void awaitWithExecutionException() { @Test void awaitWithCancelledCommand() { sut.cancel(); - assertThatThrownBy(() -> LettuceFutures.awaitOrCancel(sut, 5, TimeUnit.SECONDS)).isInstanceOf( - CancellationException.class); + assertThatThrownBy(() -> LettuceFutures.awaitOrCancel(sut, 5, TimeUnit.SECONDS)) + .isInstanceOf(CancellationException.class); } @Test @@ -125,7 +124,7 @@ void completeExceptionally() { @Test void asyncGet() { - sut.getOutput().set(buffer("one")); + sut.getOutput().set(StandardCharsets.US_ASCII.encode("one")); sut.complete(); assertThat(Futures.get(sut.toCompletableFuture())).isEqualTo("one"); sut.getOutput().toString(); @@ -133,23 +132,21 @@ void asyncGet() { @Test void customKeyword() { - sut = new AsyncCommand<>( - new Command<>(MyKeywords.DUMMY, new StatusOutput<>(codec), null)); + sut = new AsyncCommand<>(new Command<>(MyKeywords.DUMMY, new StatusOutput<>(codec), null)); assertThat(sut.toString()).contains(MyKeywords.DUMMY.name()); } @Test void customKeywordWithArgs() { - sut = new AsyncCommand<>( - new Command<>(MyKeywords.DUMMY, null, new CommandArgs<>(codec))); + sut = new AsyncCommand<>(new Command<>(MyKeywords.DUMMY, null, new CommandArgs<>(codec))); sut.getArgs().add(MyKeywords.DUMMY); assertThat(sut.getArgs().toString()).contains(MyKeywords.DUMMY.name()); } @Test void getWithTimeout() throws Exception { - sut.getOutput().set(buffer("one")); + sut.getOutput().set(StandardCharsets.US_ASCII.encode("one")); sut.complete(); assertThat(sut.get(0, TimeUnit.MILLISECONDS)).isEqualTo("one"); @@ -174,13 +171,13 @@ void getInterrupted() { @Test void getInterrupted2() { Thread.currentThread().interrupt(); - assertThatThrownBy(() -> sut.get(5, TimeUnit.MILLISECONDS)).isInstanceOf(InterruptedException. class); + assertThatThrownBy(() -> sut.get(5, TimeUnit.MILLISECONDS)).isInstanceOf(InterruptedException.class); } @Test void awaitInterrupted2() { Thread.currentThread().interrupt(); - assertThatThrownBy(() -> sut.await(5, TimeUnit.MILLISECONDS)).isInstanceOf(RedisCommandInterruptedException. class); + assertThatThrownBy(() -> sut.await(5, TimeUnit.MILLISECONDS)).isInstanceOf(RedisCommandInterruptedException.class); } @Test @@ -191,7 +188,7 @@ public String get() throws RedisException { return null; } }; - assertThatThrownBy(() -> output.set(null)).isInstanceOf(IllegalStateException. class); + assertThatThrownBy(() -> output.set(null)).isInstanceOf(IllegalStateException.class); } @Test @@ -202,7 +199,7 @@ public String get() throws RedisException { return null; } }; - assertThatThrownBy(() -> output.set(0)).isInstanceOf(IllegalStateException. class); + assertThatThrownBy(() -> output.set(0)).isInstanceOf(IllegalStateException.class); } @Test diff --git a/src/test/java/io/lettuce/core/protocol/CommandArgsUnitTests.java b/src/test/java/io/lettuce/core/protocol/CommandArgsUnitTests.java index 234db454b0..e4c0252d6d 100644 --- a/src/test/java/io/lettuce/core/protocol/CommandArgsUnitTests.java +++ b/src/test/java/io/lettuce/core/protocol/CommandArgsUnitTests.java @@ -18,6 +18,7 @@ import static org.assertj.core.api.Assertions.assertThat; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.jupiter.api.Test; @@ -116,7 +117,7 @@ void addValues() { ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$1\r\n" + "1\r\n" + "$1\r\n" + "2\r\n").getBytes()); - assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); + assertThat(buffer.toString(StandardCharsets.US_ASCII)).isEqualTo(expected.toString(StandardCharsets.US_ASCII)); } @Test @@ -130,7 +131,7 @@ void addByte() { ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); - assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); + assertThat(buffer.toString(StandardCharsets.US_ASCII)).isEqualTo(expected.toString(StandardCharsets.US_ASCII)); } @Test @@ -144,7 +145,7 @@ void addByteUsingByteCodec() { ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); - assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); + assertThat(buffer.toString(StandardCharsets.US_ASCII)).isEqualTo(expected.toString(StandardCharsets.US_ASCII)); } @Test @@ -158,7 +159,7 @@ void addValueUsingByteCodec() { ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); - assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); + assertThat(buffer.toString(StandardCharsets.US_ASCII)).isEqualTo(expected.toString(StandardCharsets.US_ASCII)); } @Test @@ -172,6 +173,6 @@ void addKeyUsingByteCodec() { ByteBuf expected = Unpooled.buffer(); expected.writeBytes(("$3\r\n" + "one\r\n").getBytes()); - assertThat(buffer.toString(LettuceCharsets.ASCII)).isEqualTo(expected.toString(LettuceCharsets.ASCII)); + assertThat(buffer.toString(StandardCharsets.US_ASCII)).isEqualTo(expected.toString(StandardCharsets.US_ASCII)); } } diff --git a/src/test/java/io/lettuce/core/protocol/CommandUnitTests.java b/src/test/java/io/lettuce/core/protocol/CommandUnitTests.java index 982afe00f9..ddf4738eda 100644 --- a/src/test/java/io/lettuce/core/protocol/CommandUnitTests.java +++ b/src/test/java/io/lettuce/core/protocol/CommandUnitTests.java @@ -15,10 +15,11 @@ */ package io.lettuce.core.protocol; -import static io.lettuce.core.protocol.LettuceCharsets.buffer; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import java.nio.charset.StandardCharsets; + import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -69,7 +70,7 @@ void isDone() { @Test void get() { assertThat(sut.get()).isNull(); - sut.getOutput().set(buffer("one")); + sut.getOutput().set(StandardCharsets.US_ASCII.encode("one")); assertThat(sut.get()).isEqualTo("one"); } @@ -108,7 +109,7 @@ void customKeywordWithArgs() { @Test void getWithTimeout() { - sut.getOutput().set(buffer("one")); + sut.getOutput().set(StandardCharsets.US_ASCII.encode("one")); sut.complete(); assertThat(sut.get()).isEqualTo("one"); diff --git a/src/test/java/io/lettuce/core/protocol/DefaultEndpointUnitTests.java b/src/test/java/io/lettuce/core/protocol/DefaultEndpointUnitTests.java index f88c69b9ef..ef6db6b422 100644 --- a/src/test/java/io/lettuce/core/protocol/DefaultEndpointUnitTests.java +++ b/src/test/java/io/lettuce/core/protocol/DefaultEndpointUnitTests.java @@ -50,7 +50,6 @@ import io.lettuce.core.ClientOptions; import io.lettuce.core.RedisException; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.internal.LettuceFactories; import io.lettuce.core.output.StatusOutput; import io.lettuce.core.resource.ClientResources; @@ -70,8 +69,8 @@ class DefaultEndpointUnitTests { private DefaultEndpoint sut; - private final Command command = new Command<>(CommandType.APPEND, new StatusOutput<>( - StringCodec.UTF8), null); + private final Command command = new Command<>(CommandType.APPEND, + new StatusOutput<>(StringCodec.UTF8), null); @Mock private Channel channel; diff --git a/src/test/java/io/lettuce/core/pubsub/PubSubCommandHandlerUnitTests.java b/src/test/java/io/lettuce/core/pubsub/PubSubCommandHandlerUnitTests.java index 33a68864ee..de97352ca9 100644 --- a/src/test/java/io/lettuce/core/pubsub/PubSubCommandHandlerUnitTests.java +++ b/src/test/java/io/lettuce/core/pubsub/PubSubCommandHandlerUnitTests.java @@ -37,7 +37,6 @@ import io.lettuce.core.ClientOptions; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.metrics.DefaultCommandLatencyCollector; import io.lettuce.core.metrics.DefaultCommandLatencyCollectorOptions; import io.lettuce.core.output.StatusOutput; @@ -63,8 +62,8 @@ class PubSubCommandHandlerUnitTests { private PubSubCommandHandler sut; - private final Command command = new Command<>(CommandType.APPEND, new StatusOutput<>( - StringCodec.UTF8), null); + private final Command command = new Command<>(CommandType.APPEND, + new StatusOutput<>(StringCodec.UTF8), null); @Mock private ChannelHandlerContext context; @@ -102,8 +101,8 @@ void before() { return null; }); - when(clientResources.commandLatencyCollector()).thenReturn( - new DefaultCommandLatencyCollector(DefaultCommandLatencyCollectorOptions.create())); + when(clientResources.commandLatencyCollector()) + .thenReturn(new DefaultCommandLatencyCollector(DefaultCommandLatencyCollectorOptions.create())); when(clientResources.tracing()).thenReturn(Tracing.disabled()); sut = new PubSubCommandHandler<>(ClientOptions.create(), clientResources, StringCodec.UTF8, endpoint); @@ -183,7 +182,8 @@ void shouldPropagateInterleavedPubSubResponseToOutput() throws Exception { stack.add(command1); stack.add(command2); - sut.channelRead(context, responseBytes("+OK\r\n*4\r\n$8\r\npmessage\r\n$1\r\n*\r\n$3\r\nfoo\r\n$3\r\nbar\r\n+YEAH\r\n")); + sut.channelRead(context, + responseBytes("+OK\r\n*4\r\n$8\r\npmessage\r\n$1\r\n*\r\n$3\r\nfoo\r\n$3\r\nbar\r\n+YEAH\r\n")); assertThat(command1.get()).isEqualTo("OK"); assertThat(command2.get()).isEqualTo("YEAH"); @@ -199,10 +199,10 @@ void shouldPropagateInterleavedPubSubResponseToOutput() throws Exception { @Test void shouldNotPropagatePartialPubSubResponseToOutput() throws Exception { - Command command1 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>( - StringCodec.UTF8), null); - Command command2 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>( - StringCodec.UTF8), null); + Command command1 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); + Command command2 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); sut.channelRegistered(context); sut.channelActive(context); @@ -226,10 +226,10 @@ void shouldNotPropagatePartialPubSubResponseToOutput() throws Exception { @Test void shouldCompleteWithChunkedResponseOnStack() throws Exception { - Command command1 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>( - StringCodec.UTF8), null); - Command command2 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>( - StringCodec.UTF8), null); + Command command1 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); + Command command2 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); sut.channelRegistered(context); sut.channelActive(context); @@ -270,10 +270,10 @@ void shouldCompleteWithChunkedResponseOutOfBand() throws Exception { @Test void shouldCompleteUnsubscribe() throws Exception { - Command subCmd = new Command<>(CommandType.SUBSCRIBE, - new PubSubOutput<>(StringCodec.UTF8), null); - Command unSubCmd = new Command<>(CommandType.UNSUBSCRIBE, new PubSubOutput<>( - StringCodec.UTF8), null); + Command subCmd = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); + Command unSubCmd = new Command<>(CommandType.UNSUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); doAnswer((Answer>) inv -> { PubSubOutput out = inv.getArgument(0); @@ -300,8 +300,8 @@ void shouldCompleteUnsubscribe() throws Exception { @Test void shouldCompleteWithChunkedResponseInterleavedSending() throws Exception { - Command command1 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>( - StringCodec.UTF8), null); + Command command1 = new Command<>(CommandType.SUBSCRIBE, new PubSubOutput<>(StringCodec.UTF8), + null); sut.channelRegistered(context); sut.channelActive(context); diff --git a/src/test/java/io/lettuce/core/reactive/RedisPublisherVerification.java b/src/test/java/io/lettuce/core/reactive/RedisPublisherVerification.java index beea7bd82e..47eaefdee7 100644 --- a/src/test/java/io/lettuce/core/reactive/RedisPublisherVerification.java +++ b/src/test/java/io/lettuce/core/reactive/RedisPublisherVerification.java @@ -33,7 +33,6 @@ import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.output.ValueListOutput; import io.lettuce.core.protocol.Command; import io.lettuce.core.protocol.CommandArgs; diff --git a/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingElastiCacheCluster.java b/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingElastiCacheCluster.java index 6b6c41b200..53611e3d99 100644 --- a/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingElastiCacheCluster.java +++ b/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingElastiCacheCluster.java @@ -22,7 +22,6 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.masterslave.MasterSlave; import io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection; @@ -36,12 +35,11 @@ public static void main(String[] args) { // Syntax: redis://[password@]host[:port][/databaseNumber] RedisClient redisClient = RedisClient.create(); - List nodes = Arrays.asList(RedisURI.create("redis://host1"), - RedisURI.create("redis://host2"), + List nodes = Arrays.asList(RedisURI.create("redis://host1"), RedisURI.create("redis://host2"), RedisURI.create("redis://host3")); - StatefulRedisMasterSlaveConnection connection = MasterSlave - .connect(redisClient, StringCodec.UTF8, nodes); + StatefulRedisMasterSlaveConnection connection = MasterSlave.connect(redisClient, StringCodec.UTF8, + nodes); connection.setReadFrom(ReadFrom.MASTER_PREFERRED); System.out.println("Connected to Redis"); diff --git a/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingRedisSentinel.java b/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingRedisSentinel.java index 618baafe26..d78d03145a 100644 --- a/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingRedisSentinel.java +++ b/src/test/java/io/lettuce/examples/ConnectToMasterSlaveUsingRedisSentinel.java @@ -19,7 +19,6 @@ import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.codec.StringCodec; -import io.lettuce.core.codec.Utf8StringCodec; import io.lettuce.core.masterslave.MasterSlave; import io.lettuce.core.masterslave.StatefulRedisMasterSlaveConnection; diff --git a/src/test/jmh/io/lettuce/core/codec/StringCodecBenchmark.java b/src/test/jmh/io/lettuce/core/codec/StringCodecBenchmark.java index e522db3262..3a99ea5151 100644 --- a/src/test/jmh/io/lettuce/core/codec/StringCodecBenchmark.java +++ b/src/test/jmh/io/lettuce/core/codec/StringCodecBenchmark.java @@ -24,7 +24,6 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.infra.Blackhole; -import io.lettuce.core.protocol.LettuceCharsets; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; @@ -74,13 +73,13 @@ public void decodeUtf8Unpooled(Input input) { public static class Input { Blackhole blackhole; - StringCodec asciiCodec = new StringCodec(LettuceCharsets.ASCII); - StringCodec utf8Codec = new StringCodec(LettuceCharsets.UTF8); + StringCodec asciiCodec = new StringCodec(StandardCharsets.US_ASCII); + StringCodec utf8Codec = new StringCodec(StandardCharsets.UTF_8); StringCodec isoCodec = new StringCodec(StandardCharsets.ISO_8859_1); String teststring = "hello üäü~∑†®†ª€∂‚¶¢ Wørld"; String teststringPlain = "hello uufadsfasdfadssdfadfs"; - ByteBuffer input = ByteBuffer.wrap(teststring.getBytes(LettuceCharsets.UTF8)); + ByteBuffer input = ByteBuffer.wrap(teststring.getBytes(StandardCharsets.UTF_8)); ByteBuf byteBuf = Unpooled.buffer(512); diff --git a/src/test/jmh/io/lettuce/core/codec/Utf8StringCodecBenchmark.java b/src/test/jmh/io/lettuce/core/codec/Utf8StringCodecBenchmark.java index 602d5c7c11..f996e80ca5 100644 --- a/src/test/jmh/io/lettuce/core/codec/Utf8StringCodecBenchmark.java +++ b/src/test/jmh/io/lettuce/core/codec/Utf8StringCodecBenchmark.java @@ -16,6 +16,7 @@ package io.lettuce.core.codec; import java.nio.ByteBuffer; +import java.nio.charset.StandardCharsets; import org.openjdk.jmh.annotations.Benchmark; import org.openjdk.jmh.annotations.Scope; @@ -23,8 +24,6 @@ import org.openjdk.jmh.annotations.State; import org.openjdk.jmh.infra.Blackhole; -import io.lettuce.core.protocol.LettuceCharsets; - /** * Benchmark for {@link Utf8StringCodec}. * @@ -50,7 +49,7 @@ public static class Input { Utf8StringCodec codec = new Utf8StringCodec(); String teststring = "hello üäü~∑†®†ª€∂‚¶¢ Wørld"; - ByteBuffer input = ByteBuffer.wrap(teststring.getBytes(LettuceCharsets.UTF8)); + ByteBuffer input = ByteBuffer.wrap(teststring.getBytes(StandardCharsets.UTF_8)); @Setup public void setup(Blackhole bh) {