Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test base code improvements #1240

Merged
merged 1 commit into from
Oct 10, 2024
Merged
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
51 changes: 30 additions & 21 deletions src/test/java/io/nats/client/utils/TestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,8 @@ public static void runInServer(boolean debug, boolean jetstream, Options.Builder
{
initRunServerInfo(nc);

if (vc != null) {
if (!vc.runTest(RUN_SERVER_INFO)) {
return;
}
if (vc != null && !vc.runTest(RUN_SERVER_INFO)) {
return;
}

try {
Expand All @@ -257,41 +255,52 @@ public static void runInServer(boolean debug, boolean jetstream, Options.Builder
public static class LongRunningNatsTestServer extends NatsTestServer {
public final boolean jetstream;
public final Options.Builder builder;
public final Connection nc;

public LongRunningNatsTestServer(boolean debug, boolean jetstream, Options.Builder builder) throws IOException, InterruptedException {
super(debug, jetstream);
this.jetstream = jetstream;
this.builder = builder == null ? new Options.Builder() : builder;
nc = connect();
initRunServerInfo(nc);
}

public Connection connect() throws IOException, InterruptedException {
return standardConnection(builder.server(getURI()).build());
}

@Override
public void close() throws Exception {
try { nc.close(); } catch (Exception ignore) {};
super.close();
}

public void run(InServerTest inServerTest) throws Exception {
run(null, inServerTest);
run(null, null, inServerTest);
}

public void run(VersionCheck vc, InServerTest inServerTest) throws Exception {
if (vc != null && !vc.runTest(RUN_SERVER_INFO)) {
return;
run(null, vc, inServerTest);
}

public void run(Options.Builder builder, VersionCheck vc, InServerTest inServerTest) throws Exception {
if (vc != null && RUN_SERVER_INFO != null) {
if (!vc.runTest(RUN_SERVER_INFO)) {
return;
}
vc = null; // since we've already determined it should run, null this out so we don't check below
}

try {
inServerTest.test(nc);
if (builder == null) {
builder = new Options.Builder();
}
finally {
if (jetstream) {
cleanupJs(nc);

try (Connection nc = standardConnection(builder.server(getURI()).build()))
{
initRunServerInfo(nc);

if (vc != null && !vc.runTest(RUN_SERVER_INFO)) {
return;
}

try {
inServerTest.test(nc);
}
finally {
if (jetstream) {
cleanupJs(nc);
}
}
}
}
Expand Down
Loading