Skip to content

Commit

Permalink
Clean up more warnings in client tests
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Carbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Apr 4, 2024
1 parent 4b6140f commit 960ef67
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 70 deletions.
21 changes: 10 additions & 11 deletions java/client/src/test/java/glide/api/RedisClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ public void invokeScript_returns_success() {
testResponse.complete(payload);

// match on protobuf request
when(commandManager.<Object>submitScript(eq(script), eq(List.of()), eq(List.of()), any()))
when(commandManager.submitScript(eq(script), eq(List.of()), eq(List.of()), any()))
.thenReturn(testResponse);

// exercise
Expand All @@ -641,7 +641,7 @@ public void invokeScript_with_ScriptOptions_returns_success() {
testResponse.complete(payload);

// match on protobuf request
when(commandManager.<Object>submitScript(
when(commandManager.submitScript(
eq(script), eq(List.of("key1", "key2")), eq(List.of("arg1", "arg2")), any()))
.thenReturn(testResponse);

Expand All @@ -660,8 +660,8 @@ public void pttl_returns_success() {
String key = "testKey";
long pttl = 999000L;

CompletableFuture<Long> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(pttl);
CompletableFuture<Long> testResponse = new CompletableFuture<>();
testResponse.complete(pttl);

// match on protobuf request
when(commandManager.<Long>submitNewCommand(eq(PTTL), eq(new String[] {key}), any()))
Expand Down Expand Up @@ -937,8 +937,8 @@ public void strlen_returns_success() {
String key = "testKey";
Long value = 10L;

CompletableFuture<Long> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(value);
CompletableFuture<Long> testResponse = new CompletableFuture<>();
testResponse.complete(value);

// match on protobuf request
when(commandManager.<Long>submitNewCommand(eq(Strlen), eq(new String[] {key}), any()))
Expand Down Expand Up @@ -2012,7 +2012,6 @@ public void zrange_by_score_with_reverse_returns_success() {
String key = "testKey";
RangeByScore rangeByScore =
new RangeByScore(new ScoreBoundary(3, false), InfScoreBound.NEGATIVE_INFINITY);
boolean reversed = true;
String[] arguments =
new String[] {key, rangeByScore.getStart(), rangeByScore.getEnd(), "BYSCORE", "REV"};
String[] value = new String[] {"two", "one"};
Expand Down Expand Up @@ -2183,8 +2182,8 @@ public void type_returns_success() {
String[] arguments = new String[] {key};
String value = "none";

CompletableFuture<String> testResponse = mock(CompletableFuture.class);
when(testResponse.get()).thenReturn(value);
CompletableFuture<String> testResponse = new CompletableFuture<>();
testResponse.complete(value);

// match on protobuf request
when(commandManager.<String>submitNewCommand(eq(Type), eq(arguments), any()))
Expand All @@ -2203,9 +2202,9 @@ public void type_returns_success() {
@Test
public void time_returns_success() {
// setup
CompletableFuture<String[]> testResponse = mock(CompletableFuture.class);
CompletableFuture<String[]> testResponse = new CompletableFuture<>();
String[] payload = new String[] {"UnixTime", "ms"};
when(testResponse.get()).thenReturn(payload);
testResponse.complete(payload);

// match on protobuf request
when(commandManager.<String[]>submitNewCommand(eq(Time), eq(new String[0]), any()))
Expand Down
119 changes: 60 additions & 59 deletions java/client/src/test/java/glide/api/RedisClusterClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ public void setUp() {
public void custom_command_returns_single_value() {
var commandManager = new TestCommandManager(null);

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

var value = client.customCommand(TEST_ARGS).get();
assertEquals("TEST", value.getSingleValue());
try(var client = new TestClient(commandManager, "TEST")) {
var value = client.customCommand(TEST_ARGS).get();
assertEquals("TEST", value.getSingleValue());
}
}

@Test
Expand All @@ -73,10 +73,10 @@ public void custom_command_returns_multi_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("key1", "value1", "key2", "value2");
var client = new TestClient(commandManager, data);

var value = client.customCommand(TEST_ARGS).get();
assertEquals(data, value.getMultiValue());
try (var client = new TestClient(commandManager, data)) {
var value = client.customCommand(TEST_ARGS).get();
assertEquals(data, value.getMultiValue());
}
}

@Test
Expand All @@ -86,10 +86,10 @@ public void custom_command_with_single_node_route_returns_single_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("key1", "value1", "key2", "value2");
var client = new TestClient(commandManager, data);

var value = client.customCommand(TEST_ARGS, RANDOM).get();
assertEquals(data, value.getSingleValue());
try (var client = new TestClient(commandManager, data)) {
var value = client.customCommand(TEST_ARGS, RANDOM).get();
assertEquals(data, value.getSingleValue());
}
}

@Test
Expand All @@ -98,10 +98,10 @@ public void custom_command_with_multi_node_route_returns_multi_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("key1", "value1", "key2", "value2");
var client = new TestClient(commandManager, data);

var value = client.customCommand(TEST_ARGS, ALL_NODES).get();
assertEquals(data, value.getMultiValue());
try (var client = new TestClient(commandManager, data)) {
var value = client.customCommand(TEST_ARGS, ALL_NODES).get();
assertEquals(data, value.getMultiValue());
}
}

@Test
Expand All @@ -111,10 +111,10 @@ public void custom_command_returns_single_value_on_constant_response() {
new TestCommandManager(
Response.newBuilder().setConstantResponse(ConstantResponse.OK).build());

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

var value = client.customCommand(TEST_ARGS, ALL_NODES).get();
assertEquals("OK", value.getSingleValue());
try (var client = new TestClient(commandManager, "OK")) {
var value = client.customCommand(TEST_ARGS, ALL_NODES).get();
assertEquals("OK", value.getSingleValue());
}
}

private static class TestClient extends RedisClusterClient {
Expand Down Expand Up @@ -366,11 +366,11 @@ public void info_with_single_node_route_returns_single_value() {
var commandManager = new TestCommandManager(null);

var data = "info string";
var client = new TestClient(commandManager, data);

var value = client.info(RANDOM).get();
assertAll(
try (var client = new TestClient(commandManager, data)) {
var value = client.info(RANDOM).get();
assertAll(
() -> assertTrue(value.hasSingleData()), () -> assertEquals(data, value.getSingleValue()));
}
}

@Test
Expand All @@ -379,11 +379,11 @@ public void info_with_multi_node_route_returns_multi_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("key1", "value1", "key2", "value2");
var client = new TestClient(commandManager, data);

var value = client.info(ALL_NODES).get();
assertAll(
try (var client = new TestClient(commandManager, data)) {
var value = client.info(ALL_NODES).get();
assertAll(
() -> assertTrue(value.hasMultiData()), () -> assertEquals(data, value.getMultiValue()));
}
}

@Test
Expand All @@ -392,11 +392,11 @@ public void info_with_options_and_single_node_route_returns_single_value() {
var commandManager = new TestCommandManager(null);

var data = "info string";
var client = new TestClient(commandManager, data);

var value = client.info(InfoOptions.builder().build(), RANDOM).get();
assertAll(
try (var client = new TestClient(commandManager, data)) {
var value = client.info(InfoOptions.builder().build(), RANDOM).get();
assertAll(
() -> assertTrue(value.hasSingleData()), () -> assertEquals(data, value.getSingleValue()));
}
}

@Test
Expand All @@ -405,11 +405,11 @@ public void info_with_options_and_multi_node_route_returns_multi_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("key1", "value1", "key2", "value2");
var client = new TestClient(commandManager, data);

var value = client.info(InfoOptions.builder().build(), ALL_NODES).get();
assertAll(
try (var client = new TestClient(commandManager, data)) {
var value = client.info(InfoOptions.builder().build(), ALL_NODES).get();
assertAll(
() -> assertTrue(value.hasMultiData()), () -> assertEquals(data, value.getMultiValue()));
}
}

@SneakyThrows
Expand Down Expand Up @@ -437,21 +437,22 @@ public void clientId_with_multi_node_route_returns_success() {
var commandManager = new TestCommandManager(null);

var data = Map.of("n1", 42L);
var client = new TestClient(commandManager, data);
try (var client = new TestClient(commandManager, data)) {
var value = client.clientId(ALL_NODES).get();

var value = client.clientId(ALL_NODES).get();
assertEquals(data, value.getMultiValue());
assertEquals(data, value.getMultiValue());
}
}

@Test
@SneakyThrows
public void clientId_with_single_node_route_returns_success() {
var commandManager = new TestCommandManager(null);

var client = new TestClient(commandManager, 42L);

var value = client.clientId(RANDOM).get();
assertEquals(42, value.getSingleValue());
try (var client = new TestClient(commandManager, 42L)) {
var value = client.clientId(RANDOM).get();
assertEquals(42, value.getSingleValue());
}
}

@SneakyThrows
Expand All @@ -478,10 +479,10 @@ public void clientGetName_returns_success() {
public void clientGetName_with_single_node_route_returns_success() {
var commandManager = new TestCommandManager(null);

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

var value = client.clientGetName(RANDOM).get();
assertEquals("TEST", value.getSingleValue());
try (var client = new TestClient(commandManager, "TEST")) {
var value = client.clientGetName(RANDOM).get();
assertEquals("TEST", value.getSingleValue());
}
}

@Test
Expand All @@ -490,10 +491,10 @@ public void clientGetName_with_multi_node_route_returns_success() {
var commandManager = new TestCommandManager(null);

var data = Map.of("n1", "TEST");
var client = new TestClient(commandManager, data);

var value = client.clientGetName(ALL_NODES).get();
assertEquals(data, value.getMultiValue());
try (var client = new TestClient(commandManager, data)) {
var value = client.clientGetName(ALL_NODES).get();
assertEquals(data, value.getMultiValue());
}
}

@SneakyThrows
Expand Down Expand Up @@ -612,11 +613,11 @@ public void configGet_with_single_node_route_returns_single_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("timeout", "1000", "maxmemory", "1GB");
var client = new TestClient(commandManager, data);

var value = client.configGet(TEST_ARGS, RANDOM).get();
assertAll(
try (var client = new TestClient(commandManager, data)) {
var value = client.configGet(TEST_ARGS, RANDOM).get();
assertAll(
() -> assertTrue(value.hasSingleData()), () -> assertEquals(data, value.getSingleValue()));
}
}

@Test
Expand All @@ -625,11 +626,11 @@ public void configGet_with_multi_node_route_returns_multi_value() {
var commandManager = new TestCommandManager(null);

var data = Map.of("node1", Map.of("timeout", "1000", "maxmemory", "1GB"));
var client = new TestClient(commandManager, data);

var value = client.configGet(TEST_ARGS, ALL_NODES).get();
assertAll(
try (var client = new TestClient(commandManager, data)) {
var value = client.configGet(TEST_ARGS, ALL_NODES).get();
assertAll(
() -> assertTrue(value.hasMultiData()), () -> assertEquals(data, value.getMultiValue()));
}
}

@SneakyThrows
Expand Down

0 comments on commit 960ef67

Please sign in to comment.