Skip to content

Commit

Permalink
Introduce clusterTests gradle task.
Browse files Browse the repository at this point in the history
  • Loading branch information
YoEight committed Sep 25, 2023
1 parent f6942b6 commit 7fd4471
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 3 deletions.
32 changes: 30 additions & 2 deletions db-client-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ dependencies {
tasks.withType(Test).configureEach {
testLogging {
events "PASSED", "SKIPPED", "FAILED"

showExceptions true
exceptionFormat "full"
showCauses true
Expand All @@ -79,6 +78,23 @@ tasks.register("generateCertificates", Exec) {
commandLine 'docker', 'compose', '--file', '../configure-tls-for-tests.yml', 'up'
}

tasks.register("startDockerCompose", Exec) {
description = "Starts ESDB cluster"
commandLine 'docker', 'compose', '--file', '../docker-compose.yml', 'up', '-d'
}

tasks.register("stopDockerCompose", Exec) {
description = "Stop ESDB cluster"
commandLine 'docker', 'compose', '--file', '../docker-compose.yml', 'down'
}


tasks.register("miscTests", Test) {
useJUnitPlatform {
include("**/MiscTests.class")
}
}

tasks.register("singleNodeTests", Test) {
useJUnitPlatform {
include("**/StreamsTests.class")
Expand All @@ -97,12 +113,24 @@ tasks.register("secureNodeTests", Test) {
}
}

tasks.register("clusterTests", Test) {
dependsOn startDockerCompose
finalizedBy stopDockerCompose
environment "SECURE", "true"
environment "CLUSTER", "true"

useJUnitPlatform {
include("**/StreamsTests.class")
include("**/PersistentSubscriptionsTests.class")
}
}

tasks.register("ci", Test) {
useJUnitPlatform()
}

test {
dependsOn singleNodeTests, secureNodeTests
dependsOn miscTests, singleNodeTests, secureNodeTests, clusterTests
}

protobuf {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package com.eventstore.dbclient;

import io.grpc.Status;
import io.grpc.StatusRuntimeException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

public class ClientTracker {
private static final Logger logger = LoggerFactory.getLogger(ClientTracker.class);
Expand All @@ -21,6 +25,59 @@ public synchronized EventStoreDBClient getDefaultClient(Database database) {
if (defaultClient == null) {
EventStoreDBClientSettings settings = database.defaultSettingsBuilder().buildConnectionSettings();
defaultClient = EventStoreDBClient.create(settings);

if (settings.isTls() && settings.getDefaultCredentials() != null) {
for (int count = 0; count < 50; count++) {
logger.debug(String.format("Checking if admin user is available...%d/50", count));
try {
defaultClient.readStream("$users", ReadStreamOptions.get()).get(1, TimeUnit.SECONDS);
logger.debug("Admin account is available!");
break;
} catch (InterruptedException | TimeoutException e) {
if (e instanceof TimeoutException) {
logger.debug("Request timed out, retrying...");
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
} else
throw new RuntimeException(e);

} catch (ExecutionException e) {
if (e.getCause() instanceof StatusRuntimeException) {
StatusRuntimeException grpcExc = (StatusRuntimeException) e.getCause();
Status.Code code = grpcExc.getStatus().getCode();

if (code == Status.Code.PERMISSION_DENIED
|| code == Status.Code.UNAUTHENTICATED
|| code == Status.Code.DEADLINE_EXCEEDED
|| code == Status.Code.NOT_FOUND
|| code == Status.Code.UNAVAILABLE) {
logger.debug("Admin not available, retrying", grpcExc);
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
continue;
}
}

if (e.getCause() instanceof NotLeaderException) {
logger.debug("Can't access admin because of no leader exception error, retrying...");
try {
Thread.sleep(500);
} catch (InterruptedException ex) {
throw new RuntimeException(ex);
}
continue;
}

throw new RuntimeException(e);
}
}
}
}

return defaultClient;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
public interface DeadlineTests extends ConnectionAware {
@Test
default void testDefaultDeadline() throws Throwable {
EventStoreDBClient client = getDatabase().connectWith(opts -> opts.defaultDeadline(1));
EventStoreDBClient client = getDatabase().connectWith(opts ->
opts.defaultDeadline(1)
.maxDiscoverAttempts(3));
UUID id = UUID.randomUUID();

EventData data = EventDataBuilder.binary(id, "type", new byte[]{}).build();
Expand Down

0 comments on commit 7fd4471

Please sign in to comment.