Skip to content

Commit

Permalink
Add kotlin client created with uniffi interop to java benchmarks.
Browse files Browse the repository at this point in the history
Signed-off-by: Yury-Fridlyand <[email protected]>
  • Loading branch information
Yury-Fridlyand committed Oct 16, 2023
1 parent b89bd23 commit 773b620
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
5 changes: 5 additions & 0 deletions java/benchmarks/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 773b620

Please sign in to comment.