rabbah commented on a change in pull request #3418: support cleanup of 
cloudant/kafka trigger dbs
URL: 
https://github.com/apache/incubator-openwhisk/pull/3418#discussion_r173779081
 
 

 ##########
 File path: 
tests/src/test/scala/whisk/core/database/test/CleanUpWhisksDbSkriptTests.scala
 ##########
 @@ -257,19 +266,262 @@ class CleanUpWhisksDbSkriptTests
     }
 
     // execute script
-    val (_, _, _, kept) = runScript(dbUrl, dbName, authDBName)
+    val (_, _, _, kept) = runScript(dbUrl, dbName, authDBName, "whisks")
     println(s"kept: $kept")
 
     // Check, that script kept documents in DB
     val ids = documents.keys
     println(s"ids: $ids")
-    kept should contain allElementsOf ids
+    kept should contain("3 doc(s) for namespace whisk.system")
+
+    val databaseResponse = client.getAllDocs(includeDocs = 
Some(true)).futureValue
+    databaseResponse should be('right)
+
+    val databaseDocuments = 
databaseResponse.right.get.fields("rows").convertTo[List[JsObject]]
+
+    val databaseDocumentIDs = 
databaseDocuments.map(_.fields("id").convertTo[String])
+    databaseDocumentIDs should contain allElementsOf ids
+
+    // Delete database
+    client.deleteDb().futureValue
+  }
+
+  it should "mark documents for deletion in cloudanttrigger if namespace does 
not exist" in {
+    // Create whisks db
+    val dbName = dbPrefix + "cleanup_cloudanttrigger_test_mark_for_deletion"
+    val client = createDatabase(dbName, None)
+
+    // Create document/action with random namespace
+    val documents = Map(
+      ":AHA04676_dev:vision-cloudant-trigger" -> JsObject("dbname" -> 
JsString("openwhisk-darkvision-dev")),
+      ":AHA04676_stage:vision-cloudant-trigger" -> JsObject("dbname" -> 
JsString("openwhisk-darkvision-stage")),
+      ":AHA04676_prod:vision-cloudant-trigger" -> JsObject("dbname" -> 
JsString("openwhisk-darkvision-prod")))
+
+    documents.foreach {
+      case (id, document) =>
+        client.putDoc(id, document).futureValue
+    }
+
+    // execute script
+    val (marked, _, _, _) = runScript(dbUrl, dbName, authDBName, 
"cloudanttrigger")
+    println(s"marked: $marked")
+
+    // Check, that script marked document to be deleted: output + document 
from DB
+    val ids = documents.keys
+    println(s"ids: $ids")
+    marked should contain allElementsOf ids
+
+    val databaseResponse = client.getAllDocs(includeDocs = 
Some(true)).futureValue
+    databaseResponse should be('right)
+    val databaseDocuments = 
databaseResponse.right.get.fields("rows").convertTo[List[JsObject]]
+
+    databaseDocuments.foreach { doc =>
+      doc.fields("doc").asJsObject.fields.keys should 
contain("markedForDeletion")
+    }
+
+    // Delete database
+    client.deleteDb().futureValue
+  }
+
+  it should "not mark documents for deletion in cloudanttrigger if namespace 
does exist" in {
+    // Create whisks db
+    val dbName = dbPrefix + 
"cleanup_cloudanttrigger_test_not_mark_for_deletion"
+    val client = createDatabase(dbName, None)
+
+    // Create document/action with whisk-system namespace
+    val documents = Map(
+      ":whisk.system:vision-cloudant-trigger" -> JsObject("dbname" -> 
JsString("openwhisk-darkvision-dev")),
+      ":whisk.system:vision-cloudant-trigger2" -> JsObject("dbname" -> 
JsString("openwhisk-darkvision-dev")),
+      ":whisk.system:vision-cloudant-trigger3" -> JsObject("dbname" -> 
JsString("openwhisk-darkvision-dev")))
+
+    documents.foreach {
+      case (id, document) =>
+        client.putDoc(id, document).futureValue
+    }
+
+    // execute script
+    val (_, _, _, kept) = runScript(dbUrl, dbName, authDBName, 
"cloudanttrigger")
+    println(s"kept: $kept")
+
+    // Check, that script did not mark documents for deletion
+    val ids = documents.keys
+    println(s"ids: $ids")
+    kept should contain("3 doc(s) for namespace whisk.system")
+
+    val databaseResponse = client.getAllDocs(includeDocs = 
Some(true)).futureValue
+    databaseResponse should be('right)
+
+    val databaseDocuments = 
databaseResponse.right.get.fields("rows").convertTo[List[JsObject]]
+    val databaseDocumentIDs = 
databaseDocuments.map(_.fields("id").convertTo[String])
+    databaseDocumentIDs should contain allElementsOf ids
+
+    // Delete database
+    client.deleteDb().futureValue
+  }
+
+  it should "mark documents for deletion in kafkatrigger if namespace does not 
exist" in {
+    // Create whisks db
+    val dbName = dbPrefix + "cleanup_kafkatrigger_test_mark_for_deletion"
+    val client = createDatabase(dbName, None)
+
+    // Create document/action with random namespace
+    val documents = Map(
+      "/ajack...@uk.ibm.com_dev/badgers" -> JsObject(
+        "triggerURL" -> JsString(
+          
"https://xxx:x...@openwhisk.ng.bluemix.net/api/v1/namespaces/AJackson%40uk.ibm.com_dev/triggers/badgers";)),
 
 Review comment:
   remove and sanitize all references to ids.

----------------------------------------------------------------
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

Reply via email to