From 0883985da5d80ea2578228d67702e9aed5c0188b Mon Sep 17 00:00:00 2001 From: acarbonetto Date: Tue, 10 Oct 2023 10:27:25 -0700 Subject: [PATCH] spotless apply Signed-off-by: acarbonetto --- java/README.md | 2 +- .../benchmarks/BenchmarkingApp.java | 63 ++++++++----------- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/java/README.md b/java/README.md index 12ae1966f2..e21777aa57 100644 --- a/java/README.md +++ b/java/README.md @@ -29,7 +29,7 @@ These IDE plugins can auto-format code on file save or by single click: You can run benchmarks using `./gradlew run`. You can set arguments using the args flag like: ```shell -./gradlew run --args="--clients lettuce" +./gradlew run --args="--resultsFile=output.csv --dataSize \"2 5\" --concurrentTasks \"2 10\" --clients all --host localhost --port 6279 --clientCount \"2 5\" --tls" ``` The following arguments are accepted: diff --git a/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java b/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java index c071ac01ae..3f9a5ecaa9 100644 --- a/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java +++ b/java/benchmarks/src/main/java/javababushka/benchmarks/BenchmarkingApp.java @@ -3,9 +3,7 @@ import java.io.FileWriter; import java.io.IOException; import java.util.Arrays; -import java.util.List; import java.util.Optional; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.CommandLineParser; @@ -103,26 +101,8 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce } } - if (line.hasOption("dataSize")) { - runConfiguration.dataSize = Integer.parseInt(line.getOptionValue("dataSize")); - } - if (line.hasOption("concurrentTasks")) { - String concurrentTasks = line.getOptionValue("concurrentTasks"); - - // remove optional square brackets - if (concurrentTasks.startsWith("[") && concurrentTasks.endsWith("]")) { - concurrentTasks = concurrentTasks.substring(1, concurrentTasks.length() - 1); - } - // check if it's the correct format - if (!concurrentTasks.matches("\\d+(\\s+\\d+)?")) { - throw new ParseException("Invalid concurrentTasks"); - } - // split the string into a list of integers - runConfiguration.concurrentTasks = - Arrays.stream(concurrentTasks.split("\\s+")) - .map(Integer::parseInt) - .collect(Collectors.toList()); + runConfiguration.concurrentTasks = parseIntListOption(line.getOptionValue("concurrentTasks")); } if (line.hasOption("clients")) { @@ -162,15 +142,11 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce } if (line.hasOption("clientCount")) { - String clientCount = line.getOptionValue("clientCount"); + runConfiguration.clientCount = parseIntListOption(line.getOptionValue("clientCount")); + } - // check if it's the correct format - if (!clientCount.matches("\\d+(\\s+\\d+)?")) { - throw new ParseException("Invalid concurrentTasks"); - } - // split the string into a list of integers - runConfiguration.clientCount = - Arrays.stream(clientCount.split("\\s+")).mapToInt(Integer::parseInt).toArray(); + if (line.hasOption("dataSize")) { + runConfiguration.dataSize = parseIntListOption(line.getOptionValue("dataSize")); } if (line.hasOption("tls")) { @@ -180,6 +156,21 @@ private static RunConfiguration verifyOptions(CommandLine line) throws ParseExce return runConfiguration; } + private static int[] parseIntListOption(String line) throws ParseException { + String lineValue = line; + + // remove optional square brackets + if (lineValue.startsWith("[") && lineValue.endsWith("]")) { + lineValue = lineValue.substring(1, lineValue.length() - 1); + } + // check if it's the correct format + if (!lineValue.matches("\\d+(\\s+\\d+)?")) { + throw new ParseException("Invalid option: " + line); + } + // split the string into a list of integers + return Arrays.stream(lineValue.split("\\s+")).mapToInt(Integer::parseInt).toArray(); + } + public enum ClientName { JEDIS("Jedis"), JEDIS_ASYNC("Jedis async"), @@ -209,8 +200,8 @@ public boolean isEqual(String other) { public static class RunConfiguration { public String configuration; public Optional resultsFile; - public int dataSize; - public List concurrentTasks; + public int[] dataSize; + public int[] concurrentTasks; public ClientName[] clients; public String host; public int port; @@ -221,12 +212,12 @@ public static class RunConfiguration { public RunConfiguration() { configuration = "Release"; resultsFile = Optional.empty(); - dataSize = 20; - concurrentTasks = List.of(10, 100); + dataSize = new int[] {20}; + concurrentTasks = new int[] {10, 100}; clients = new ClientName[] { - // ClientName.BABUSHKA, - ClientName.JEDIS, ClientName.JEDIS_ASYNC, ClientName.LETTUCE, ClientName.LETTUCE_ASYNC + // ClientName.BABUSHKA, + ClientName.JEDIS, ClientName.JEDIS_ASYNC, ClientName.LETTUCE, ClientName.LETTUCE_ASYNC }; host = "localhost"; port = 6379; @@ -234,4 +225,4 @@ public RunConfiguration() { tls = false; } } -} \ No newline at end of file +}