From 085964c5dffcf1e3a38842c335d5e2ded9369cfa Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Tue, 10 Dec 2024 14:07:50 -0800 Subject: [PATCH] Java: fix type assertions (#2637) fix type assertions Signed-off-by: Yury-Fridlyand --- .../java/glide/ExceptionHandlingTests.java | 19 +- .../ConnectionWithGlideMockTests.java | 7 +- .../src/test/java/glide/ffi/FfiTest.java | 9 +- .../glide/managers/CommandManagerTest.java | 3 +- .../glide/managers/ConnectionManagerTest.java | 6 +- .../test/java/glide/ErrorHandlingTests.java | 7 +- .../test/java/glide/SharedClientTests.java | 3 +- .../test/java/glide/SharedCommandTests.java | 410 +++++++++--------- .../glide/cluster/ClusterClientTests.java | 6 +- .../test/java/glide/cluster/CommandTests.java | 13 +- .../java/glide/standalone/CommandTests.java | 19 +- .../standalone/StandaloneClientTests.java | 6 +- 12 files changed, 265 insertions(+), 243 deletions(-) diff --git a/java/client/src/test/java/glide/ExceptionHandlingTests.java b/java/client/src/test/java/glide/ExceptionHandlingTests.java index 7f6ebe0ec2..9782d29719 100644 --- a/java/client/src/test/java/glide/ExceptionHandlingTests.java +++ b/java/client/src/test/java/glide/ExceptionHandlingTests.java @@ -5,6 +5,7 @@ import static glide.ffi.resolvers.SocketListenerResolver.getSocket; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mockStatic; @@ -94,7 +95,7 @@ public void channel_is_closed_when_failed_to_connect() { var exception = assertThrows(ExecutionException.class, future::get); // a ClosingException thrown from CallbackDispatcher::completeRequest and then // rethrown by ConnectionManager::exceptionHandler - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); assertTrue(channelHandler.wasClosed); } @@ -110,7 +111,7 @@ public void channel_is_closed_when_disconnected_on_command() { var exception = assertThrows(ExecutionException.class, future::get); // a ClosingException thrown from CallbackDispatcher::completeRequest and then // rethrown by CommandManager::exceptionHandler - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); // check the channel assertTrue(channelHandler.wasClosed); } @@ -127,7 +128,7 @@ public void channel_is_not_closed_when_error_was_in_command_pipeline() { var exception = assertThrows(ExecutionException.class, future::get); // a RequestException thrown from CallbackDispatcher::completeRequest and then // rethrown by CommandManager::exceptionHandler - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); // check the channel assertFalse(channelHandler.wasClosed); } @@ -144,8 +145,8 @@ public void command_manager_rethrows_non_GlideException_too() { var exception = assertThrows(ExecutionException.class, future::get); // a IOException thrown from CallbackDispatcher::completeRequest and then wrapped // by a RuntimeException and rethrown by CommandManager::exceptionHandler - assertTrue(exception.getCause() instanceof RuntimeException); - assertTrue(exception.getCause().getCause() instanceof IOException); + assertInstanceOf(RuntimeException.class, exception.getCause()); + assertInstanceOf(IOException.class, exception.getCause().getCause()); // check the channel assertFalse(channelHandler.wasClosed); } @@ -163,8 +164,8 @@ public void connection_manager_rethrows_non_GlideException_too() { var exception = assertThrows(ExecutionException.class, future::get); // a IOException thrown from CallbackDispatcher::completeRequest and then wrapped // by a RuntimeException and rethrown by ConnectionManager::exceptionHandler - assertTrue(exception.getCause() instanceof RuntimeException); - assertTrue(exception.getCause().getCause() instanceof IOException); + assertInstanceOf(RuntimeException.class, exception.getCause()); + assertInstanceOf(IOException.class, exception.getCause().getCause()); // check the channel assertTrue(channelHandler.wasClosed); } @@ -186,7 +187,7 @@ public void close_connection_on_response_with_closing_error() { var exception = assertThrows(ExecutionException.class, future1::get); // a ClosingException thrown from CallbackDispatcher::completeRequest and then // rethrown by CommandManager::exceptionHandler - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); // check the channel assertTrue(channelHandler.wasClosed); @@ -254,7 +255,7 @@ public void close_connection_on_response_without_error_but_with_incorrect_callba var exception = assertThrows(ExecutionException.class, future1::get); // a ClosingException thrown from CallbackDispatcher::completeRequest and then // rethrown by CommandManager::exceptionHandler - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); assertEquals( exception.getCause().getMessage(), "Client is in an erroneous state and should close"); // check the channel diff --git a/java/client/src/test/java/glide/connection/ConnectionWithGlideMockTests.java b/java/client/src/test/java/glide/connection/ConnectionWithGlideMockTests.java index bca0be3017..afc6c9e9c3 100644 --- a/java/client/src/test/java/glide/connection/ConnectionWithGlideMockTests.java +++ b/java/client/src/test/java/glide/connection/ConnectionWithGlideMockTests.java @@ -5,6 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -150,7 +151,7 @@ public Response.Builder commandRequest(CommandRequest request) { var exception = assertThrows(ExecutionException.class, () -> testConnection().get(1, SECONDS)); assertAll( - () -> assertTrue(exception.getCause() instanceof ClosingException), + () -> assertInstanceOf(ClosingException.class, exception.getCause()), () -> assertEquals("You shall not pass!", exception.getCause().getMessage())); } @@ -161,7 +162,7 @@ public void rethrow_error_on_read_when_malformed_packet_received() { var exception = assertThrows(ExecutionException.class, () -> testConnection().get(1, SECONDS)); assertAll( - () -> assertTrue(exception.getCause() instanceof ClosingException), + () -> assertInstanceOf(ClosingException.class, exception.getCause()), () -> assertTrue( exception @@ -178,7 +179,7 @@ public void rethrow_error_if_UDS_channel_closed() { try { var exception = assertThrows(ExecutionException.class, () -> client.customCommand(new String[0]).get()); - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); } finally { // restart mock to let other tests pass if this one failed startRustCoreLibMock(null); diff --git a/java/client/src/test/java/glide/ffi/FfiTest.java b/java/client/src/test/java/glide/ffi/FfiTest.java index 5a118c6af4..3f507e37fc 100644 --- a/java/client/src/test/java/glide/ffi/FfiTest.java +++ b/java/client/src/test/java/glide/ffi/FfiTest.java @@ -4,6 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -84,7 +85,7 @@ public void respValueToJavaValue_Okay() { public void respValueToJavaValue_Int(Long input) { long ptr = FfiTest.createLeakedInt(input); Object longValue = GlideValueResolver.valueFromPointer(ptr); - assertTrue(longValue instanceof Long); + assertInstanceOf(Long.class, longValue); assertEquals(input, longValue); } @@ -109,7 +110,7 @@ public void respValueToJavaValue_Array() { long[] array = {1L, 2L, 3L}; long ptr = FfiTest.createLeakedLongArray(array); Object longArrayValue = GlideValueResolver.valueFromPointer(ptr); - assertTrue(longArrayValue instanceof Object[]); + assertInstanceOf(Object[].class, longArrayValue); Object[] result = (Object[]) longArrayValue; assertArrayEquals(new Object[] {1L, 2L, 3L}, result); } @@ -120,7 +121,7 @@ public void respValueToJavaValue_Map() { long[] values = {1L, 2L, 3L}; long ptr = FfiTest.createLeakedMap(keys, values); Object mapValue = GlideValueResolver.valueFromPointer(ptr); - assertTrue(mapValue instanceof HashMap); + assertInstanceOf(HashMap.class, mapValue); HashMap result = (HashMap) mapValue; assertAll( () -> assertEquals(1L, result.get(12L)), @@ -156,7 +157,7 @@ public void respValueToJavaValue_Set() { long[] array = {1L, 2L, 2L}; long ptr = FfiTest.createLeakedLongSet(array); Object longSetValue = GlideValueResolver.valueFromPointer(ptr); - assertTrue(longSetValue instanceof HashSet); + assertInstanceOf(HashSet.class, longSetValue); HashSet result = (HashSet) longSetValue; assertAll( () -> assertTrue(result.contains(1L)), diff --git a/java/client/src/test/java/glide/managers/CommandManagerTest.java b/java/client/src/test/java/glide/managers/CommandManagerTest.java index 418377ccd9..069be2d038 100644 --- a/java/client/src/test/java/glide/managers/CommandManagerTest.java +++ b/java/client/src/test/java/glide/managers/CommandManagerTest.java @@ -8,6 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertAll; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -131,7 +132,7 @@ public void submitNewCommand_return_String_result() { Object respPointer = result.get(); // verify - assertTrue(respPointer instanceof String); + assertInstanceOf(String.class, respPointer); assertEquals(testString, respPointer); } diff --git a/java/client/src/test/java/glide/managers/ConnectionManagerTest.java b/java/client/src/test/java/glide/managers/ConnectionManagerTest.java index 80e9783c88..50de31c64a 100644 --- a/java/client/src/test/java/glide/managers/ConnectionManagerTest.java +++ b/java/client/src/test/java/glide/managers/ConnectionManagerTest.java @@ -7,9 +7,9 @@ import static glide.api.models.configuration.StandaloneSubscriptionConfiguration.PubSubChannelMode.EXACT; import static glide.api.models.configuration.StandaloneSubscriptionConfiguration.PubSubChannelMode.PATTERN; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; -import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -245,7 +245,7 @@ public void connection_on_empty_response_throws_ClosingException() { ExecutionException.class, () -> connectionManager.connectToValkey(glideClientConfiguration).get()); - assertTrue(executionException.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, executionException.getCause()); assertEquals("Unexpected empty data in response", executionException.getCause().getMessage()); verify(channel).close(); } @@ -265,7 +265,7 @@ public void connection_on_resp_pointer_throws_ClosingException() { ExecutionException.class, () -> connectionManager.connectToValkey(glideClientConfiguration).get()); - assertTrue(executionException.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, executionException.getCause()); assertEquals("Unexpected data in response", executionException.getCause().getMessage()); verify(channel).close(); } diff --git a/java/integTest/src/test/java/glide/ErrorHandlingTests.java b/java/integTest/src/test/java/glide/ErrorHandlingTests.java index 5b64e37d50..c9ec731a66 100644 --- a/java/integTest/src/test/java/glide/ErrorHandlingTests.java +++ b/java/integTest/src/test/java/glide/ErrorHandlingTests.java @@ -3,6 +3,7 @@ import static glide.TestUtilities.commonClientConfig; import static org.junit.jupiter.api.Assertions.assertAll; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -33,7 +34,7 @@ public void basic_client_tries_to_connect_to_wrong_address() { .build()) .get()); assertAll( - () -> assertTrue(exception.getCause() instanceof ClosingException), + () -> assertInstanceOf(ClosingException.class, exception.getCause()), () -> assertTrue(exception.getCause().getMessage().contains("Connection refused"))); } @@ -46,7 +47,7 @@ public void basic_client_tries_wrong_command() { ExecutionException.class, () -> regularClient.customCommand(new String[] {"pewpew"}).get()); assertAll( - () -> assertTrue(exception.getCause() instanceof RequestException), + () -> assertInstanceOf(RequestException.class, exception.getCause()), () -> assertTrue(exception.getCause().getMessage().contains("unknown command"))); } } @@ -60,7 +61,7 @@ public void basic_client_tries_wrong_command_arguments() { ExecutionException.class, () -> regularClient.customCommand(new String[] {"ping", "pang", "pong"}).get()); assertAll( - () -> assertTrue(exception.getCause() instanceof RequestException), + () -> assertInstanceOf(RequestException.class, exception.getCause()), () -> assertTrue(exception.getCause().getMessage().contains("wrong number of arguments"))); } diff --git a/java/integTest/src/test/java/glide/SharedClientTests.java b/java/integTest/src/test/java/glide/SharedClientTests.java index 26a4144e96..ba77cec81f 100644 --- a/java/integTest/src/test/java/glide/SharedClientTests.java +++ b/java/integTest/src/test/java/glide/SharedClientTests.java @@ -7,6 +7,7 @@ import static glide.api.BaseClient.OK; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertInstanceOf; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -173,7 +174,7 @@ public void inflight_requests_limit(boolean clusterMode, int inflightRequestsLim responses.get(inflightRequestsLimit).get(100, TimeUnit.MILLISECONDS); fail("Expected the last request to throw an exception"); } catch (ExecutionException e) { - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); assertTrue(e.getCause().getMessage().contains("maximum inflight requests")); } diff --git a/java/integTest/src/test/java/glide/SharedCommandTests.java b/java/integTest/src/test/java/glide/SharedCommandTests.java index d9517eb6a3..59c6c88feb 100644 --- a/java/integTest/src/test/java/glide/SharedCommandTests.java +++ b/java/integTest/src/test/java/glide/SharedCommandTests.java @@ -245,7 +245,7 @@ public void append(BaseClient client) { assertEquals(1, client.sadd(key2, new String[] {"a"}).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.append(key2, "z").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -734,15 +734,15 @@ public void test_incr_commands_type_error(BaseClient client) { assertEquals(OK, client.set(key1, "foo").get()); Exception incrException = assertThrows(ExecutionException.class, () -> client.incr(key1).get()); - assertTrue(incrException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, incrException.getCause()); Exception incrByException = assertThrows(ExecutionException.class, () -> client.incrBy(key1, 3).get()); - assertTrue(incrByException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, incrByException.getCause()); Exception incrByFloatException = assertThrows(ExecutionException.class, () -> client.incrByFloat(key1, 3.5).get()); - assertTrue(incrByFloatException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, incrByFloatException.getCause()); } @SneakyThrows @@ -807,7 +807,7 @@ public void strlen(BaseClient client) { assertEquals(1, client.lpush(nonStringKey, new String[] {"_"}).get()); Exception exception = assertThrows(ExecutionException.class, () -> client.strlen(nonStringKey).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); } @SneakyThrows @@ -846,12 +846,12 @@ public void setrange(BaseClient client) { assertEquals(1, client.lpush(nonStringKey, new String[] {"_"}).get()); Exception exception = assertThrows(ExecutionException.class, () -> client.setrange(nonStringKey, 0, "_").get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); exception = assertThrows( ExecutionException.class, () -> client.setrange(stringKey, Integer.MAX_VALUE, "_").get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); } @SneakyThrows @@ -875,12 +875,12 @@ public void setrange_binary(BaseClient client) { Exception exception = assertThrows( ExecutionException.class, () -> client.setrange(nonStringKey, 0, gs("_")).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); exception = assertThrows( ExecutionException.class, () -> client.setrange(stringKey, Integer.MAX_VALUE, gs("_")).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); } @SneakyThrows @@ -913,7 +913,7 @@ public void getrange(BaseClient client) { assertEquals(1, client.lpush(nonStringKey, new String[] {"_"}).get()); Exception exception = assertThrows(ExecutionException.class, () -> client.getrange(nonStringKey, 0, -1).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); } @SneakyThrows @@ -946,7 +946,7 @@ public void getrange_binary(BaseClient client) { assertEquals(1, client.lpush(nonStringKey, new GlideString[] {gs("_")}).get()); Exception exception = assertThrows(ExecutionException.class, () -> client.getrange(nonStringKey, 0, -1).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); } @SneakyThrows @@ -1176,7 +1176,7 @@ public void hsetnx(BaseClient client) { assertEquals(OK, client.set(key2, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.hsetnx(key2, field, "value").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1195,7 +1195,7 @@ public void hsetnx_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.hsetnx(key2, field, gs("value")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1255,7 +1255,7 @@ public void hlen(BaseClient client) { assertEquals(OK, client.set(key2, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.hlen(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1279,7 +1279,7 @@ public void hlen_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.hlen(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1305,7 +1305,7 @@ public void hvals(BaseClient client) { assertEquals(OK, client.set(key2, "value2").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.hvals(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1332,7 +1332,7 @@ public void hvals_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("value2")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.hvals(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1483,11 +1483,11 @@ public void hincrBy_hincrByFloat_type_error(BaseClient client) { Exception hincrByException = assertThrows(ExecutionException.class, () -> client.hincrBy(key, field, 2).get()); - assertTrue(hincrByException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, hincrByException.getCause()); Exception hincrByFloatException = assertThrows(ExecutionException.class, () -> client.hincrByFloat(key, field, 2.5).get()); - assertTrue(hincrByFloatException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, hincrByFloatException.getCause()); } @SneakyThrows @@ -1509,7 +1509,7 @@ public void hkeys(BaseClient client) { assertEquals(OK, client.set(key2, "value").get()); Exception executionException = assertThrows(ExecutionException.class, () -> client.hkeys(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1531,7 +1531,7 @@ public void hkeys_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("value")).get()); Exception executionException = assertThrows(ExecutionException.class, () -> client.hkeys(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1716,18 +1716,18 @@ public void lpush_lpop_lrange_type_error(BaseClient client) { Exception lpushException = assertThrows(ExecutionException.class, () -> client.lpush(key, new String[] {"foo"}).get()); - assertTrue(lpushException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lpushException.getCause()); Exception lpopException = assertThrows(ExecutionException.class, () -> client.lpop(key).get()); - assertTrue(lpopException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lpopException.getCause()); Exception lpopCountException = assertThrows(ExecutionException.class, () -> client.lpopCount(key, 2).get()); - assertTrue(lpopCountException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lpopCountException.getCause()); Exception lrangeException = assertThrows(ExecutionException.class, () -> client.lrange(key, 0, -1).get()); - assertTrue(lrangeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lrangeException.getCause()); } @SneakyThrows @@ -1741,18 +1741,18 @@ public void lpush_lpop_lrange_binary_type_error(BaseClient client) { Exception lpushException = assertThrows( ExecutionException.class, () -> client.lpush(key, new GlideString[] {gs("foo")}).get()); - assertTrue(lpushException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lpushException.getCause()); Exception lpopException = assertThrows(ExecutionException.class, () -> client.lpop(key).get()); - assertTrue(lpopException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lpopException.getCause()); Exception lpopCountException = assertThrows(ExecutionException.class, () -> client.lpopCount(key, 2).get()); - assertTrue(lpopCountException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lpopCountException.getCause()); Exception lrangeException = assertThrows(ExecutionException.class, () -> client.lrange(key, 0, -1).get()); - assertTrue(lrangeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lrangeException.getCause()); } @SneakyThrows @@ -1773,7 +1773,7 @@ public void lindex(BaseClient client) { assertEquals(OK, client.set(key2, "value").get()); Exception executionException = assertThrows(ExecutionException.class, () -> client.lindex(key2, 0).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1794,7 +1794,7 @@ public void lindex_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("value")).get()); Exception executionException = assertThrows(ExecutionException.class, () -> client.lindex(key2, 0).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -1816,7 +1816,7 @@ public void ltrim_existing_non_existing_key_and_type_error(BaseClient client) { Exception ltrimException = assertThrows(ExecutionException.class, () -> client.ltrim(key, 0, 1).get()); - assertTrue(ltrimException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, ltrimException.getCause()); } @SneakyThrows @@ -1840,7 +1840,7 @@ public void ltrim_binary_existing_non_existing_key_and_type_error(BaseClient cli Exception ltrimException = assertThrows(ExecutionException.class, () -> client.ltrim(key, 0, 1).get()); - assertTrue(ltrimException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, ltrimException.getCause()); } @SneakyThrows @@ -1859,7 +1859,7 @@ public void llen_existing_non_existing_key_and_type_error(BaseClient client) { Exception lrangeException = assertThrows(ExecutionException.class, () -> client.llen(key2).get()); - assertTrue(lrangeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lrangeException.getCause()); } @SneakyThrows @@ -1916,14 +1916,14 @@ public void lpos(BaseClient client) { assertThrows( ExecutionException.class, () -> client.lpos(key, "a", LPosOptions.builder().rank(0L).build()).get()); - assertTrue(lposException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposException.getCause()); // invalid maxlen value ExecutionException lposMaxlenException = assertThrows( ExecutionException.class, () -> client.lpos(key, "a", LPosOptions.builder().maxLength(-1L).build()).get()); - assertTrue(lposMaxlenException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposMaxlenException.getCause()); // non-existent key assertNull(client.lpos("non-existent_key", "a").get()); @@ -1933,7 +1933,7 @@ public void lpos(BaseClient client) { assertEquals(2L, client.sadd(wrong_data_type, new String[] {"a", "b"}).get()); ExecutionException lposWrongKeyDataTypeException = assertThrows(ExecutionException.class, () -> client.lpos(wrong_data_type, "a").get()); - assertTrue(lposWrongKeyDataTypeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposWrongKeyDataTypeException.getCause()); } @SneakyThrows @@ -1968,14 +1968,14 @@ public void lpos_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.lpos(key, gs("a"), LPosOptions.builder().rank(0L).build()).get()); - assertTrue(lposException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposException.getCause()); // invalid maxlen value ExecutionException lposMaxlenException = assertThrows( ExecutionException.class, () -> client.lpos(key, gs("a"), LPosOptions.builder().maxLength(-1L).build()).get()); - assertTrue(lposMaxlenException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposMaxlenException.getCause()); // non-existent key assertNull(client.lpos(gs("non-existent_key"), gs("a")).get()); @@ -1985,7 +1985,7 @@ public void lpos_binary(BaseClient client) { assertEquals(2L, client.sadd(wrong_data_type, new GlideString[] {gs("a"), gs("b")}).get()); ExecutionException lposWrongKeyDataTypeException = assertThrows(ExecutionException.class, () -> client.lpos(wrong_data_type, gs("a")).get()); - assertTrue(lposWrongKeyDataTypeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposWrongKeyDataTypeException.getCause()); } @SneakyThrows @@ -2002,7 +2002,7 @@ public void lposCount(BaseClient client) { // invalid count value ExecutionException lposCountException = assertThrows(ExecutionException.class, () -> client.lposCount(key, "a", -1L).get()); - assertTrue(lposCountException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposCountException.getCause()); // with option assertArrayEquals( @@ -2029,7 +2029,7 @@ public void lposCount(BaseClient client) { ExecutionException lposWrongKeyDataTypeException = assertThrows( ExecutionException.class, () -> client.lposCount(wrong_data_type, "a", 1L).get()); - assertTrue(lposWrongKeyDataTypeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposWrongKeyDataTypeException.getCause()); } @SneakyThrows @@ -2047,7 +2047,7 @@ public void lposCount_binary(BaseClient client) { // invalid count value ExecutionException lposCountException = assertThrows(ExecutionException.class, () -> client.lposCount(key, gs("a"), -1L).get()); - assertTrue(lposCountException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposCountException.getCause()); // with option assertArrayEquals( @@ -2074,7 +2074,7 @@ public void lposCount_binary(BaseClient client) { ExecutionException lposWrongKeyDataTypeException = assertThrows( ExecutionException.class, () -> client.lposCount(wrong_data_type, gs("a"), 1L).get()); - assertTrue(lposWrongKeyDataTypeException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, lposWrongKeyDataTypeException.getCause()); } @SneakyThrows @@ -2117,10 +2117,10 @@ public void rpush_rpop_type_error(BaseClient client) { Exception rpushException = assertThrows(ExecutionException.class, () -> client.rpush(key, new String[] {"foo"}).get()); - assertTrue(rpushException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, rpushException.getCause()); Exception rpopException = assertThrows(ExecutionException.class, () -> client.rpop(key).get()); - assertTrue(rpopException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, rpopException.getCause()); } @SneakyThrows @@ -2134,10 +2134,10 @@ public void rpush_rpop_binary_type_error(BaseClient client) { Exception rpushException = assertThrows( ExecutionException.class, () -> client.rpush(key, new GlideString[] {gs("foo")}).get()); - assertTrue(rpushException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, rpushException.getCause()); Exception rpopException = assertThrows(ExecutionException.class, () -> client.rpop(key).get()); - assertTrue(rpopException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, rpopException.getCause()); } @SneakyThrows @@ -2201,16 +2201,16 @@ public void sadd_srem_scard_smembers_key_with_non_set_value(BaseClient client) { Exception e = assertThrows(ExecutionException.class, () -> client.sadd(key, new String[] {"baz"}).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); e = assertThrows(ExecutionException.class, () -> client.srem(key, new String[] {"baz"}).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); e = assertThrows(ExecutionException.class, () -> client.scard(key).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); e = assertThrows(ExecutionException.class, () -> client.smembers(key).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); } @SneakyThrows @@ -2344,8 +2344,8 @@ public void rename_binary(BaseClient client) { GlideString key1 = gs("{key}" + UUID.randomUUID()); assertEquals(OK, client.set(key1, gs("foo")).get()); - assertEquals(OK, client.rename(key1, gs((key1.toString() + "_rename"))).get()); - assertEquals(1L, client.exists(new GlideString[] {gs(key1.toString() + "_rename")}).get()); + assertEquals(OK, client.rename(key1, gs((key1 + "_rename"))).get()); + assertEquals(1L, client.exists(new GlideString[] {gs(key1 + "_rename")}).get()); // key doesn't exist ExecutionException executionException = @@ -2427,7 +2427,7 @@ public void sismember(BaseClient client) { assertEquals(OK, client.set(key2, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.sismember(key2, member).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -2446,7 +2446,7 @@ public void sismember_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.sismember(key2, member).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -2484,7 +2484,7 @@ public void sinterstore(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.sinterstore(key1, new String[] {key5}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // overwrite destination - not a set assertEquals(0, client.sinterstore(key5, new String[] {key1, key2}).get()); @@ -2493,7 +2493,7 @@ public void sinterstore(BaseClient client) { // wrong arguments executionException = assertThrows(ExecutionException.class, () -> client.sinterstore(key5, new String[0]).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -2532,7 +2532,7 @@ public void sinterstore_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.sinterstore(key1, new GlideString[] {key5}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // overwrite destination - not a set assertEquals(0, client.sinterstore(key5, new GlideString[] {key1, key2}).get()); @@ -2542,7 +2542,7 @@ public void sinterstore_binary(BaseClient client) { executionException = assertThrows( ExecutionException.class, () -> client.sinterstore(key5, new GlideString[0]).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3313,11 +3313,11 @@ public void zadd_and_zaddIncr_wrong_type(BaseClient client) { ExecutionException executionExceptionZadd = assertThrows(ExecutionException.class, () -> client.zadd("foo", membersScores).get()); - assertTrue(executionExceptionZadd.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionExceptionZadd.getCause()); ExecutionException executionExceptionZaddIncr = assertThrows(ExecutionException.class, () -> client.zaddIncr("foo", "one", 2.0).get()); - assertTrue(executionExceptionZaddIncr.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionExceptionZaddIncr.getCause()); } @SneakyThrows @@ -3330,12 +3330,12 @@ public void zadd_binary_and_zaddIncr_binary_wrong_type(BaseClient client) { ExecutionException executionExceptionZadd = assertThrows(ExecutionException.class, () -> client.zadd(gs("foo"), membersScores).get()); - assertTrue(executionExceptionZadd.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionExceptionZadd.getCause()); ExecutionException executionExceptionZaddIncr = assertThrows( ExecutionException.class, () -> client.zaddIncr(gs("foo"), gs("one"), 2.0).get()); - assertTrue(executionExceptionZaddIncr.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionExceptionZaddIncr.getCause()); } @SneakyThrows @@ -3523,7 +3523,7 @@ public void zrem(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.zrem("foo", new String[] {"bar"}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3543,7 +3543,7 @@ public void zcard(BaseClient client) { assertEquals(OK, client.set("foo", "bar").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zcard("foo").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3562,7 +3562,7 @@ public void zpopmin(BaseClient client) { assertEquals(OK, client.set(key, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zpopmin(key).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3586,7 +3586,7 @@ public void zpopmin_binary(BaseClient client) { assertEquals(OK, client.set(key, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zpopmin(key).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3723,7 +3723,7 @@ public void zpopmax(BaseClient client) { assertEquals(OK, client.set(key, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zpopmax(key).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3747,7 +3747,7 @@ public void zpopmax_binary(BaseClient client) { assertEquals(OK, client.set(key, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zpopmax(key).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3885,7 +3885,7 @@ public void zscore(BaseClient client) { assertEquals(OK, client.set(key2, "bar").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zscore(key2, "one").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3910,7 +3910,7 @@ public void zrevrank_binary(BaseClient client) { assertEquals(OK, client.set(key, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zrevrank(key, gs("one")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3934,7 +3934,7 @@ public void zrank(BaseClient client) { assertEquals(OK, client.set(key, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zrank(key, "one").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -3978,13 +3978,13 @@ public void zdiff_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zdiff(new GlideString[] {nonExistentKey, key2}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.zdiffWithScores(new GlideString[] {nonExistentKey, key2}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4008,7 +4008,7 @@ public void zrevrank(BaseClient client) { assertEquals(OK, client.set(key, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zrevrank(key, "one").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4047,13 +4047,13 @@ public void zdiff(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zdiff(new String[] {nonExistentKey, key2}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.zdiffWithScores(new String[] {nonExistentKey, key2}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4085,7 +4085,7 @@ public void zmscore(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.zmscore(key2, new String[] {"one"}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4130,7 +4130,7 @@ public void zdiffstore(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zdiffstore(key4, new String[] {key5, key1}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4185,7 +4185,7 @@ public void zcount_binary(BaseClient client) { client .zcount(key2, InfScoreBound.NEGATIVE_INFINITY, InfScoreBound.POSITIVE_INFINITY) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4223,7 +4223,7 @@ public void zcount(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zcount(key2, NEGATIVE_INFINITY, POSITIVE_INFINITY).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4263,7 +4263,7 @@ public void zremrangebylex_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zremrangebylex(key2, new LexBoundary("a"), new LexBoundary("c")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4294,7 +4294,7 @@ public void zremrangebyrank(BaseClient client) { assertEquals(OK, client.set(key2, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zremrangebyrank(key2, 2, 1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4333,7 +4333,7 @@ public void zremrangebylex(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zremrangebylex(key2, new LexBoundary("a"), new LexBoundary("c")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4379,7 +4379,7 @@ public void zremrangebyscore_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zremrangebyscore(key2, new ScoreBoundary(1), new ScoreBoundary(2)).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4423,7 +4423,7 @@ public void zremrangebyscore(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zremrangebyscore(key2, new ScoreBoundary(1), new ScoreBoundary(2)).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4471,7 +4471,7 @@ public void zlexcount_binary(BaseClient client) { client .zlexcount(key2, InfLexBound.NEGATIVE_INFINITY, InfLexBound.POSITIVE_INFINITY) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4517,7 +4517,7 @@ public void zlexcount(BaseClient client) { client .zlexcount(key2, InfLexBound.NEGATIVE_INFINITY, InfLexBound.POSITIVE_INFINITY) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4557,7 +4557,7 @@ public void zrangestore_binary_by_index(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zrangestore(destination, key, new RangeByIndex(3, 1)).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4596,7 +4596,7 @@ public void zrangestore_by_index(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zrangestore(destination, key, new RangeByIndex(3, 1)).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4669,7 +4669,7 @@ public void zrangestore_binary_by_score(BaseClient client) { key, new RangeByScore(new ScoreBoundary(0), new ScoreBoundary(3))) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4741,7 +4741,7 @@ public void zrangestore_by_score(BaseClient client) { key, new RangeByScore(new ScoreBoundary(0), new ScoreBoundary(3))) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4807,7 +4807,7 @@ public void zrangestore_binary_by_lex(BaseClient client) { key, new RangeByLex(new LexBoundary("a"), new LexBoundary("c"))) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -4873,7 +4873,7 @@ public void zrangestore_by_lex(BaseClient client) { key, new RangeByLex(new LexBoundary("a"), new LexBoundary("c"))) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -5126,7 +5126,7 @@ public void zunion(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zunion(new KeyArray(new String[] {key1, key3})).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -5216,7 +5216,7 @@ public void zunion_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zunion(new KeyArrayBinary(new GlideString[] {key1, key3})).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -5297,7 +5297,7 @@ key3, new WeightedKeysBinary(List.of(Pair.of(key1, 2.0), Pair.of(key2, 2.0)))) ExecutionException.class, () -> client.zinterstore(key3, new KeyArrayBinary(new GlideString[] {key4, key2})).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -5559,7 +5559,7 @@ public void zinterstore(BaseClient client) { assertThrows( ExecutionException.class, () -> client.zinterstore(key3, new KeyArray(new String[] {key4, key2})).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -6026,9 +6026,9 @@ public void xadd_xlen_and_xtrim(BaseClient client) { assertEquals(OK, client.set(key2, "xtrimtest").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.xtrim(key2, new MinId("0-1")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows(ExecutionException.class, () -> client.xlen(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -6094,9 +6094,9 @@ public void xadd_xlen_and_xtrim_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("xtrimtest")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.xtrim(key2, new MinId("0-1")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows(ExecutionException.class, () -> client.xlen(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -6183,8 +6183,8 @@ public void xread_binary(BaseClient client) { // setup first entries in streams key1 and key2 Map timestamp_1_1_map = new LinkedHashMap<>(); - timestamp_1_1_map.put(field1, gs(field1.toString() + "1")); - timestamp_1_1_map.put(field3, gs(field3.toString() + "1")); + timestamp_1_1_map.put(field1, gs(field1 + "1")); + timestamp_1_1_map.put(field3, gs(field3 + "1")); GlideString timestamp_1_1 = client .xadd(key1, timestamp_1_1_map, StreamAddOptionsBinary.builder().id(gs("1-1")).build()) @@ -6195,7 +6195,7 @@ public void xread_binary(BaseClient client) { client .xadd( key2, - Map.of(field2, gs(field2.toString() + "1")), + Map.of(field2, gs(field2 + "1")), StreamAddOptionsBinary.builder().id(gs("2-1")).build()) .get(); assertNotNull(timestamp_2_1); @@ -6205,7 +6205,7 @@ public void xread_binary(BaseClient client) { client .xadd( key1, - Map.of(field1, gs(field1.toString() + "2")), + Map.of(field1, gs(field1 + "2")), StreamAddOptionsBinary.builder().id(gs("1-2")).build()) .get(); assertNotNull(timestamp_1_2); @@ -6214,15 +6214,15 @@ public void xread_binary(BaseClient client) { client .xadd( key2, - Map.of(field2, gs(field2.toString() + "2")), + Map.of(field2, gs(field2 + "2")), StreamAddOptionsBinary.builder().id(gs("2-2")).build()) .get(); assertNotNull(timestamp_2_2); // setup third entries in streams key1 and key2 Map timestamp_1_3_map = new LinkedHashMap<>(); - timestamp_1_3_map.put(field1, gs(field1.toString() + "3")); - timestamp_1_3_map.put(field3, gs(field3.toString() + "3")); + timestamp_1_3_map.put(field1, gs(field1 + "3")); + timestamp_1_3_map.put(field3, gs(field3 + "3")); GlideString timestamp_1_3 = client .xadd(key1, timestamp_1_3_map, StreamAddOptionsBinary.builder().id(gs("1-3")).build()) @@ -6233,7 +6233,7 @@ public void xread_binary(BaseClient client) { client .xadd( key2, - Map.of(field2, gs(field2.toString() + "3")), + Map.of(field2, gs(field2 + "3")), StreamAddOptionsBinary.builder().id(gs("2-3")).build()) .get(); assertNotNull(timestamp_2_3); @@ -6243,19 +6243,19 @@ public void xread_binary(BaseClient client) { // check key1 Map expected_key1 = new LinkedHashMap<>(); - expected_key1.put(timestamp_1_2, new GlideString[][] {{field1, gs(field1.toString() + "2")}}); + expected_key1.put(timestamp_1_2, new GlideString[][] {{field1, gs(field1 + "2")}}); expected_key1.put( timestamp_1_3, new GlideString[][] { - {field1, gs(field1.toString() + "3")}, - {field3, gs(field3.toString() + "3")} + {field1, gs(field1 + "3")}, + {field3, gs(field3 + "3")} }); assertDeepEquals(expected_key1, result.get(key1)); // check key2 Map expected_key2 = new LinkedHashMap<>(); - expected_key2.put(timestamp_2_2, new GlideString[][] {{field2, gs(field2.toString() + "2")}}); - expected_key2.put(timestamp_2_3, new GlideString[][] {{field2, gs(field2.toString() + "3")}}); + expected_key2.put(timestamp_2_2, new GlideString[][] {{field2, gs(field2 + "2")}}); + expected_key2.put(timestamp_2_3, new GlideString[][] {{field2, gs(field2 + "3")}}); assertDeepEquals(expected_key2, result.get(key2)); } @@ -6323,7 +6323,7 @@ public void xread_binary_return_failures(BaseClient client) { // setup first entries in streams key1 and key2 Map timestamp_1_1_map = new LinkedHashMap<>(); - timestamp_1_1_map.put(field1, gs(field1.toString() + "1")); + timestamp_1_1_map.put(field1, gs(field1 + "1")); GlideString timestamp_1_1 = client .xadd(key1, timestamp_1_1_map, StreamAddOptionsBinary.builder().id(gs("1-1")).build()) @@ -6411,7 +6411,7 @@ public void xdel(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.xdel(key2, new String[] {streamId3}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -8071,7 +8071,7 @@ public void xpending_xclaim_binary(BaseClient client) { System.out.println("xpending result:"); for (int i = 0; i < pending_results_extended.length; i++) { - System.out.println((GlideString) pending_results_extended[i][0]); + System.out.println(pending_results_extended[i][0]); } // because of idle time return, we have to remove it from the expected results @@ -9094,7 +9094,7 @@ public void linsert(BaseClient client) { assertEquals(OK, client.set(key2, "linsert").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.linsert(key2, AFTER, "p", "e").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9116,11 +9116,11 @@ public void zrange_binary_with_different_types_of_keys(BaseClient client) { assertEquals(OK, client.set(key, gs("value")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zrange(key, query).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows(ExecutionException.class, () -> client.zrangeWithScores(key, query).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9146,7 +9146,7 @@ public void linsert_binary(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.linsert(key2, AFTER, gs("p"), gs("e")).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9173,7 +9173,7 @@ public void brpop(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.brpop(new String[] {"foo"}, .0001).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9201,7 +9201,7 @@ public void brpop_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.brpop(new GlideString[] {gs("foo")}, .0001).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9223,11 +9223,11 @@ public void rpushx(BaseClient client) { assertEquals(OK, client.set(key3, "bar").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.rpushx(key3, new String[] {"_"}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // empty element list executionException = assertThrows(ExecutionException.class, () -> client.rpushx(key2, new String[0]).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9254,7 +9254,7 @@ public void blpop(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.blpop(new String[] {"foo"}, .0001).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9282,7 +9282,7 @@ public void blpop_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.blpop(new GlideString[] {gs("foo")}, .0001).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9307,7 +9307,7 @@ public void lpushx(BaseClient client) { // empty element list executionException = assertThrows(ExecutionException.class, () -> client.lpushx(key2, new String[0]).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9538,11 +9538,11 @@ public void zrange_with_different_types_of_keys(BaseClient client) { assertEquals(OK, client.set(key, "value").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.zrange(key, query).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows(ExecutionException.class, () -> client.zrangeWithScores(key, query).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9559,7 +9559,7 @@ public void pfadd(BaseClient client) { assertEquals(OK, client.set("foo", "bar").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.pfadd("foo", new String[0]).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9577,7 +9577,7 @@ public void pfadd_binary(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.pfadd(gs("foo"), new GlideString[0]).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9601,7 +9601,7 @@ public void pfcount(BaseClient client) { assertEquals(OK, client.set("foo", "bar").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.pfcount(new String[] {"foo"}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9626,7 +9626,7 @@ public void pfcount_binary(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.pfcount(new GlideString[] {gs("foo")}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9652,11 +9652,11 @@ public void pfmerge(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.pfmerge("foo", new String[] {key1}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.pfmerge(key1, new String[] {"foo"}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -9685,12 +9685,12 @@ public void pfmerge_binary(BaseClient client) { assertThrows( ExecutionException.class, () -> client.pfmerge(gs("foo"), new GlideString[] {key1}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.pfmerge(key1, new GlideString[] {gs("foo")}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10037,7 +10037,7 @@ public void geoadd(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key2, membersToCoordinates).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10075,7 +10075,7 @@ public void geoadd_binary(BaseClient client) { ExecutionException executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key2, membersToCoordinates).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10086,31 +10086,31 @@ public void geoadd_invalid_args(BaseClient client) { ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geoadd(key, Map.of()).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of("Place", new GeospatialData(-181, 0))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of("Place", new GeospatialData(181, 0))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of("Place", new GeospatialData(0, 86))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of("Place", new GeospatialData(0, -86))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10121,31 +10121,31 @@ public void geoadd_binary_invalid_args(BaseClient client) { ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geoadd(key, Map.of()).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of(gs("Place"), new GeospatialData(-181, 0))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of(gs("Place"), new GeospatialData(181, 0))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of(gs("Place"), new GeospatialData(0, 86))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows( ExecutionException.class, () -> client.geoadd(key, Map.of(gs("Place"), new GeospatialData(0, -86))).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10177,7 +10177,7 @@ public void geopos(BaseClient client) { assertEquals(OK, client.set(key2, "geopos").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geopos(key2, members).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10209,7 +10209,7 @@ public void geopos_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("geopos")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geopos(key2, members).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10248,7 +10248,7 @@ public void geodist(BaseClient client) { assertEquals(OK, client.set(key2, "geodist").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geodist(key2, member1, member2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10287,7 +10287,7 @@ public void geodist_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("geodist")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geodist(key2, member1, member2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10316,7 +10316,7 @@ public void geohash(BaseClient client) { assertEquals(OK, client.set(key2, "geohash").get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geohash(key2, members).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10345,7 +10345,7 @@ public void geohash_binary(BaseClient client) { assertEquals(OK, client.set(key2, gs("geohash")).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.geohash(key2, members).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10368,12 +10368,12 @@ public void bitcount(BaseClient client) { // Exception thrown due to the key holding a value with the wrong type ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.bitcount(key2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown due to the key holding a value with the wrong type executionException = assertThrows(ExecutionException.class, () -> client.bitcount(key2, 1, 1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertEquals(16L, client.bitcount(key1, 2, 5, BitmapIndexType.BYTE).get()); @@ -10386,21 +10386,21 @@ public void bitcount(BaseClient client) { assertThrows( ExecutionException.class, () -> client.bitcount(key2, 1, 1, BitmapIndexType.BIT).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } else { // Exception thrown because BIT and BYTE options were implemented after 7.0.0 executionException = assertThrows( ExecutionException.class, () -> client.bitcount(key1, 2, 5, BitmapIndexType.BYTE).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown because BIT and BYTE options were implemented after 7.0.0 executionException = assertThrows( ExecutionException.class, () -> client.bitcount(key1, 5, 30, BitmapIndexType.BIT).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } if (SERVER_VERSION.isGreaterThanOrEqualTo("8.0.0")) { assertEquals(26L, client.bitcount(key1, 0).get()); @@ -10412,13 +10412,13 @@ public void bitcount(BaseClient client) { // Exception thrown due to the key holding a value with the wrong type executionException = assertThrows(ExecutionException.class, () -> client.bitcount(key2, 1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } else { // Exception thrown because optional end was implemented after 8.0.0 executionException = assertThrows(ExecutionException.class, () -> client.bitcount(key1, 5).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } } @@ -10437,18 +10437,18 @@ public void setbit(BaseClient client) { // Exception thrown due to the negative offset ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.setbit(key1, -1, 1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown due to the value set not being 0 or 1 executionException = assertThrows(ExecutionException.class, () -> client.setbit(key1, 1, 2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown: key is not a string assertEquals(1, client.sadd(key2, new String[] {"value"}).get()); executionException = assertThrows(ExecutionException.class, () -> client.setbit(key2, 1, 1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10475,12 +10475,12 @@ public void getbit(BaseClient client) { // Exception thrown due to the negative offset ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.getbit(key1, -1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown due to the key holding a value with the wrong type assertEquals(1, client.sadd(key2, new String[] {value}).get()); executionException = assertThrows(ExecutionException.class, () -> client.getbit(key2, 1).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -10507,13 +10507,13 @@ public void bitpos(BaseClient client) { assertEquals(1, client.sadd(key3, new String[] {value}).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.bitpos(key3, 0).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows(ExecutionException.class, () -> client.bitpos(key3, 1, 2).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); executionException = assertThrows(ExecutionException.class, () -> client.bitpos(key3, 0, 1, 4).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); if (SERVER_VERSION.isGreaterThanOrEqualTo("7.0.0")) { assertEquals(24, client.bitpos(key1, 0, 3, 5, BitmapIndexType.BYTE).get()); @@ -10526,21 +10526,21 @@ public void bitpos(BaseClient client) { assertThrows( ExecutionException.class, () -> client.bitpos(key3, 1, 4, 5, BitmapIndexType.BIT).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } else { // Exception thrown because BIT and BYTE options were implemented after 7.0.0 executionException = assertThrows( ExecutionException.class, () -> client.bitpos(key1, 0, 3, 5, BitmapIndexType.BYTE).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown because BIT and BYTE options were implemented after 7.0.0 executionException = assertThrows( ExecutionException.class, () -> client.bitpos(key1, 1, 43, -2, BitmapIndexType.BIT).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } } @@ -10585,7 +10585,7 @@ public void bitop(BaseClient client) { // https://github.com/valkey-io/valkey-glide/issues/1447 ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.get(destination).get()); - assertTrue(executionException.getCause() instanceof RuntimeException); + assertInstanceOf(RuntimeException.class, executionException.getCause()); assertEquals(0, client.setbit(key1, 0, 1).get()); assertEquals(1L, client.bitop(BitwiseOperation.NOT, destination, new String[] {key1}).get()); assertEquals("\u001e", client.get(destination).get()); @@ -10613,14 +10613,14 @@ public void bitop(BaseClient client) { assertThrows( ExecutionException.class, () -> client.bitop(BitwiseOperation.OR, destination, new String[] {}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // NOT with more than one source key executionException = assertThrows( ExecutionException.class, () -> client.bitop(BitwiseOperation.NOT, destination, new String[] {key1, key2}).get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -11439,7 +11439,7 @@ public void bitfieldReadOnly(BaseClient client) { client .bitfieldReadOnly(key2, new BitFieldReadOnlySubCommands[] {unsignedOffsetGet}) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Offset must be >= 0 executionException = @@ -11453,7 +11453,7 @@ public void bitfieldReadOnly(BaseClient client) { new BitFieldGet(new UnsignedEncoding(5), new Offset(-1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Encoding must be > 0 executionException = @@ -11467,7 +11467,7 @@ public void bitfieldReadOnly(BaseClient client) { new BitFieldGet(new UnsignedEncoding(-1), new Offset(1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Encoding must be < 64 for unsigned bit encoding executionException = @@ -11481,7 +11481,7 @@ public void bitfieldReadOnly(BaseClient client) { new BitFieldGet(new UnsignedEncoding(64), new Offset(1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Encoding must be < 65 for signed bit encoding executionException = @@ -11495,7 +11495,7 @@ public void bitfieldReadOnly(BaseClient client) { new BitFieldGet(new SignedEncoding(65), new Offset(1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -11544,7 +11544,7 @@ public void bitfieldReadOnly_binary(BaseClient client) { client .bitfieldReadOnly(key2, new BitFieldReadOnlySubCommands[] {unsignedOffsetGet}) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Offset must be >= 0 executionException = @@ -11558,7 +11558,7 @@ public void bitfieldReadOnly_binary(BaseClient client) { new BitFieldGet(new UnsignedEncoding(5), new Offset(-1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Encoding must be > 0 executionException = @@ -11572,7 +11572,7 @@ public void bitfieldReadOnly_binary(BaseClient client) { new BitFieldGet(new UnsignedEncoding(-1), new Offset(1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Encoding must be < 64 for unsigned bit encoding executionException = @@ -11586,7 +11586,7 @@ public void bitfieldReadOnly_binary(BaseClient client) { new BitFieldGet(new UnsignedEncoding(64), new Offset(1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Encoding must be < 65 for signed bit encoding executionException = @@ -11600,7 +11600,7 @@ public void bitfieldReadOnly_binary(BaseClient client) { new BitFieldGet(new SignedEncoding(65), new Offset(1)) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -11715,7 +11715,7 @@ public void bitfield(BaseClient client) { new BitFieldSet(new UnsignedEncoding(-1), new Offset(1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Offset must be > 0 executionException = @@ -11729,7 +11729,7 @@ public void bitfield(BaseClient client) { new BitFieldIncrby(new UnsignedEncoding(5), new Offset(-1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Unsigned bit encoding must be < 64 executionException = @@ -11743,7 +11743,7 @@ public void bitfield(BaseClient client) { new BitFieldIncrby(new UnsignedEncoding(64), new Offset(1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Signed bit encoding must be < 65 executionException = @@ -11757,7 +11757,7 @@ public void bitfield(BaseClient client) { new BitFieldSet(new SignedEncoding(65), new Offset(1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown due to the key holding a value with the wrong type assertEquals(1, client.sadd(setKey, new String[] {foobar}).get()); @@ -11772,7 +11772,7 @@ public void bitfield(BaseClient client) { new BitFieldSet(new SignedEncoding(3), new Offset(1), 2) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -11887,7 +11887,7 @@ public void bitfield_binary(BaseClient client) { new BitFieldSet(new UnsignedEncoding(-1), new Offset(1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Offset must be > 0 executionException = @@ -11901,7 +11901,7 @@ public void bitfield_binary(BaseClient client) { new BitFieldIncrby(new UnsignedEncoding(5), new Offset(-1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Unsigned bit encoding must be < 64 executionException = @@ -11915,7 +11915,7 @@ public void bitfield_binary(BaseClient client) { new BitFieldIncrby(new UnsignedEncoding(64), new Offset(1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Signed bit encoding must be < 65 executionException = @@ -11929,7 +11929,7 @@ public void bitfield_binary(BaseClient client) { new BitFieldSet(new SignedEncoding(65), new Offset(1), 1) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); // Exception thrown due to the key holding a value with the wrong type assertEquals(1, client.sadd(setKey, new GlideString[] {foobar}).get()); @@ -11944,7 +11944,7 @@ public void bitfield_binary(BaseClient client) { new BitFieldSet(new SignedEncoding(3), new Offset(1), 2) }) .get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } @SneakyThrows @@ -14551,7 +14551,7 @@ public void zscan(BaseClient client) { // Setup test data - use a large number of entries to force an iterative cursor. Map numberMap = new HashMap<>(); for (Double i = 0.0; i < 50000; i++) { - numberMap.put("member" + String.valueOf(i), i); + numberMap.put("member" + i, i); } String[] charMembers = new String[] {"a", "b", "c", "d", "e"}; Map charMap = new HashMap<>(); @@ -14744,11 +14744,11 @@ public void zscan_binary(BaseClient client) { // Setup test data - use a large number of entries to force an iterative cursor. Map numberMap = new HashMap<>(); for (Double i = 0.0; i < 50000; i++) { - numberMap.put(gs("member" + String.valueOf(i)), i); + numberMap.put(gs("member" + i), i); } Map numberMap_strings = new HashMap<>(); for (Double i = 0.0; i < 50000; i++) { - numberMap_strings.put("member" + String.valueOf(i), i); + numberMap_strings.put("member" + i, i); } GlideString[] charMembers = new GlideString[] {gs("a"), gs("b"), gs("c"), gs("d"), gs("e")}; @@ -14908,7 +14908,7 @@ public void zscan_binary(BaseClient client) { Stream stream = Arrays.stream(fieldsArray); // Check if all fields start with "member" - assertTrue(stream.allMatch(field -> ((GlideString) field).toString().startsWith("member"))); + assertTrue(stream.allMatch(field -> field.toString().startsWith("member"))); } // Exceptions @@ -15284,7 +15284,7 @@ public void hscan_binary(BaseClient client) { Stream stream = Arrays.stream(fieldsArray); // Check if all fields dont start with "num" - assertTrue(stream.allMatch(field -> !((GlideString) field).toString().startsWith("num"))); + assertTrue(stream.allMatch(field -> !field.toString().startsWith("num"))); } // Exceptions @@ -15421,7 +15421,7 @@ public void xinfoStream(BaseClient client) { assertEquals(groupName, groupInfo.get("name")); Object[] pending = (Object[]) groupInfo.get("pending"); assertEquals(1, pending.length); - assertEquals(true, Arrays.toString((Object[]) pending[0]).contains(streamId1_0)); + assertTrue(Arrays.toString((Object[]) pending[0]).contains(streamId1_0)); Object[] consumers = (Object[]) groupInfo.get("consumers"); assertEquals(1, consumers.length); diff --git a/java/integTest/src/test/java/glide/cluster/ClusterClientTests.java b/java/integTest/src/test/java/glide/cluster/ClusterClientTests.java index b777a0c9fe..f737233251 100644 --- a/java/integTest/src/test/java/glide/cluster/ClusterClientTests.java +++ b/java/integTest/src/test/java/glide/cluster/ClusterClientTests.java @@ -60,7 +60,7 @@ public void can_connect_with_auth_requirepass() { assertThrows( ExecutionException.class, () -> GlideClusterClient.createClient(commonClusterClientConfig().build()).get()); - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); // Creation of a new client with credentials GlideClusterClient auth_client = @@ -129,7 +129,7 @@ public void can_connect_with_auth_acl() { ExecutionException executionException = assertThrows(ExecutionException.class, () -> testUserClient.set("foo", "bar").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); client.customCommand(new String[] {"ACL", "DELUSER", username}).get(); @@ -161,7 +161,7 @@ public void closed_client_throws_ExecutionException_with_ClosingException_as_cau client.close(); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.set("foo", "bar").get()); - assertTrue(executionException.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, executionException.getCause()); } @SneakyThrows diff --git a/java/integTest/src/test/java/glide/cluster/CommandTests.java b/java/integTest/src/test/java/glide/cluster/CommandTests.java index 3a1150770a..5e96ecb1d6 100644 --- a/java/integTest/src/test/java/glide/cluster/CommandTests.java +++ b/java/integTest/src/test/java/glide/cluster/CommandTests.java @@ -473,7 +473,7 @@ public void config_rewrite_non_existent_config_file() { if (configFile.isEmpty()) { ExecutionException executionException = assertThrows(ExecutionException.class, () -> clusterClient.configRewrite().get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } else { assertEquals(OK, clusterClient.configRewrite().get()); } @@ -495,7 +495,7 @@ public void configGet_with_no_args_returns_error() { var exception = assertThrows( ExecutionException.class, () -> clusterClient.configGet(new String[] {}).get()); - assertTrue(exception.getCause() instanceof GlideException); + assertInstanceOf(GlideException.class, exception.getCause()); } @Test @@ -3169,6 +3169,9 @@ public void scriptExists() { .get(); assertArrayEquals(expected, result); assertArrayEquals(expected, result2); + script1.close(); + script2.close(); + script3.close(); } @Test @@ -3202,6 +3205,9 @@ public void scriptExistsBinary() { .get(); assertArrayEquals(expected, result); assertArrayEquals(expected, result2); + script1.close(); + script2.close(); + script3.close(); } @Test @@ -3229,6 +3235,7 @@ public void scriptFlush() { assertEquals(OK, clusterClient.scriptFlush(FlushMode.ASYNC, ALL_PRIMARIES).get()); result = clusterClient.scriptExists(new String[] {script.getHash()}, ALL_PRIMARIES).get(); assertArrayEquals(new Boolean[] {false}, result); + script.close(); } @Test @@ -3277,6 +3284,7 @@ public void scriptKill_with_route() { assertTrue(scriptKilled); } finally { waitForNotBusy(clusterClient::scriptKill); + script.close(); } } @@ -3340,6 +3348,7 @@ public void scriptKill_unkillable() { promise.get(); } catch (Exception ignored) { } + script.close(); } } } diff --git a/java/integTest/src/test/java/glide/standalone/CommandTests.java b/java/integTest/src/test/java/glide/standalone/CommandTests.java index f7e4943e3a..20d539f5bd 100644 --- a/java/integTest/src/test/java/glide/standalone/CommandTests.java +++ b/java/integTest/src/test/java/glide/standalone/CommandTests.java @@ -200,7 +200,7 @@ public void simple_select_test() { public void select_test_gives_error() { ExecutionException e = assertThrows(ExecutionException.class, () -> regularClient.select(-1).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); } @Test @@ -230,7 +230,7 @@ public void move() { // Incorrect argument - DB index must be non-negative ExecutionException e = assertThrows(ExecutionException.class, () -> regularClient.move(key1, -1L).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); } @Test @@ -260,7 +260,7 @@ public void move_binary() { // Incorrect argument - DB index must be non-negative ExecutionException e = assertThrows(ExecutionException.class, () -> regularClient.move(key1, -1L).get()); - assertTrue(e.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, e.getCause()); } @Test @@ -304,7 +304,7 @@ public void config_rewrite_non_existent_config_file() { if (configFile.isEmpty()) { ExecutionException executionException = assertThrows(ExecutionException.class, () -> regularClient.configRewrite().get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); } else { assertEquals(OK, regularClient.configRewrite().get()); } @@ -316,7 +316,7 @@ public void configGet_with_no_args_returns_error() { var exception = assertThrows( ExecutionException.class, () -> regularClient.configGet(new String[] {}).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); assertTrue(exception.getCause().getMessage().contains("wrong number of arguments")); } @@ -347,7 +347,7 @@ public void configSet_with_unknown_parameter_returns_error() { assertThrows( ExecutionException.class, () -> regularClient.configSet(Map.of("Unknown Option", "Unknown Value")).get()); - assertTrue(exception.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, exception.getCause()); } @Test @@ -1590,6 +1590,8 @@ public void scriptExists() { Boolean[] result = regularClient.scriptExists(new String[] {sha1_1, sha1_2, nonExistentSha1}).get(); assertArrayEquals(expected, result); + script1.close(); + script2.close(); } @Test @@ -1611,6 +1613,8 @@ public void scriptExistsBinary() { Boolean[] result = regularClient.scriptExists(new GlideString[] {sha1_1, sha1_2, nonExistentSha1}).get(); assertArrayEquals(expected, result); + script1.close(); + script2.close(); } @Test @@ -1637,6 +1641,7 @@ public void scriptFlush() { assertEquals(OK, regularClient.scriptFlush(FlushMode.ASYNC).get()); result = regularClient.scriptExists(new String[] {script.getHash()}).get(); assertArrayEquals(new Boolean[] {false}, result); + script.close(); } @Test @@ -1682,6 +1687,7 @@ public void scriptKill() { assertTrue(scriptKilled); } finally { waitForNotBusy(regularClient::scriptKill); + script.close(); } } @@ -1742,6 +1748,7 @@ public void scriptKill_unkillable() { promise.get(); } catch (Exception ignored) { } + script.close(); } } } diff --git a/java/integTest/src/test/java/glide/standalone/StandaloneClientTests.java b/java/integTest/src/test/java/glide/standalone/StandaloneClientTests.java index 02551a6b9c..3c00ddf4d9 100644 --- a/java/integTest/src/test/java/glide/standalone/StandaloneClientTests.java +++ b/java/integTest/src/test/java/glide/standalone/StandaloneClientTests.java @@ -59,7 +59,7 @@ public void can_connect_with_auth_require_pass() { assertThrows( ExecutionException.class, () -> GlideClient.createClient(commonClientConfig().build()).get()); - assertTrue(exception.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, exception.getCause()); // Creation of a new client with credentials GlideClient auth_client = @@ -125,7 +125,7 @@ public void can_connect_with_auth_acl() { assertEquals(value, testUserClient.get(key).get()); ExecutionException executionException = assertThrows(ExecutionException.class, () -> testUserClient.set("foo", "bar").get()); - assertTrue(executionException.getCause() instanceof RequestException); + assertInstanceOf(RequestException.class, executionException.getCause()); client.customCommand(new String[] {"ACL", "DELUSER", username}).get(); @@ -164,7 +164,7 @@ public void closed_client_throws_ExecutionException_with_ClosingException_as_cau client.close(); ExecutionException executionException = assertThrows(ExecutionException.class, () -> client.set("key", "value").get()); - assertTrue(executionException.getCause() instanceof ClosingException); + assertInstanceOf(ClosingException.class, executionException.getCause()); } @SneakyThrows