You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@unomi.apache.org by jk...@apache.org on 2023/01/03 14:12:28 UTC

[unomi] 02/02: UNOMI-597: rollback missing function to make the iTests working on 1.x

This is an automated email from the ASF dual-hosted git repository.

jkevan pushed a commit to branch backport-UNOMI-597
in repository https://gitbox.apache.org/repos/asf/unomi.git

commit d7d51f13d3e6d22b3b97151e43f4cb7ee4d948b0
Author: Kevan <ke...@jahia.com>
AuthorDate: Tue Jan 3 15:12:11 2023 +0100

    UNOMI-597: rollback missing function to make the iTests working on 1.x
---
 .../test/java/org/apache/unomi/itests/BaseIT.java  | 27 ++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
index 584d7e2fb..27588c61a 100644
--- a/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
+++ b/itests/src/test/java/org/apache/unomi/itests/BaseIT.java
@@ -76,6 +76,8 @@ public abstract class BaseIT {
     protected static final String URL = "http://localhost:" + HTTP_PORT;
     protected static final String KARAF_DIR = "target/exam";
     protected static final String UNOMI_KEY = "670c26d1cc413346c3b2fd9ce65dab41";
+    protected static final int DEFAULT_TRYING_TIMEOUT = 2000;
+    protected static final int DEFAULT_TRYING_TRIES = 30;
 
     @Inject
     @Filter(timeout = 600000)
@@ -257,6 +259,31 @@ public abstract class BaseIT {
         return value;
     }
 
+    protected <T> void waitForNullValue(String failMessage, Supplier<T> call, int timeout, int retries) throws InterruptedException {
+        int count = 0;
+        while (call.get() != null) {
+            if (count++ > retries) {
+                Assert.fail(failMessage);
+            }
+            Thread.sleep(timeout);
+        }
+    }
+
+    protected <T> T shouldBeTrueUntilEnd(String failMessage, Supplier<T> call, Predicate<T> predicate, int timeout, int retries)
+            throws InterruptedException {
+        int count = 0;
+        T value = null;
+        while (count <= retries) {
+            count++;
+            value = call.get();
+            if (!predicate.test(value)) {
+                Assert.fail(failMessage);
+            }
+            Thread.sleep(timeout);
+        }
+        return value;
+    }
+
     protected String bundleResourceAsString(final String resourcePath) throws IOException {
         final java.net.URL url = bundleContext.getBundle().getResource(resourcePath);
         if (url != null) {