From 4a687682d59d4ba8a89910aafc866fb63b1cb89e Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Fri, 22 Jan 2021 14:00:58 +0100 Subject: [PATCH] Reinstate master-replica wording #1518 After community feedback, we're getting back to Master/Replica from Upstream/Replica to not introduce confusion with the term Upstream. --- .../core/cluster/PubSubClusterEndpoint.java | 4 +- .../masterreplica/AutodiscoveryConnector.java | 14 ++-- .../core/masterreplica/MasterReplica.java | 12 ++-- ...r.java => MasterReplicaChannelWriter.java} | 34 +++++----- ...a => MasterReplicaConnectionProvider.java} | 18 ++--- ...ector.java => MasterReplicaConnector.java} | 6 +- ...java => MasterReplicaTopologyRefresh.java} | 8 +-- ...aNode.java => RedisMasterReplicaNode.java} | 8 +-- .../ReplicaTopologyProvider.java | 6 +- .../core/masterreplica/SentinelConnector.java | 18 ++--- .../SentinelTopologyProvider.java | 2 +- ...efulRedisMasterReplicaConnectionImpl.java} | 8 +-- ...java => StaticMasterReplicaConnector.java} | 16 ++--- .../StaticMasterReplicaTopologyProvider.java | 2 +- .../core/models/role/RedisInstance.java | 21 +++++- .../core/models/role/RedisMasterInstance.java | 2 - ... MasterReplicaChannelWriterUnitTests.java} | 68 +++++++++---------- ...erReplicaConnectionProviderUnitTests.java} | 10 +-- ...erReplicaSentinelSslIntegrationTests.java} | 4 +- ...eplicaTest.java => MasterReplicaTest.java} | 9 +-- ...sterReplicaTopologyProviderUnitTests.java} | 9 +-- ...asterReplicaTopologyRefreshUnitTests.java} | 10 +-- ....java => MasterReplicaUtilsUnitTests.java} | 36 +++++----- ...Test.java => StaticMasterReplicaTest.java} | 17 ++--- 24 files changed, 181 insertions(+), 161 deletions(-) rename src/main/java/io/lettuce/core/masterreplica/{UpstreamReplicaChannelWriter.java => MasterReplicaChannelWriter.java} (86%) rename src/main/java/io/lettuce/core/masterreplica/{UpstreamReplicaConnectionProvider.java => MasterReplicaConnectionProvider.java} (94%) rename src/main/java/io/lettuce/core/masterreplica/{UpstreamReplicaConnector.java => MasterReplicaConnector.java} (87%) rename src/main/java/io/lettuce/core/masterreplica/{UpstreamReplicaTopologyRefresh.java => MasterReplicaTopologyRefresh.java} (94%) rename src/main/java/io/lettuce/core/masterreplica/{RedisUpstreamReplicaNode.java => RedisMasterReplicaNode.java} (87%) rename src/main/java/io/lettuce/core/masterreplica/{StatefulRedisUpstreamReplicaConnectionImpl.java => StatefulRedisMasterReplicaConnectionImpl.java} (80%) rename src/main/java/io/lettuce/core/masterreplica/{StaticUpstreamReplicaConnector.java => StaticMasterReplicaConnector.java} (75%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaChannelWriterUnitTests.java => MasterReplicaChannelWriterUnitTests.java} (61%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaConnectionProviderUnitTests.java => MasterReplicaConnectionProviderUnitTests.java} (86%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaSentinelSslIntegrationTests.java => MasterReplicaSentinelSslIntegrationTests.java} (94%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaTest.java => MasterReplicaTest.java} (96%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaTopologyProviderUnitTests.java => MasterReplicaTopologyProviderUnitTests.java} (96%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaTopologyRefreshUnitTests.java => MasterReplicaTopologyRefreshUnitTests.java} (88%) rename src/test/java/io/lettuce/core/masterreplica/{UpstreamReplicaUtilsUnitTests.java => MasterReplicaUtilsUnitTests.java} (64%) rename src/test/java/io/lettuce/core/masterreplica/{StaticUpstreamReplicaTest.java => StaticMasterReplicaTest.java} (91%) diff --git a/src/main/java/io/lettuce/core/cluster/PubSubClusterEndpoint.java b/src/main/java/io/lettuce/core/cluster/PubSubClusterEndpoint.java index 5fb220ff6b..b47996ab07 100644 --- a/src/main/java/io/lettuce/core/cluster/PubSubClusterEndpoint.java +++ b/src/main/java/io/lettuce/core/cluster/PubSubClusterEndpoint.java @@ -35,7 +35,7 @@ public class PubSubClusterEndpoint extends PubSubEndpoint { private final NotifyingMessageListener multicast = new NotifyingMessageListener(); - private final UpstreamMessageListener upstream = new UpstreamMessageListener(); + private final MasterMessageListener upstream = new MasterMessageListener(); private volatile boolean nodeMessagePropagation = false; @@ -108,7 +108,7 @@ protected void notifyListeners(PubSubMessage output) { } } - private class UpstreamMessageListener extends NotifyingMessageListener { + private class MasterMessageListener extends NotifyingMessageListener { @Override public void message(RedisClusterNode node, K channel, V message) { diff --git a/src/main/java/io/lettuce/core/masterreplica/AutodiscoveryConnector.java b/src/main/java/io/lettuce/core/masterreplica/AutodiscoveryConnector.java index 75b6c02bc6..5759eab0ac 100644 --- a/src/main/java/io/lettuce/core/masterreplica/AutodiscoveryConnector.java +++ b/src/main/java/io/lettuce/core/masterreplica/AutodiscoveryConnector.java @@ -34,13 +34,13 @@ import io.lettuce.core.models.role.RedisNodeDescription; /** - * {@link UpstreamReplicaConnector} to connect unmanaged Redis Master/Replica with auto-discovering master and replica nodes - * from a single {@link RedisURI}. + * {@link MasterReplicaConnector} to connect unmanaged Redis Master/Replica with auto-discovering master and replica nodes from + * a single {@link RedisURI}. * * @author Mark Paluch * @since 5.1 */ -class AutodiscoveryConnector implements UpstreamReplicaConnector { +class AutodiscoveryConnector implements MasterReplicaConnector { private final RedisClient redisClient; @@ -112,8 +112,8 @@ private Mono> initializeConnection(Re ReplicaTopologyProvider topologyProvider = new ReplicaTopologyProvider(connectionAndUri.getT2(), connectionAndUri.getT1()); - UpstreamReplicaTopologyRefresh refresh = new UpstreamReplicaTopologyRefresh(redisClient, topologyProvider); - UpstreamReplicaConnectionProvider connectionProvider = new UpstreamReplicaConnectionProvider<>(redisClient, codec, + MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(redisClient, topologyProvider); + MasterReplicaConnectionProvider connectionProvider = new MasterReplicaConnectionProvider<>(redisClient, codec, redisURI, (Map) initialConnections); Mono> refreshFuture = refresh.getNodes(redisURI); @@ -122,10 +122,10 @@ private Mono> initializeConnection(Re connectionProvider.setKnownNodes(nodes); - UpstreamReplicaChannelWriter channelWriter = new UpstreamReplicaChannelWriter(connectionProvider, + MasterReplicaChannelWriter channelWriter = new MasterReplicaChannelWriter(connectionProvider, redisClient.getResources()); - StatefulRedisUpstreamReplicaConnectionImpl connection = new StatefulRedisUpstreamReplicaConnectionImpl<>( + StatefulRedisMasterReplicaConnectionImpl connection = new StatefulRedisMasterReplicaConnectionImpl<>( channelWriter, codec, redisURI.getTimeout()); connection.setOptions(redisClient.getOptions()); diff --git a/src/main/java/io/lettuce/core/masterreplica/MasterReplica.java b/src/main/java/io/lettuce/core/masterreplica/MasterReplica.java index c555c23362..a3321cad45 100644 --- a/src/main/java/io/lettuce/core/masterreplica/MasterReplica.java +++ b/src/main/java/io/lettuce/core/masterreplica/MasterReplica.java @@ -57,12 +57,12 @@ *

* Master-Replica topologies are either static or semi-static. Redis Standalone instances with attached replicas provide no * failover/HA mechanism. Redis Sentinel managed instances are controlled by Redis Sentinel and allow failover (which include - * upstream promotion). The {@link MasterReplica} API supports both mechanisms. The topology is provided by a + * master promotion). The {@link MasterReplica} API supports both mechanisms. The topology is provided by a * {@link TopologyProvider}: * *

    *
  • {@link ReplicaTopologyProvider}: Dynamic topology lookup using the {@code INFO REPLICATION} output. Replicas are listed - * as {@code replicaN=...} entries. The initial connection can either point to a upstream or a replica and the topology provider + * as {@code replicaN=...} entries. The initial connection can either point to a master or a replica and the topology provider * will discover nodes. The connection needs to be re-established outside of lettuce in a case of Master/Replica failover or * topology changes.
  • *
  • {@link StaticMasterReplicaTopologyProvider}: Topology is defined by the list of {@link RedisURI URIs} and the @@ -83,7 +83,7 @@ * *
      *
    • Redis Sentinel: At least one Sentinel must be reachable, the masterId must be registered and at least one host must be - * available (upstream or replica). Allows for runtime-recovery based on Sentinel Events.
    • + * available (master or replica). Allows for runtime-recovery based on Sentinel Events. *
    • Static Setup (auto-discovery): The initial endpoint must be reachable. No recovery/reconfiguration during runtime.
    • *
    • Static Setup (provided hosts): All endpoints must be reachable. No recovery/reconfiguration during runtime.
    • *
    @@ -98,7 +98,7 @@ public class MasterReplica { * {@link RedisCodec codec} to encode/decode keys. *

    * This {@link MasterReplica} performs auto-discovery of nodes using either Redis Sentinel or Master/Replica. A - * {@link RedisURI} can point to either a upstream or a replica host. + * {@link RedisURI} can point to either a master or a replica host. *

    * * @param redisClient the Redis client. @@ -118,7 +118,7 @@ public static StatefulRedisMasterReplicaConnection connect(RedisCli * supplied {@link RedisCodec codec} to encode/decode keys. *

    * This {@link MasterReplica} performs auto-discovery of nodes using either Redis Sentinel or Master/Replica. A - * {@link RedisURI} can point to either a upstream or a replica host. + * {@link RedisURI} can point to either a master or a replica host. *

    * * @param redisClient the Redis client. @@ -224,7 +224,7 @@ private static CompletableFuture(redisClient, codec, first).connectAsync(); } - return new StaticUpstreamReplicaConnector<>(redisClient, codec, uriList).connectAsync(); + return new StaticMasterReplicaConnector<>(redisClient, codec, uriList).connectAsync(); } private static boolean isSentinel(RedisURI redisURI) { diff --git a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaChannelWriter.java b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaChannelWriter.java similarity index 86% rename from src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaChannelWriter.java rename to src/main/java/io/lettuce/core/masterreplica/MasterReplicaChannelWriter.java index bb7cdf99ed..9899dbadfd 100644 --- a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaChannelWriter.java +++ b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaChannelWriter.java @@ -23,7 +23,7 @@ import io.lettuce.core.RedisException; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.internal.LettuceAssert; -import io.lettuce.core.masterreplica.UpstreamReplicaConnectionProvider.Intent; +import io.lettuce.core.masterreplica.MasterReplicaConnectionProvider.Intent; import io.lettuce.core.protocol.ConnectionFacade; import io.lettuce.core.protocol.ProtocolKeyword; import io.lettuce.core.protocol.RedisCommand; @@ -34,9 +34,9 @@ * * @author Mark Paluch */ -class UpstreamReplicaChannelWriter implements RedisChannelWriter { +class MasterReplicaChannelWriter implements RedisChannelWriter { - private UpstreamReplicaConnectionProvider upstreamReplicaConnectionProvider; + private MasterReplicaConnectionProvider masterReplicaConnectionProvider; private final ClientResources clientResources; @@ -44,9 +44,9 @@ class UpstreamReplicaChannelWriter implements RedisChannelWriter { private boolean inTransaction; - UpstreamReplicaChannelWriter(UpstreamReplicaConnectionProvider upstreamReplicaConnectionProvider, + MasterReplicaChannelWriter(MasterReplicaConnectionProvider masterReplicaConnectionProvider, ClientResources clientResources) { - this.upstreamReplicaConnectionProvider = upstreamReplicaConnectionProvider; + this.masterReplicaConnectionProvider = masterReplicaConnectionProvider; this.clientResources = clientResources; } @@ -65,7 +65,7 @@ public RedisCommand write(RedisCommand command) { } Intent intent = inTransaction ? Intent.WRITE : getIntent(command.getType()); - CompletableFuture> future = (CompletableFuture) upstreamReplicaConnectionProvider + CompletableFuture> future = (CompletableFuture) masterReplicaConnectionProvider .getConnectionAsync(intent); if (isEndTransaction(command.getType())) { @@ -118,7 +118,7 @@ private static void writeCommand(RedisCommand command, StatefulR // Currently: Retain order Intent intent = inTransaction ? Intent.WRITE : getIntent(commands); - CompletableFuture> future = (CompletableFuture) upstreamReplicaConnectionProvider + CompletableFuture> future = (CompletableFuture) masterReplicaConnectionProvider .getConnectionAsync(intent); for (RedisCommand command : commands) { @@ -207,9 +207,9 @@ public CompletableFuture closeAsync() { CompletableFuture future = null; - if (upstreamReplicaConnectionProvider != null) { - future = upstreamReplicaConnectionProvider.closeAsync(); - upstreamReplicaConnectionProvider = null; + if (masterReplicaConnectionProvider != null) { + future = masterReplicaConnectionProvider.closeAsync(); + masterReplicaConnectionProvider = null; } if (future == null) { @@ -219,8 +219,8 @@ public CompletableFuture closeAsync() { return future; } - UpstreamReplicaConnectionProvider getUpstreamReplicaConnectionProvider() { - return upstreamReplicaConnectionProvider; + MasterReplicaConnectionProvider getUpstreamReplicaConnectionProvider() { + return masterReplicaConnectionProvider; } @Override @@ -234,17 +234,17 @@ public ClientResources getClientResources() { @Override public void setAutoFlushCommands(boolean autoFlush) { - upstreamReplicaConnectionProvider.setAutoFlushCommands(autoFlush); + masterReplicaConnectionProvider.setAutoFlushCommands(autoFlush); } @Override public void flushCommands() { - upstreamReplicaConnectionProvider.flushCommands(); + masterReplicaConnectionProvider.flushCommands(); } @Override public void reset() { - upstreamReplicaConnectionProvider.reset(); + masterReplicaConnectionProvider.reset(); } /** @@ -254,7 +254,7 @@ public void reset() { * @param readFrom the read from setting, must not be {@code null} */ public void setReadFrom(ReadFrom readFrom) { - upstreamReplicaConnectionProvider.setReadFrom(readFrom); + masterReplicaConnectionProvider.setReadFrom(readFrom); } /** @@ -263,7 +263,7 @@ public void setReadFrom(ReadFrom readFrom) { * @return the read from setting */ public ReadFrom getReadFrom() { - return upstreamReplicaConnectionProvider.getReadFrom(); + return masterReplicaConnectionProvider.getReadFrom(); } private static boolean isSuccessfullyCompleted(CompletableFuture connectFuture) { diff --git a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaConnectionProvider.java b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaConnectionProvider.java similarity index 94% rename from src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaConnectionProvider.java rename to src/main/java/io/lettuce/core/masterreplica/MasterReplicaConnectionProvider.java index f9d7a65946..9953b532e7 100644 --- a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaConnectionProvider.java +++ b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaConnectionProvider.java @@ -43,9 +43,9 @@ * @author Mark Paluch * @since 4.1 */ -class UpstreamReplicaConnectionProvider { +class MasterReplicaConnectionProvider { - private static final InternalLogger logger = InternalLoggerFactory.getInstance(UpstreamReplicaConnectionProvider.class); + private static final InternalLogger logger = InternalLoggerFactory.getInstance(MasterReplicaConnectionProvider.class); private final boolean debugEnabled = logger.isDebugEnabled(); @@ -61,7 +61,7 @@ class UpstreamReplicaConnectionProvider { private ReadFrom readFrom; - UpstreamReplicaConnectionProvider(RedisClient redisClient, RedisCodec redisCodec, RedisURI initialRedisUri, + MasterReplicaConnectionProvider(RedisClient redisClient, RedisCodec redisCodec, RedisURI initialRedisUri, Map> initialConnections) { this.initialRedisUri = initialRedisUri; @@ -77,9 +77,9 @@ class UpstreamReplicaConnectionProvider { } /** - * Retrieve a {@link StatefulRedisConnection} by the intent. {@link UpstreamReplicaConnectionProvider.Intent#WRITE} - * intentions use the master connection, {@link UpstreamReplicaConnectionProvider.Intent#READ} intentions lookup one or more - * read candidates using the {@link ReadFrom} setting. + * Retrieve a {@link StatefulRedisConnection} by the intent. {@link MasterReplicaConnectionProvider.Intent#WRITE} intentions + * use the master connection, {@link MasterReplicaConnectionProvider.Intent#READ} intentions lookup one or more read + * candidates using the {@link ReadFrom} setting. * * @param intent command intent * @return the connection. @@ -98,9 +98,9 @@ public StatefulRedisConnection getConnection(Intent intent) { } /** - * Retrieve a {@link StatefulRedisConnection} by the intent. {@link UpstreamReplicaConnectionProvider.Intent#WRITE} - * intentions use the master connection, {@link UpstreamReplicaConnectionProvider.Intent#READ} intentions lookup one or more - * read candidates using the {@link ReadFrom} setting. + * Retrieve a {@link StatefulRedisConnection} by the intent. {@link MasterReplicaConnectionProvider.Intent#WRITE} intentions + * use the master connection, {@link MasterReplicaConnectionProvider.Intent#READ} intentions lookup one or more read + * candidates using the {@link ReadFrom} setting. * * @param intent command intent * @return the connection. diff --git a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaConnector.java b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaConnector.java similarity index 87% rename from src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaConnector.java rename to src/main/java/io/lettuce/core/masterreplica/MasterReplicaConnector.java index 8b9ed9e184..3904773cc0 100644 --- a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaConnector.java +++ b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaConnector.java @@ -20,15 +20,15 @@ import io.lettuce.core.codec.RedisCodec; /** - * Interface declaring an asynchronous connect method to connect a Upstream/Replica setup. + * Interface declaring an asynchronous connect method to connect a Master/Replica setup. * * @author Mark Paluch * @since 5.1 */ -interface UpstreamReplicaConnector { +interface MasterReplicaConnector { /** - * Asynchronously connect to a Upstream/Replica setup given {@link RedisCodec}. + * Asynchronously connect to a Master/Replica setup given {@link RedisCodec}. * * @return Future that is notified about the connection progress. */ diff --git a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyRefresh.java b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaTopologyRefresh.java similarity index 94% rename from src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyRefresh.java rename to src/main/java/io/lettuce/core/masterreplica/MasterReplicaTopologyRefresh.java index 7f5b1138c7..8964c0bb80 100644 --- a/src/main/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyRefresh.java +++ b/src/main/java/io/lettuce/core/masterreplica/MasterReplicaTopologyRefresh.java @@ -37,9 +37,9 @@ * * @author Mark Paluch */ -class UpstreamReplicaTopologyRefresh { +class MasterReplicaTopologyRefresh { - private static final InternalLogger logger = InternalLoggerFactory.getInstance(UpstreamReplicaTopologyRefresh.class); + private static final InternalLogger logger = InternalLoggerFactory.getInstance(MasterReplicaTopologyRefresh.class); private static final StringCodec CODEC = StringCodec.UTF8; @@ -49,11 +49,11 @@ class UpstreamReplicaTopologyRefresh { private final ScheduledExecutorService eventExecutors; - UpstreamReplicaTopologyRefresh(RedisClient client, TopologyProvider topologyProvider) { + MasterReplicaTopologyRefresh(RedisClient client, TopologyProvider topologyProvider) { this(new RedisClientNodeConnectionFactory(client), client.getResources().eventExecutorGroup(), topologyProvider); } - UpstreamReplicaTopologyRefresh(NodeConnectionFactory nodeConnectionFactory, ScheduledExecutorService eventExecutors, + MasterReplicaTopologyRefresh(NodeConnectionFactory nodeConnectionFactory, ScheduledExecutorService eventExecutors, TopologyProvider topologyProvider) { this.nodeConnectionFactory = nodeConnectionFactory; diff --git a/src/main/java/io/lettuce/core/masterreplica/RedisUpstreamReplicaNode.java b/src/main/java/io/lettuce/core/masterreplica/RedisMasterReplicaNode.java similarity index 87% rename from src/main/java/io/lettuce/core/masterreplica/RedisUpstreamReplicaNode.java rename to src/main/java/io/lettuce/core/masterreplica/RedisMasterReplicaNode.java index 2e481faa12..db7643abaf 100644 --- a/src/main/java/io/lettuce/core/masterreplica/RedisUpstreamReplicaNode.java +++ b/src/main/java/io/lettuce/core/masterreplica/RedisMasterReplicaNode.java @@ -24,13 +24,13 @@ * @author Mark Paluch * @author Adam McElwee */ -class RedisUpstreamReplicaNode implements RedisNodeDescription { +class RedisMasterReplicaNode implements RedisNodeDescription { private final RedisURI redisURI; private final Role role; - RedisUpstreamReplicaNode(String host, int port, RedisURI seed, Role role) { + RedisMasterReplicaNode(String host, int port, RedisURI seed, Role role) { this.redisURI = RedisURI.builder(seed).withHost(host).withPort(port).build(); this.role = role; @@ -50,10 +50,10 @@ public Role getRole() { public boolean equals(Object o) { if (this == o) return true; - if (!(o instanceof RedisUpstreamReplicaNode)) + if (!(o instanceof RedisMasterReplicaNode)) return false; - RedisUpstreamReplicaNode that = (RedisUpstreamReplicaNode) o; + RedisMasterReplicaNode that = (RedisMasterReplicaNode) o; if (!redisURI.equals(that.redisURI)) return false; diff --git a/src/main/java/io/lettuce/core/masterreplica/ReplicaTopologyProvider.java b/src/main/java/io/lettuce/core/masterreplica/ReplicaTopologyProvider.java index 76cee71cd1..51ba9d4d90 100644 --- a/src/main/java/io/lettuce/core/masterreplica/ReplicaTopologyProvider.java +++ b/src/main/java/io/lettuce/core/masterreplica/ReplicaTopologyProvider.java @@ -142,7 +142,7 @@ private List getReplicasFromInfo(String info) { String ip = getNested(IP_PATTERN, group, 1); String port = getNested(PORT_PATTERN, group, 1); - replicas.add(new RedisUpstreamReplicaNode(ip, Integer.parseInt(port), redisURI, RedisInstance.Role.SLAVE)); + replicas.add(new RedisMasterReplicaNode(ip, Integer.parseInt(port), redisURI, RedisInstance.Role.SLAVE)); } return replicas; @@ -163,7 +163,7 @@ private RedisNodeDescription getMasterFromInfo(String info) { String host = masterHostMatcher.group(1); int port = Integer.parseInt(masterPortMatcher.group(1)); - return new RedisUpstreamReplicaNode(host, port, redisURI, RedisInstance.Role.UPSTREAM); + return new RedisMasterReplicaNode(host, port, redisURI, RedisInstance.Role.UPSTREAM); } private String getNested(Pattern pattern, String string, int group) { @@ -196,7 +196,7 @@ private RedisNodeDescription getRedisNodeDescription(Matcher matcher) { + RedisInstance.Role.REPLICA); } - return new RedisUpstreamReplicaNode(redisURI.getHost(), redisURI.getPort(), redisURI, role); + return new RedisMasterReplicaNode(redisURI.getHost(), redisURI.getPort(), redisURI, role); } } diff --git a/src/main/java/io/lettuce/core/masterreplica/SentinelConnector.java b/src/main/java/io/lettuce/core/masterreplica/SentinelConnector.java index dcdad7ad7d..16081f2f67 100644 --- a/src/main/java/io/lettuce/core/masterreplica/SentinelConnector.java +++ b/src/main/java/io/lettuce/core/masterreplica/SentinelConnector.java @@ -31,12 +31,12 @@ import io.netty.util.internal.logging.InternalLoggerFactory; /** - * {@link UpstreamReplicaConnector} to connect a Sentinel-managed Master/Replica setup using a Sentinel {@link RedisURI}. + * {@link MasterReplicaConnector} to connect a Sentinel-managed Master/Replica setup using a Sentinel {@link RedisURI}. * * @author Mark Paluch * @since 5.1 */ -class SentinelConnector implements UpstreamReplicaConnector { +class SentinelConnector implements MasterReplicaConnector { private static final InternalLogger LOG = InternalLoggerFactory.getInstance(SentinelConnector.class); @@ -59,8 +59,8 @@ public CompletableFuture> connectAsyn SentinelTopologyRefresh sentinelTopologyRefresh = new SentinelTopologyRefresh(redisClient, redisURI.getSentinelMasterId(), redisURI.getSentinels()); - UpstreamReplicaTopologyRefresh refresh = new UpstreamReplicaTopologyRefresh(redisClient, topologyProvider); - UpstreamReplicaConnectionProvider connectionProvider = new UpstreamReplicaConnectionProvider<>(redisClient, codec, + MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(redisClient, topologyProvider); + MasterReplicaConnectionProvider connectionProvider = new MasterReplicaConnectionProvider<>(redisClient, codec, redisURI, Collections.emptyMap()); Runnable runnable = getTopologyRefreshRunnable(refresh, connectionProvider); @@ -76,12 +76,12 @@ public CompletableFuture> connectAsyn } private Mono> initializeConnection(RedisCodec codec, - SentinelTopologyRefresh sentinelTopologyRefresh, UpstreamReplicaConnectionProvider connectionProvider, + SentinelTopologyRefresh sentinelTopologyRefresh, MasterReplicaConnectionProvider connectionProvider, Runnable runnable, List nodes) { connectionProvider.setKnownNodes(nodes); - UpstreamReplicaChannelWriter channelWriter = new UpstreamReplicaChannelWriter(connectionProvider, + MasterReplicaChannelWriter channelWriter = new MasterReplicaChannelWriter(connectionProvider, redisClient.getResources()) { @Override @@ -91,7 +91,7 @@ public CompletableFuture closeAsync() { }; - StatefulRedisUpstreamReplicaConnectionImpl connection = new StatefulRedisUpstreamReplicaConnectionImpl<>( + StatefulRedisMasterReplicaConnectionImpl connection = new StatefulRedisMasterReplicaConnectionImpl<>( channelWriter, codec, redisURI.getTimeout()); connection.setOptions(redisClient.getOptions()); @@ -102,8 +102,8 @@ public CompletableFuture closeAsync() { }).then(Mono.just(connection)); } - private Runnable getTopologyRefreshRunnable(UpstreamReplicaTopologyRefresh refresh, - UpstreamReplicaConnectionProvider connectionProvider) { + private Runnable getTopologyRefreshRunnable(MasterReplicaTopologyRefresh refresh, + MasterReplicaConnectionProvider connectionProvider) { return () -> { try { diff --git a/src/main/java/io/lettuce/core/masterreplica/SentinelTopologyProvider.java b/src/main/java/io/lettuce/core/masterreplica/SentinelTopologyProvider.java index e4adf40f25..208734a4de 100644 --- a/src/main/java/io/lettuce/core/masterreplica/SentinelTopologyProvider.java +++ b/src/main/java/io/lettuce/core/masterreplica/SentinelTopologyProvider.java @@ -133,7 +133,7 @@ private RedisNodeDescription toNode(Map map, RedisInstance.Role String ip = map.get("ip"); String port = map.get("port"); - return new RedisUpstreamReplicaNode(ip, Integer.parseInt(port), sentinelUri, role); + return new RedisMasterReplicaNode(ip, Integer.parseInt(port), sentinelUri, role); } } diff --git a/src/main/java/io/lettuce/core/masterreplica/StatefulRedisUpstreamReplicaConnectionImpl.java b/src/main/java/io/lettuce/core/masterreplica/StatefulRedisMasterReplicaConnectionImpl.java similarity index 80% rename from src/main/java/io/lettuce/core/masterreplica/StatefulRedisUpstreamReplicaConnectionImpl.java rename to src/main/java/io/lettuce/core/masterreplica/StatefulRedisMasterReplicaConnectionImpl.java index dd4a3f959a..c9274c1143 100644 --- a/src/main/java/io/lettuce/core/masterreplica/StatefulRedisUpstreamReplicaConnectionImpl.java +++ b/src/main/java/io/lettuce/core/masterreplica/StatefulRedisMasterReplicaConnectionImpl.java @@ -24,7 +24,7 @@ /** * @author Mark Paluch */ -class StatefulRedisUpstreamReplicaConnectionImpl extends StatefulRedisConnectionImpl +class StatefulRedisMasterReplicaConnectionImpl extends StatefulRedisConnectionImpl implements StatefulRedisMasterReplicaConnection { /** @@ -34,7 +34,7 @@ class StatefulRedisUpstreamReplicaConnectionImpl extends StatefulRedisConn * @param codec Codec used to encode/decode keys and values. * @param timeout Maximum time to wait for a response. */ - StatefulRedisUpstreamReplicaConnectionImpl(UpstreamReplicaChannelWriter writer, RedisCodec codec, Duration timeout) { + StatefulRedisMasterReplicaConnectionImpl(MasterReplicaChannelWriter writer, RedisCodec codec, Duration timeout) { super(writer, NoOpPushHandler.INSTANCE, codec, timeout); } @@ -49,8 +49,8 @@ public ReadFrom getReadFrom() { } @Override - public UpstreamReplicaChannelWriter getChannelWriter() { - return (UpstreamReplicaChannelWriter) super.getChannelWriter(); + public MasterReplicaChannelWriter getChannelWriter() { + return (MasterReplicaChannelWriter) super.getChannelWriter(); } } diff --git a/src/main/java/io/lettuce/core/masterreplica/StaticUpstreamReplicaConnector.java b/src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaConnector.java similarity index 75% rename from src/main/java/io/lettuce/core/masterreplica/StaticUpstreamReplicaConnector.java rename to src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaConnector.java index bc645477e5..27c23298cf 100644 --- a/src/main/java/io/lettuce/core/masterreplica/StaticUpstreamReplicaConnector.java +++ b/src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaConnector.java @@ -30,13 +30,13 @@ import io.lettuce.core.models.role.RedisNodeDescription; /** - * {@link UpstreamReplicaConnector} to connect to a static declared Master/Replica setup providing a fixed array of + * {@link MasterReplicaConnector} to connect to a static declared Master/Replica setup providing a fixed array of * {@link RedisURI}. This connector determines roles and remains using only the provided endpoints. * * @author Mark Paluch * @since 5.1 */ -class StaticUpstreamReplicaConnector implements UpstreamReplicaConnector { +class StaticMasterReplicaConnector implements MasterReplicaConnector { private final RedisClient redisClient; @@ -44,7 +44,7 @@ class StaticUpstreamReplicaConnector implements UpstreamReplicaConnector redisURIs; - StaticUpstreamReplicaConnector(RedisClient redisClient, RedisCodec codec, Iterable redisURIs) { + StaticMasterReplicaConnector(RedisClient redisClient, RedisCodec codec, Iterable redisURIs) { this.redisClient = redisClient; this.codec = codec; this.redisURIs = redisURIs; @@ -59,8 +59,8 @@ public CompletableFuture> connectAsyn RedisURI seedNode = redisURIs.iterator().next(); - UpstreamReplicaTopologyRefresh refresh = new UpstreamReplicaTopologyRefresh(redisClient, topologyProvider); - UpstreamReplicaConnectionProvider connectionProvider = new UpstreamReplicaConnectionProvider<>(redisClient, codec, + MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(redisClient, topologyProvider); + MasterReplicaConnectionProvider connectionProvider = new MasterReplicaConnectionProvider<>(redisClient, codec, seedNode, initialConnections); return refresh.getNodes(seedNode).flatMap(nodes -> { @@ -74,14 +74,14 @@ public CompletableFuture> connectAsyn } private Mono> initializeConnection(RedisCodec codec, RedisURI seedNode, - UpstreamReplicaConnectionProvider connectionProvider, List nodes) { + MasterReplicaConnectionProvider connectionProvider, List nodes) { connectionProvider.setKnownNodes(nodes); - UpstreamReplicaChannelWriter channelWriter = new UpstreamReplicaChannelWriter(connectionProvider, + MasterReplicaChannelWriter channelWriter = new MasterReplicaChannelWriter(connectionProvider, redisClient.getResources()); - StatefulRedisUpstreamReplicaConnectionImpl connection = new StatefulRedisUpstreamReplicaConnectionImpl<>( + StatefulRedisMasterReplicaConnectionImpl connection = new StatefulRedisMasterReplicaConnectionImpl<>( channelWriter, codec, seedNode.getTimeout()); connection.setOptions(redisClient.getOptions()); diff --git a/src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaTopologyProvider.java b/src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaTopologyProvider.java index c1ca8fab5a..890511aa98 100644 --- a/src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaTopologyProvider.java +++ b/src/main/java/io/lettuce/core/masterreplica/StaticMasterReplicaTopologyProvider.java @@ -117,7 +117,7 @@ private static Mono getNodeDescription(RedisURI uri, StatefulRedisConnection connection) { return connection.reactive().role().collectList().map(RoleParser::parse) - .map(it -> new RedisUpstreamReplicaNode(uri.getHost(), uri.getPort(), uri, it.getRole())); + .map(it -> new RedisMasterReplicaNode(uri.getHost(), uri.getPort(), uri, it.getRole())); } } diff --git a/src/main/java/io/lettuce/core/models/role/RedisInstance.java b/src/main/java/io/lettuce/core/models/role/RedisInstance.java index 9a5d627ed7..23a75b78df 100644 --- a/src/main/java/io/lettuce/core/models/role/RedisInstance.java +++ b/src/main/java/io/lettuce/core/models/role/RedisInstance.java @@ -34,9 +34,13 @@ public interface RedisInstance { */ enum Role { - @Deprecated MASTER { + @Override + public boolean isMaster() { + return true; + } + @Override public boolean isUpstream() { return true; @@ -56,6 +60,11 @@ public boolean isReplica() { UPSTREAM { + @Override + public boolean isMaster() { + return true; + } + @Override public boolean isUpstream() { return true; @@ -78,10 +87,18 @@ public boolean isReplica() { * @return {@code true} if the role indicates that the role is a replication source. * @since 6.0 */ - public boolean isUpstream() { + public boolean isMaster() { return false; } + /** + * @return {@code true} if the role indicates that the role is a replication source. + * @since 6.1 + */ + public boolean isUpstream() { + return isMaster(); + } + /** * @return {@code true} if the role indicates that the role is a replicated node (replica). * @since 6.0 diff --git a/src/main/java/io/lettuce/core/models/role/RedisMasterInstance.java b/src/main/java/io/lettuce/core/models/role/RedisMasterInstance.java index 5636a879ca..4669f8dfe4 100644 --- a/src/main/java/io/lettuce/core/models/role/RedisMasterInstance.java +++ b/src/main/java/io/lettuce/core/models/role/RedisMasterInstance.java @@ -22,10 +22,8 @@ * * @author Mark Paluch * @since 3.0 - * @deprecated since 6.0 in favor of {@link RedisUpstreamInstance} */ @SuppressWarnings("serial") -@Deprecated public class RedisMasterInstance extends RedisUpstreamInstance { public RedisMasterInstance() { diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaChannelWriterUnitTests.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaChannelWriterUnitTests.java similarity index 61% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaChannelWriterUnitTests.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaChannelWriterUnitTests.java index 1bae53fc87..72a026eb89 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaChannelWriterUnitTests.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaChannelWriterUnitTests.java @@ -46,10 +46,10 @@ */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -class UpstreamReplicaChannelWriterUnitTests { +class MasterReplicaChannelWriterUnitTests { @Mock - private UpstreamReplicaConnectionProvider connectionProvider; + private MasterReplicaConnectionProvider connectionProvider; @Mock private ClientResources clientResources; @@ -63,18 +63,18 @@ void shouldReturnIntentForWriteCommand() { RedisCommand set = new Command<>(CommandType.SET, null); RedisCommand mset = new Command<>(CommandType.MSET, null); - assertThat(UpstreamReplicaChannelWriter.getIntent(Arrays.asList(set, mset))) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.WRITE); + assertThat(MasterReplicaChannelWriter.getIntent(Arrays.asList(set, mset))) + .isEqualTo(MasterReplicaConnectionProvider.Intent.WRITE); - assertThat(UpstreamReplicaChannelWriter.getIntent(Collections.singletonList(set))) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.WRITE); + assertThat(MasterReplicaChannelWriter.getIntent(Collections.singletonList(set))) + .isEqualTo(MasterReplicaConnectionProvider.Intent.WRITE); } @Test void shouldReturnDefaultIntentForNoCommands() { - assertThat(UpstreamReplicaChannelWriter.getIntent(Collections.emptyList())) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.WRITE); + assertThat(MasterReplicaChannelWriter.getIntent(Collections.emptyList())) + .isEqualTo(MasterReplicaConnectionProvider.Intent.WRITE); } @Test @@ -83,11 +83,11 @@ void shouldReturnIntentForReadCommand() { RedisCommand get = new Command<>(CommandType.GET, null); RedisCommand mget = new Command<>(CommandType.MGET, null); - assertThat(UpstreamReplicaChannelWriter.getIntent(Arrays.asList(get, mget))) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.READ); + assertThat(MasterReplicaChannelWriter.getIntent(Arrays.asList(get, mget))) + .isEqualTo(MasterReplicaConnectionProvider.Intent.READ); - assertThat(UpstreamReplicaChannelWriter.getIntent(Collections.singletonList(get))) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.READ); + assertThat(MasterReplicaChannelWriter.getIntent(Collections.singletonList(get))) + .isEqualTo(MasterReplicaConnectionProvider.Intent.READ); } @Test @@ -96,34 +96,34 @@ void shouldReturnIntentForMixedCommands() { RedisCommand set = new Command<>(CommandType.SET, null); RedisCommand mget = new Command<>(CommandType.MGET, null); - assertThat(UpstreamReplicaChannelWriter.getIntent(Arrays.asList(set, mget))) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.WRITE); + assertThat(MasterReplicaChannelWriter.getIntent(Arrays.asList(set, mget))) + .isEqualTo(MasterReplicaConnectionProvider.Intent.WRITE); - assertThat(UpstreamReplicaChannelWriter.getIntent(Collections.singletonList(set))) - .isEqualTo(UpstreamReplicaConnectionProvider.Intent.WRITE); + assertThat(MasterReplicaChannelWriter.getIntent(Collections.singletonList(set))) + .isEqualTo(MasterReplicaConnectionProvider.Intent.WRITE); } @Test void shouldBindTransactionsToMaster() { - UpstreamReplicaChannelWriter writer = new UpstreamReplicaChannelWriter(connectionProvider, clientResources); + MasterReplicaChannelWriter writer = new MasterReplicaChannelWriter(connectionProvider, clientResources); - when(connectionProvider.getConnectionAsync(any(UpstreamReplicaConnectionProvider.Intent.class))) + when(connectionProvider.getConnectionAsync(any(MasterReplicaConnectionProvider.Intent.class))) .thenReturn(CompletableFuture.completedFuture(connection)); writer.write(mockCommand(CommandType.MULTI)); writer.write(mockCommand(CommandType.GET)); writer.write(mockCommand(CommandType.EXEC)); - verify(connectionProvider, times(3)).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.WRITE); + verify(connectionProvider, times(3)).getConnectionAsync(MasterReplicaConnectionProvider.Intent.WRITE); } @Test void shouldBindTransactionsToMasterInBatch() { - UpstreamReplicaChannelWriter writer = new UpstreamReplicaChannelWriter(connectionProvider, clientResources); + MasterReplicaChannelWriter writer = new MasterReplicaChannelWriter(connectionProvider, clientResources); - when(connectionProvider.getConnectionAsync(any(UpstreamReplicaConnectionProvider.Intent.class))) + when(connectionProvider.getConnectionAsync(any(MasterReplicaConnectionProvider.Intent.class))) .thenReturn(CompletableFuture.completedFuture(connection)); List> commands = Arrays.asList(mockCommand(CommandType.MULTI), @@ -131,47 +131,47 @@ void shouldBindTransactionsToMasterInBatch() { writer.write(commands); - verify(connectionProvider).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.WRITE); + verify(connectionProvider).getConnectionAsync(MasterReplicaConnectionProvider.Intent.WRITE); } @Test void shouldDeriveIntentFromCommandTypeAfterTransaction() { - UpstreamReplicaChannelWriter writer = new UpstreamReplicaChannelWriter(connectionProvider, clientResources); + MasterReplicaChannelWriter writer = new MasterReplicaChannelWriter(connectionProvider, clientResources); - when(connectionProvider.getConnectionAsync(any(UpstreamReplicaConnectionProvider.Intent.class))) + when(connectionProvider.getConnectionAsync(any(MasterReplicaConnectionProvider.Intent.class))) .thenReturn(CompletableFuture.completedFuture(connection)); writer.write(mockCommand(CommandType.MULTI)); writer.write(mockCommand(CommandType.EXEC)); writer.write(mockCommand(CommandType.GET)); - verify(connectionProvider, times(2)).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.WRITE); - verify(connectionProvider).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.READ); + verify(connectionProvider, times(2)).getConnectionAsync(MasterReplicaConnectionProvider.Intent.WRITE); + verify(connectionProvider).getConnectionAsync(MasterReplicaConnectionProvider.Intent.READ); } @Test void shouldDeriveIntentFromCommandTypeAfterDiscardedTransaction() { - UpstreamReplicaChannelWriter writer = new UpstreamReplicaChannelWriter(connectionProvider, clientResources); + MasterReplicaChannelWriter writer = new MasterReplicaChannelWriter(connectionProvider, clientResources); - when(connectionProvider.getConnectionAsync(any(UpstreamReplicaConnectionProvider.Intent.class))) + when(connectionProvider.getConnectionAsync(any(MasterReplicaConnectionProvider.Intent.class))) .thenReturn(CompletableFuture.completedFuture(connection)); writer.write(mockCommand(CommandType.MULTI)); writer.write(mockCommand(CommandType.DISCARD)); writer.write(mockCommand(CommandType.GET)); - verify(connectionProvider, times(2)).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.WRITE); - verify(connectionProvider).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.READ); + verify(connectionProvider, times(2)).getConnectionAsync(MasterReplicaConnectionProvider.Intent.WRITE); + verify(connectionProvider).getConnectionAsync(MasterReplicaConnectionProvider.Intent.READ); } @Test void shouldDeriveIntentFromCommandBatchTypeAfterDiscardedTransaction() { - UpstreamReplicaChannelWriter writer = new UpstreamReplicaChannelWriter(connectionProvider, clientResources); + MasterReplicaChannelWriter writer = new MasterReplicaChannelWriter(connectionProvider, clientResources); - when(connectionProvider.getConnectionAsync(any(UpstreamReplicaConnectionProvider.Intent.class))) + when(connectionProvider.getConnectionAsync(any(MasterReplicaConnectionProvider.Intent.class))) .thenReturn(CompletableFuture.completedFuture(connection)); List> commands = Arrays.asList(mockCommand(CommandType.MULTI), @@ -180,8 +180,8 @@ void shouldDeriveIntentFromCommandBatchTypeAfterDiscardedTransaction() { writer.write(commands); writer.write(Collections.singletonList(mockCommand(CommandType.GET))); - verify(connectionProvider).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.WRITE); - verify(connectionProvider).getConnectionAsync(UpstreamReplicaConnectionProvider.Intent.READ); + verify(connectionProvider).getConnectionAsync(MasterReplicaConnectionProvider.Intent.WRITE); + verify(connectionProvider).getConnectionAsync(MasterReplicaConnectionProvider.Intent.READ); } private static Command mockCommand(CommandType multi) { diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaConnectionProviderUnitTests.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaConnectionProviderUnitTests.java similarity index 86% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaConnectionProviderUnitTests.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaConnectionProviderUnitTests.java index 3019fcb972..d6511a1836 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaConnectionProviderUnitTests.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaConnectionProviderUnitTests.java @@ -47,9 +47,9 @@ */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -class UpstreamReplicaConnectionProviderUnitTests { +class MasterReplicaConnectionProviderUnitTests { - private UpstreamReplicaConnectionProvider sut; + private MasterReplicaConnectionProvider sut; @Mock RedisClient clientMock; @@ -66,10 +66,10 @@ class UpstreamReplicaConnectionProviderUnitTests { void before() { nodeConnectionMock = (StatefulRedisConnection) channelHandlerMock; - sut = new UpstreamReplicaConnectionProvider<>(clientMock, StringCodec.UTF8, RedisURI.create("localhost", 1), + sut = new MasterReplicaConnectionProvider<>(clientMock, StringCodec.UTF8, RedisURI.create("localhost", 1), Collections.emptyMap()); sut.setKnownNodes(Arrays.asList( - new RedisUpstreamReplicaNode("localhost", 1, RedisURI.create("localhost", 1), RedisInstance.Role.UPSTREAM))); + new RedisMasterReplicaNode("localhost", 1, RedisURI.create("localhost", 1), RedisInstance.Role.UPSTREAM))); } @Test @@ -80,7 +80,7 @@ void shouldCloseConnections() { when(clientMock.connectAsync(eq(StringCodec.UTF8), any())) .thenReturn(ConnectionFuture.completed(null, nodeConnectionMock)); - StatefulRedisConnection connection = sut.getConnection(UpstreamReplicaConnectionProvider.Intent.READ); + StatefulRedisConnection connection = sut.getConnection(MasterReplicaConnectionProvider.Intent.READ); assertThat(connection).isNotNull(); sut.close(); diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaSentinelSslIntegrationTests.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaSentinelSslIntegrationTests.java similarity index 94% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaSentinelSslIntegrationTests.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaSentinelSslIntegrationTests.java index b531cc35f1..7f4ba7ffe1 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaSentinelSslIntegrationTests.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaSentinelSslIntegrationTests.java @@ -39,12 +39,12 @@ * @author Mark Paluch */ @ExtendWith(LettuceExtension.class) -class UpstreamReplicaSentinelSslIntegrationTests extends TestSupport { +class MasterReplicaSentinelSslIntegrationTests extends TestSupport { private final ClientResources clientResources; @Inject - UpstreamReplicaSentinelSslIntegrationTests(ClientResources clientResources) { + MasterReplicaSentinelSslIntegrationTests(ClientResources clientResources) { this.clientResources = clientResources.mutate() .socketAddressResolver(MappingSocketAddressResolver.create(DnsResolver.jvmDefault(), hostAndPort -> { diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTest.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java similarity index 96% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTest.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java index 52f4ba0b55..a0d0fa42f9 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTest.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTest.java @@ -15,9 +15,8 @@ */ package io.lettuce.core.masterreplica; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.*; import java.util.Collections; import java.util.List; @@ -42,9 +41,11 @@ import io.lettuce.test.settings.TestSettings; /** + * Integration tests for master/replica via {@link MasterReplica}. + * * @author Mark Paluch */ -class UpstreamReplicaTest extends AbstractRedisClientTest { +class MasterReplicaTest extends AbstractRedisClientTest { private RedisURI masterURI = RedisURI.Builder.redis(host, TestSettings.port(3)).withPassword(passwd) .withClientName("my-client").withDatabase(5).build(); diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyProviderUnitTests.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTopologyProviderUnitTests.java similarity index 96% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyProviderUnitTests.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaTopologyProviderUnitTests.java index fd1a795ad6..75290b4875 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyProviderUnitTests.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTopologyProviderUnitTests.java @@ -15,9 +15,8 @@ */ package io.lettuce.core.masterreplica; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.mockito.Mockito.mock; +import static org.assertj.core.api.Assertions.*; +import static org.mockito.Mockito.*; import java.util.List; @@ -30,9 +29,11 @@ import io.lettuce.test.settings.TestSettings; /** + * Unit tests for {@link ReplicaTopologyProvider}. + * * @author Mark Paluch */ -class UpstreamReplicaTopologyProviderUnitTests { +class MasterReplicaTopologyProviderUnitTests { private StatefulRedisConnection connectionMock = mock(StatefulRedisConnection.class); diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyRefreshUnitTests.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTopologyRefreshUnitTests.java similarity index 88% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyRefreshUnitTests.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaTopologyRefreshUnitTests.java index 37a5f2c1be..f7b7c7effb 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaTopologyRefreshUnitTests.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaTopologyRefreshUnitTests.java @@ -47,12 +47,12 @@ */ @ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) -class UpstreamReplicaTopologyRefreshUnitTests { +class MasterReplicaTopologyRefreshUnitTests { - private static final RedisUpstreamReplicaNode UPSTREAM = new RedisUpstreamReplicaNode("localhost", 1, new RedisURI(), + private static final RedisMasterReplicaNode UPSTREAM = new RedisMasterReplicaNode("localhost", 1, new RedisURI(), RedisInstance.Role.UPSTREAM); - private static final RedisUpstreamReplicaNode REPLICA = new RedisUpstreamReplicaNode("localhost", 2, new RedisURI(), + private static final RedisMasterReplicaNode REPLICA = new RedisMasterReplicaNode("localhost", 2, new RedisURI(), RedisInstance.Role.REPLICA); @Mock @@ -93,7 +93,7 @@ void tearDown() { @Test void shouldRetrieveTopology() { - UpstreamReplicaTopologyRefresh refresh = new UpstreamReplicaTopologyRefresh(connectionFactory, executorService, + MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(connectionFactory, executorService, provider); CompletableFuture> master = CompletableFuture.completedFuture(connection); @@ -112,7 +112,7 @@ void shouldRetrieveTopology() { @Test void shouldRetrieveTopologyWithFailedNode() { - UpstreamReplicaTopologyRefresh refresh = new UpstreamReplicaTopologyRefresh(connectionFactory, executorService, + MasterReplicaTopologyRefresh refresh = new MasterReplicaTopologyRefresh(connectionFactory, executorService, provider); CompletableFuture> connected = CompletableFuture.completedFuture(connection); diff --git a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaUtilsUnitTests.java b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaUtilsUnitTests.java similarity index 64% rename from src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaUtilsUnitTests.java rename to src/test/java/io/lettuce/core/masterreplica/MasterReplicaUtilsUnitTests.java index 7e0f7f63f6..9d200de1ce 100644 --- a/src/test/java/io/lettuce/core/masterreplica/UpstreamReplicaUtilsUnitTests.java +++ b/src/test/java/io/lettuce/core/masterreplica/MasterReplicaUtilsUnitTests.java @@ -15,7 +15,7 @@ */ package io.lettuce.core.masterreplica; -import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat; +import static org.assertj.core.api.AssertionsForInterfaceTypes.*; import java.util.Arrays; @@ -25,21 +25,23 @@ import io.lettuce.core.models.role.RedisInstance; /** + * Unit tests for {@link RedisMasterReplicaNode}. + * * @author Mark Paluch */ -class UpstreamReplicaUtilsUnitTests { +class MasterReplicaUtilsUnitTests { @Test void isChangedShouldReturnFalse() { - RedisUpstreamReplicaNode upstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 111), + RedisMasterReplicaNode upstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 111), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode replica = new RedisUpstreamReplicaNode("host", 234, RedisURI.create("host", 234), + RedisMasterReplicaNode replica = new RedisMasterReplicaNode("host", 234, RedisURI.create("host", 234), RedisInstance.Role.REPLICA); - RedisUpstreamReplicaNode newupstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 555), + RedisMasterReplicaNode newupstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 555), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode newslave = new RedisUpstreamReplicaNode("host", 234, RedisURI.create("host", 666), + RedisMasterReplicaNode newslave = new RedisMasterReplicaNode("host", 234, RedisURI.create("host", 666), RedisInstance.Role.REPLICA); assertThat(ReplicaUtils.isChanged(Arrays.asList(upstream, replica), Arrays.asList(newupstream, newslave))).isFalse(); @@ -52,12 +54,12 @@ void isChangedShouldReturnFalse() { @Test void isChangedShouldReturnTrueBecauseSlaveIsGone() { - RedisUpstreamReplicaNode upstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 111), + RedisMasterReplicaNode upstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 111), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode replica = new RedisUpstreamReplicaNode("host", 234, RedisURI.create("host", 234), + RedisMasterReplicaNode replica = new RedisMasterReplicaNode("host", 234, RedisURI.create("host", 234), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode newupstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 111), + RedisMasterReplicaNode newupstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 111), RedisInstance.Role.UPSTREAM); assertThat(ReplicaUtils.isChanged(Arrays.asList(upstream, replica), Arrays.asList(newupstream))).isTrue(); @@ -66,14 +68,14 @@ void isChangedShouldReturnTrueBecauseSlaveIsGone() { @Test void isChangedShouldReturnTrueBecauseHostWasMigrated() { - RedisUpstreamReplicaNode upstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 111), + RedisMasterReplicaNode upstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 111), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode replica = new RedisUpstreamReplicaNode("host", 234, RedisURI.create("host", 234), + RedisMasterReplicaNode replica = new RedisMasterReplicaNode("host", 234, RedisURI.create("host", 234), RedisInstance.Role.REPLICA); - RedisUpstreamReplicaNode newupstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 555), + RedisMasterReplicaNode newupstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 555), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode newslave = new RedisUpstreamReplicaNode("newhost", 234, RedisURI.create("newhost", 666), + RedisMasterReplicaNode newslave = new RedisMasterReplicaNode("newhost", 234, RedisURI.create("newhost", 666), RedisInstance.Role.REPLICA); assertThat(ReplicaUtils.isChanged(Arrays.asList(upstream, replica), Arrays.asList(newupstream, newslave))).isTrue(); @@ -85,14 +87,14 @@ void isChangedShouldReturnTrueBecauseHostWasMigrated() { @Test void isChangedShouldReturnTrueBecauseRolesSwitched() { - RedisUpstreamReplicaNode upstream = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 111), + RedisMasterReplicaNode upstream = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 111), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode replica = new RedisUpstreamReplicaNode("host", 234, RedisURI.create("host", 234), + RedisMasterReplicaNode replica = new RedisMasterReplicaNode("host", 234, RedisURI.create("host", 234), RedisInstance.Role.UPSTREAM); - RedisUpstreamReplicaNode newslave = new RedisUpstreamReplicaNode("host", 1234, RedisURI.create("host", 111), + RedisMasterReplicaNode newslave = new RedisMasterReplicaNode("host", 1234, RedisURI.create("host", 111), RedisInstance.Role.REPLICA); - RedisUpstreamReplicaNode newupstream = new RedisUpstreamReplicaNode("host", 234, RedisURI.create("host", 234), + RedisMasterReplicaNode newupstream = new RedisMasterReplicaNode("host", 234, RedisURI.create("host", 234), RedisInstance.Role.UPSTREAM); assertThat(ReplicaUtils.isChanged(Arrays.asList(upstream, replica), Arrays.asList(newupstream, newslave))).isTrue(); diff --git a/src/test/java/io/lettuce/core/masterreplica/StaticUpstreamReplicaTest.java b/src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java similarity index 91% rename from src/test/java/io/lettuce/core/masterreplica/StaticUpstreamReplicaTest.java rename to src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java index 1d156e69bb..d42deaf1f5 100644 --- a/src/test/java/io/lettuce/core/masterreplica/StaticUpstreamReplicaTest.java +++ b/src/test/java/io/lettuce/core/masterreplica/StaticMasterReplicaTest.java @@ -15,9 +15,8 @@ */ package io.lettuce.core.masterreplica; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; -import static org.junit.jupiter.api.Assumptions.assumeTrue; +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assumptions.*; import java.util.Arrays; import java.util.Collections; @@ -40,9 +39,11 @@ import io.lettuce.test.settings.TestSettings; /** + * Integration tests for static master/replica via {@link MasterReplica}. + * * @author Mark Paluch */ -class StaticUpstreamReplicaTest extends AbstractRedisClientTest { +class StaticMasterReplicaTest extends AbstractRedisClientTest { private StatefulRedisMasterReplicaConnection connection; @@ -196,7 +197,7 @@ static String replicaCall(StatefulRedisMasterReplicaConnection c @Test void testConnectionCount() { - UpstreamReplicaConnectionProvider connectionProvider = getConnectionProvider(); + MasterReplicaConnectionProvider connectionProvider = getConnectionProvider(); assertThat(connectionProvider.getConnectionCount()).isEqualTo(0); replicaCall(connection); @@ -209,7 +210,7 @@ void testConnectionCount() { @Test void testReconfigureTopology() { - UpstreamReplicaConnectionProvider connectionProvider = getConnectionProvider(); + MasterReplicaConnectionProvider connectionProvider = getConnectionProvider(); replicaCall(connection); @@ -218,8 +219,8 @@ void testReconfigureTopology() { assertThat(connectionProvider.getConnectionCount()).isEqualTo(0); } - UpstreamReplicaConnectionProvider getConnectionProvider() { - UpstreamReplicaChannelWriter writer = ((StatefulRedisUpstreamReplicaConnectionImpl) connection).getChannelWriter(); + MasterReplicaConnectionProvider getConnectionProvider() { + MasterReplicaChannelWriter writer = ((StatefulRedisMasterReplicaConnectionImpl) connection).getChannelWriter(); return writer.getUpstreamReplicaConnectionProvider(); } }