You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwhisk.apache.org by gi...@git.apache.org on 2017/05/29 06:42:18 UTC
[GitHub] cbickel commented on a change in pull request #2283: Add tool to delete logs from old activations
cbickel commented on a change in pull request #2283: Add tool to delete logs from old activations
URL: https://github.com/apache/incubator-openwhisk/pull/2283#discussion_r118874046
##########
File path: tests/src/test/scala/whisk/core/database/test/RemoveLogsTests.scala
##########
@@ -0,0 +1,104 @@
+/*
+ * Copyright 2015-2016 IBM Corporation
+ *
+ * Licensed 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 whisk.core.database.test
+
+import java.io.File
+import java.time.Instant
+import java.time.temporal.ChronoUnit
+
+import org.junit.runner.RunWith
+import org.scalatest.FlatSpec
+import org.scalatest.junit.JUnitRunner
+
+import common.StreamLogging
+import common.TestUtils
+import common.WhiskProperties
+import common.WskActorSystem
+import whisk.core.entity.ActivationId
+import whisk.core.entity.EntityName
+import whisk.core.entity.EntityPath
+import whisk.core.entity.Subject
+import whisk.core.entity.WhiskActivation
+import whisk.core.entity.ActivationLogs
+
+@RunWith(classOf[JUnitRunner])
+class RemoveLogsTests
+ extends FlatSpec
+ with DatabaseScriptTestUtils
+ with StreamLogging
+ with WskActorSystem {
+
+ val designDocPath = WhiskProperties.getFileRelativeToWhiskHome("ansible/files/logCleanup_design_document_for_activations_db.json").getAbsolutePath
+ val removeLogsToolPath = WhiskProperties.getFileRelativeToWhiskHome("tools/db/deleteLogsFromActivations.py").getAbsolutePath
+
+ /** Runs the clean up script to delete old activations */
+ def removeLogsTool(dbUrl: String, dbName: String, days: Int, docsPerRequest: Int = 20) = {
+ println(s"Running removeLogs tool: $dbUrl, $dbName, $days, $docsPerRequest")
+
+ val cmd = Seq(python, removeLogsToolPath, "--dbUrl", dbUrl, "--dbName", dbName, "--days", days.toString, "--docsPerRequest", docsPerRequest.toString)
+ val rr = TestUtils.runCmd(0, new File("."), cmd: _*)
+ }
+
+ behavior of "Activation Log Cleanup Skript"
+
+ it should "delete logs in old activation and keep log in new activation" in {
+ val dbName = dbPrefix + "test_log_cleanup_1"
+ val db = createDatabase(dbName, Some(designDocPath))
+
+ try {
+ // Create an old and a new activation
+ val oldActivation = WhiskActivation(
+ namespace = EntityPath("testns1"),
+ name = EntityName("testname1"),
+ subject = Subject("test-sub"),
+ activationId = ActivationId.apply(),
+ start = Instant.now.minus(2, ChronoUnit.DAYS),
+ end = Instant.now,
+ logs = ActivationLogs(Vector("first line", "second line")))
+
+ val newActivation = WhiskActivation(
+ namespace = EntityPath("testns1"),
+ name = EntityName("testname1"),
+ subject = Subject("test-sub"),
+ activationId = ActivationId.apply(),
+ start = Instant.now,
+ end = Instant.now,
+ logs = ActivationLogs(Vector("first line", "second line")))
+
+ db.putDoc(oldActivation.docid.asString, oldActivation.toJson).futureValue shouldBe 'right
+ db.putDoc(newActivation.docid.asString, newActivation.toJson).futureValue shouldBe 'right
+
+ // Run the tool to delete logs from activations that are older than 1 day
+ removeLogsTool(dbUrl, dbName, 1)
Review comment:
The script does a check, if the activation is older than the given days (in milliseconds).
I'd like to avoid the tests of the edge cases. The reason is, that I think, that they will fail in the pipeline, if the test is a bit slower than expected.
----------------------------------------------------------------
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:
users@infra.apache.org
With regards,
Apache Git Services