From 48d3c07fd6c26bacc89ff0c1effb13c99b15b285 Mon Sep 17 00:00:00 2001 From: Chetan Mehrotra Date: Thu, 21 Jun 2018 12:04:40 +0530 Subject: [PATCH] Adapt large attachment test Use lower size for Cosmos as max limit is 2MB. For ArtifactStore configured with AttachmentStore use large size like 5MB --- .../cosmosdb/CosmosDBArtifactStoreTests.scala | 5 ++++- .../behavior/ArtifactStoreAttachmentBehaviors.scala | 11 ++++++++--- .../test/behavior/ArtifactStoreBehaviorBase.scala | 8 ++++++++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala b/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala index d1e727b215d..bb45c723a2d 100644 --- a/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala +++ b/tests/src/test/scala/whisk/core/database/cosmosdb/CosmosDBArtifactStoreTests.scala @@ -20,7 +20,10 @@ package whisk.core.database.cosmosdb import org.junit.runner.RunWith import org.scalatest.FlatSpec import org.scalatest.junit.JUnitRunner +import whisk.core.entity.size._ import whisk.core.database.test.behavior.ArtifactStoreBehavior @RunWith(classOf[JUnitRunner]) -class CosmosDBArtifactStoreTests extends FlatSpec with CosmosDBStoreBehaviorBase with ArtifactStoreBehavior {} +class CosmosDBArtifactStoreTests extends FlatSpec with CosmosDBStoreBehaviorBase with ArtifactStoreBehavior { + override protected def maxAttachmentSizeWithoutAttachmentStore = 1.MB +} diff --git a/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala b/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala index 82b6b80d330..1438e79d858 100644 --- a/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala +++ b/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreAttachmentBehaviors.scala @@ -22,10 +22,10 @@ import java.util.Base64 import akka.http.scaladsl.model.{ContentTypes, Uri} import akka.stream.IOResult +import scala.concurrent.duration.DurationInt import akka.stream.scaladsl.{Sink, StreamConverters} import akka.util.{ByteString, ByteStringBuilder} import whisk.common.TransactionId -import whisk.core.entity.size._ import whisk.core.database.{AttachmentSupport, CacheChangeNotification, NoDocumentException} import whisk.core.entity.Attachments.{Attached, Attachment, Inline} import whisk.core.entity.test.ExecHelpers @@ -113,17 +113,22 @@ trait ArtifactStoreAttachmentBehaviors extends ArtifactStoreBehaviorBase with Ex getAttachmentBytes(i2, attached(action2)).futureValue.result() shouldBe decode(code1) } - it should "put and read 5 MB attachment" in { + it should "put and read large attachment" in { implicit val tid: TransactionId = transid() - val size = Math.max(nonInlinedAttachmentSize(entityStore), 5.MB.toBytes.toInt) + val size = Math.max(nonInlinedAttachmentSize(entityStore), getAttachmentSizeForTest(entityStore)) val base64 = encodedRandomBytes(size) val exec = javaDefault(base64, Some("hello")) val javaAction = WhiskAction(namespace, EntityName("attachment_large"), exec) + //Have more patience as reading large attachments take time specially for remote + //storage like Cosmos + implicit val patienceConfig: PatienceConfig = PatienceConfig(timeout = 1.minute) + val i1 = WhiskAction.put(entityStore, javaAction, old = None).futureValue val action2 = entityStore.get[WhiskAction](i1, attachmentHandler).futureValue + val action3 = WhiskAction.get(entityStore, i1.id, i1.rev).futureValue docsToDelete += ((entityStore, i1)) diff --git a/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreBehaviorBase.scala b/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreBehaviorBase.scala index eafce189843..6c7ae277b36 100644 --- a/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreBehaviorBase.scala +++ b/tests/src/test/scala/whisk/core/database/test/behavior/ArtifactStoreBehaviorBase.scala @@ -30,6 +30,7 @@ import whisk.core.database.test.DbUtils import whisk.core.database.test.behavior.ArtifactStoreTestUtil.storeAvailable import whisk.core.database.{ArtifactStore, AttachmentStore, StaleParameter} import whisk.core.entity._ +import whisk.core.entity.size._ import whisk.utils.JsHelpers import scala.util.{Random, Try} @@ -161,6 +162,13 @@ trait ArtifactStoreBehaviorBase case _ => None } + protected def getAttachmentSizeForTest(store: ArtifactStore[_]): Int = { + val mb = getAttachmentStore(store).map(_ => 5.MB).getOrElse(maxAttachmentSizeWithoutAttachmentStore) + mb.toBytes.toInt + } + + protected def maxAttachmentSizeWithoutAttachmentStore: ByteSize = 5.MB + private def assertAttachmentStoreIsEmpty(): Unit = { Seq(authStore, entityStore, activationStore).foreach { s => for {