From a282db6232749d4f21aa9c65063be1ee5145d388 Mon Sep 17 00:00:00 2001 From: Marcin Lewandowski Date: Thu, 12 Oct 2023 10:21:57 +0200 Subject: [PATCH] better WaitForIndexing impl --- .../java/net/ravendb/client/ClusterTestBase.java | 2 +- .../java/net/ravendb/client/IndexesTestBase.java | 2 +- .../operations/indexes/IndexOperationsTest.java | 2 +- .../net/ravendb/client/driver/RavenTestDriver.java | 14 +++++++++++--- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/test/java/net/ravendb/client/ClusterTestBase.java b/src/test/java/net/ravendb/client/ClusterTestBase.java index dd9c71d8..7581ab27 100644 --- a/src/test/java/net/ravendb/client/ClusterTestBase.java +++ b/src/test/java/net/ravendb/client/ClusterTestBase.java @@ -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); } } diff --git a/src/test/java/net/ravendb/client/IndexesTestBase.java b/src/test/java/net/ravendb/client/IndexesTestBase.java index f19b1b76..a4d5b93a 100644 --- a/src/test/java/net/ravendb/client/IndexesTestBase.java +++ b/src/test/java/net/ravendb/client/IndexesTestBase.java @@ -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 { diff --git a/src/test/java/net/ravendb/client/documents/operations/indexes/IndexOperationsTest.java b/src/test/java/net/ravendb/client/documents/operations/indexes/IndexOperationsTest.java index ff22c429..c32e6d9d 100644 --- a/src/test/java/net/ravendb/client/documents/operations/indexes/IndexOperationsTest.java +++ b/src/test/java/net/ravendb/client/documents/operations/indexes/IndexOperationsTest.java @@ -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); diff --git a/src/test/java/net/ravendb/client/driver/RavenTestDriver.java b/src/test/java/net/ravendb/client/driver/RavenTestDriver.java index c28753e2..ac6ff910 100644 --- a/src/test/java/net/ravendb/client/driver/RavenTestDriver.java +++ b/src/test/java/net/ravendb/client/driver/RavenTestDriver.java @@ -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) { @@ -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; } @@ -223,6 +227,10 @@ public static void waitForIndexing(IDocumentStore store, String database, Durati } } + if (allowErrors) { + return; + } + IndexErrors[] errors = admin.send(new GetIndexErrorsOperation()); String allIndexErrorsText = "";