Skip to content

Commit

Permalink
spotless apply
Browse files Browse the repository at this point in the history
Signed-off-by: acarbonetto <[email protected]>
  • Loading branch information
acarbonetto committed Oct 10, 2023
1 parent 035ef20 commit 0883985
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 37 deletions.
2 changes: 1 addition & 1 deletion java/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")) {
Expand Down Expand Up @@ -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")) {
Expand All @@ -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"),
Expand Down Expand Up @@ -209,8 +200,8 @@ public boolean isEqual(String other) {
public static class RunConfiguration {
public String configuration;
public Optional<FileWriter> resultsFile;
public int dataSize;
public List<Integer> concurrentTasks;
public int[] dataSize;
public int[] concurrentTasks;
public ClientName[] clients;
public String host;
public int port;
Expand All @@ -221,17 +212,17 @@ 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;
clientCount = new int[] {1, 2};
tls = false;
}
}
}
}

0 comments on commit 0883985

Please sign in to comment.