dubeejw closed pull request #160: fix failing test and other test cleanup URL: https://github.com/apache/incubator-openwhisk-package-cloudant/pull/160
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala b/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala index bb342d4..4c9e0b7 100644 --- a/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala +++ b/tests/src/test/scala/system/health/CloudantHealthFeedTests.scala @@ -64,8 +64,8 @@ class CloudantHealthFeedTests (wp, assetHelper) => implicit val wskprops = wp // shadow global props and make implicit val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" + val ruleName = s"dummyCloudantRule-${System.currentTimeMillis}" + val actionName = s"dummyCloudantAction-${System.currentTimeMillis}" val packageName = "dummyCloudantPackage" val feed = "changes" @@ -134,8 +134,8 @@ class CloudantHealthFeedTests (wp, assetHelper) => implicit val wskprops = wp // shadow global props and make implicit val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" + val ruleName = s"dummyCloudantRule-${System.currentTimeMillis}" + val actionName = s"dummyCloudantAction-${System.currentTimeMillis}" val packageName = "dummyCloudantPackage" val feed = "changes" diff --git a/tests/src/test/scala/system/packages/CloudantAccountActionsTests.scala b/tests/src/test/scala/system/packages/CloudantAccountActionsTests.scala index 3dee996..343de72 100644 --- a/tests/src/test/scala/system/packages/CloudantAccountActionsTests.scala +++ b/tests/src/test/scala/system/packages/CloudantAccountActionsTests.scala @@ -62,7 +62,7 @@ class CloudantAccountActionsTests extends FlatSpec //create database println("Invoking the create-database action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/create-database", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/create-database", Map("dbname" -> dbName.toJson))) { activation => activation.response.success shouldBe true @@ -95,7 +95,7 @@ class CloudantAccountActionsTests extends FlatSpec //create database println("Invoking the create-database action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/create-database")) { + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/create-database")) { activation => activation.response.success shouldBe false val result = activation.response.result.get @@ -125,7 +125,7 @@ class CloudantAccountActionsTests extends FlatSpec } println("Invoking the read-database action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/read-database", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/read-database", Map("dbname" -> credential.dbname.toJson))) { activation => activation.response.success shouldBe true @@ -157,7 +157,7 @@ class CloudantAccountActionsTests extends FlatSpec } println("Invoking the read-database action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/read-database", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/read-database", Map("dbname" -> "doesNotExistDB".toJson))) { activation => activation.response.success shouldBe false @@ -188,14 +188,14 @@ class CloudantAccountActionsTests extends FlatSpec } println("Invoking the delete-database action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/delete-database", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/delete-database", Map("dbname" -> credential.dbname.toJson))) { activation => activation.response.success shouldBe true } val response = CloudantUtil.readTestDatabase(credential) - response.get("error").getAsString() shouldBe "not_found" - response.get("reason").getAsString() shouldBe "Database does not exist." + response.get("error").getAsString shouldBe "not_found" + response.get("reason").getAsString shouldBe "Database does not exist." } finally { CloudantUtil.unsetUp(credential) @@ -224,7 +224,7 @@ class CloudantAccountActionsTests extends FlatSpec } println("Invoking the delete-database action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/delete-database", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/delete-database", Map("dbname" -> credential.dbname.toJson))) { activation => activation.response.success shouldBe false @@ -259,7 +259,7 @@ class CloudantAccountActionsTests extends FlatSpec } println("Invoking the list-all-databases action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/list-all-databases")) { + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/list-all-databases")) { activation => activation.response.success shouldBe true val result = activation.response.result.get @@ -299,7 +299,7 @@ class CloudantAccountActionsTests extends FlatSpec } println("Invoking the list-all-databases action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/list-all-databases")) { + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/list-all-databases")) { activation => activation.response.success shouldBe false val result = activation.response.result.get diff --git a/tests/src/test/scala/system/packages/CloudantBindingTests.scala b/tests/src/test/scala/system/packages/CloudantBindingTests.scala index 6110cfe..c619a09 100644 --- a/tests/src/test/scala/system/packages/CloudantBindingTests.scala +++ b/tests/src/test/scala/system/packages/CloudantBindingTests.scala @@ -61,7 +61,7 @@ class CloudantBindingTests extends FlatSpec } println("Invoking the document-create action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/create-document", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/create-document", Map( "dbname" -> myCloudantCreds.dbname.toJson, "doc" -> JsObject("message" -> "I used the url parameter.".toJson)))) { @@ -100,7 +100,7 @@ class CloudantBindingTests extends FlatSpec } println("Invoking the document-create action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/create-document", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/create-document", Map( "dbname" -> myCloudantCreds.dbname.toJson, "doc" -> JsObject("message" -> "This time I didn't use the URL param.".toJson)))) { diff --git a/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala b/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala index 145250f..3bcbd4e 100644 --- a/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala +++ b/tests/src/test/scala/system/packages/CloudantDatabaseActionsTests.scala @@ -490,7 +490,7 @@ class CloudantDatabaseActionsTests extends FlatSpec response.get("ok").getAsString shouldBe "true" println("Invoking the delete-document action.") - withActivation(wsk.activation, wsk.action.invoke(s"${packageName}/delete-document", + withActivation(wsk.activation, wsk.action.invoke(s"$packageName/delete-document", Map("docrev" -> response.get("rev").getAsString.toJson))) { activation => activation.response.success shouldBe false diff --git a/tests/src/test/scala/system/packages/CloudantFeedTests.scala b/tests/src/test/scala/system/packages/CloudantFeedTests.scala index e0be2db..987291b 100644 --- a/tests/src/test/scala/system/packages/CloudantFeedTests.scala +++ b/tests/src/test/scala/system/packages/CloudantFeedTests.scala @@ -62,7 +62,7 @@ class CloudantFeedTests } // create whisk stuff - var feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "username" -> myCloudantCreds.user.toJson, @@ -93,7 +93,7 @@ class CloudantFeedTests } // create whisk stuff - var feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "username" -> myCloudantCreds.user.toJson, @@ -124,7 +124,7 @@ class CloudantFeedTests } // create whisk stuff - var feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "username" -> myCloudantCreds.user.toJson, @@ -155,7 +155,7 @@ class CloudantFeedTests } // create whisk stuff - var feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "password" -> myCloudantCreds.password.toJson, @@ -204,8 +204,8 @@ class CloudantFeedTests (wp, assetHelper) => implicit val wskprops = wp // shadow global props and make implicit val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" + val ruleName = s"dummyCloudantRule-${System.currentTimeMillis}" + val actionName = s"dummyCloudantAction-${System.currentTimeMillis}" val packageName = "dummyCloudantPackage" val feed = "changes" @@ -227,7 +227,7 @@ class CloudantFeedTests } println("Creating cloudant trigger feed.") - val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "username" -> myCloudantCreds.user.toJson, @@ -245,7 +245,7 @@ class CloudantFeedTests // Create test docs in cloudant and assert that document was inserted successfully println("Creating a test doc-1 in the cloudant") val response1 = CloudantUtil.createDocument(myCloudantCreds, "{\"test\":\"test_doc_1\"}") - response1.get("ok").getAsString() should be("true") + response1.get("ok").getAsString should be("true") println("Checking for activations") val activations = wsk.activation.pollFor(N = 1, Some(triggerName), retries = 30).length @@ -254,7 +254,7 @@ class CloudantFeedTests println("Creating a test doc-2 in the cloudant") val response2 = CloudantUtil.createDocument(myCloudantCreds, "{\"test\":\"test_doc_2\"}") - response2.get("ok").getAsString() should be("true") + response2.get("ok").getAsString should be("true") println("No activations should be created for test_doc_2 since trigger is disabled") val newactivations = wsk.activation.pollFor(N = 2, Some(triggerName)).length @@ -270,8 +270,8 @@ class CloudantFeedTests (wp, assetHelper) => implicit val wskprops = wp // shadow global props and make implicit val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" + val ruleName = s"dummyCloudantRule-${System.currentTimeMillis}" + val actionName = s"dummyCloudantAction-${System.currentTimeMillis}" val packageName = "dummyCloudantPackage" val feed = "changes" @@ -298,7 +298,7 @@ class CloudantFeedTests getResponse.get("ok").getAsString shouldBe "true" println("Creating cloudant trigger feed.") - val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "username" -> myCloudantCreds.user.toJson, @@ -317,7 +317,7 @@ class CloudantFeedTests // Create test docs in cloudant and assert that document was inserted successfully println("Creating a test doc-1 in the cloudant") val response1 = CloudantUtil.createDocument(myCloudantCreds, "{\"kind\":\"fruit\", \"type\":\"apple\"}") - response1.get("ok").getAsString() should be("true") + response1.get("ok").getAsString should be("true") println("Checking for activations") val activations = wsk.activation.pollFor(N = 1, Some(triggerName), retries = 30).length @@ -326,7 +326,7 @@ class CloudantFeedTests println("Creating a test doc-2 in the cloudant") val response2 = CloudantUtil.createDocument(myCloudantCreds, "{\"kind\":\"dairy\",\"type\":\"butter\"}") - response2.get("ok").getAsString() should be("true") + response2.get("ok").getAsString should be("true") println("checking for new activations (not expected since it should be filtered out)") val noNewActivations = wsk.activation.pollFor(N = 2, Some(triggerName)).length @@ -335,7 +335,7 @@ class CloudantFeedTests println("Creating a test doc-3 in the cloudant") val response3 = CloudantUtil.createDocument(myCloudantCreds, "{\"kind\":\"debatable\", \"type\":\"tomato\"}") - response3.get("ok").getAsString() should be("true") + response3.get("ok").getAsString should be("true") println("Checking for new activations (should now have 2)") val newActivations = wsk.activation.pollFor(N = 3, Some(triggerName), retries = 30).length @@ -349,8 +349,6 @@ class CloudantFeedTests } it should "not return fields in configuration that are not passed in during trigger create" in withAssetCleaner(wskprops) { - val currentTime = s"${System.currentTimeMillis}" - (wp, assetHelper) => implicit val wskProps = wp val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" @@ -360,7 +358,7 @@ class CloudantFeedTests try { CloudantUtil.setUp(myCloudantCreds) - // the package alarms should be there + // the package cloudant should be there val packageGetResult = wsk.pkg.get("/whisk.system/cloudant") println("fetched package cloudant") packageGetResult.stdout should include("ok") @@ -422,8 +420,6 @@ class CloudantFeedTests } it should "reject trigger update without passing in any updatable parameters" in withAssetCleaner(wskprops) { - val currentTime = s"${System.currentTimeMillis}" - (wp, assetHelper) => implicit val wskProps = wp val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" @@ -433,7 +429,7 @@ class CloudantFeedTests try { CloudantUtil.setUp(myCloudantCreds) - // the package alarms should be there + // the package cloudant should be there val packageGetResult = wsk.pkg.get("/whisk.system/cloudant") println("fetched package cloudant") packageGetResult.stdout should include("ok") @@ -477,8 +473,6 @@ class CloudantFeedTests } it should "reject trigger update when query_params is passed in and no filter is defined" in withAssetCleaner(wskprops) { - val currentTime = s"${System.currentTimeMillis}" - (wp, assetHelper) => implicit val wskProps = wp val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" @@ -488,7 +482,7 @@ class CloudantFeedTests try { CloudantUtil.setUp(myCloudantCreds) - // the package alarms should be there + // the package cloudant should be there val packageGetResult = wsk.pkg.get("/whisk.system/cloudant") println("fetched package cloudant") packageGetResult.stdout should include("ok") @@ -536,8 +530,8 @@ class CloudantFeedTests (wp, assetHelper) => implicit val wskProps = wp // shadow global props and make implicit val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" + val ruleName = s"dummyCloudantRule-${System.currentTimeMillis}" + val actionName = s"dummyCloudantAction-${System.currentTimeMillis}" val packageName = "dummyCloudantPackage" val feed = "changes" @@ -564,7 +558,7 @@ class CloudantFeedTests getResponse.get("ok").getAsString shouldBe "true" println("Creating cloudant trigger feed.") - val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { + assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { (trigger, name) => trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( "username" -> myCloudantCreds.user.toJson, @@ -583,7 +577,7 @@ class CloudantFeedTests // Create test docs in cloudant and assert that document was inserted successfully println("Creating a test doc-1 in the cloudant") val response1 = CloudantUtil.createDocument(myCloudantCreds, "{\"kind\":\"fruit\", \"type\":\"apple\"}") - response1.get("ok").getAsString() should be("true") + response1.get("ok").getAsString should be("true") println("Checking for activations") val activations = wsk.activation.pollFor(N = 1, Some(triggerName), retries = 30).length @@ -592,7 +586,7 @@ class CloudantFeedTests println("Creating a test doc-2 in the cloudant") val response2 = CloudantUtil.createDocument(myCloudantCreds, "{\"kind\":\"dairy\",\"type\":\"butter\"}") - response2.get("ok").getAsString() should be("true") + response2.get("ok").getAsString should be("true") println("checking for new activations (not expected since it should be filtered out)") val noNewActivations = wsk.activation.pollFor(N = 2, Some(triggerName)).length @@ -636,7 +630,7 @@ class CloudantFeedTests println("Creating a test doc-3 in the cloudant") val response3 = CloudantUtil.createDocument(myCloudantCreds, "{\"kind\":\"berry\", \"type\":\"avocado\"}") - response3.get("ok").getAsString() should be("true") + response3.get("ok").getAsString should be("true") println("Checking for new activations (should now have 2)") val newActivations = wsk.activation.pollFor(N = 3, Some(triggerName), retries = 30).length diff --git a/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala b/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala index 63dc28c..da9d518 100644 --- a/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala +++ b/tests/src/test/scala/system/packages/CloudantFeedWebTests.scala @@ -35,7 +35,7 @@ class CloudantFeedWebTests val wskprops = WskProps() val webAction = "/whisk.system/cloudantWeb/changesWebAction" - val webActionURL = s"https://${wskprops.apihost}/api/v1/web${webAction}.http" + val webActionURL = s"https://${wskprops.apihost}/api/v1/web$webAction.http" val requiredParams = JsObject( "triggerName" -> JsString("/invalidNamespace/invalidTrigger"), diff --git a/tests/src/test/scala/system/packages/CloudantMultiWorkersTests.scala b/tests/src/test/scala/system/packages/CloudantMultiWorkersTests.scala index 6280d25..42f3ed2 100644 --- a/tests/src/test/scala/system/packages/CloudantMultiWorkersTests.scala +++ b/tests/src/test/scala/system/packages/CloudantMultiWorkersTests.scala @@ -27,8 +27,12 @@ import org.scalatest.{FlatSpec, Matchers} import spray.json.DefaultJsonProtocol.{StringJsonFormat, _} import spray.json.{pimpAny, _} import system.CloudantUtil -import whisk.core.database.test.DatabaseScriptTestUtils -import whisk.utils.JsHelpers +import whisk.core.WhiskConfig +import whisk.core.database.test.ExtendedCouchDbRestClient +import whisk.utils.{JsHelpers, retry} + +import scala.concurrent.Await +import scala.concurrent.duration.DurationInt @RunWith(classOf[JUnitRunner]) @@ -36,8 +40,7 @@ class CloudantMultiWorkersTests extends FlatSpec with Matchers with WskActorSystem with WskTestHelpers - with StreamLogging - with DatabaseScriptTestUtils { + with StreamLogging { val wskprops = WskProps() val wsk = new Wsk @@ -45,8 +48,15 @@ class CloudantMultiWorkersTests extends FlatSpec val user = auth.fst val password = auth.snd + val dbProtocol = WhiskProperties.getProperty("db.protocol") + val dbHost = WhiskProperties.getProperty("db.host") + val dbPort = WhiskProperties.getProperty("db.port").toInt + val dbUsername = WhiskProperties.getProperty("db.username") + val dbPassword = WhiskProperties.getProperty("db.password") + val dbPrefix = WhiskProperties.getProperty(WhiskConfig.dbPrefix) + val webAction = "/whisk.system/cloudantWeb/changesWebAction" - val webActionURL = s"https://${wskprops.apihost}/api/v1/web${webAction}.http" + val webActionURL = s"https://${wskprops.apihost}/api/v1/web$webAction.http" val myCloudantCreds = CloudantUtil.Credential.makeFromVCAPFile("cloudantNoSQLDB", this.getClass.getSimpleName) @@ -91,14 +101,19 @@ class CloudantMultiWorkersTests extends FlatSpec makePostCallWithExpectedResult(worker11Params, 200) val dbName = s"${dbPrefix}cloudanttrigger" - val documents = getAllDocs(dbName) - - val worker1Doc = documents - .fields("rows") - .convertTo[List[JsObject]] - .filter(_.fields("id").convertTo[String].equals(s":_:$worker11Trigger")) - - JsHelpers.getFieldPath(worker1Doc(0), "doc", "worker") shouldBe Some(JsString("worker11")) + val client = new ExtendedCouchDbRestClient(dbProtocol, dbHost, dbPort, dbUsername, dbPassword, dbName) + + retry({ + val result = Await.result(client.getAllDocs(includeDocs = Some(true)), 15.seconds) + result should be('right) + val documents = result.right.get + val worker11Doc = documents + .fields("rows") + .convertTo[List[JsObject]] + .filter(_.fields("id").convertTo[String].equals(s":_:$worker11Trigger")) + + JsHelpers.getFieldPath(worker11Doc.head, "doc", "worker") shouldBe Some(JsString("worker11")) + }) } finally { //delete trigger feeds and triggers makeDeleteCallWithExpectedResult(worker10Params, DONTCARE_EXIT) diff --git a/tests/src/test/scala/system/packages/CloudantTriggerPersistencyTest.scala b/tests/src/test/scala/system/packages/CloudantTriggerPersistencyTest.scala deleted file mode 100644 index 0c85987..0000000 --- a/tests/src/test/scala/system/packages/CloudantTriggerPersistencyTest.scala +++ /dev/null @@ -1,100 +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 system.packages - -import common._ -import org.junit.runner.RunWith -import org.scalatest.FlatSpec -import org.scalatest.junit.JUnitRunner -import spray.json.DefaultJsonProtocol.{IntJsonFormat, StringJsonFormat} -import spray.json.pimpAny -import system.CloudantUtil - -/** - * Tests for Cloudant trigger service - */ -@RunWith(classOf[JUnitRunner]) -class CloudantTriggerPersistencyTest - extends FlatSpec - with TestHelpers - with WskTestHelpers - with WskActorSystem { - - val dbUsername = WhiskProperties.getProperty("db.username") - val dbPassword = WhiskProperties.getProperty("db.password") - val dbPrefix = WhiskProperties.getProperty("db.prefix") - - val wskprops = WskProps() - val wsk = new Wsk - - val myCloudantCreds = CloudantUtil.Credential.makeFromVCAPFile("cloudantNoSQLDB", this.getClass.getSimpleName) - - val cloudantTriggerDBCreds = new CloudantUtil.Credential(dbUsername, dbPassword, dbPrefix + "cloudanttrigger") - - behavior of "Cloudant trigger service" - - - ignore should "persist trigger into Cloudant" in withAssetCleaner(wskprops) { - (wp, assetHelper) => - implicit val wskprops = wp // shadow global props and make implicit - val namespace = wsk.namespace.list().stdout.trim.split("\n").last - val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val trigger = "/" + namespace + "/" + triggerName - val packageName = "/" + namespace + "/dummyCloudantPackage" - val feed = "changes" - try { - CloudantUtil.setUp(myCloudantCreds) - - val packageGetResult = wsk.pkg.get("/whisk.system/cloudant") - println("Fetching cloudant package.") - packageGetResult.stdout should include("ok") - - println("Creating cloudant package binding.") - assetHelper.withCleaner(wsk.pkg, packageName) { - (pkg, name) => pkg.bind("/whisk.system/cloudant", name) - } - - println("Creating cloudant trigger feed.") - val feedCreationResult = wsk.trigger.create(trigger, - feed = Some(s"$packageName/$feed"), - parameters = Map( - "username" -> myCloudantCreds.user.toJson, - "password" -> myCloudantCreds.password.toJson, - "host" -> myCloudantCreds.host().toJson, - "dbname" -> myCloudantCreds.dbname.toJson, - "maxTriggers" -> 1.toJson)) - feedCreationResult.stdout should include("ok") - - println("Getting cloudanttrigger doc from the cloudant") - val docId = s":${namespace}:${triggerName}" - val persistedResponse = CloudantUtil.getDocument(cloudantTriggerDBCreds, docId) - - println("Deleting cloudant trigger feed.") - val feedDeletionResult = wsk.trigger.delete(trigger) - feedDeletionResult.stdout should include("ok") - - println("Getting cloudanttrigger doc from the cloudant") - val removedResponse = CloudantUtil.getDocument(cloudantTriggerDBCreds, docId) - - persistedResponse.get("id").getAsString() should be(docId) - removedResponse.get("error").getAsString() should be("not_found") - } finally { - CloudantUtil.unsetUp(myCloudantCreds) - } - } - -} diff --git a/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala b/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala deleted file mode 100644 index e78cc24..0000000 --- a/tests/src/test/scala/system/redundancy/CloudantRedundancyTests.scala +++ /dev/null @@ -1,220 +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 system.redundancy - -import com.jayway.restassured.RestAssured -import com.jayway.restassured.config.SSLConfig -import common._ -import org.junit.runner.RunWith -import org.scalatest.junit.JUnitRunner -import org.scalatest.{BeforeAndAfterAll, FlatSpec, Matchers} -import spray.json.DefaultJsonProtocol.StringJsonFormat -import spray.json.{pimpAny, _} -import system.CloudantUtil - -/** - * These tests verify that a cloudant redundancy (master/slave) configuration - * works as expected. They will only run properly in an environment with two - * cloudant containers running concurrently and env var HOST_INDEX set to host0 in - * one container and host1 in the other. This test also assumes that redis and - * the active endpoint authorization are configured. For the auth set the - * ENDPOINT_AUTH env var in your containers to match the testing.auth property - * found in your whisk.properties. To configure redis simply set the REDIS_URL - * env var in your containers to point to the openwhisk redis container and make - * sure the container is deployed. You can run redis.yml to deploy it. - */ -@RunWith(classOf[JUnitRunner]) -class CloudantRedundancyTests - extends FlatSpec - with Matchers - with BeforeAndAfterAll - with WskTestHelpers { - - val wskprops = WskProps() - val wsk = new Wsk - val myCloudantCreds = CloudantUtil.Credential.makeFromVCAPFile("cloudantNoSQLDB", this.getClass.getSimpleName) - val edgeHost = WhiskProperties.getEdgeHost - val auth = WhiskProperties.getBasicAuth - val user = auth.fst - val password = auth.snd - - val endpointPrefix = s"https://$user:$password@$edgeHost/cloudanttrigger/worker0/" - val defaultAction = Some(TestUtils.getTestActionFilename("hello.js")) - - behavior of "Cloudant redundancy tests" - - it should "fire cloudant trigger before the swap" in withAssetCleaner(wskprops) { - (wp, assetHelper) => - implicit val wskprops = wp // shadow global props and make implicit - val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" - val packageName = "dummyCloudantPackage" - val feed = "changes" - - try { - CloudantUtil.setUp(myCloudantCreds) - - // the package cloudant should be there - val packageGetResult = wsk.pkg.get("/whisk.system/cloudant") - println("fetched package cloudant") - packageGetResult.stdout should include("ok") - - // create package binding - assetHelper.withCleaner(wsk.pkg, packageName) { - (pkg, name) => pkg.bind("/whisk.system/cloudant", name) - } - - // create action - assetHelper.withCleaner(wsk.action, actionName) { (action, name) => - action.create(name, defaultAction) - } - - // create whisk stuff - val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { - (trigger, name) => - trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( - "username" -> myCloudantCreds.user.toJson, - "password" -> myCloudantCreds.password.toJson, - "host" -> myCloudantCreds.host().toJson, - "dbname" -> myCloudantCreds.dbname.toJson)) - } - - // create rule - assetHelper.withCleaner(wsk.rule, ruleName) { (rule, name) => - rule.create(name, trigger = triggerName, action = actionName) - } - - Thread.sleep(3000) - - // create a test doc in the sample db - println("create a test doc and wait for trigger") - CloudantUtil.createDocument(myCloudantCreds, "{\"test\":\"test_doc1\"}") - - // get activation list of the trigger, expecting exactly 1 - val activations = wsk.activation.pollFor(N = 1, Some(triggerName), retries = 30).length - println(s"Found activation size (should be exactly 1): $activations") - withClue("Change feed trigger count: ") { activations should be(1) } - - // delete the whisk trigger, which must also delete the feed - wsk.trigger.delete(triggerName) - } finally { - CloudantUtil.unsetUp(myCloudantCreds) - } - } - - it should "perform active swap by setting host0 active=false" in { - val endpointURL = endpointPrefix + "0/active?active=false" - val expectedResult = "{\"worker\":\"worker0\",\"host\":\"host0\",\"active\":\"swapping\"}".parseJson.asJsObject - - makeGetCallWithExpectedResult(endpointURL, expectedResult) - } - - it should "verify active swap by checking for host0 active=false" in { - val endpointURL = endpointPrefix + "0/active" - val expectedResult = "{\"worker\":\"worker0\",\"host\":\"host0\",\"active\":false}".parseJson.asJsObject - - Thread.sleep(3000) - makeGetCallWithExpectedResult(endpointURL, expectedResult) - } - - it should "verify active swap by checking for host1 active=true" in { - val endpointURL = endpointPrefix + "1/active" - val expectedResult = "{\"worker\":\"worker0\",\"host\":\"host1\",\"active\":true}".parseJson.asJsObject - - makeGetCallWithExpectedResult(endpointURL, expectedResult) - } - - it should "fire cloudant trigger again after the swap" in withAssetCleaner(wskprops) { - (wp, assetHelper) => - implicit val wskprops = wp // shadow global props and make implicit - val triggerName = s"dummyCloudantTrigger-${System.currentTimeMillis}" - val ruleName = s"dummyAlarmsRule-${System.currentTimeMillis}" - val actionName = s"dummyAlarmsAction-${System.currentTimeMillis}" - val packageName = "dummyCloudantPackage" - val feed = "changes" - - try { - CloudantUtil.setUp(myCloudantCreds) - - // the package cloudant should be there - val packageGetResult = wsk.pkg.get("/whisk.system/cloudant") - println("fetched package cloudant") - packageGetResult.stdout should include("ok") - - // create package binding - assetHelper.withCleaner(wsk.pkg, packageName) { - (pkg, name) => pkg.bind("/whisk.system/cloudant", name) - } - - // create action - assetHelper.withCleaner(wsk.action, actionName) { (action, name) => - action.create(name, defaultAction) - } - - // create whisk stuff - val feedCreationResult = assetHelper.withCleaner(wsk.trigger, triggerName, confirmDelete = false) { - (trigger, name) => - trigger.create(name, feed = Some(s"$packageName/$feed"), parameters = Map( - "username" -> myCloudantCreds.user.toJson, - "password" -> myCloudantCreds.password.toJson, - "host" -> myCloudantCreds.host().toJson, - "dbname" -> myCloudantCreds.dbname.toJson)) - } - - // create rule - assetHelper.withCleaner(wsk.rule, ruleName) { (rule, name) => - rule.create(name, trigger = triggerName, action = actionName) - } - - Thread.sleep(3000) - - // create a test doc in the sample db - println("create a test doc and wait for trigger") - CloudantUtil.createDocument(myCloudantCreds, "{\"test\":\"test_doc1\"}") - - // get activation list of the trigger, expecting exactly 1 - val activations = wsk.activation.pollFor(N = 1, Some(triggerName), retries = 30).length - println(s"Found activation size (should be exactly 1): $activations") - withClue("Change feed trigger count: ") { activations should be(1) } - - // delete the whisk trigger, which must also delete the feed - wsk.trigger.delete(triggerName) - } finally { - CloudantUtil.unsetUp(myCloudantCreds) - } - } - - private def makeGetCallWithExpectedResult(endpointURL: String, expectedResult: JsObject) = { - val response = RestAssured. - given(). - config(RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())). - get(endpointURL) - assert(response.statusCode() == 200) - var result = response.body.asString.parseJson.asJsObject - JsObject(result.fields - "hostMachine") shouldBe expectedResult - } - - override def afterAll() { - //swap back to original configuration - RestAssured. - given(). - config(RestAssured.config().sslConfig(new SSLConfig().relaxedHTTPSValidation())). - get(endpointPrefix + "0/active?active=true") - } - -} ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services