You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by du...@apache.org on 2017/11/01 19:25:49 UTC

[incubator-openwhisk] branch master updated: Replace sequence with REST implementation (#2917)

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

dubeejw pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk.git


The following commit(s) were added to refs/heads/master by this push:
     new 17936ca  Replace sequence with REST implementation (#2917)
17936ca is described below

commit 17936cae39890eb97b5e1d738c9b125498ac38a3
Author: Vincent <sh...@us.ibm.com>
AuthorDate: Wed Nov 1 15:25:47 2017 -0400

    Replace sequence with REST implementation (#2917)
    
    * Replace WskConsoleTests with REST implementation
    
    Partially-Closes: #2430
    
    * Replace sequence with REST implementation
---
 tests/src/test/scala/common/rest/WskRest.scala     | 24 ++++++++++------
 .../scala/system/basic/WskCliConsoleTests.scala    | 30 ++++++++++++++++++++
 .../scala/system/basic/WskCliSequenceTests.scala   | 32 ++++++++++++++++++++++
 .../test/scala/system/basic/WskConsoleTests.scala  | 19 +++++++++----
 .../scala/system/basic/WskRestConsoleTests.scala   | 30 ++++++++++++++++++++
 .../scala/system/basic/WskRestSequenceTests.scala  | 32 ++++++++++++++++++++++
 .../test/scala/system/basic/WskSequenceTests.scala |  7 ++---
 7 files changed, 156 insertions(+), 18 deletions(-)

diff --git a/tests/src/test/scala/common/rest/WskRest.scala b/tests/src/test/scala/common/rest/WskRest.scala
index d31ade1..199d7d6 100644
--- a/tests/src/test/scala/common/rest/WskRest.scala
+++ b/tests/src/test/scala/common/rest/WskRest.scala
@@ -18,7 +18,6 @@
 package common.rest
 
 import java.io.File
-import java.time.Clock
 import java.time.Instant
 import java.util.Base64
 import java.security.cert.X509Certificate
@@ -356,6 +355,7 @@ class WskRestAction
         case Some(k) if (k == "sequence" || k == "native") => {
           bodyContent = bodyContent ++ Map("exec" -> exec.toJson)
         }
+        case _ =>
       }
 
       bodyContent = bodyContent ++ {
@@ -606,11 +606,9 @@ class WskRestActivation extends RunWskRestCmd with HasActivationRest with WaitFo
   override def console(duration: Duration, since: Option[Duration] = None, expectedExitCode: Int = SUCCESS_EXIT)(
     implicit wp: WskProps): RestResult = {
     var sinceTime = System.currentTimeMillis()
-    val utc = Instant.now(Clock.systemUTC()).toEpochMilli
     sinceTime = since map { s =>
       sinceTime - s.toMillis
     } getOrElse sinceTime
-    val pollTimeout = duration.toSeconds
     waitForActivationConsole(duration, Instant.ofEpochMilli(sinceTime))
   }
 
@@ -766,7 +764,6 @@ class WskRestActivation extends RunWskRestCmd with HasActivationRest with WaitFo
 
   def waitForActivationConsole(totalWait: Duration = 30 seconds, sinceTime: Instant)(
     implicit wp: WskProps): RestResult = {
-    var result = new RestResult(NotFound)
     Thread.sleep(totalWait.toMillis)
     listActivation(since = Some(sinceTime))(wp)
   }
@@ -1149,10 +1146,15 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd with Matchers with ScalaFu
   }
   val connectionContext = new HttpsConnectionContext(SSL.nonValidatingContext, Some(sslConfig))
 
+  def isStatusCodeExpected(expectedExitCode: Int, statusCode: Int): Boolean = {
+    return statusCode == expectedExitCode
+  }
+
   def validateStatusCode(expectedExitCode: Int, statusCode: Int) = {
     if ((expectedExitCode != DONTCARE_EXIT) && (expectedExitCode != ANY_ERROR_EXIT))
-      if (statusCode != expectedExitCode)
+      if (!isStatusCodeExpected(expectedExitCode, statusCode)) {
         statusCode shouldBe expectedExitCode
+      }
   }
 
   def getNamePath(noun: String, name: String)(implicit wp: WskProps): Path = {
@@ -1297,10 +1299,14 @@ class RunWskRestCmd() extends FlatSpec with RunWskCmd with Matchers with ScalaFu
     } getOrElse Some(parameters.toJson.toString())
     val resp = requestEntity(POST, path, paramMap, input)
     val r = new RestResult(resp.status.intValue, getRespData(resp))
-    if (blocking || result) {
-      validateStatusCode(OK.intValue, r.statusCode.intValue)
-    } else {
-      validateStatusCode(expectedExitCode, r.statusCode.intValue)
+    // If the statusCode does not not equal to expectedExitCode, it is acceptable that the statusCode
+    // equals to 200 for the case that either blocking or result is set to true.
+    if (!isStatusCodeExpected(expectedExitCode, r.statusCode.intValue)) {
+      if (blocking || result) {
+        validateStatusCode(OK.intValue, r.statusCode.intValue)
+      } else {
+        r.statusCode.intValue shouldBe expectedExitCode
+      }
     }
     r
   }
diff --git a/tests/src/test/scala/system/basic/WskCliConsoleTests.scala b/tests/src/test/scala/system/basic/WskCliConsoleTests.scala
new file mode 100644
index 0000000..e8652d3
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskCliConsoleTests.scala
@@ -0,0 +1,30 @@
+/*
+ * 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 system.basic;
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import common.Wsk
+
+/**
+ * Tests of the text console
+ */
+@RunWith(classOf[JUnitRunner])
+class WskCliConsoleTests extends WskConsoleTests {
+  override val wsk: Wsk = new Wsk
+}
diff --git a/tests/src/test/scala/system/basic/WskCliSequenceTests.scala b/tests/src/test/scala/system/basic/WskCliSequenceTests.scala
new file mode 100644
index 0000000..e1d0db7
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskCliSequenceTests.scala
@@ -0,0 +1,32 @@
+/*
+ * 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 system.basic
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.Wsk
+
+/**
+ * Tests sequence execution
+ */
+
+@RunWith(classOf[JUnitRunner])
+class WskCliSequenceTests extends WskSequenceTests {
+  override val wsk: common.Wsk = new Wsk
+}
diff --git a/tests/src/test/scala/system/basic/WskConsoleTests.scala b/tests/src/test/scala/system/basic/WskConsoleTests.scala
index 6f27b3a..ba0548b 100644
--- a/tests/src/test/scala/system/basic/WskConsoleTests.scala
+++ b/tests/src/test/scala/system/basic/WskConsoleTests.scala
@@ -29,7 +29,7 @@ import org.scalatest.junit.JUnitRunner
 
 import common.TestHelpers
 import common.TestUtils
-import common.Wsk
+import common.BaseWsk
 import common.WskProps
 import common.WskTestHelpers
 import spray.json.DefaultJsonProtocol.IntJsonFormat
@@ -40,10 +40,10 @@ import spray.json.pimpAny
  * Tests of the text console
  */
 @RunWith(classOf[JUnitRunner])
-class WskConsoleTests extends TestHelpers with WskTestHelpers {
+abstract class WskConsoleTests extends TestHelpers with WskTestHelpers {
 
-  implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  implicit val wskprops: common.WskProps = WskProps()
+  val wsk: BaseWsk
   val guestNamespace = wskprops.namespace
 
   /**
@@ -70,7 +70,16 @@ class WskConsoleTests extends TestHelpers with WskTestHelpers {
     val start = Instant.now.minusSeconds(5)
     val payload = new String("from the console!".getBytes, "UTF-8")
     val run = wsk.action.invoke(fullActionName, Map("payload" -> payload.toJson))
-    withActivation(wsk.activation, run, totalWait = 30 seconds) { activation =>
+    withActivation(wsk.activation, run, totalWait = 30.seconds) { activation =>
+      // Time recorded by invoker, some contingency to make query more robust
+      val queryTime = activation.start.minusMillis(500)
+      // since: poll for activations since specified point in time (absolute)
+      val activations = wsk.activation.pollFor(N = 1, Some(actionName), since = Some(queryTime), retries = 80).length
+      withClue(
+        s"expected activations of action '${actionName}' since ${queryTime.toString} / initial activation ${activation.activationId}:") {
+        activations should be(1)
+      }
+
       val duration = Duration(Instant.now.minusMillis(start.toEpochMilli).toEpochMilli, MILLISECONDS)
       val pollTime = 10 seconds
       // since: poll for activations since specified number of seconds ago (relative)
diff --git a/tests/src/test/scala/system/basic/WskRestConsoleTests.scala b/tests/src/test/scala/system/basic/WskRestConsoleTests.scala
new file mode 100644
index 0000000..b84c5cd
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskRestConsoleTests.scala
@@ -0,0 +1,30 @@
+/*
+ * 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 system.basic;
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+import common.rest.WskRest
+
+/**
+ * Tests of the text console
+ */
+@RunWith(classOf[JUnitRunner])
+class WskRestConsoleTests extends WskConsoleTests {
+  override val wsk: WskRest = new WskRest
+}
diff --git a/tests/src/test/scala/system/basic/WskRestSequenceTests.scala b/tests/src/test/scala/system/basic/WskRestSequenceTests.scala
new file mode 100644
index 0000000..bef4823
--- /dev/null
+++ b/tests/src/test/scala/system/basic/WskRestSequenceTests.scala
@@ -0,0 +1,32 @@
+/*
+ * 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 system.basic
+
+import org.junit.runner.RunWith
+import org.scalatest.junit.JUnitRunner
+
+import common.rest.WskRest
+
+/**
+ * Tests sequence execution
+ */
+
+@RunWith(classOf[JUnitRunner])
+class WskRestSequenceTests extends WskSequenceTests {
+  override val wsk: common.rest.WskRest = new WskRest
+}
diff --git a/tests/src/test/scala/system/basic/WskSequenceTests.scala b/tests/src/test/scala/system/basic/WskSequenceTests.scala
index 81c699d..99fa8fa 100644
--- a/tests/src/test/scala/system/basic/WskSequenceTests.scala
+++ b/tests/src/test/scala/system/basic/WskSequenceTests.scala
@@ -32,7 +32,7 @@ import common.StreamLogging
 import common.TestHelpers
 import common.TestUtils
 import common.TestUtils._
-import common.Wsk
+import common.BaseWsk
 import common.WskProps
 import common.WskTestHelpers
 
@@ -47,12 +47,11 @@ import whisk.http.Messages.sequenceIsTooLong
 /**
  * Tests sequence execution
  */
-
 @RunWith(classOf[JUnitRunner])
-class WskSequenceTests extends TestHelpers with ScalatestRouteTest with WskTestHelpers with StreamLogging {
+abstract class WskSequenceTests extends TestHelpers with ScalatestRouteTest with WskTestHelpers with StreamLogging {
 
   implicit val wskprops = WskProps()
-  val wsk = new Wsk
+  val wsk: BaseWsk
   val allowedActionDuration = 120 seconds
   val shortDuration = 10 seconds
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@openwhisk.apache.org" <co...@openwhisk.apache.org>'].