Skip to content

Commit

Permalink
Java: Rename RedisClient, RedisClusterClient to GlideClient, GlideClu…
Browse files Browse the repository at this point in the history
…sterClient
  • Loading branch information
shohamazon committed Jun 27, 2024
1 parent d5cb19d commit 0dbe3c8
Show file tree
Hide file tree
Showing 27 changed files with 290 additions and 297 deletions.
4 changes: 2 additions & 2 deletions java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ Other useful gradle developer commands:
### Standalone Redis:

```java
import glide.api.RedisClient;
import glide.api.GlideClient;

RedisClient client = RedisClient.CreateClient().get();
GlideClient client = GlideClient.CreateClient().get();

CompletableFuture<String> setResponse = client.set("key", "foobar");
assert setResponse.get() == "OK" : "Failed on client.set("key", "foobar") request";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
import static java.util.concurrent.TimeUnit.SECONDS;

import glide.api.BaseClient;
import glide.api.RedisClient;
import glide.api.RedisClusterClient;
import glide.api.GlideClient;
import glide.api.GlideClusterClient;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import glide.benchmarks.clients.AsyncClient;
import glide.benchmarks.utils.ConnectionSettings;
import java.util.concurrent.CompletableFuture;
Expand All @@ -23,8 +23,8 @@ public class GlideAsyncClient implements AsyncClient<String> {
public void connectToRedis(ConnectionSettings connectionSettings) {

if (connectionSettings.clusterMode) {
RedisClusterClientConfiguration config =
RedisClusterClientConfiguration.builder()
GlideClusterClientConfiguration config =
GlideClusterClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
Expand All @@ -33,14 +33,14 @@ public void connectToRedis(ConnectionSettings connectionSettings) {
.useTLS(connectionSettings.useSsl)
.build();
try {
redisClient = RedisClusterClient.CreateClient(config).get(10, SECONDS);
redisClient = GlideClusterClient.CreateClient(config).get(10, SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}

} else {
RedisClientConfiguration config =
RedisClientConfiguration.builder()
GlideClientConfiguration config =
GlideClientConfiguration.builder()
.address(
NodeAddress.builder()
.host(connectionSettings.host)
Expand All @@ -50,7 +50,7 @@ public void connectToRedis(ConnectionSettings connectionSettings) {
.build();

try {
redisClient = RedisClient.CreateClient(config).get(10, SECONDS);
redisClient = GlideClient.CreateClient(config).get(10, SECONDS);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
throw new RuntimeException(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.SortOptions;
import glide.api.models.commands.function.FunctionRestorePolicy;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.managers.CommandManager;
import glide.managers.ConnectionManager;
import java.util.Arrays;
Expand All @@ -66,26 +66,26 @@
* Async (non-blocking) client for Redis in Standalone mode. Use {@link #CreateClient} to request a
* client to Redis.
*/
public class RedisClient extends BaseClient
public class GlideClient extends BaseClient
implements GenericCommands,
ServerManagementCommands,
ConnectionManagementCommands,
ScriptingAndFunctionsCommands,
TransactionsCommands {

protected RedisClient(ConnectionManager connectionManager, CommandManager commandManager) {
protected GlideClient(ConnectionManager connectionManager, CommandManager commandManager) {
super(connectionManager, commandManager);
}

/**
* Async request for an async (non-blocking) Redis client in Standalone mode.
*
* @param config Redis client Configuration
* @return A Future to connect and return a RedisClient
* @return A Future to connect and return a GlideClient
*/
public static CompletableFuture<RedisClient> CreateClient(
@NonNull RedisClientConfiguration config) {
return CreateClient(config, RedisClient::new);
public static CompletableFuture<GlideClient> CreateClient(
@NonNull GlideClientConfiguration config) {
return CreateClient(config, GlideClient::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import glide.api.models.commands.InfoOptions;
import glide.api.models.commands.SortClusterOptions;
import glide.api.models.commands.function.FunctionRestorePolicy;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import glide.api.models.configuration.RequestRoutingConfiguration.SingleNodeRoute;
import glide.managers.CommandManager;
Expand All @@ -72,26 +72,26 @@
* Async (non-blocking) client for Redis in Cluster mode. Use {@link #CreateClient} to request a
* client to Redis.
*/
public class RedisClusterClient extends BaseClient
public class GlideClusterClient extends BaseClient
implements ConnectionManagementClusterCommands,
GenericClusterCommands,
ServerManagementClusterCommands,
ScriptingAndFunctionsClusterCommands,
TransactionsClusterCommands {

protected RedisClusterClient(ConnectionManager connectionManager, CommandManager commandManager) {
protected GlideClusterClient(ConnectionManager connectionManager, CommandManager commandManager) {
super(connectionManager, commandManager);
}

/**
* Async request for an async (non-blocking) Redis client in Cluster mode.
*
* @param config Redis cluster client Configuration
* @return A Future to connect and return a RedisClusterClient
* @return A Future to connect and return a GlideClusterClient
*/
public static CompletableFuture<RedisClusterClient> CreateClient(
@NonNull RedisClusterClientConfiguration config) {
return CreateClient(config, RedisClusterClient::new);
public static CompletableFuture<GlideClusterClient> CreateClient(
@NonNull GlideClusterClientConfiguration config) {
return CreateClient(config, GlideClusterClient::new);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api.models.commands;

import glide.api.RedisClient;
import glide.api.RedisClusterClient;
import glide.api.GlideClient;
import glide.api.GlideClusterClient;
import glide.api.models.configuration.RequestRoutingConfiguration.Route;
import glide.api.models.configuration.RequestRoutingConfiguration.SingleNodeRoute;

Expand All @@ -11,15 +11,15 @@
* Defines flushing mode for:
*
* <ul>
* <li><code>FLUSHALL</code> command implemented by {@link RedisClient#flushall(FlushMode)},
* {@link RedisClusterClient#flushall(FlushMode)}, and {@link
* RedisClusterClient#flushall(FlushMode, SingleNodeRoute)}.
* <li><code>FLUSHDB</code> command implemented by {@link RedisClient#flushdb(FlushMode)}, {@link
* RedisClusterClient#flushdb(FlushMode)}, and {@link RedisClusterClient#flushdb(FlushMode,
* <li><code>FLUSHALL</code> command implemented by {@link GlideClient#flushall(FlushMode)},
* {@link GlideClusterClient#flushall(FlushMode)}, and {@link
* GlideClusterClient#flushall(FlushMode, SingleNodeRoute)}.
* <li><code>FLUSHDB</code> command implemented by {@link GlideClient#flushdb(FlushMode)}, {@link
* GlideClusterClient#flushdb(FlushMode)}, and {@link GlideClusterClient#flushdb(FlushMode,
* SingleNodeRoute)}.
* <li><code>FUNCTION FLUSH</code> command implemented by {@link
* RedisClient#functionFlush(FlushMode)}, {@link RedisClusterClient#functionFlush(FlushMode)},
* and {@link RedisClusterClient#functionFlush(FlushMode, Route)}.
* GlideClient#functionFlush(FlushMode)}, {@link GlideClusterClient#functionFlush(FlushMode)},
* and {@link GlideClusterClient#functionFlush(FlushMode, Route)}.
* </ul>
*
* @see <a href="https://valkey.io/commands/flushall/">flushall</a>, <a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import lombok.Getter;
import lombok.experimental.SuperBuilder;

/** Represents the configuration settings for a Standalone Redis client. */
/** Represents the configuration settings for a Standalone Glide client. */
@Getter
@SuperBuilder
public class RedisClientConfiguration extends BaseClientConfiguration {
public class GlideClientConfiguration extends BaseClientConfiguration {
/** Strategy used to determine how and when to reconnect, in case of connection failures. */
private final BackoffStrategy reconnectStrategy;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
* values is used.
*/
@SuperBuilder
public class RedisClusterClientConfiguration extends BaseClientConfiguration {}
public class GlideClusterClientConfiguration extends BaseClientConfiguration {}
29 changes: 15 additions & 14 deletions java/client/src/main/java/glide/managers/ConnectionManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
import connection_request.ConnectionRequestOuterClass.ConnectionRequest;
import connection_request.ConnectionRequestOuterClass.TlsMode;
import glide.api.models.configuration.BaseClientConfiguration;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.configuration.ReadFrom;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.RedisClusterClientConfiguration;
import glide.api.models.exceptions.ClosingException;
import glide.connectors.handlers.ChannelHandler;
import java.util.concurrent.CompletableFuture;
Expand All @@ -24,9 +24,9 @@
@RequiredArgsConstructor
public class ConnectionManager {

// TODO: consider making connection manager static, and moving the ChannelHandler to the
// RedisClient.

// TODO: consider making connection manager static, and moving the
// ChannelHandler to the
// GlideClient.
/** UDS connection representation. */
private final ChannelHandler channel;

Expand Down Expand Up @@ -66,13 +66,13 @@ private Response exceptionHandler(Throwable e) {
* @return ConnectionRequest protobuf message
*/
private ConnectionRequest createConnectionRequest(BaseClientConfiguration configuration) {
if (configuration instanceof RedisClusterClientConfiguration) {
return setupConnectionRequestBuilderRedisClusterClient(
(RedisClusterClientConfiguration) configuration)
if (configuration instanceof GlideClusterClientConfiguration) {
return setupConnectionRequestBuilderGlideClusterClient(
(GlideClusterClientConfiguration) configuration)
.build();
}

return setupConnectionRequestBuilderRedisClient((RedisClientConfiguration) configuration)
return setupConnectionRequestBuilderGlideClient((GlideClientConfiguration) configuration)
.build();
}

Expand Down Expand Up @@ -123,8 +123,8 @@ private ConnectionRequest.Builder setupConnectionRequestBuilderBaseConfiguration
*
* @param configuration Connection Request Configuration
*/
private ConnectionRequest.Builder setupConnectionRequestBuilderRedisClient(
RedisClientConfiguration configuration) {
private ConnectionRequest.Builder setupConnectionRequestBuilderGlideClient(
GlideClientConfiguration configuration) {
ConnectionRequest.Builder connectionRequestBuilder =
setupConnectionRequestBuilderBaseConfiguration(configuration);
connectionRequestBuilder.setClusterModeEnabled(false);
Expand All @@ -150,8 +150,8 @@ private ConnectionRequest.Builder setupConnectionRequestBuilderRedisClient(
* @param configuration
*/
private ConnectionRequestOuterClass.ConnectionRequest.Builder
setupConnectionRequestBuilderRedisClusterClient(
RedisClusterClientConfiguration configuration) {
setupConnectionRequestBuilderGlideClusterClient(
GlideClusterClientConfiguration configuration) {
ConnectionRequest.Builder connectionRequestBuilder =
setupConnectionRequestBuilderBaseConfiguration(configuration);
connectionRequestBuilder.setClusterModeEnabled(true);
Expand All @@ -175,7 +175,8 @@ private ConnectionRequestOuterClass.ReadFrom mapReadFromEnum(ReadFrom readFrom)

/** Check a response received from Glide. */
private Void checkGlideRsResponse(Response response) {
// Note: errors are already handled before in CallbackDispatcher, but we double-check
// Note: errors are already handled before in CallbackDispatcher, but we
// double-check
if (response.hasRequestError()) {
throwClosingError(
"Unhandled request error in response: " + response.getRequestError().getMessage());
Expand Down
6 changes: 3 additions & 3 deletions java/client/src/test/java/glide/ExceptionHandlingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import static response.ResponseOuterClass.RequestErrorType.Unspecified;

import connection_request.ConnectionRequestOuterClass;
import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.exceptions.ClosingException;
import glide.api.models.exceptions.ConnectionException;
import glide.api.models.exceptions.ExecAbortException;
Expand Down Expand Up @@ -275,8 +275,8 @@ public void response_resolver_does_not_expect_errors() {
}

/** Create a config which causes connection failure. */
private static RedisClientConfiguration createDummyConfig() {
return RedisClientConfiguration.builder().build();
private static GlideClientConfiguration createDummyConfig() {
return GlideClientConfiguration.builder().build();
}

/** Test ChannelHandler extension which allows to validate whether the channel was closed. */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide.api;

import static glide.api.BaseClient.CreateClient;
import static glide.api.BaseClient.buildChannelHandler;
import static glide.api.RedisClient.CreateClient;
import static glide.api.RedisClient.buildCommandManager;
import static glide.api.RedisClient.buildConnectionManager;
import static glide.api.BaseClient.buildCommandManager;
import static glide.api.BaseClient.buildConnectionManager;
import static glide.api.GlideClient.CreateClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.mockito.ArgumentMatchers.any;
Expand All @@ -13,7 +14,7 @@
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

import glide.api.models.configuration.RedisClientConfiguration;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.exceptions.ClosingException;
import glide.connectors.handlers.ChannelHandler;
import glide.connectors.resources.ThreadPoolResource;
Expand All @@ -28,7 +29,7 @@
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

public class RedisClientCreateTest {
public class GlideClientCreateTest {

private MockedStatic<BaseClient> mockedClient;
private ChannelHandler channelHandler;
Expand Down Expand Up @@ -64,17 +65,17 @@ public void teardown() {

@Test
@SneakyThrows
public void createClient_with_default_config_successfully_returns_RedisClient() {
public void createClient_with_default_config_successfully_returns_GlideClient() {
// setup
CompletableFuture<Void> connectToRedisFuture = new CompletableFuture<>();
connectToRedisFuture.complete(null);
RedisClientConfiguration config = RedisClientConfiguration.builder().build();
GlideClientConfiguration config = GlideClientConfiguration.builder().build();

when(connectionManager.connectToRedis(eq(config))).thenReturn(connectToRedisFuture);

// exercise
CompletableFuture<RedisClient> result = CreateClient(config);
RedisClient client = result.get();
CompletableFuture<GlideClient> result = CreateClient(config);
GlideClient client = result.get();

// verify
assertEquals(connectionManager, client.connectionManager);
Expand All @@ -83,18 +84,18 @@ public void createClient_with_default_config_successfully_returns_RedisClient()

@Test
@SneakyThrows
public void createClient_with_custom_config_successfully_returns_RedisClient() {
public void createClient_with_custom_config_successfully_returns_GlideClient() {
// setup
CompletableFuture<Void> connectToRedisFuture = new CompletableFuture<>();
connectToRedisFuture.complete(null);
RedisClientConfiguration config =
RedisClientConfiguration.builder().threadPoolResource(threadPoolResource).build();
GlideClientConfiguration config =
GlideClientConfiguration.builder().threadPoolResource(threadPoolResource).build();

when(connectionManager.connectToRedis(eq(config))).thenReturn(connectToRedisFuture);

// exercise
CompletableFuture<RedisClient> result = CreateClient(config);
RedisClient client = result.get();
CompletableFuture<GlideClient> result = CreateClient(config);
GlideClient client = result.get();

// verify
assertEquals(connectionManager, client.connectionManager);
Expand All @@ -108,13 +109,13 @@ public void createClient_error_on_connection_throws_ExecutionException() {
CompletableFuture<Void> connectToRedisFuture = new CompletableFuture<>();
ClosingException exception = new ClosingException("disconnected");
connectToRedisFuture.completeExceptionally(exception);
RedisClientConfiguration config =
RedisClientConfiguration.builder().threadPoolResource(threadPoolResource).build();
GlideClientConfiguration config =
GlideClientConfiguration.builder().threadPoolResource(threadPoolResource).build();

when(connectionManager.connectToRedis(eq(config))).thenReturn(connectToRedisFuture);

// exercise
CompletableFuture<RedisClient> result = CreateClient(config);
CompletableFuture<GlideClient> result = CreateClient(config);

ExecutionException executionException = assertThrows(ExecutionException.class, result::get);

Expand Down
Loading

0 comments on commit 0dbe3c8

Please sign in to comment.