Skip to content

Commit

Permalink
Adapt large attachment test
Browse files Browse the repository at this point in the history
Use lower size for Cosmos as max limit is 2MB. For ArtifactStore configured with AttachmentStore use large size like 5MB
  • Loading branch information
chetanmeh committed Jun 21, 2018
1 parent faa3fa4 commit 48d3c07
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 48d3c07

Please sign in to comment.