Skip to content

Commit

Permalink
OAK-11136: (refactor) remove duplicate assertEventually in ES tests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriziofortino committed Sep 19, 2024
1 parent 3e31573 commit 84c22d2
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.apache.jackrabbit.oak.api.Tree;
import org.apache.jackrabbit.oak.plugins.index.AsyncIndexUpdate;
import org.apache.jackrabbit.oak.plugins.index.IndexEditorProvider;
import org.apache.jackrabbit.oak.plugins.index.TestUtil;
import org.apache.jackrabbit.oak.plugins.index.TrackingCorruptIndexHandler;
import org.apache.jackrabbit.oak.plugins.index.counter.NodeCounterEditorProvider;
import org.apache.jackrabbit.oak.plugins.index.elastic.index.ElasticIndexEditorProvider;
Expand Down Expand Up @@ -176,7 +177,7 @@ protected ElasticMetricHandler getMetricHandler() {
}

protected void assertEventually(Runnable r) {
ElasticTestUtils.assertEventually(r,
TestUtil.assertEventually(r,
((useAsyncIndexing() ? DEFAULT_ASYNC_INDEXING_TIME_IN_SECONDS * 1000L : 0) + BULK_FLUSH_INTERVAL_MS_DEFAULT) * 5);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import java.io.IOException;
import java.time.Duration;

import static org.apache.jackrabbit.oak.plugins.index.elastic.ElasticTestUtils.assertEventually;
import static org.apache.jackrabbit.oak.plugins.index.TestUtil.assertEventually;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
*/
package org.apache.jackrabbit.oak.plugins.index.elastic;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Random;

public final class ElasticTestUtils {
private static final Logger LOG = LoggerFactory.getLogger(ElasticTestUtils.class);

// Set this connection string as
// <scheme>://<hostname>:<port>?key_id=<>,key_secret=<>
Expand All @@ -35,36 +31,6 @@ public final class ElasticTestUtils {
public static final String ELASTIC_KNN_PLUGIN_URI_KEY = "elasticKnnPluginUri";
public static final String ELASTIC_KNN_PLUGIN_URI = System.getProperty(ELASTIC_KNN_PLUGIN_URI_KEY);

public static void assertEventually(Runnable r, long timeoutMillis) {
final long start = System.currentTimeMillis();
long lastAttempt = 0;
int attempts = 0;

while (true) {
try {
attempts++;
LOG.info("assertEventually attempt count:{}", attempts);
lastAttempt = System.currentTimeMillis();
r.run();
return;
} catch (Throwable e) {
long elapsedTime = lastAttempt - start;
LOG.trace("assertEventually attempt {} failed because of {}", attempts, e.getMessage());
if (elapsedTime >= timeoutMillis) {
String msg = String.format("Condition not satisfied after %1.2f seconds and %d attempts",
elapsedTime / 1000d, attempts);
throw new AssertionError(msg, e);
}
try {
Thread.sleep(100);
} catch (InterruptedException ex) {
ex.printStackTrace();
}

}
}
}

public static String randomString(int size) {
return randomString(new Random(42), size);
}
Expand Down

0 comments on commit 84c22d2

Please sign in to comment.