Skip to content
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

Merged

Conversation

acarbonetto
Copy link
Contributor

Issue #, if available:

Description of changes:

This PR cleans up the command manager and how we create protobuf commands. This also removes the Command.java model that is no longer needed (as we don't expose any Command object in the API).

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
@acarbonetto acarbonetto requested a review from a team as a code owner February 7, 2024 19:25
@acarbonetto acarbonetto changed the title Java: Refactor command_manager and remove command Java: Refactor CommandManager.java and remove Command.java Feb 7, 2024
String payload = (String) response.get();

// verify
assertEquals(testResponse, response);
assertEquals(value, payload);
}

@Test
public void customCommand_interruptedException() throws ExecutionException, InterruptedException {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test is better covered in IT - this test really doesn't do anything.

Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
* @param response Redis protobuf message
* @return Response Object
*/
protected Object handleObjectResponse(Response response) {
Copy link
Contributor Author

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.

@@ -34,25 +36,21 @@ public static CompletableFuture<RedisClusterClient> CreateClient(

@Override
public CompletableFuture<ClusterValue<Object>> customCommand(String[] args) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Future PR to switch this to customCommand(String... args)

* @param responseHandler The handler for the response object
* @return A result promise of type T
*/
protected <T> CompletableFuture<T> submitCommandToChannel(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed from submitNewCommand to submitCommandToChannel to be more specific and to being unambiguous with the public methods.

*/
private Response exceptionHandler(Throwable e) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to the end of the file.

@@ -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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor:
I don't know about Java, but in Rust it's considered a code smell to import enum value names without the enum name, mostly because it might cause name collisions, and reduces legibility - it's less clear that the passed value is an enum of a certain kind.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.

@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: I think that createDummyCommand conveyed intention rather nicely. consider sendDummyCommand instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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.
I DO agree that the "dummy" command conveyed information to a reader that this parameter is irrelevant to the test. Maybe I can do something about that and make it more obvious...

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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()

@@ -24,7 +25,7 @@ public void custom_command_returns_single_value() {

var client = new TestClient(commandManager, "TEST");

var value = client.customCommand(new String[0]).get();
var value = client.customCommand(new String[] {"test"}).get();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is the added argument needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, because the server will fail on the backend if you pass an empty list. So this better represents our use case... even if our white box testing doesn't case.


ArgumentCaptor<RedisRequest.Builder> captor =
ArgumentCaptor.forClass(RedisRequest.Builder.class);

service.submitNewCommand(CustomCommand, new String[0], routeType, r -> null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why the change in order of calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the Mapping down to be closer to where it's being used.

Signed-off-by: Andrew Carbonetto <andrew.carbonetto@improving.com>
@acarbonetto acarbonetto merged commit fa8403e into valkey-io:main Feb 8, 2024
11 checks passed
@acarbonetto acarbonetto deleted the java/integ_acarbo_clean_command_manager branch February 8, 2024 17:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants