You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by dg...@apache.org on 2019/06/18 18:17:10 UTC
[incubator-openwhisk-catalog] branch master updated: remove
deprecated combinators package (#300)
This is an automated email from the ASF dual-hosted git repository.
dgrove pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-openwhisk-catalog.git
The following commit(s) were added to refs/heads/master by this push:
new ccd4a53 remove deprecated combinators package (#300)
ccd4a53 is described below
commit ccd4a537ea42f1f8f0f5ee0467e5d608c407dc49
Author: David Grove <dg...@users.noreply.github.com>
AuthorDate: Tue Jun 18 14:17:05 2019 -0400
remove deprecated combinators package (#300)
---
packages/combinators/eca.js | 66 -------
packages/combinators/forwarder.js | 74 --------
packages/combinators/manifest.yaml | 140 --------------
packages/combinators/retry.js | 65 -------
packages/combinators/trycatch.js | 86 ---------
packages/installCatalog.sh | 3 -
packages/installCatalogUsingWskdeploy.sh | 3 -
packages/installCombinators.sh | 72 -------
.../packages/combinators/CombinatorTests.scala | 209 ---------------------
9 files changed, 718 deletions(-)
diff --git a/packages/combinators/eca.js b/packages/combinators/eca.js
deleted file mode 100644
index 76172c5..0000000
--- a/packages/combinators/eca.js
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * 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.
- */
-
-// Runs a boolean check on the input arguments (an action),
-// if true (any non-error value), runs an action, else, returns {}.
-// Example invocation:
-// $ wsk action invoke -br eca \
-// -p '$conditionName' check \
-// -p '$actionName' test \
-// -p x 12 -p password 'ok'
-
-var openwhisk = require('openwhisk');
-
-function main (args) {
- const wsk = openwhisk({ignore_certs: args.$ignore_certs || false});
-
- const conditionName = args.$conditionName;
- const actionName = args.$actionName;
-
- delete args.$ignore_certs;
- delete args.$conditionName;
- delete args.$actionName;
-
- if (typeof conditionName !== 'string') {
- return { error: "Expected an argument '$conditionName' of type 'string'." };
- }
-
- if (typeof actionName !== 'string') {
- return { error: "Expected an argument '$actionName' of type 'string'." };
- }
-
- return wsk.actions
- .invoke({
- actionName: conditionName,
- params: args,
- blocking: true
- })
- .then(() => {
- return wsk.actions
- .invoke({
- actionName: actionName,
- params: args,
- blocking: true
- })
- .then(activation => activation.response.result)
- .catch(error => {
- console.log(error);
- return { error: `There was a problem invoking ${actionName}` };
- });
- })
- .catch(error => ({ '$eca': 'Condition was false.' }));
-}
diff --git a/packages/combinators/forwarder.js b/packages/combinators/forwarder.js
deleted file mode 100644
index 29370a0..0000000
--- a/packages/combinators/forwarder.js
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * 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.
- */
-
-// Augments an action with the ability to "forward parameters around".
-// Example invocation:
-// $ wsk -v action invoke -br dfwd \
-// -p '$actionName' test \
-// -p '$actionArgs' '[ "x" ]' \
-// -p '$forward' '[ "y" ]' \
-// -p x 11 -p y 42
-
-var openwhisk = require('openwhisk');
-
-function main (args) {
- const wsk = openwhisk({ignore_certs: args.$ignore_certs || false});
-
- delete args.$ignore_certs;
- const actionName = args.$actionName;
- const actionArgs = args.$actionArgs;
- const toForward = args.$forward;
-
- if (typeof actionName !== 'string') {
- return { error: "Expected an argument '$actionName' of type 'string'." };
- }
-
- if (!Array.isArray(actionArgs)) {
- return { error: "Expected an array argument '$actionArgs'." };
- }
-
- if (!Array.isArray(toForward)) {
- return { error: "Expected an array argument '$toFoward'." };
- }
-
- let subArgs = {};
- for (const k of actionArgs) {
- subArgs[k] = args[k];
- }
-
- let result = {};
- for (const k of toForward) {
- result[k] = args[k];
- }
-
- return wsk.actions
- .invoke({
- actionName: actionName,
- params: subArgs,
- blocking: true
- })
- .then(activation => {
- for (let k in activation.response.result) {
- result[k] = activation.response.result[k];
- }
- return result;
- })
- .catch(error => {
- console.log(error);
- return { error: `There was a problem invoking ${actionName}` };
- });
-}
diff --git a/packages/combinators/manifest.yaml b/packages/combinators/manifest.yaml
deleted file mode 100644
index 81d2c1d..0000000
--- a/packages/combinators/manifest.yaml
+++ /dev/null
@@ -1,140 +0,0 @@
-#
-# 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.
-#
-project:
- name: WhiskSystem
- packages:
- combinators:
- license: Apache-2.0
- version: 0.0.1
- public: true
- annotations:
- description: Actions combinators for richer composition
- actions:
- eca:
- version: 0.0.1
- function: eca.js
- annotations:
- provide-api-key: true,
- description: "Event-Condition-Action: run condition action and if the result is successful run next action."
- parameters: [
- {
- "name": "$conditionName",
- "required": true,
- "type": "string",
- "description": "Name of action to run to compute condition. Must return error to indicate false predicate."
- },
- {
- "name": "$actionName",
- "required": true,
- "type": "string",
- "description": "Name of action to run if result of condition action is not error."
- }
- ]
- sampleInput: {
- "$conditionName": "utils/echo",
- "$actionName": "utils/echo",
- "error": true
- }
- sampleOutput: { "$eca": "Condition was false" }
- forwarder:
- version: 0.0.1
- function: forwarder.js
- annotations:
- provide-api-key: true,
- description: "Forward parameters around another action."
- parameters: [
- {
- "name": "$actionName",
- "required": true,
- "type": "string",
- "description": "Name of action to run to compute condition. Must return error to indicate false predicate."
- },
- {
- "name": "$actionArgs",
- "required": true,
- "type": "array",
- "description": "Array of parameters names from input arguments to pass to action."
- },
- {
- "name": "$forward",
- "required": true,
- "type": "array",
- "description": "Array of parameters names from input arguments to merge with result of action."
- }
- ]
- sampleInput: {
- "$actionName": "utils/echo",
- "$actionArgs": [ "x" ],
- "$forward": [ "y" ],
- "x": true,
- "y": true
- }
- sampleOutput: {
- "x": true,
- "y": true
- }
- retry:
- version: 0.0.1
- function: retry.js
- annotations:
- provide-api-key: true,
- description: "Retry invoking an action until success or attempt count is exhausted, which ever comes first."
- parameters: [
- {
- "name": "$actionName",
- "required": true,
- "type": "string",
- "description": "Name of action to run."
- },
- {
- "name": "$attempts",
- "required": true,
- "type": "integer",
- "description": "Number of attempts, must be >= 1."
- }
- ]
- sampleInput: {
- "$actionName": "utils/echo",
- "error": true
- }
- sampleOutput: { "error": "Invocation failed. No retries left." }
- trycatch:
- version: 0.0.1
- function: trycatch.js
- annotations:
- provide-api-key: true,
- description: "Wraps an action with a try-catch. If the action fails, invokes a second action to handle the error."
- parameters: [
- {
- "name": "$tryName",
- "required": true,
- "type": "string",
- "description": "Name of action to wrap with a try."
- },
- {
- "name": "$catchName",
- "required": true,
- "type": "string",
- "description": "Name of action to run if there is a try error."
- }
- ]
- sampleInput: {
- "$tryName": "utils/echo",
- "$catchName": "utils/echo",
- "error": true
- }
- sampleOutput: { "error": true }
diff --git a/packages/combinators/retry.js b/packages/combinators/retry.js
deleted file mode 100644
index eea9958..0000000
--- a/packages/combinators/retry.js
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * 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.
- */
-
-// Expects an object with three arguments:
-//
-// - $actionName: name of the action to invoke
-// - $attempts: integer, number of times the action should be tried (>= 1)
-// - all other arguments are passed to the inner action
-
-var openwhisk = require('openwhisk');
-
-function main (args) {
- const wsk = openwhisk({ignore_certs: args.$ignore_certs || false});
-
- const actionName = args.$actionName;
- const attempts = args.$attempts;
-
- delete args.$ignore_certs;
- delete args.$actionName;
- delete args.$attempts;
-
- if (typeof actionName !== 'string') {
- return { error: `Expected an argument '$actionName' of type 'string', got '${actionName}'.` };
- }
-
- if (typeof attempts !== 'number' || attempts < 1) {
- return { error: `Expected an argument '$attempts' of type 'number' and greater than zero, got '${attempts}'.` };
- }
-
- return new Promise(function (resolve, reject) {
- function retry (n) {
- if (n <= 0) {
- reject('Invocation failed. No retries left.');
- } else {
- wsk.actions
- .invoke({
- actionName: actionName,
- params: args,
- blocking: true
- })
- .then(activation => resolve(activation.response.result) )
- .catch(error => {
- console.log(`attempt ${n} failed, retrying`);
- retry(n - 1);
- });
- }
- }
-
- retry(attempts);
- });
-}
diff --git a/packages/combinators/trycatch.js b/packages/combinators/trycatch.js
deleted file mode 100644
index a474460..0000000
--- a/packages/combinators/trycatch.js
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * 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.
- */
-
-// Runs a boolean check on the input arguments (an action),
-// if true (any non-error value), runs an action, else, returns {}.
-// Example invocation:
-// $ wsk action invoke -br eca \
-// -p '$conditionName' check \
-// -p '$actionName' test \
-// -p x 12 -p password 'ok'
-
-var openwhisk = require('openwhisk');
-
-function main (args) {
- const wsk = openwhisk({ignore_certs: args.$ignore_certs || false});
-
- const tryName = args.$tryName;
- const catchName = args.$catchName;
-
- delete args.$ignore_certs;
- delete args.$tryName;
- delete args.$catchName;
-
- if (typeof tryName !== 'string') {
- return { error: "Expected an argument '$tryName' of type 'string'." };
- }
-
- if (typeof catchName !== 'string') {
- return { error: "Expected an argument '$catchName' of type 'string'." };
- }
-
- return wsk.actions
- .invoke({
- actionName: tryName,
- params: args,
- blocking: true
- })
- .then(activation => activation.response.result)
- .catch(error => {
- console.log(`try ${tryName} failed, catching with ${catchName}`);
-
- var catchArgs;
- try {
- catchArgs = error.error.response.result;
- } catch (e) {
- catchArgs = error;
- }
-
- return wsk.actions
- .invoke({
- actionName: catchName,
- params: catchArgs,
- blocking: true
- })
- .then(activation => activation.response.result)
- .catch(error => {
- try {
- // if the action ran and failed, the result field is guaranteed
- // to contain an error field causing the overall action to fail
- // with that error
- return error.error.response.result;
- } catch (e) {
- return {
- error: {
- message: `There was a problem invoking ${catchName}.`,
- cause: error.error
- }
- };
- }
- });
- });
-}
diff --git a/packages/installCatalog.sh b/packages/installCatalog.sh
index ecb08ba..230ef61 100755
--- a/packages/installCatalog.sh
+++ b/packages/installCatalog.sh
@@ -33,9 +33,6 @@ source "$SCRIPTDIR/util.sh"
echo Installing OpenWhisk packages
-if [ $SKIP_DEPRECATED_PACKAGES == "false" ]; then
- runPackageInstallScript "$SCRIPTDIR" installCombinators.sh
-fi
runPackageInstallScript "$SCRIPTDIR" installGit.sh
runPackageInstallScript "$SCRIPTDIR" installSlack.sh
runPackageInstallScript "$SCRIPTDIR" installSystem.sh
diff --git a/packages/installCatalogUsingWskdeploy.sh b/packages/installCatalogUsingWskdeploy.sh
index 4c7dc9b..e53e017 100755
--- a/packages/installCatalogUsingWskdeploy.sh
+++ b/packages/installCatalogUsingWskdeploy.sh
@@ -33,9 +33,6 @@ source "$SCRIPTDIR/util.sh"
echo Installing OpenWhisk packages
-if [ $SKIP_DEPRECATED_PACKAGES == "false" ]; then
- deployProject "$SCRIPTDIR/combinators/"
-fi
deployProject "$SCRIPTDIR/github/"
deployProject "$SCRIPTDIR/slack/"
diff --git a/packages/installCombinators.sh b/packages/installCombinators.sh
deleted file mode 100755
index e230913..0000000
--- a/packages/installCombinators.sh
+++ /dev/null
@@ -1,72 +0,0 @@
-#!/bin/bash
-#
-# 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.
-#
-# use the command line interface to install standard actions deployed
-# automatically.
-#
-SCRIPTDIR="$(cd $(dirname "$0")/ && pwd)"
-PACKAGE_HOME=$SCRIPTDIR
-source "$PACKAGE_HOME/util.sh"
-
-echo Installing action combinator package.
-PKGNAME=combinators
-
-createPackage "$PKGNAME" -a description "Actions combinators for richer composition"
-
-waitForAll
-
-install "$PACKAGE_HOME/$PKGNAME/eca.js" \
- "$PKGNAME/eca" \
- -a description 'Event-Condition-Action: run condition action and if the result is successful run next action.' \
- -a parameters '[
- { "name": "$conditionName", "required": true, "type": "string", "description": "Name of action to run to compute condition. Must return error to indicate false predicate." },
- { "name": "$actionName", "required": true, "type": "string", "description": "Name of action to run if result of condition action is not error." } ]' \
- -a sampleInput '{ "$conditionName": "utils/echo", "$actionName": "utils/echo", "error": true }' \
- -a sampleOutput '{ "$eca": "Condition was false" }'
-
-install "$PACKAGE_HOME/$PKGNAME/forwarder.js" \
- "$PKGNAME/forwarder" \
- -a description 'Forward parameters around another action.' \
- -a parameters '[
- { "name": "$actionName", "required": true, "type": "string", "description": "Name of action to run to compute condition. Must return error to indicate false predicate." },
- { "name": "$actionArgs", "required": true, "type": "array", "description": "Array of parameters names from input arguments to pass to action." },
- { "name": "$forward", "required": true, "type": "array", "description": "Array of parameters names from input arguments to merge with result of action." } ]' \
- -a sampleInput '{ "$actionName": "utils/echo", "$actionArgs": [ "x" ], "$forward": [ "y" ], "x": true, "y": true }' \
- -a sampleOutput '{ "x": true, "y": true }'
-
-install "$PACKAGE_HOME/$PKGNAME/retry.js" \
- "$PKGNAME/retry" \
- -a description 'Retry invoking an action until success or attempt count is exhausted, which ever comes first.' \
- -a parameters '[
- { "name": "$actionName", "required": true, "type": "string", "description": "Name of action to run." },
- { "name": "$attempts", "required": true, "type": "integer", "description": "Name of attempts, must be >= 1." } ]' \
- -a sampleInput '{ "$actionName": "utils/echo", "error": true }' \
- -a sampleOutput '{ "error": "Invocation failed. No retries left." }'
-
-install "$PACKAGE_HOME/$PKGNAME/trycatch.js" \
- "$PKGNAME/trycatch" \
- -a description 'Wraps an action with a try-catch. If the action fails, invokes a second action to handle the error.' \
- -a parameters '[
- { "name": "$tryName", "required": true, "type": "string", "description": "Name of action to wrap with a try." },
- { "name": "$catchName", "required": true, "type": "string", "description": "Name of action to run if there is a try error." } ]' \
- -a sampleInput '{ "$tryName": "utils/echo", "$catchName": "utils/echo", "error": true }' \
- -a sampleOutput '{ "error": true }'
-
-waitForAll
-
-echo combinator package ERRORS = $ERRORS
-exit $ERRORS
diff --git a/tests/src/test/scala/packages/combinators/CombinatorTests.scala b/tests/src/test/scala/packages/combinators/CombinatorTests.scala
deleted file mode 100644
index 968afa3..0000000
--- a/tests/src/test/scala/packages/combinators/CombinatorTests.scala
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * 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 packages.combinators
-
-import org.junit.runner.RunWith
-import org.scalatest.junit.JUnitRunner
-
-import common.{ TestHelpers, Wsk, WskProps, WskTestHelpers }
-import spray.json._
-import spray.json.DefaultJsonProtocol._
-
-@RunWith(classOf[JUnitRunner])
-class CombinatorTests extends TestHelpers with WskTestHelpers {
- implicit val wskprops = WskProps()
- val wsk = new Wsk()
-
- val catalogNamespace = "whisk.system"
- val echo = s"/$catalogNamespace/utils/echo"
- val hello = s"/$catalogNamespace/samples/greeting"
- def combinator(c: String) = s"/$catalogNamespace/combinators/$c"
- val ignoreCerts = Map("$ignore_certs" -> true.toJson)
-
- behavior of "retry"
-
- it should "retry action up to n times" in {
- val rr = wsk.action.invoke(
- combinator("retry"),
- ignoreCerts ++ Map("$actionName" -> echo.toJson,
- "$attempts" -> 3.toJson,
- "error" -> true.toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe false
- activation.logs.get.length shouldBe 3
- activation.response.result shouldBe Some {
- JsObject("error" -> "Invocation failed. No retries left.".toJson)
- }
- }
- }
-
- it should "retry action just once when successful" in {
- val rr = wsk.action.invoke(
- combinator("retry"),
- ignoreCerts ++ Map("$actionName" -> echo.toJson,
- "$attempts" -> 3.toJson,
- "success" -> true.toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe true
- activation.logs.get.length shouldBe 0
- activation.response.result shouldBe Some {
- JsObject("success" -> true.toJson)
- }
- }
- }
-
- behavior of "eca"
-
- it should "run condition action when predicate is true" in {
- val continue = wsk.action.invoke(
- combinator("eca"),
- ignoreCerts ++ Map("$conditionName" -> echo.toJson,
- "$actionName" -> hello.toJson,
- "name" -> "eca".toJson,
- "place" -> "test".toJson))
-
- withActivation(wsk.activation, continue) { activation =>
- activation.response.success shouldBe true
- activation.response.result shouldBe Some {
- JsObject("payload" -> "Hello, eca from test!".toJson)
- }
- }
- }
-
- it should "not run condition action when predicate is false" in {
- val break = wsk.action.invoke(
- combinator("eca"),
- ignoreCerts ++ Map("$conditionName" -> echo.toJson,
- "$actionName" -> hello.toJson,
- "error" -> true.toJson))
-
- withActivation(wsk.activation, break) { activation =>
- activation.response.success shouldBe true
- activation.response.result shouldBe Some {
- JsObject("$eca" -> "Condition was false.".toJson)
- }
- }
- }
-
- behavior of "forwarder"
-
- it should "forward parameters" in {
- val rr = wsk.action.invoke(
- combinator("forwarder"),
- ignoreCerts ++ Map("$actionName" -> hello.toJson,
- "$actionArgs" -> Array("name", "place").toJson,
- "$forward" -> Array("xyz").toJson,
- "name" -> "forwarder".toJson,
- "place" -> "test".toJson,
- "xyz" -> "zyx".toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe true
- activation.response.result shouldBe Some {
- JsObject(
- "payload" -> "Hello, forwarder from test!".toJson,
- "xyz" -> "zyx".toJson)
- }
- }
- }
-
- it should "return error when intermediate action fails" in {
- val rr = wsk.action.invoke(
- combinator("forwarder"),
- ignoreCerts ++ Map("$actionName" -> echo.toJson,
- "$actionArgs" -> Array("error").toJson,
- "$forward" -> Array("xyz").toJson,
- "error" -> true.toJson,
- "xyz" -> "zyx".toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe false
- activation.response.result shouldBe Some {
- JsObject("error" -> s"There was a problem invoking $echo".toJson)
- }
- }
- }
-
- behavior of "trycatch"
-
- it should "try and continue when there is no error" in {
- val rr = wsk.action.invoke(
- combinator("trycatch"),
- ignoreCerts ++ Map("$tryName" -> echo.toJson,
- "$catchName" -> hello.toJson,
- "name" -> "trycatch".toJson,
- "place" -> "test".toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe true
- activation.response.result shouldBe Some {
- JsObject(
- "name" -> "trycatch".toJson,
- "place" -> "test".toJson)
- }
- }
- }
-
- it should "catch and handle when there is an error" in {
- val rr = wsk.action.invoke(
- combinator("trycatch"),
- ignoreCerts ++ Map("$tryName" -> echo.toJson,
- "$catchName" -> hello.toJson,
- "error" -> true.toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe true
- activation.response.result shouldBe Some {
- JsObject("payload" -> "Hello, stranger from somewhere!".toJson)
- }
- }
- }
-
- it should "catch and preserve handler error when handler fails" in {
- val rr = wsk.action.invoke(
- combinator("trycatch"),
- ignoreCerts ++ Map("$tryName" -> echo.toJson,
- "$catchName" -> echo.toJson,
- "error" -> true.toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe false
- activation.response.result shouldBe Some {
- JsObject("error" -> true.toJson)
- }
- }
- }
-
- it should "catch and chain exception when catch handler fails" in {
- val badCatchName = "invalid%name"
- val rr = wsk.action.invoke(
- combinator("trycatch"),
- ignoreCerts ++ Map("$tryName" -> echo.toJson,
- "$catchName" -> badCatchName.toJson,
- "error" -> true.toJson))
-
- withActivation(wsk.activation, rr) { activation =>
- activation.response.success shouldBe false
- val error = activation.response.result.get.fields("error").asJsObject
- error.fields("message") shouldBe JsString(s"There was a problem invoking $badCatchName.")
- error.fields("cause") shouldBe a[JsString]
- }
- }
-}