Skip to content

Commit

Permalink
Cassandra: Add support for creating Cluster objects without JMX repor…
Browse files Browse the repository at this point in the history
…ting (#1199)
  • Loading branch information
brasse authored and rnorth committed Mar 19, 2019
1 parent 541dbf4 commit 2a4c91e
Showing 1 changed file with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class CassandraContainer<SELF extends CassandraContainer<SELF>> extends G

private String configLocation;
private String initScriptPath;
private boolean enableJmxReporting;

public CassandraContainer() {
this(IMAGE + ":3.11.2");
Expand All @@ -41,6 +42,7 @@ public CassandraContainer(String dockerImageName) {
super(dockerImageName);
addExposedPort(CQL_PORT);
setStartupAttempts(3);
this.enableJmxReporting = false;
}

@Override
Expand Down Expand Up @@ -116,6 +118,14 @@ public SELF withInitScript(String initScriptPath) {
return self();
}

/**
* Initialize Cassandra client with JMX reporting enabled or disabled
*/
public SELF withJmxReporting(boolean enableJmxReporting) {
this.enableJmxReporting = enableJmxReporting;
return self();
}

/**
* Get username
*
Expand Down Expand Up @@ -146,14 +156,21 @@ public String getPassword() {
* Can be used to obtain connections to Cassandra in the container
*/
public Cluster getCluster() {
return getCluster(this);
return getCluster(this, enableJmxReporting);
}

public static Cluster getCluster(ContainerState containerState) {
return Cluster.builder()
public static Cluster getCluster(ContainerState containerState, boolean enableJmxReporting) {
final Cluster.Builder builder = Cluster.builder()
.addContactPoint(containerState.getContainerIpAddress())
.withPort(containerState.getMappedPort(CQL_PORT))
.build();
.withPort(containerState.getMappedPort(CQL_PORT));
if (!enableJmxReporting) {
builder.withoutJMXReporting();
}
return builder.build();
}

public static Cluster getCluster(ContainerState containerState) {
return getCluster(containerState, false);
}

private DatabaseDelegate getDatabaseDelegate() {
Expand Down

0 comments on commit 2a4c91e

Please sign in to comment.