Skip to content

Commit

Permalink
Added property-passing to Connector instantiation
Browse files Browse the repository at this point in the history
  • Loading branch information
stanbrub committed Mar 7, 2025
1 parent ebbe7b1 commit f9f971d
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 29 deletions.
26 changes: 13 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.10.1</version>
<version>3.11.2</version>
<configuration>
<excludePackageNames>*.connect,*.controller,*.generator,*.jfr,*.metric,*.run,*.util</excludePackageNames>
<show>public</show>
Expand All @@ -167,7 +167,7 @@
'core.autocrlf' to true -->
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.43.0</version>
<version>2.44.2</version>
<configuration>
<java>
<includes>
Expand All @@ -193,7 +193,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
<configuration>
<excludes>
<exclude>/io/deephaven/benchmark/tests/**/*Test</exclude>
Expand All @@ -203,14 +203,14 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<version>5.9.3</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.5.1</version>
<version>3.5.2</version>
<configuration>
<forkCount>0</forkCount>
<includes>
Expand All @@ -221,7 +221,7 @@
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.9.2</version>
<version>5.9.3</version>
</dependency>
</dependencies>
<executions>
Expand All @@ -247,39 +247,39 @@
<dependency>
<groupId>io.netty</groupId>
<artifactId>netty-all</artifactId>
<version>4.1.100.Final</version>
<version>4.1.114.Final</version>
</dependency>
<!-- Added because of conflicts -->
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-all</artifactId>
<version>1.58.0</version>
<version>1.65.1</version>
</dependency>
<!-- Added because of conflicts -->
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.25.3</version>
<version>3.25.4</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-avro-serializer</artifactId>
<version>7.7.1</version>
<version>7.9.0</version>
</dependency>
<dependency>
<groupId>io.confluent</groupId>
<artifactId>kafka-protobuf-serializer</artifactId>
<version>7.7.1</version>
<version>7.9.0</version>
</dependency>
<dependency>
<groupId>io.deephaven</groupId>
<artifactId>deephaven-java-client-barrage-dagger</artifactId>
<version>0.36.1</version>
<version>0.37.6</version>
</dependency>
<dependency>
<groupId>io.deephaven</groupId>
<artifactId>deephaven-log-to-slf4j</artifactId>
<version>0.36.1</version>
<version>0.37.6</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/io/deephaven/benchmark/api/BenchQuery.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2025 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.api;

import java.io.Closeable;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Properties;
import java.util.concurrent.Future;
import java.util.function.Consumer;
import java.util.function.Function;
Expand All @@ -24,6 +25,7 @@ final public class BenchQuery implements Closeable {
final QueryLog queryLog;
final Map<String, Consumer<ResultTable>> snapshotFetchers = new LinkedHashMap<>();
final Map<String, Function<ResultTable, Boolean>> tickingFetchers = new LinkedHashMap<>();
final Properties props = new Properties();
private Connector session = null;

BenchQuery(Bench bench, String logic, QueryLog queryLog) {
Expand Down Expand Up @@ -58,6 +60,16 @@ public BenchQuery fetchDuring(String table, Function<ResultTable, Boolean> table
return this;
}

/**
* Add properties to be passed to the <code>Connector</code> used in the query
*/
public BenchQuery withProperty(String name, String value) {
if (value != null && !value.isBlank()) {
props.setProperty(name, value);
}
return this;
}

/**
* Execute the query logic through a session
*/
Expand Down Expand Up @@ -97,10 +109,10 @@ public void close() {
// Add function defs in separate query so if there are errors in the "logic" part, the line numbers match up
private void executeBarrageQuery(String logic) {
if (session == null) {
var deephavenServer = bench.property("deephaven.addr", "localhost:10000");
var connectorClass = bench.property("connector.class", "io.deephaven.benchmark.connect.BarrageConnector");
var connectorAuth = bench.property("deephaven.auth", "");
session = ConnectorFactory.create(connectorClass, deephavenServer, connectorAuth);
var localProps = Bench.profile.getProperties();
localProps.putAll(props);
session = ConnectorFactory.create(connectorClass, localProps);
}
String snippetsLogic = Bench.profile.replaceProperties(Snippets.getFunctions(logic));
if (!snippetsLogic.isBlank()) {
Expand Down
17 changes: 11 additions & 6 deletions src/main/java/io/deephaven/benchmark/api/Profile.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2022-2024 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2025 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.api;

import java.io.InputStream;
Expand All @@ -13,19 +13,20 @@
import io.deephaven.benchmark.util.Log;

/**
* Represents properties for a the Benchmark API .profile file in addition to allowing retrieval of System and
* environment properties.
* Represents properties for the Benchmark API profile file in addition to allowing retrieval of System and environment
* properties. The default property file (e.g. default.properties) for the profile can be overridden with
* <code>System.setProperty("benchmark.profile.default", "my-properties-path")</code>.
*/
class Profile {
final private URL url;
final private Properties props;

/**
* Initialize the profile from the supplied benchmark.profile property. That that property is absent, use the
* default properties file.
* Initialize the profile from the supplied "benchmark.profile" property. If that property is absent, use the
* "benchmark.profile.default" property. If that property is absent, use the "default.properties" resource file.
*/
Profile() {
this(System.getProperty("benchmark.profile", "default.properties"));
this(System.getProperty("benchmark.profile", getProfileDefaultFile()));
}

/**
Expand Down Expand Up @@ -218,4 +219,8 @@ private URL findProfileAsResource(Class<?> parentClass, String uri) {
}
}

static String getProfileDefaultFile() {
return System.getProperty("benchmark.profile.default", "default.properties");
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2022-2023 Deephaven Data Labs and Patent Pending */
/* Copyright (c) 2022-2025 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.connect;

import java.util.*;
Expand Down Expand Up @@ -51,7 +51,9 @@ class BarrageConnector implements Connector {
*
* @param hostPort a host and port string for connecting to a Deephaven worker (ex. localhost:10000)
*/
BarrageConnector(String hostPort, String userPass) {
BarrageConnector(Properties props) {
var hostPort = props.getProperty("deephaven.addr", "localhost:10000");
var userPass = props.getProperty("deephaven.auth", "");
var host = hostPort.replaceAll(":.*", "");
var port = hostPort.replaceAll(".*:", "");
if (host.isEmpty() || port.isEmpty())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
/* Copyright (c) 2022-2025 Deephaven Data Labs and Patent Pending */
package io.deephaven.benchmark.connect;

import java.util.Properties;

/**
* Instantiate the <code>Connector</code> for the given full-qualified class name with the given properties.
*/
public class ConnectorFactory {
static public Connector create(String connectorClassName, String hostPort, String userPass) {
static public Connector create(String connectorClassName, Properties props) {
try {
var myClass = Class.forName(connectorClassName);
var constructor = myClass.getDeclaredConstructor(String.class, String.class);
return (Connector) constructor.newInstance(hostPort, userPass);
var constructor = myClass.getDeclaredConstructor(Properties.class);
return (Connector) constructor.newInstance(props);
} catch (Exception ex) {
throw new RuntimeException("Failed to instantiate Connector: " + hostPort, ex);
throw new RuntimeException("Failed to instantiate Connector: " + connectorClassName, ex);
}
}

Expand Down

0 comments on commit f9f971d

Please sign in to comment.