From 773b620c6f79f3215ff1eaa962bf18f38ec85d20 Mon Sep 17 00:00:00 2001 From: Yury-Fridlyand Date: Mon, 16 Oct 2023 12:11:16 -0700 Subject: [PATCH] Add kotlin client created with uniffi interop to java benchmarks. Signed-off-by: Yury-Fridlyand --- java/benchmarks/build.gradle | 5 ++ .../benchmarks/BenchmarkingApp.java | 4 ++ .../benchmarks/kotlin/KotlinClient.java | 53 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100644 java/benchmarks/src/main/java/javababushka/benchmarks/kotlin/KotlinClient.java diff --git a/java/benchmarks/build.gradle b/java/benchmarks/build.gradle index 8d9e500284..df7a45f6a5 100644 --- a/java/benchmarks/build.gradle +++ b/java/benchmarks/build.gradle @@ -18,6 +18,11 @@ dependencies { implementation 'io.lettuce:lettuce-core:6.2.6.RELEASE' implementation 'commons-cli:commons-cli:1.5.0' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.13.0' + + // Required for interop + implementation "net.java.dev.jna:jna:5.8.0" + implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.20" + implementation files("../../kotlin/client/build/libs/kotlinbabushka-0.0.1.jar") } // Apply a specific Java toolchain to ease working on different environments. diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java b/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java index 66ea1f5029..42cbf416b9 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java @@ -11,6 +11,7 @@ import java.util.stream.Stream; import javababushka.benchmarks.jedis.JedisClient; import javababushka.benchmarks.jedis.JedisPseudoAsyncClient; +import javababushka.benchmarks.kotlin.KotlinClient; import javababushka.benchmarks.lettuce.LettuceAsyncClient; import javababushka.benchmarks.lettuce.LettuceClient; import org.apache.commons.cli.CommandLine; @@ -52,6 +53,8 @@ public static void main(String[] args) { case LETTUCE_ASYNC: testClientSetGet(LettuceAsyncClient::new, runConfiguration, true); break; + case KOTLIN: + testClientSetGet(KotlinClient::new, runConfiguration, false); case BABUSHKA: System.out.println("Babushka not yet configured"); break; @@ -188,6 +191,7 @@ public enum ClientName { LETTUCE("Lettuce"), LETTUCE_ASYNC("Lettuce async"), BABUSHKA("Babushka"), + KOTLIN("Kotlin"), ALL("All"), ALL_SYNC("All sync"), ALL_ASYNC("All async"); diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/kotlin/KotlinClient.java b/java/benchmarks/src/main/java/javababushka/benchmarks/kotlin/KotlinClient.java new file mode 100644 index 0000000000..2cd8931ca3 --- /dev/null +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/kotlin/KotlinClient.java @@ -0,0 +1,53 @@ +package javababushka.benchmarks.kotlin; + +import babushka.BabushkaClient; +import babushka.BabushkaClientData; +import babushka.BabushkaRedisException; +import javababushka.benchmarks.SyncClient; +import javababushka.benchmarks.utils.ConnectionSettings; + +public class KotlinClient implements SyncClient { + + private BabushkaClient client = new BabushkaClient(); + private BabushkaClientData data = null; + + @Override + public void connectToRedis() { + connectToRedis(new ConnectionSettings("localhost", 6379, false)); + } + + @Override + public void connectToRedis(ConnectionSettings connectionSettings) { + try { + data = client.connect(String.format( + "%s://%s:%d", + connectionSettings.useSsl ? "rediss" : "redis", + connectionSettings.host, + connectionSettings.port)); + } catch (BabushkaRedisException e) { + System.out.printf("Failed to connect: %s%n", e.getMessage()); + e.printStackTrace(); + } + } + + @Override + public String getName() { + return "kotlin"; + } + + @Override + public void set(String key, String value) { + + } + + @Override + public String get(String key) { + try { + return client.get3(data, key); + } catch (BabushkaRedisException e) { + System.out.printf("failed to get3: %s%n", e.getMessage()); + e.printStackTrace(); + } + return null; + } +}