Skip to content

Commit

Permalink
Test base code improvements (#1240)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Oct 10, 2024
1 parent 43f9a01 commit e0d25fd
Showing 1 changed file with 30 additions and 21 deletions.
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

0 comments on commit e0d25fd

Please sign in to comment.