Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,10 @@ If you use CCM, it **must** be with `CcmRule`.
For an example of a Simulacron-based parallelizable test, see `NodeTargetingIT`. For a CCM-based
test, see `DirectCompressionIT`.

Currently `CcmRule` based tests will not preserve CCM config directory upon failure. To have CCM
logs available in case of failure during automated testing combine it with `PreserveLogsRule` so
that logs can be uploaded.

##### Serial tests

These tests cannot run in parallel, in general because they require CCM clusters of different sizes,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@
import com.datastax.oss.driver.api.core.config.DriverConfigLoader;
import com.datastax.oss.driver.api.core.session.Session;
import com.datastax.oss.driver.api.testinfra.ccm.CcmRule;
import com.datastax.oss.driver.api.testinfra.ccm.PreserveLogsRule;
import com.datastax.oss.driver.api.testinfra.session.SessionRule;
import com.datastax.oss.driver.api.testinfra.session.SessionUtils;
import com.datastax.oss.driver.categories.ParallelizableTests;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.RuleChain;
Expand All @@ -42,6 +44,8 @@ public class ConnectKeyspaceIT {
@ClassRule
public static final TestRule CHAIN = RuleChain.outerRule(CCM_RULE).around(SESSION_RULE);

@Rule public PreserveLogsRule LOGS_RULE = new PreserveLogsRule(CCM_RULE.getCcmBridge());

@Test
public void should_connect_to_existing_keyspace() {
CqlIdentifier keyspace = SESSION_RULE.keyspace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class BaseCcmRule extends CassandraResourceRule {
new Thread(
() -> {
try {
ccmBridge.remove();
ccmBridge.removeOrStop();
} catch (Exception e) {
// silently remove as may have already been removed.
}
Expand All @@ -57,7 +57,7 @@ protected void before() {

@Override
protected void after() {
ccmBridge.remove();
ccmBridge.removeOrStop();
}

private Statement buildErrorStatement(
Expand Down Expand Up @@ -232,4 +232,8 @@ public ProtocolVersion getHighestProtocolVersion() {
return DefaultProtocolVersion.V3;
}
}

public CcmBridge getCcmBridge() {
return ccmBridge;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,8 @@ public class CcmBridge implements AutoCloseable {
private final List<String> dseWorkloads;
private final String jvmArgs;

private boolean keepLogs = false;

private CcmBridge(
Path configDirectory,
int[] nodes,
Expand Down Expand Up @@ -378,6 +380,14 @@ public void remove() {
execute("remove");
}

public void removeOrStop() {
if (keepLogs) {
stop();
} else {
remove();
}
}

public void pause(int n) {
execute("node" + n, "pause");
}
Expand Down Expand Up @@ -471,7 +481,11 @@ protected void processLine(String line, int logLevel) {

@Override
public void close() {
remove();
removeOrStop();
}

public void setKeepLogs(boolean keepLogs) {
this.keepLogs = keepLogs;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,6 @@ protected void after() {
CURRENT.compareAndSet(this, null);
}

public CcmBridge getCcmBridge() {
return ccmBridge;
}

public static Builder builder() {
return new Builder();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.datastax.oss.driver.api.testinfra.ccm;

import org.junit.rules.TestWatcher;
import org.junit.runner.Description;

public class PreserveLogsRule extends TestWatcher {
private final CcmBridge ccmBridge;

public PreserveLogsRule(CcmBridge ccmBridge) {
this.ccmBridge = ccmBridge;
}

@Override
protected void failed(Throwable e, Description description) {
ccmBridge.setKeepLogs(true);
}
}