You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by en...@apache.org on 2021/01/08 00:56:03 UTC
[sling-org-apache-sling-jcr-jackrabbit-usermanager] branch master
updated: SLING-10040 Resolve solar warning
This is an automated email from the ASF dual-hosted git repository.
enorman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-jcr-jackrabbit-usermanager.git
The following commit(s) were added to refs/heads/master by this push:
new 0b1da76 SLING-10040 Resolve solar warning
0b1da76 is described below
commit 0b1da76a86ab7e62769167754130c008f68a5f9d
Author: Eric Norman <en...@apache.org>
AuthorDate: Thu Jan 7 16:55:51 2021 -0800
SLING-10040 Resolve solar warning
replacing the use of Thread.sleep() with an awaitility statement
---
pom.xml | 6 ++++
.../sling/jcr/jackrabbit/usermanager/it/Retry.java | 40 ++++++----------------
.../usermanager/it/UserManagerTestSupport.java | 9 +++--
3 files changed, 23 insertions(+), 32 deletions(-)
diff --git a/pom.xml b/pom.xml
index d59f1a6..b6df18d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -268,5 +268,11 @@
<version>3.0.6</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.awaitility</groupId>
+ <artifactId>awaitility</artifactId>
+ <version>4.0.0</version>
+ <scope>test</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/Retry.java b/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/Retry.java
index 3b16d86..4c3de9e 100644
--- a/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/Retry.java
+++ b/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/Retry.java
@@ -18,22 +18,20 @@
*/
package org.apache.sling.jcr.jackrabbit.usermanager.it;
-import static org.junit.Assert.fail;
+import static org.awaitility.Awaitility.await;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.concurrent.TimeUnit;
/** Simple Retry loop for tests */
public abstract class Retry {
- private Logger logger = LoggerFactory.getLogger(getClass());
private long timeoutMsec;
private long nextIterationDelay;
- public Retry(long timeoutMsec, long nextIterationDelay) throws InterruptedException {
+ public Retry(long timeoutMsec, long nextIterationDelay) {
this(timeoutMsec, nextIterationDelay, true);
}
- public Retry(long timeoutMsec, long nextIterationDelay, boolean autorun) throws InterruptedException {
+ public Retry(long timeoutMsec, long nextIterationDelay, boolean autorun) {
this.timeoutMsec = timeoutMsec;
this.nextIterationDelay = nextIterationDelay;
if (autorun) {
@@ -41,29 +39,13 @@ public abstract class Retry {
}
}
- protected void run() throws InterruptedException {
- final long timeout = System.currentTimeMillis() + timeoutMsec;
- Throwable lastT = null;
- while (System.currentTimeMillis() < timeout) {
- try {
- lastT = null;
- exec();
- break;
- } catch(Throwable t) {
- if (logger.isDebugEnabled()) {
- logger.warn(String.format("exec failed: %s", t.getMessage()), t);
- } else {
- logger.warn("exec failed: {}", t.getMessage());
- }
- lastT = t;
- Thread.sleep(nextIterationDelay);
- }
- }
-
- if (lastT != null) {
- fail("Failed after " + timeoutMsec + " msec: " + lastT);
- }
+ protected void run() {
+ // retry until the exec call returns true and doesn't throw any exception
+ await().atMost(timeoutMsec, TimeUnit.MILLISECONDS)
+ .pollInterval(nextIterationDelay, TimeUnit.MILLISECONDS)
+ .ignoreExceptions()
+ .until(this::exec);
}
- protected abstract void exec();
+ protected abstract boolean exec();
}
diff --git a/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/UserManagerTestSupport.java b/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/UserManagerTestSupport.java
index cbb36e7..deeebee 100644
--- a/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/UserManagerTestSupport.java
+++ b/src/test/java/org/apache/sling/jcr/jackrabbit/usermanager/it/UserManagerTestSupport.java
@@ -18,6 +18,7 @@
*/
package org.apache.sling.jcr.jackrabbit.usermanager.it;
+import static org.apache.sling.testing.paxexam.SlingOptions.awaitility;
import static org.apache.sling.testing.paxexam.SlingOptions.sling;
import static org.apache.sling.testing.paxexam.SlingOptions.slingQuickstartOakTar;
import static org.junit.Assert.assertEquals;
@@ -57,7 +58,7 @@ public abstract class UserManagerTestSupport extends TestSupport {
private Class<?> serviceClass;
public WaitForServiceUpdated(long timeoutMsec, long nextIterationDelay, BundleContext bundleContext,
- Class<?> serviceClass, String expectedKey, Object expectedValue) throws InterruptedException {
+ Class<?> serviceClass, String expectedKey, Object expectedValue) {
super(timeoutMsec, nextIterationDelay, false);
this.bundleContext = bundleContext;
this.serviceClass = serviceClass;
@@ -67,10 +68,11 @@ public abstract class UserManagerTestSupport extends TestSupport {
}
@Override
- protected void exec() {
+ protected boolean exec() {
ServiceReference<?> serviceReference = bundleContext.getServiceReference(serviceClass);
assertNotNull(serviceReference);
assertEquals(expectedValue, serviceReference.getProperty(expectedKey));
+ return true;
}
}
@@ -102,7 +104,8 @@ public abstract class UserManagerTestSupport extends TestSupport {
// Sling JCR UserManager
testBundle("bundle.filename"),
mavenBundle().groupId("org.apache.sling").artifactId("org.apache.sling.jcr.jackrabbit.accessmanager").versionAsInProject(),
- junitBundles()
+ junitBundles(),
+ awaitility()
).remove(
usermanager
);