From 4b9f8de55247669480759f6a73c8aaf473c616d6 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Wed, 25 Oct 2023 11:38:36 -0700 Subject: [PATCH] Remove duplicates. Reorganize and fix imports. Signed-off-by: Yury-Fridlyand --- .../javababushka/benchmarks/AsyncClient.java | 16 ---- .../benchmarks/BenchmarkingApp.java | 10 +-- .../java/javababushka/benchmarks/Client.java | 13 ---- .../javababushka/benchmarks/SyncClient.java | 7 -- .../clients/{ => babushka}/JniSyncClient.java | 3 +- .../clients/{ => jedis}/JedisClient.java | 4 +- .../{ => jedis}/JedisPseudoAsyncClient.java | 3 +- .../{ => lettuce}/LettuceAsyncClient.java | 3 +- .../clients/{ => lettuce}/LettuceClient.java | 3 +- .../benchmarks/jedis/JedisClient.java | 65 ----------------- .../jedis/JedisPseudoAsyncClient.java | 39 ---------- .../lettuce/LettuceAsyncClient.java | 73 ------------------- .../benchmarks/lettuce/LettuceClient.java | 56 -------------- .../benchmarks/jedis/JedisClientIT.java | 12 +-- .../lettuce/LettuceAsyncClientIT.java | 1 + .../benchmarks/lettuce/LettuceClientIT.java | 1 + 16 files changed, 21 insertions(+), 288 deletions(-) delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/AsyncClient.java delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/Client.java delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/SyncClient.java rename java/benchmarks/src/main/java/javababushka/benchmarks/clients/{ => babushka}/JniSyncClient.java (99%) rename java/benchmarks/src/main/java/javababushka/benchmarks/clients/{ => jedis}/JedisClient.java (93%) rename java/benchmarks/src/main/java/javababushka/benchmarks/clients/{ => jedis}/JedisPseudoAsyncClient.java (91%) rename java/benchmarks/src/main/java/javababushka/benchmarks/clients/{ => lettuce}/LettuceAsyncClient.java (94%) rename java/benchmarks/src/main/java/javababushka/benchmarks/clients/{ => lettuce}/LettuceClient.java (92%) delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisClient.java delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisPseudoAsyncClient.java delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceAsyncClient.java delete mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceClient.java diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/AsyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/AsyncClient.java deleted file mode 100644 index a688775084..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/AsyncClient.java +++ /dev/null @@ -1,16 +0,0 @@ -package javababushka.benchmarks; - -import java.util.concurrent.Future; - -public interface AsyncClient extends Client { - - long DEFAULT_TIMEOUT = 1000; - - Future asyncSet(String key, String value); - - Future asyncGet(String key); - - T waitForResult(Future future); - - T waitForResult(Future future, long timeout); -} diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java b/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java index fb0578947f..9e19abd4e3 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java @@ -5,11 +5,11 @@ import java.util.Arrays; import java.util.Optional; import java.util.stream.Stream; -import javababushka.benchmarks.clients.JedisClient; -import javababushka.benchmarks.clients.JedisPseudoAsyncClient; -import javababushka.benchmarks.clients.JniSyncClient; -import javababushka.benchmarks.clients.LettuceAsyncClient; -import javababushka.benchmarks.clients.LettuceClient; +import javababushka.benchmarks.clients.babushka.JniSyncClient; +import javababushka.benchmarks.clients.jedis.JedisClient; +import javababushka.benchmarks.clients.jedis.JedisPseudoAsyncClient; +import javababushka.benchmarks.clients.lettuce.LettuceAsyncClient; +import javababushka.benchmarks.clients.lettuce.LettuceClient; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; import org.apache.commons.cli.DefaultParser; diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/Client.java b/java/benchmarks/src/main/java/javababushka/benchmarks/Client.java deleted file mode 100644 index 16ab36847d..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/Client.java +++ /dev/null @@ -1,13 +0,0 @@ -package javababushka.benchmarks; - -import javababushka.benchmarks.utils.ConnectionSettings; - -public interface Client { - void connectToRedis(); - - void connectToRedis(ConnectionSettings connectionSettings); - - default void closeConnection() {} - - String getName(); -} diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/SyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/SyncClient.java deleted file mode 100644 index c99174af3d..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/SyncClient.java +++ /dev/null @@ -1,7 +0,0 @@ -package javababushka.benchmarks; - -public interface SyncClient extends Client { - void set(String key, String value); - - String get(String key); -} diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/JniSyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniSyncClient.java similarity index 99% rename from java/benchmarks/src/main/java/javababushka/benchmarks/clients/JniSyncClient.java rename to java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniSyncClient.java index 1c3c376f07..bf9b94b352 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/JniSyncClient.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/babushka/JniSyncClient.java @@ -1,4 +1,4 @@ -package javababushka.benchmarks.clients; +package javababushka.benchmarks.clients.babushka; import java.io.IOException; import java.net.StandardProtocolFamily; @@ -8,6 +8,7 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import javababushka.benchmarks.clients.SyncClient; import javababushka.benchmarks.utils.ConnectionSettings; import javababushka.client.RedisClient; import org.apache.commons.lang3.tuple.MutablePair; diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisClient.java similarity index 93% rename from java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisClient.java rename to java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisClient.java index 4cfd294fda..fe7722b324 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisClient.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisClient.java @@ -1,5 +1,6 @@ -package javababushka.benchmarks.clients; +package javababushka.benchmarks.clients.jedis; +import javababushka.benchmarks.clients.SyncClient; import javababushka.benchmarks.utils.ConnectionSettings; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisPool; @@ -39,7 +40,6 @@ public void connectToRedis(ConnectionSettings connectionSettings) { if (!jedisResource.isConnected()) { throw new RuntimeException("failed to connect to jedis"); } - String info_result = info(); } public String info() { diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisPseudoAsyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisPseudoAsyncClient.java similarity index 91% rename from java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisPseudoAsyncClient.java rename to java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisPseudoAsyncClient.java index 1aff543c6f..e441b28ad8 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/JedisPseudoAsyncClient.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/jedis/JedisPseudoAsyncClient.java @@ -1,8 +1,9 @@ -package javababushka.benchmarks.clients; +package javababushka.benchmarks.clients.jedis; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import javababushka.benchmarks.clients.AsyncClient; /** * A jedis client with pseudo-sync capabilities. Jedis doesn't provide async API diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceAsyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/lettuce/LettuceAsyncClient.java similarity index 94% rename from java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceAsyncClient.java rename to java/benchmarks/src/main/java/javababushka/benchmarks/clients/lettuce/LettuceAsyncClient.java index 7251953845..fdde50d5f5 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceAsyncClient.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/lettuce/LettuceAsyncClient.java @@ -1,4 +1,4 @@ -package javababushka.benchmarks.clients; +package javababushka.benchmarks.clients.lettuce; import io.lettuce.core.RedisClient; import io.lettuce.core.RedisFuture; @@ -6,6 +6,7 @@ import io.lettuce.core.api.async.RedisAsyncCommands; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; +import javababushka.benchmarks.clients.AsyncClient; import javababushka.benchmarks.utils.ConnectionSettings; /** A Lettuce client with async capabilities see: https://lettuce.io/ */ diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/lettuce/LettuceClient.java similarity index 92% rename from java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceClient.java rename to java/benchmarks/src/main/java/javababushka/benchmarks/clients/lettuce/LettuceClient.java index 674fb729b0..5e4b1a633c 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/clients/LettuceClient.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/clients/lettuce/LettuceClient.java @@ -1,8 +1,9 @@ -package javababushka.benchmarks.clients; +package javababushka.benchmarks.clients.lettuce; import io.lettuce.core.RedisClient; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisStringCommands; +import javababushka.benchmarks.clients.SyncClient; import javababushka.benchmarks.utils.ConnectionSettings; /** A Lettuce client with sync capabilities see: https://lettuce.io/ */ diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisClient.java deleted file mode 100644 index 214a6cae10..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisClient.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package javababushka.benchmarks.jedis; - -import javababushka.benchmarks.SyncClient; -import javababushka.benchmarks.utils.ConnectionSettings; -import redis.clients.jedis.Jedis; -import redis.clients.jedis.JedisPool; - -public class JedisClient implements SyncClient { - - public static final String DEFAULT_HOST = "localhost"; - public static final int DEFAULT_PORT = 6379; - - protected Jedis jedisResource; - - public boolean someLibraryMethod() { - return true; - } - - @Override - public void connectToRedis() { - JedisPool pool = new JedisPool(DEFAULT_HOST, DEFAULT_PORT); - jedisResource = pool.getResource(); - } - - @Override - public void closeConnection() { - try { - jedisResource.close(); - } catch (Exception ignored) { - } - } - - @Override - public String getName() { - return "Jedis"; - } - - @Override - public void connectToRedis(ConnectionSettings connectionSettings) { - jedisResource = - new Jedis(connectionSettings.host, connectionSettings.port, connectionSettings.useSsl); - jedisResource.connect(); - } - - public String info() { - return jedisResource.info(); - } - - public String info(String section) { - return jedisResource.info(section); - } - - @Override - public void set(String key, String value) { - jedisResource.set(key, value); - } - - @Override - public String get(String key) { - return jedisResource.get(key); - } -} diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisPseudoAsyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisPseudoAsyncClient.java deleted file mode 100644 index 598c455d1e..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/jedis/JedisPseudoAsyncClient.java +++ /dev/null @@ -1,39 +0,0 @@ -package javababushka.benchmarks.jedis; - -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import javababushka.benchmarks.AsyncClient; - -// Jedis doesn't provide async API -// https://github.com/redis/jedis/issues/241 -public class JedisPseudoAsyncClient extends JedisClient implements AsyncClient { - @Override - public Future asyncSet(String key, String value) { - return CompletableFuture.runAsync(() -> super.set(key, value)); - } - - @Override - public Future asyncGet(String key) { - return CompletableFuture.supplyAsync(() -> super.get(key)); - } - - @Override - public T waitForResult(Future future) { - return waitForResult(future, DEFAULT_TIMEOUT); - } - - @Override - public T waitForResult(Future future, long timeout) { - try { - return future.get(timeout, TimeUnit.MILLISECONDS); - } catch (Exception ignored) { - return null; - } - } - - @Override - public String getName() { - return "Jedis pseudo-async"; - } -} diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceAsyncClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceAsyncClient.java deleted file mode 100644 index 1b8c4ba9b7..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceAsyncClient.java +++ /dev/null @@ -1,73 +0,0 @@ -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package javababushka.benchmarks.lettuce; - -import io.lettuce.core.RedisClient; -import io.lettuce.core.RedisFuture; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.api.async.RedisAsyncCommands; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import javababushka.benchmarks.AsyncClient; -import javababushka.benchmarks.utils.ConnectionSettings; - -public class LettuceAsyncClient implements AsyncClient { - - RedisClient client; - RedisAsyncCommands asyncCommands; - StatefulRedisConnection connection; - - @Override - public void connectToRedis() { - connectToRedis(new ConnectionSettings("localhost", 6379, false)); - } - - @Override - public void connectToRedis(ConnectionSettings connectionSettings) { - client = - RedisClient.create( - String.format( - "%s://%s:%d", - connectionSettings.useSsl ? "rediss" : "redis", - connectionSettings.host, - connectionSettings.port)); - connection = client.connect(); - asyncCommands = connection.async(); - } - - @Override - public RedisFuture asyncSet(String key, String value) { - return asyncCommands.set(key, value); - } - - @Override - public RedisFuture asyncGet(String key) { - return asyncCommands.get(key); - } - - @Override - public Object waitForResult(Future future) { - return waitForResult(future, DEFAULT_TIMEOUT); - } - - @Override - public Object waitForResult(Future future, long timeoutMS) { - try { - return future.get(timeoutMS, TimeUnit.MILLISECONDS); - } catch (Exception ignored) { - return null; - } - } - - @Override - public void closeConnection() { - connection.close(); - client.shutdown(); - } - - @Override - public String getName() { - return "Lettuce Async"; - } -} diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceClient.java deleted file mode 100644 index e4e1830bda..0000000000 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/lettuce/LettuceClient.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This Java source file was generated by the Gradle 'init' task. - */ -package javababushka.benchmarks.lettuce; - -import io.lettuce.core.RedisClient; -import io.lettuce.core.api.StatefulRedisConnection; -import io.lettuce.core.api.sync.RedisStringCommands; -import javababushka.benchmarks.SyncClient; -import javababushka.benchmarks.utils.ConnectionSettings; - -public class LettuceClient implements SyncClient { - - RedisClient client; - RedisStringCommands syncCommands; - StatefulRedisConnection connection; - - @Override - public void connectToRedis() { - connectToRedis(new ConnectionSettings("localhost", 6379, false)); - } - - @Override - public void connectToRedis(ConnectionSettings connectionSettings) { - client = - RedisClient.create( - String.format( - "%s://%s:%d", - connectionSettings.useSsl ? "rediss" : "redis", - connectionSettings.host, - connectionSettings.port)); - connection = client.connect(); - syncCommands = connection.sync(); - } - - @Override - public void set(String key, String value) { - syncCommands.set(key, value); - } - - @Override - public String get(String key) { - return (String) syncCommands.get(key); - } - - @Override - public void closeConnection() { - connection.close(); - client.shutdown(); - } - - @Override - public String getName() { - return "Lettuce"; - } -} diff --git a/java/benchmarks/src/test/java/javababushka/benchmarks/jedis/JedisClientIT.java b/java/benchmarks/src/test/java/javababushka/benchmarks/jedis/JedisClientIT.java index 12f800260f..9a6dbbe93e 100644 --- a/java/benchmarks/src/test/java/javababushka/benchmarks/jedis/JedisClientIT.java +++ b/java/benchmarks/src/test/java/javababushka/benchmarks/jedis/JedisClientIT.java @@ -7,7 +7,9 @@ import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; +import javababushka.benchmarks.clients.jedis.JedisClient; import javababushka.benchmarks.utils.Benchmarking; import javababushka.benchmarks.utils.ChosenAction; import org.junit.jupiter.api.BeforeAll; @@ -23,12 +25,6 @@ static void initializeJedisClient() { jedisClient.connectToRedis(); } - @Test - public void someLibraryMethodReturnsTrue() { - JedisClient classUnderTest = new JedisClient(); - assertTrue(classUnderTest.someLibraryMethod(), "someLibraryMethod should return 'true'"); - } - @Test public void testResourceInfo() { String result = jedisClient.info(); @@ -56,7 +52,7 @@ public void testResourceSetGet() { ChosenAction.GET_NON_EXISTING, () -> jedisClient.get(Benchmarking.generateKeyGet())); actions.put(ChosenAction.SET, () -> jedisClient.set(Benchmarking.generateKeySet(), value)); - Map> latencies = + Map> latencies = Map.of( ChosenAction.GET_EXISTING, new ArrayList<>(), ChosenAction.GET_NON_EXISTING, new ArrayList<>(), @@ -66,6 +62,6 @@ public void testResourceSetGet() { latencies.get(latency.getKey()).add(latency.getValue()); } - Benchmarking.printResults(Benchmarking.calculateResults(latencies)); + Benchmarking.printResults(Benchmarking.calculateResults(latencies), 0, iterations); } } diff --git a/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceAsyncClientIT.java b/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceAsyncClientIT.java index c051c1b2a4..ee9ad8cb35 100644 --- a/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceAsyncClientIT.java +++ b/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceAsyncClientIT.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.fail; import io.lettuce.core.RedisFuture; +import javababushka.benchmarks.clients.lettuce.LettuceAsyncClient; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; diff --git a/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceClientIT.java b/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceClientIT.java index 445cc5b584..5cbf8186b0 100644 --- a/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceClientIT.java +++ b/java/benchmarks/src/test/java/javababushka/benchmarks/lettuce/LettuceClientIT.java @@ -4,6 +4,7 @@ package javababushka.benchmarks.lettuce; import java.util.HashMap; +import javababushka.benchmarks.clients.lettuce.LettuceClient; import javababushka.benchmarks.utils.Benchmarking; import javababushka.benchmarks.utils.ChosenAction; import org.junit.jupiter.api.AfterAll;