gora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From djkevi...@apache.org
Subject [31/32] gora git commit: Add log based waiting strategy for the aerospike tests
Date Thu, 27 Jul 2017 18:45:57 GMT
Add log based waiting strategy for the aerospike tests


Project: http://git-wip-us.apache.org/repos/asf/gora/repo
Commit: http://git-wip-us.apache.org/repos/asf/gora/commit/7a5d7677
Tree: http://git-wip-us.apache.org/repos/asf/gora/tree/7a5d7677
Diff: http://git-wip-us.apache.org/repos/asf/gora/diff/7a5d7677

Branch: refs/heads/master
Commit: 7a5d7677e6ae10318907876c58727d68bdd72bac
Parents: 38037ca
Author: nishadi <ndimeshi@gmail.com>
Authored: Thu Jul 27 22:53:13 2017 +0530
Committer: nishadi <ndimeshi@gmail.com>
Committed: Thu Jul 27 22:53:13 2017 +0530

----------------------------------------------------------------------
 .../gora/aerospike/GoraAerospikeTestDriver.java |  5 +-
 .../store/AerospikeStartupLogWaitStrategy.java  | 53 ++++++++++++++++++++
 .../aerospike/store/TestAerospikeStore.java     |  7 ++-
 3 files changed, 59 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/gora/blob/7a5d7677/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
index 74b32b1..88ae360 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/GoraAerospikeTestDriver.java
@@ -46,10 +46,6 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
 
   @Override
   public void setUpClass() throws Exception {
-
-    // Wait for the aerospike server to be started in the container
-    Thread.sleep(5000);
-
     properties.setProperty("gora.aerospikestore.server.ip", "localhost");
     properties.setProperty("gora.aerospikestore.server.port",
             aerospikeContainer.getMappedPort(3000).toString());
@@ -57,6 +53,7 @@ public class GoraAerospikeTestDriver extends GoraTestDriver {
 
   @Override
   public void tearDownClass() throws Exception {
+    aerospikeContainer.stop();
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/gora/blob/7a5d7677/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
new file mode 100644
index 0000000..8b9cf5e
--- /dev/null
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/AerospikeStartupLogWaitStrategy.java
@@ -0,0 +1,53 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.gora.aerospike.store;
+
+import org.testcontainers.containers.ContainerLaunchException;
+import org.testcontainers.containers.GenericContainer;
+import org.testcontainers.containers.output.OutputFrame;
+import org.testcontainers.containers.output.WaitingConsumer;
+
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Predicate;
+
+public class AerospikeStartupLogWaitStrategy extends GenericContainer.AbstractWaitStrategy
{
+
+  private static final String regEx = ".*heartbeat-received: self 0 foreign 0.*";
+
+  private int times = 2;
+
+  protected void waitUntilReady() {
+    WaitingConsumer waitingConsumer = new WaitingConsumer();
+    this.container.followOutput(waitingConsumer);
+    Predicate waitPredicate = (outputFrame) -> {
+      String trimmedFrameText = ((OutputFrame) outputFrame).getUtf8String().replaceFirst("\n$",
"");
+      return trimmedFrameText.matches(regEx);
+    };
+
+    try {
+      waitingConsumer.waitUntil(waitPredicate, this.startupTimeout.getSeconds(), TimeUnit.SECONDS,
+              this.times);
+    } catch (TimeoutException var4) {
+      throw new ContainerLaunchException(
+              "Timed out waiting for log output matching Aerospike server startup Log  \'"
+ regEx
+                      + "\'");
+    }
+  }
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/gora/blob/7a5d7677/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
----------------------------------------------------------------------
diff --git a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
index 11ed458..c1b4e2d 100644
--- a/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
+++ b/gora-aerospike/src/test/java/org/apache/gora/aerospike/store/TestAerospikeStore.java
@@ -30,7 +30,8 @@ import org.junit.Ignore;
 import org.junit.Test;
 import org.testcontainers.containers.GenericContainer;
 
-import static org.apache.gora.examples.WebPageDataCreator.SORTED_URLS;
+import java.time.Duration;
+
 import static org.apache.gora.examples.WebPageDataCreator.URLS;
 
 /**
@@ -41,7 +42,9 @@ public class TestAerospikeStore extends DataStoreTestBase {
   private static final String DOCKER_CONTAINER_NAME = "aerospike/aerospike-server:latest";
 
   @ClassRule
-  public static GenericContainer aerospikeContainer = new GenericContainer(DOCKER_CONTAINER_NAME);
+  public static GenericContainer aerospikeContainer = new GenericContainer(DOCKER_CONTAINER_NAME)
+          .withExposedPorts(3000).waitingFor(new AerospikeStartupLogWaitStrategy())
+          .withStartupTimeout(Duration.ofSeconds(240));
 
   static {
     setTestDriver(new GoraAerospikeTestDriver(aerospikeContainer));


Mime
View raw message