Skip to content

Commit

Permalink
Update docs and tests for review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Feb 2, 2024
1 parent 6488a4d commit a13860a
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 92 deletions.
10 changes: 7 additions & 3 deletions java/client/src/main/java/glide/api/BaseClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ protected Object handleObjectResponse(Response response) {
}

/**
* Checks that the Response is empty.
* Checks that the Response contains the simple-string Ok.
*
* @return An empty response
* @return An Ok response
* @throws RedisException if there's a type mismatch
*/
protected Ok handleOkResponse(Response response) {
Object value = handleObjectResponse(response);
Expand All @@ -124,6 +125,7 @@ protected Ok handleOkResponse(Response response) {
*
* @param response Redis protobuf message
* @return Response as a <code>String</code>
* @throws RedisException if there's a type mismatch
*/
protected String handleStringResponse(Response response) {
Object value = handleObjectResponse(response);
Expand All @@ -145,6 +147,7 @@ protected String handleStringResponse(Response response) {
*
* @param response Redis protobuf message
* @return Response as an <code>Object[]</code>
* @throws RedisException if there's a type mismatch
*/
protected Object[] handleArrayResponse(Response response) {
Object value = handleObjectResponse(response);
Expand All @@ -162,7 +165,8 @@ protected Object[] handleArrayResponse(Response response) {
* the value as a <code>Map</code>.
*
* @param response Redis protobuf message
* @return Response as a <code>Map</code>.
* @return Response as a <code>Map</code>
* @throws RedisException if there's a type mismatch
*/
@SuppressWarnings("unchecked")
protected Map<Object, Object> handleMapResponse(Response response) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public interface ClusterBaseCommands {
* this function.
* @example Returns a list of all <em>pub</em>/<em>sub</em> clients:
* <p><code>
* Object result = client.customCommand("CLIENT", "LIST", "TYPE", "PUBSUB").get();
* Object result = client.customCommand(ALL_NODES, "CLIENT", "LIST", "TYPE", "PUBSUB").get();
* </code>
* @param route Routing configuration for the command
* @param args Arguments for the custom command including the command name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ public final class SetOptions {
/**
* Set command to return the old string stored at <code>key</code>, or <code>null</code> if <code>
* key</code> did not exist. An error is returned and <code>SET</code> aborted if the value stored
* at <code>key
* </code> is not a string. Equivalent to <code>GET</code> in the Redis API.
* at <code>key</code> is not a string. Equivalent to <code>GET</code> in the Redis API.
*/
private final boolean returnOldValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ public boolean isSingleNodeRoute() {
return true;
}
}
}
}
29 changes: 0 additions & 29 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,35 +69,6 @@ public void customCommand_returns_success() {
assertEquals(value, payload);
}

@SneakyThrows
@Test
public void customCommand_throws_InterruptedException() {
// setup
String key = "testKey";
Object value = "testValue";
String cmd = "GETSTRING";
String[] arguments = new String[] {cmd, key};
CompletableFuture<Object> testResponse = mock(CompletableFuture.class);
InterruptedException interruptedException = new InterruptedException();
when(testResponse.get()).thenThrow(interruptedException);

// match on protobuf request
when(commandManager.submitNewCommand(eq(CustomCommand), eq(arguments), any()))
.thenReturn(testResponse);

// exercise
InterruptedException exception =
assertThrows(
InterruptedException.class,
() -> {
CompletableFuture<Object> response = service.customCommand(arguments);
response.get();
});

// verify
assertEquals(interruptedException, exception);
}

@SneakyThrows
@Test
public void ping_returns_success() {
Expand Down
27 changes: 0 additions & 27 deletions java/client/src/test/java/glide/api/RedisClusterClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,33 +154,6 @@ public void customCommand_success() {
assertEquals(value, payload);
}

@SneakyThrows
@Test
public void customCommand_interruptedException() {
// setup
String key = "testKey";
String cmd = "GETSTRING";
String[] arguments = new String[] {cmd, key};
CompletableFuture<ClusterValue<Object>> testResponse = mock(CompletableFuture.class);
InterruptedException interruptedException = new InterruptedException();
when(testResponse.get()).thenThrow(interruptedException);
when(commandManager.<ClusterValue<Object>>submitNewCommand(
eq(CustomCommand), any(), any(), any()))
.thenReturn(testResponse);

// exercise
InterruptedException exception =
assertThrows(
InterruptedException.class,
() -> {
CompletableFuture<ClusterValue<Object>> response = service.customCommand(arguments);
response.get();
});

// verify
assertEquals(interruptedException, exception);
}

@SneakyThrows
@Test
public void info_returns_string() {
Expand Down
29 changes: 0 additions & 29 deletions java/client/src/test/java/glide/managers/CommandManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,35 +120,6 @@ public void submitNewCommand_return_String_result() {
assertEquals(testString, respPointer);
}

@SneakyThrows
@Test
public void submitNewCommand_throws_ClosingException() {
// setup
String errorMsg = "Closing";
Response closingErrorResponse = Response.newBuilder().setClosingError(errorMsg).build();
BaseCommandResponseResolver handler =
new BaseCommandResponseResolver((ptr) -> closingErrorResponse);

CompletableFuture<Response> futureResponse = new CompletableFuture<>();
when(channelHandler.write(any(), anyBoolean())).thenReturn(futureResponse);
ClosingException closingException = new ClosingException(errorMsg);
futureResponse.completeExceptionally(closingException);

// exercise
ExecutionException e =
assertThrows(
ExecutionException.class,
() -> {
CompletableFuture<Object> result =
service.submitNewCommand(CustomCommand, new String[0], Optional.empty(), handler);
result.get();
});

// verify
assertEquals(closingException, e.getCause());
assertEquals(errorMsg, e.getCause().getMessage());
}

@ParameterizedTest
@EnumSource(value = SimpleRoute.class)
public void prepare_request_with_simple_routes(SimpleRoute routeType) {
Expand Down

0 comments on commit a13860a

Please sign in to comment.