Skip to content

Commit

Permalink
better WaitForIndexing impl
Browse files Browse the repository at this point in the history
  • Loading branch information
ml054 committed Oct 12, 2023
1 parent a5ad532 commit a282db6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/test/java/net/ravendb/client/ClusterTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ public static void waitForIndexingInTheCluster(IDocumentStore store, String dbNa
new GetDatabaseRecordOperation(ObjectUtils.firstNonNull(dbName, store.getDatabase())));

for (String nodeTag : record.getTopology().getAllNodes()) {
waitForIndexing(store, dbName, timeout, nodeTag);
waitForIndexing(store, dbName, timeout, false, nodeTag);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/test/java/net/ravendb/client/IndexesTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void waitForIndexing(IDocumentStore store, String database, Duration time
}

public void waitForIndexing(IDocumentStore store, String database, Duration timeout, String nodeTag) {
RemoteTestBase.waitForIndexing(store, database, timeout, nodeTag);
RemoteTestBase.waitForIndexing(store, database, timeout, false, nodeTag);
}

public IndexErrors[] waitForIndexingErrors(IDocumentStore store, Duration timeout, String... indexNames) throws InterruptedException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ public void canListErrors() throws Exception {
session.saveChanges();
}

waitForIndexing(store, store.getDatabase());
waitForIndexing(store, store.getDatabase(), null, true, null);

waitForValue(() -> store.maintenance().send(new GetIndexErrorsOperation())[0].getErrors().length, 1);
waitForValue(() -> store.maintenance().send(new GetIndexErrorsOperation(new String[] { indexDef.getName() }))[0].getErrors().length, 1);
Expand Down
14 changes: 11 additions & 3 deletions src/test/java/net/ravendb/client/driver/RavenTestDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ public static void waitForIndexing(IDocumentStore store, String database) {
}

public static void waitForIndexing(IDocumentStore store, String database, Duration timeout) {
waitForIndexing(store, database, timeout, null);
waitForIndexing(store, database, timeout, false, null);
}

public static void waitForIndexing(IDocumentStore store, String database, Duration timeout, String nodeTag) {
public static void waitForIndexing(IDocumentStore store, String database, Duration timeout, boolean allowErrors, String nodeTag) {
MaintenanceOperationExecutor admin = store.maintenance().forDatabase(database);

if (timeout == null) {
Expand All @@ -212,7 +212,11 @@ public static void waitForIndexing(IDocumentStore store, String database, Durati
return;
}

if (Arrays.stream(databaseStatistics.getIndexes()).anyMatch(x -> IndexState.ERROR.equals(x.getState()))) {
long erroredIndexesCount = Arrays.stream(databaseStatistics.getIndexes()).filter(x -> IndexState.ERROR.equals(x.getState())).count();
if (allowErrors) {
// wait for all indexes to become non stale
} else if (erroredIndexesCount > 0) {
// have at least some errors
break;
}

Expand All @@ -223,6 +227,10 @@ public static void waitForIndexing(IDocumentStore store, String database, Durati
}
}

if (allowErrors) {
return;
}


IndexErrors[] errors = admin.send(new GetIndexErrorsOperation());
String allIndexErrorsText = "";
Expand Down

0 comments on commit a282db6

Please sign in to comment.