You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pinot.apache.org by ap...@apache.org on 2021/06/09 18:29:41 UTC

[incubator-pinot] 01/01: improve robustness of basic auth (tls) realtime integration tests

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

apucher pushed a commit to branch basic-auth-tls-realtime-integration-stability
in repository https://gitbox.apache.org/repos/asf/incubator-pinot.git

commit 9d0143bc359660944c36c06639d135b7e94ca961
Author: Alexander Pucher <al...@alexpucher.com>
AuthorDate: Wed Jun 9 11:29:00 2021 -0700

    improve robustness of basic auth (tls) realtime integration tests
---
 .../test/java/org/apache/pinot/util/TestUtils.java | 30 ++++++++++++++++++++++
 .../tests/BasicAuthRealtimeIntegrationTest.java    | 21 +++++++--------
 .../tests/BasicAuthTlsRealtimeIntegrationTest.java | 21 +++++++--------
 3 files changed, 52 insertions(+), 20 deletions(-)

diff --git a/pinot-common/src/test/java/org/apache/pinot/util/TestUtils.java b/pinot-common/src/test/java/org/apache/pinot/util/TestUtils.java
index da175b7..d2775f2 100644
--- a/pinot-common/src/test/java/org/apache/pinot/util/TestUtils.java
+++ b/pinot-common/src/test/java/org/apache/pinot/util/TestUtils.java
@@ -106,4 +106,34 @@ public class TestUtils {
       Assert.fail("Failed to meet condition in " + timeoutMs + "ms" + errorMessageSuffix);
     }
   }
+
+  /**
+   * Wait for a result to be returned
+   *
+   * @param supplier result value supplier
+   * @param timeoutMs timeout
+   * @return result value (non-throwable)
+   * @throws InterruptedException if {@code Thread.sleep()} is interrupted
+   */
+  public static <T> T waitForResult(SupplierWithException<T> supplier, long timeoutMs)
+      throws InterruptedException {
+    long tEnd = System.currentTimeMillis() + timeoutMs;
+    while (tEnd > System.currentTimeMillis()) {
+      try {
+        return supplier.get();
+      } catch (Throwable ignore) {
+        // ignore
+      }
+
+      Thread.sleep(1000);
+    }
+
+    throw new IllegalStateException("Failed to return result in " + timeoutMs + "ms");
+  }
+
+  @FunctionalInterface
+  public interface SupplierWithException<T> {
+    T get()
+        throws Exception;
+  }
 }
diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthRealtimeIntegrationTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthRealtimeIntegrationTest.java
index fbe6cad..75c7157 100644
--- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthRealtimeIntegrationTest.java
+++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthRealtimeIntegrationTest.java
@@ -169,21 +169,22 @@ public class BasicAuthRealtimeIntegrationTest extends BaseClusterIntegrationTest
 
     // schedule offline segment generation
     Assert.assertNotNull(_controllerStarter.getTaskManager().scheduleTasks());
-    Thread.sleep(5000);
 
-    ResultSetGroup resultAfterOffline = getPinotConnection().execute(query);
+    // wait for offline segments
+    JsonNode offlineSegments = TestUtils.waitForResult(() -> {
+      JsonNode segmentSets = JsonUtils.stringToJsonNode(
+          sendGetRequest(_controllerRequestURLBuilder.forSegmentListAPI(getTableName()), AUTH_HEADER));
+      JsonNode currentOfflineSegments =
+          new IntRange(0, segmentSets.size()).stream().map(segmentSets::get).filter(s -> s.has("OFFLINE"))
+              .map(s -> s.get("OFFLINE")).findFirst().get();
+      Assert.assertFalse(currentOfflineSegments.isEmpty());
+      return currentOfflineSegments;
+    }, 30000);
 
     // Verify constant row count
+    ResultSetGroup resultAfterOffline = getPinotConnection().execute(query);
     Assert.assertEquals(resultBeforeOffline.getResultSet(0).getLong(0), resultAfterOffline.getResultSet(0).getLong(0));
 
-    // list offline segments
-    JsonNode segmentSets = JsonUtils
-        .stringToJsonNode(sendGetRequest(_controllerRequestURLBuilder.forSegmentListAPI(getTableName()), AUTH_HEADER));
-    JsonNode offlineSegments =
-        new IntRange(0, segmentSets.size()).stream().map(segmentSets::get).filter(s -> s.has("OFFLINE"))
-            .map(s -> s.get("OFFLINE")).findFirst().get();
-    Assert.assertFalse(offlineSegments.isEmpty());
-
     // download and sanity-check size of offline segment(s)
     for (int i = 0; i < offlineSegments.size(); i++) {
       String segment = offlineSegments.get(i).asText();
diff --git a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthTlsRealtimeIntegrationTest.java b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthTlsRealtimeIntegrationTest.java
index db98f2f..de222cb 100644
--- a/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthTlsRealtimeIntegrationTest.java
+++ b/pinot-integration-tests/src/test/java/org/apache/pinot/integration/tests/BasicAuthTlsRealtimeIntegrationTest.java
@@ -230,21 +230,22 @@ public class BasicAuthTlsRealtimeIntegrationTest extends BaseClusterIntegrationT
 
     // schedule offline segment generation
     Assert.assertNotNull(_controllerStarter.getTaskManager().scheduleTasks());
-    Thread.sleep(5000);
 
-    ResultSetGroup resultAfterOffline = getPinotConnection().execute(query);
+    // wait for offline segments
+    JsonNode offlineSegments = TestUtils.waitForResult(() -> {
+      JsonNode segmentSets = JsonUtils.stringToJsonNode(
+          sendGetRequest(_controllerRequestURLBuilder.forSegmentListAPI(getTableName()), AUTH_HEADER));
+      JsonNode currentOfflineSegments =
+          new IntRange(0, segmentSets.size()).stream().map(segmentSets::get).filter(s -> s.has("OFFLINE"))
+              .map(s -> s.get("OFFLINE")).findFirst().get();
+      Assert.assertFalse(currentOfflineSegments.isEmpty());
+      return currentOfflineSegments;
+    }, 30000);
 
     // Verify constant row count
+    ResultSetGroup resultAfterOffline = getPinotConnection().execute(query);
     Assert.assertEquals(resultBeforeOffline.getResultSet(0).getLong(0), resultAfterOffline.getResultSet(0).getLong(0));
 
-    // list offline segments
-    JsonNode segmentSets = JsonUtils
-        .stringToJsonNode(sendGetRequest(_controllerRequestURLBuilder.forSegmentListAPI(getTableName()), AUTH_HEADER));
-    JsonNode offlineSegments =
-        new IntRange(0, segmentSets.size()).stream().map(segmentSets::get).filter(s -> s.has("OFFLINE"))
-            .map(s -> s.get("OFFLINE")).findFirst().get();
-    Assert.assertFalse(offlineSegments.isEmpty());
-
     // download and sanity-check size of offline segment(s)
     for (int i = 0; i < offlineSegments.size(); i++) {
       String segment = offlineSegments.get(i).asText();

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@pinot.apache.org
For additional commands, e-mail: commits-help@pinot.apache.org