-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Java: Refactor CommandManager.java and remove Command.java #916
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api; | ||
|
||
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't heard of that in Java. I will look that one up. |
||
|
||
import glide.api.commands.BaseCommands; | ||
import glide.api.models.configuration.RedisClientConfiguration; | ||
import glide.managers.CommandManager; | ||
import glide.managers.ConnectionManager; | ||
import glide.managers.models.Command; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
|
@@ -30,8 +31,6 @@ public static CompletableFuture<RedisClient> CreateClient(RedisClientConfigurati | |
|
||
@Override | ||
public CompletableFuture<Object> customCommand(String[] args) { | ||
Command command = | ||
Command.builder().requestType(Command.RequestType.CUSTOM_COMMAND).arguments(args).build(); | ||
return commandManager.submitNewCommand(command, this::handleObjectResponse); | ||
return commandManager.submitNewCommand(CustomCommand, args, this::handleObjectResponse); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
/** Copyright GLIDE-for-Redis Project Contributors - SPDX Identifier: Apache-2.0 */ | ||
package glide.api; | ||
|
||
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand; | ||
acarbonetto marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
import glide.api.commands.ClusterBaseCommands; | ||
import glide.api.models.ClusterValue; | ||
import glide.api.models.configuration.RedisClusterClientConfiguration; | ||
import glide.api.models.configuration.RequestRoutingConfiguration.Route; | ||
import glide.managers.CommandManager; | ||
import glide.managers.ConnectionManager; | ||
import glide.managers.models.Command; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
/** | ||
|
@@ -34,25 +36,21 @@ public static CompletableFuture<RedisClusterClient> CreateClient( | |
|
||
@Override | ||
public CompletableFuture<ClusterValue<Object>> customCommand(String[] args) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Future PR to switch this to |
||
Command command = | ||
Command.builder().requestType(Command.RequestType.CUSTOM_COMMAND).arguments(args).build(); | ||
// TODO if a command returns a map as a single value, ClusterValue misleads user | ||
return commandManager.submitNewCommand( | ||
command, response -> ClusterValue.of(handleObjectResponse(response))); | ||
CustomCommand, | ||
args, | ||
Optional.empty(), | ||
response -> ClusterValue.of(handleObjectResponse(response))); | ||
} | ||
|
||
@Override | ||
@SuppressWarnings("unchecked") | ||
public CompletableFuture<ClusterValue<Object>> customCommand(String[] args, Route route) { | ||
Command command = | ||
Command.builder() | ||
.requestType(Command.RequestType.CUSTOM_COMMAND) | ||
.arguments(args) | ||
.route(route) | ||
.build(); | ||
|
||
return commandManager.submitNewCommand( | ||
command, | ||
CustomCommand, | ||
args, | ||
Optional.of(route), | ||
response -> | ||
route.isSingleNodeRoute() | ||
? ClusterValue.ofSingleValue(handleObjectResponse(response)) | ||
|
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static redis_request.RedisRequestOuterClass.RequestType.CustomCommand; | ||
import static response.ResponseOuterClass.RequestErrorType.Disconnect; | ||
import static response.ResponseOuterClass.RequestErrorType.ExecAbort; | ||
import static response.ResponseOuterClass.RequestErrorType.Timeout; | ||
|
@@ -26,8 +27,6 @@ | |
import glide.managers.BaseCommandResponseResolver; | ||
import glide.managers.CommandManager; | ||
import glide.managers.ConnectionManager; | ||
import glide.managers.models.Command; | ||
import glide.managers.models.Command.RequestType; | ||
import io.netty.channel.ChannelFuture; | ||
import java.io.IOException; | ||
import java.util.concurrent.CancellationException; | ||
|
@@ -95,7 +94,7 @@ public void channel_is_closed_when_disconnected_on_command() { | |
var channelHandler = new TestChannelHandler(callbackDispatcher); | ||
var commandManager = new CommandManager(channelHandler); | ||
|
||
var future = commandManager.submitNewCommand(createDummyCommand(), r -> null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. minor: I think that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createDummyCommand made more sense when we had the Command.java, but that was removed in this PR. Instead, we're just passing the object parameters directly. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changes to using TEST_ARGS. I think it adds about the same as the createDummyCommand() |
||
var future = commandManager.submitNewCommand(CustomCommand, new String[0], r -> null); | ||
callbackDispatcher.completeRequest(null); | ||
var exception = assertThrows(ExecutionException.class, future::get); | ||
// a ClosingException thrown from CallbackDispatcher::completeRequest and then | ||
|
@@ -112,7 +111,7 @@ public void channel_is_not_closed_when_error_was_in_command_pipeline() { | |
var channelHandler = new TestChannelHandler(callbackDispatcher); | ||
var commandManager = new CommandManager(channelHandler); | ||
|
||
var future = commandManager.submitNewCommand(createDummyCommand(), r -> null); | ||
var future = commandManager.submitNewCommand(CustomCommand, new String[0], r -> null); | ||
callbackDispatcher.completeRequest(null); | ||
var exception = assertThrows(ExecutionException.class, future::get); | ||
// a RequestException thrown from CallbackDispatcher::completeRequest and then | ||
|
@@ -129,7 +128,7 @@ public void command_manager_rethrows_non_RedisException_too() { | |
var channelHandler = new TestChannelHandler(callbackDispatcher); | ||
var commandManager = new CommandManager(channelHandler); | ||
|
||
var future = commandManager.submitNewCommand(createDummyCommand(), r -> null); | ||
var future = commandManager.submitNewCommand(CustomCommand, new String[0], r -> null); | ||
callbackDispatcher.completeRequest(null); | ||
var exception = assertThrows(ExecutionException.class, future::get); | ||
// a IOException thrown from CallbackDispatcher::completeRequest and then wrapped | ||
|
@@ -210,7 +209,7 @@ public void dont_close_connection_when_callback_dispatcher_receives_response_wit | |
var channelHandler = new TestChannelHandler(callbackDispatcher); | ||
var commandManager = new CommandManager(channelHandler); | ||
|
||
var future = commandManager.submitNewCommand(createDummyCommand(), r -> null); | ||
var future = commandManager.submitNewCommand(CustomCommand, new String[0], r -> null); | ||
var response = | ||
Response.newBuilder() | ||
.setCallbackIdx(0) | ||
|
@@ -280,10 +279,6 @@ private static RedisClientConfiguration createDummyConfig() { | |
return RedisClientConfiguration.builder().build(); | ||
} | ||
|
||
private static Command createDummyCommand() { | ||
return Command.builder().requestType(RequestType.CUSTOM_COMMAND).build(); | ||
} | ||
|
||
/** Test ChannelHandler extension which allows to validate whether the channel was closed. */ | ||
private static class TestChannelHandler extends ChannelHandler { | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moving this below. There should be about a dozen handleXResponse functions to be included in upcoming PRs and they should be below the CreateClient calls.