-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ISSUE-183 JMAP scenario for triaging downloads (#184)
- Loading branch information
1 parent
312771a
commit 2405fe0
Showing
7 changed files
with
158 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
src/it/scala-2.13/org/apache/james/gatling/jmap/rfc8621/DownloadAttachmentIT.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.apache.james.gatling.jmap.rfc8621 | ||
|
||
import org.apache.james.gatling.Fixture | ||
import org.apache.james.gatling.jmap.rfc8621.scenari.DownloadAttachmentScenario | ||
|
||
import scala.concurrent.duration._ | ||
|
||
class DownloadAttachmentIT extends JmapIT { | ||
before { | ||
users.foreach(server.sendMessage(Fixture.homer.username)) | ||
} | ||
|
||
scenario((userFeederBuilder, recipientFeederBuilder) => { | ||
new DownloadAttachmentScenario().generate(20 seconds, userFeederBuilder, recipientFeederBuilder, | ||
provisionMailWithAttachments = Some(true)) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...scala-2.13/org/apache/james/gatling/jmap/rfc8621/scenari/DownloadAttachmentScenario.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.apache.james.gatling.jmap.rfc8621.scenari | ||
|
||
import io.gatling.core.Predef._ | ||
import io.gatling.core.structure.ScenarioBuilder | ||
import io.gatling.http.Predef._ | ||
import io.gatling.http.check.HttpCheck | ||
import org.apache.james.gatling.control.RecipientFeeder.RecipientFeederBuilder | ||
import org.apache.james.gatling.control.UserFeeder.UserFeederBuilder | ||
import org.apache.james.gatling.jmap.rfc8621.scenari.DownloadAttachmentScenario.{emailGetAttachmentsProperties, emailWithAttachmentsIdsKey} | ||
import org.apache.james.gatling.jmap.rfc8621.{JmapEmail, JmapHttp, JmapMailbox, SessionStep} | ||
|
||
import scala.concurrent.duration._ | ||
import scala.util.Properties | ||
|
||
object DownloadAttachmentScenario { | ||
val emailGetAttachmentsProperties = "[\"attachments\"]" | ||
val emailWithAttachmentsIdsKey = "emailWithAttachmentsIds" | ||
} | ||
|
||
class DownloadAttachmentScenario { | ||
|
||
def generate(duration: Duration, userFeeder: UserFeederBuilder, recipientFeeder: RecipientFeederBuilder, | ||
provisionMailWithAttachments: Option[Boolean] = None): ScenarioBuilder = { | ||
|
||
val provisionMailWithAttachmentsValue: Boolean = provisionMailWithAttachments.getOrElse(Properties.envOrNone("PROVISION_MAIL_WITH_ATTACHMENTS") match { | ||
case Some(value) => value.toBoolean | ||
case _ => false | ||
}) | ||
|
||
scenario("DownloadAttachmentScenario") | ||
.feed(userFeeder) | ||
.exec(SessionStep.retrieveAccountId) | ||
.doIf(_ => provisionMailWithAttachmentsValue) { | ||
exec(JmapMailbox.provisionUsersWithMessagesAndAttachment(recipientFeeder, numberOfMessages = 10)) | ||
} | ||
.during(duration.toSeconds.toInt) { | ||
exec(JmapEmail.queryEmails(callName = "emailQuery hasAttachment", JmapEmail.filterAttachments()) | ||
.check(JmapHttp.statusOk, JmapHttp.noError, nonEmptyListMessageIdsChecks())) | ||
.doIf(session => !session(emailWithAttachmentsIdsKey).asOption[Seq[String]].forall(_.isEmpty)) { | ||
pause(1 second, 2 seconds) | ||
.exec(JmapEmail.getRandomEmails(properties = emailGetAttachmentsProperties, emailIdsKey = emailWithAttachmentsIdsKey) | ||
.check(JmapHttp.statusOk, JmapHttp.noError, JmapEmail.nonEmptyEmailsChecks, nonEmptyBlobIdChecks())) | ||
.pause(1 second, 2 seconds) | ||
.exec(JmapHttp.download(callName = "Download Attachment") | ||
.check(JmapHttp.statusOk)) | ||
} | ||
} | ||
} | ||
|
||
private def nonEmptyListMessageIdsChecks(): HttpCheck = | ||
jsonPath("$.methodResponses[0][1].ids[*]").findAll.optional.saveAs(emailWithAttachmentsIdsKey) | ||
|
||
private def nonEmptyBlobIdChecks(): HttpCheck = | ||
jsonPath("$.methodResponses[0][1].list[0].attachments[0].blobId").find.saveAs("blobId") | ||
} | ||
|
16 changes: 16 additions & 0 deletions
16
...-2.13/org/apache/james/gatling/simulation/jmap/rfc8621/DownloadAttachmentSimulation.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package org.apache.james.gatling.simulation.jmap.rfc8621 | ||
|
||
import io.gatling.core.Predef._ | ||
import io.gatling.core.scenario.Simulation | ||
import org.apache.james.gatling.jmap.rfc8621.scenari.DownloadAttachmentScenario | ||
import org.apache.james.gatling.simulation.Configuration.UserCount | ||
import org.apache.james.gatling.simulation.{Configuration, HttpSettings, UsersFeederWebAdminFactory} | ||
|
||
class DownloadAttachmentSimulation extends Simulation { | ||
private val scenario: DownloadAttachmentScenario = new DownloadAttachmentScenario() | ||
private val feederFactory: UsersFeederWebAdminFactory = new UsersFeederWebAdminFactory(UserCount).initUsers | ||
|
||
setUp(scenario.generate(Configuration.ScenarioDuration, feederFactory.userFeeder(), feederFactory.recipientFeeder()) | ||
.inject(atOnceUsers(Configuration.UserCount))) | ||
.protocols(HttpSettings.httpProtocol) | ||
} |