From 256e23034f01baf461b4df0ff41f83ade0575e3e Mon Sep 17 00:00:00 2001 From: Alexey Kuzin Date: Sat, 17 Sep 2022 18:06:27 -0400 Subject: [PATCH 1/2] Do not use utility classes from dependencies We have been avoiding this previously and we need to continue keeping out of any unnecessary dependencies in the code, especially we should not use any internal classes and transitive dependencies of the dependencies, because it easily breaks dependency updates. --- .../io/tarantool/driver/TarantoolUtils.java | 7 +++--- .../driver/integration/ConnectionIT.java | 3 +-- .../ConvertersWithClusterClientIT.java | 6 ++--- .../ConvertersWithProxyClientIT.java | 10 ++++---- .../tarantool/driver/integration/Utils.java | 24 +++++++++++++++++++ 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/test/java/io/tarantool/driver/TarantoolUtils.java b/src/test/java/io/tarantool/driver/TarantoolUtils.java index 2bd79851b..dbe05ca70 100644 --- a/src/test/java/io/tarantool/driver/TarantoolUtils.java +++ b/src/test/java/io/tarantool/driver/TarantoolUtils.java @@ -1,7 +1,6 @@ package io.tarantool.driver; import io.tarantool.driver.utils.Assert; -import org.testcontainers.shaded.org.apache.commons.lang3.StringUtils; import java.util.Arrays; import java.util.Collections; @@ -18,13 +17,14 @@ private TarantoolUtils() { public static boolean versionGreaterOrEqualThen(String tarantoolVersion) { Assert.notNull(tarantoolVersion, "tarantoolVersion must not be null"); String tarantoolCiVersion = java.lang.System.getenv(TARANTOOL_VERSION); - if (StringUtils.isEmpty(tarantoolCiVersion)) { + if (tarantoolCiVersion == null || tarantoolCiVersion.isEmpty()) { return true; } TarantoolVersion ciVersion = new TarantoolVersion(tarantoolCiVersion); TarantoolVersion version = new TarantoolVersion(tarantoolVersion); return ciVersion.getMajor() >= version.getMajor() && ciVersion.getMinor() >= version.getMinor(); + } public static boolean versionWithUUID() { @@ -44,7 +44,8 @@ public static class TarantoolVersion { private Integer minor; public TarantoolVersion(String stringVersion) { - List majorMinor = StringUtils.isEmpty(stringVersion) ? Collections.emptyList() : + List majorMinor = stringVersion == null || stringVersion.isEmpty() ? + Collections.emptyList() : Arrays.stream(stringVersion.split("\\.")) .collect(Collectors.toList()); if (majorMinor.size() >= 1) { diff --git a/src/test/java/io/tarantool/driver/integration/ConnectionIT.java b/src/test/java/io/tarantool/driver/integration/ConnectionIT.java index a4de540dc..2df827062 100644 --- a/src/test/java/io/tarantool/driver/integration/ConnectionIT.java +++ b/src/test/java/io/tarantool/driver/integration/ConnectionIT.java @@ -22,7 +22,6 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.shaded.com.fasterxml.jackson.databind.util.ClassUtil; import java.util.ArrayList; import java.util.List; @@ -364,6 +363,6 @@ public void test_AddressProviderReturnsNull_shouldThrowTarantoolClientException( // then TarantoolClientException exception = assertThrows(TarantoolClientException.class, client::getVersion); - assertFalse(ClassUtil.getRootCause(exception) instanceof NullPointerException); + assertFalse(Utils.getRootCause(exception) instanceof NullPointerException); } } diff --git a/src/test/java/io/tarantool/driver/integration/ConvertersWithClusterClientIT.java b/src/test/java/io/tarantool/driver/integration/ConvertersWithClusterClientIT.java index eb7392760..54cea5a6e 100644 --- a/src/test/java/io/tarantool/driver/integration/ConvertersWithClusterClientIT.java +++ b/src/test/java/io/tarantool/driver/integration/ConvertersWithClusterClientIT.java @@ -13,13 +13,11 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIf; -import org.testcontainers.shaded.org.apache.commons.lang3.ArrayUtils; import java.time.Instant; import java.util.UUID; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.List; /** @@ -87,7 +85,7 @@ public void test_boxSelect_shouldReturnTupleWithInstant() throws Exception { public void test_boxOperations_shouldWorkWithVarbinary() throws Exception { //given byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8); - List byteList = Arrays.asList(ArrayUtils.toObject(bytes)); + List byteList = Utils.convertBytesToByteList(bytes); client.space("space_with_varbinary") .insert(tupleFactory.create(1, bytes)).get(); @@ -98,7 +96,7 @@ public void test_boxOperations_shouldWorkWithVarbinary() throws Exception { //then byte[] bytesFromTarantool = fields.getByteArray("varbinary_field"); - List byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool)); + List byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool); Assertions.assertEquals(byteList, byteListFromTarantool); } } diff --git a/src/test/java/io/tarantool/driver/integration/ConvertersWithProxyClientIT.java b/src/test/java/io/tarantool/driver/integration/ConvertersWithProxyClientIT.java index 42487e993..308091390 100644 --- a/src/test/java/io/tarantool/driver/integration/ConvertersWithProxyClientIT.java +++ b/src/test/java/io/tarantool/driver/integration/ConvertersWithProxyClientIT.java @@ -13,13 +13,11 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIf; -import org.testcontainers.shaded.org.apache.commons.lang3.ArrayUtils; import java.time.Instant; import java.util.UUID; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.List; /** @@ -89,7 +87,7 @@ public void test_crudSelect_shouldReturnTupleWithInstant() throws Exception { public void test_crudOperations_shouldWorkWithVarbinary() throws Exception { //given byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8); - List byteList = Arrays.asList(ArrayUtils.toObject(bytes)); + List byteList = Utils.convertBytesToByteList(bytes); client.space("space_with_varbinary") .insert(tupleFactory.create(1, bytes)).get(); @@ -100,7 +98,7 @@ public void test_crudOperations_shouldWorkWithVarbinary() throws Exception { //then byte[] bytesFromTarantool = fields.getByteArray("varbinary_field"); - List byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool)); + List byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool); Assertions.assertEquals(byteList, byteListFromTarantool); } @@ -108,7 +106,7 @@ public void test_crudOperations_shouldWorkWithVarbinary() throws Exception { public void test_crudOperations_shouldWorkWithBytesAsString() throws Exception { //given byte[] bytes = "hello".getBytes(StandardCharsets.UTF_8); - List byteList = Arrays.asList(ArrayUtils.toObject(bytes)); + List byteList = Utils.convertBytesToByteList(bytes); client.space("space_with_string") .insert(tupleFactory.create(1, bytes)).get(); @@ -119,7 +117,7 @@ public void test_crudOperations_shouldWorkWithBytesAsString() throws Exception { //then byte[] bytesFromTarantool = fields.getByteArray("string_field"); - List byteListFromTarantool = Arrays.asList(ArrayUtils.toObject(bytesFromTarantool)); + List byteListFromTarantool = Utils.convertBytesToByteList(bytesFromTarantool); Assertions.assertEquals(byteList, byteListFromTarantool); } } diff --git a/src/test/java/io/tarantool/driver/integration/Utils.java b/src/test/java/io/tarantool/driver/integration/Utils.java index 5576d6668..5d0a38f01 100644 --- a/src/test/java/io/tarantool/driver/integration/Utils.java +++ b/src/test/java/io/tarantool/driver/integration/Utils.java @@ -15,6 +15,8 @@ import java.util.List; import java.util.Optional; import java.util.concurrent.ExecutionException; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -103,4 +105,26 @@ private static long crc32(byte[] data) { crc32 = Integer.reverse(crc32); // result reflect return crc32 & 0x00000000ffffffffL; // the unsigned java problem } + + /** + * Converts a byte array to a list of bytes + * + * @param bytes byte array + */ + static List convertBytesToByteList(byte[] bytes) { + return IntStream.range(0, bytes.length).mapToObj(i -> bytes[i]).collect(Collectors.toList()); + } + + /** + * Find the rootmost non-null cause of an Exception recursively + * + * @param t exception + * @return root cause of the exception or the exception itself + */ + static Throwable getRootCause(Throwable t) { + while (t.getCause() != null) { + t = t.getCause(); + } + return t; + } } From 49d7babfdb57c326df79024bf3ae66de5f7d60a4 Mon Sep 17 00:00:00 2001 From: Alexey Kuzin Date: Thu, 22 Jun 2023 16:13:26 -0400 Subject: [PATCH 2/2] Remove unnecessary dependency on a Jetbrains library --- src/test/java/io/tarantool/driver/TarantoolUtils.java | 1 - src/test/java/io/tarantool/driver/integration/ReconnectIT.java | 2 -- .../tarantool/driver/integration/ssl/SslClientITEnterprise.java | 2 -- .../driver/integration/ssl/SslClientMTlsITEnterprise.java | 2 -- 4 files changed, 7 deletions(-) diff --git a/src/test/java/io/tarantool/driver/TarantoolUtils.java b/src/test/java/io/tarantool/driver/TarantoolUtils.java index dbe05ca70..8bec452eb 100644 --- a/src/test/java/io/tarantool/driver/TarantoolUtils.java +++ b/src/test/java/io/tarantool/driver/TarantoolUtils.java @@ -24,7 +24,6 @@ public static boolean versionGreaterOrEqualThen(String tarantoolVersion) { TarantoolVersion version = new TarantoolVersion(tarantoolVersion); return ciVersion.getMajor() >= version.getMajor() && ciVersion.getMinor() >= version.getMinor(); - } public static boolean versionWithUUID() { diff --git a/src/test/java/io/tarantool/driver/integration/ReconnectIT.java b/src/test/java/io/tarantool/driver/integration/ReconnectIT.java index a65c43028..8dd211c1a 100644 --- a/src/test/java/io/tarantool/driver/integration/ReconnectIT.java +++ b/src/test/java/io/tarantool/driver/integration/ReconnectIT.java @@ -19,7 +19,6 @@ import io.tarantool.driver.core.TarantoolDaemonThreadFactory; import io.tarantool.driver.exceptions.TarantoolNoSuchProcedureException; import io.tarantool.driver.mappers.factories.DefaultMessagePackMapperFactory; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -369,7 +368,6 @@ private void replaceInstancesInfo( client.space("instances_info").replace(tuple).join(); } - @NotNull private List getShuffledTarantoolServerAddresses() { List addresses = Arrays.asList( new TarantoolServerAddress(container.getRouterHost(), container.getMappedPort(3301)), diff --git a/src/test/java/io/tarantool/driver/integration/ssl/SslClientITEnterprise.java b/src/test/java/io/tarantool/driver/integration/ssl/SslClientITEnterprise.java index 98e534ec4..dfe4472d2 100644 --- a/src/test/java/io/tarantool/driver/integration/ssl/SslClientITEnterprise.java +++ b/src/test/java/io/tarantool/driver/integration/ssl/SslClientITEnterprise.java @@ -9,7 +9,6 @@ import io.tarantool.driver.api.TarantoolResult; import io.tarantool.driver.api.tuple.TarantoolTuple; import io.tarantool.driver.exceptions.TarantoolClientException; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -119,7 +118,6 @@ public void test_clientWithSsl_shouldWork() throws SSLException { assertEquals("test", result.get(0)); } - @NotNull private static SslContext getSslContext() throws SSLException { return SslContextBuilder.forClient() .trustManager(InsecureTrustManagerFactory.INSTANCE) diff --git a/src/test/java/io/tarantool/driver/integration/ssl/SslClientMTlsITEnterprise.java b/src/test/java/io/tarantool/driver/integration/ssl/SslClientMTlsITEnterprise.java index ec0cb62ac..91c8a7f5a 100644 --- a/src/test/java/io/tarantool/driver/integration/ssl/SslClientMTlsITEnterprise.java +++ b/src/test/java/io/tarantool/driver/integration/ssl/SslClientMTlsITEnterprise.java @@ -9,7 +9,6 @@ import io.tarantool.driver.api.TarantoolResult; import io.tarantool.driver.api.tuple.TarantoolTuple; import io.tarantool.driver.exceptions.TarantoolClientException; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import org.slf4j.Logger; @@ -104,7 +103,6 @@ public void test_clientWithoutCA_shouldThrowException_ifServerWithMTLS() throws assertThrows(CompletionException.class, () -> clientWithSsl.eval("return 'test'").join()); } - @NotNull private static SslContext getSslContextWithCA() throws Exception { ClassLoader classloader = Thread.currentThread().getContextClassLoader(); final File keyCertChainFile = new File(classloader