Skip to content

Commit

Permalink
Plugin infrastructure (#4)
Browse files Browse the repository at this point in the history
* Plugin infrastructure

* Last plugin architecture changes

* Adjust some differences.
  • Loading branch information
juanjmerono authored Jul 29, 2016
1 parent 81009be commit a267021
Show file tree
Hide file tree
Showing 8 changed files with 157 additions and 0 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ Configure log level

**NOTE**: You'll find a file with name _${logLevel}.log_ inside the result folder at the end of the simulation.

Add plugins to do more things
=============================

- **allowPlugins**: You can enable plugins in your test to perform specific actions:

```$mvn test -DallowPlugins=pluginName```

You can create a plugin inside plugins folder, extending _SakaiSimulationPlugin_ class and adding the steps you want to run inside an concrete tool.
For example you can add a plugin to create or remove a folder in resources each time a user reach this tool.

Exploring the results
=====================

Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<jvmArg>-Dfixed-site=${siteId}</jvmArg>
<jvmArg>-Dfixed-site-title=${siteTitle}</jvmArg>
<jvmArg>-Dfixed-tool=${toolId}</jvmArg>
<jvmArg>-Dallow-plugins=${allowPlugins}</jvmArg>
</jvmArgs>
</configuration>
<executions>
Expand Down
4 changes: 4 additions & 0 deletions src/test/resources/stresstest.properties
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,7 @@ siteTitle=.*
# Only explore tool that matches this reg exp
# For example: sakai-announcements (just browse the sakai-announcements tool)
toolId=.*
# Allow wich plugins you want to use
# Default empty do not use any plugin
# User .* to allow all plugins
allowPlugins=
46 changes: 46 additions & 0 deletions src/test/scala/computerdatabase/SakaiPluginManager.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io._
import plugins._
import io.gatling.core.Predef._
import io.gatling.core.structure._

class SakaiPluginManager {

var pluginMap = Map[Any, ChainBuilder]()

def getPlugins(dir: File, extensions: List[String]): List[File] = {
dir.listFiles.filter(_.isFile).toList.filter(!_.getName.equals("SakaiSimulationPlugin.scala")).filter { file =>
extensions.exists(file.getName.endsWith(_))
}
}

def init() {
println("Loading simulation plugins...")
// We need at least 2 options to work with Switch
pluginMap += ( "at-least-we-need-2a" -> exec() )
pluginMap += ( "at-least-we-need-2b" -> exec() )
val files = getPlugins(new File("./src/test/scala/computerdatabase/plugins"),List("scala"))
files.foreach(
f => try {
val className = f.getName.replace(".scala","")
val pluginObj = Class.forName("plugins."+className).newInstance.asInstanceOf[SakaiSimulationPlugin]
if (pluginObj.name.matches(System.getProperty("allow-plugins"))) {
if (pluginMap.contains( pluginObj.toolid ) ) {
pluginMap += ( pluginObj.toolid -> exec( pluginMap(pluginObj.toolid) , pluginObj.getSimulationChain ) )
} else {
pluginMap += ( pluginObj.toolid -> pluginObj.getSimulationChain )
}
println("Plugin ["+className+","+pluginObj.name+"] loaded !")
}
} catch {
case e: Exception => {}
}
)
}

def getPluginMap : List[(Any,ChainBuilder)] = {
pluginMap.toList
}

init()

}
5 changes: 5 additions & 0 deletions src/test/scala/computerdatabase/SakaiSimulation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import io.gatling.core.action.builder._
import java.net._
import scala.collection.mutable.ListBuffer

Expand All @@ -23,6 +24,8 @@ class SakaiSimulation extends Simulation {
val fixedToolId = System.getProperty("fixed-tool")
val fixedSiteTitle = System.getProperty("fixed-site-title")

var pluginManager = new SakaiPluginManager();

val httpProtocol = http
.baseURL(System.getProperty("test-url"))
/**.inferHtmlResources(BlackList(".*(\.css|\.js|\.png|\.jpg|\.gif|thumb).*"), WhiteList())*/
Expand Down Expand Up @@ -186,6 +189,8 @@ class SakaiSimulation extends Simulation {
.pause(pauseMin,pauseMax)
}
}
.pause(pauseMin,pauseMax)
.exec(new SwitchBuilder("${tool._1}", pluginManager.getPluginMap, None))
}

}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package plugins

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class SakaiAnnouncementsPlugin extends SakaiSimulationPlugin {

def name(): String = { "announcements-list-options" }

def description(): String = { "List options announcements" }

def toolid(): String = { "sakai-announcements" }

def getSimulationChain =
group("AnnouncementsListOptions") {
exec(http("Announcements")
.get("${tool._2}")
.headers(headers)
.check(status.is(successStatus))
.check(css("span.Mrphs-hierarchy--siteName","title").is("${site._1}"))
.check(css("a.Mrphs-hierarchy--toolName > span[class*='${tool._1}'].Mrphs-breadcrumb--icon").exists)
.check(css("a[onclick*='doOptions']","onclick").transform(_.replace("location = '","").replace("';return false;","")).optional.saveAs("annc_options")))
.doIf("${annc_options.exists()}") {
exec(http("GetOptions")
.get("${annc_options}")
.headers(headers)
.check(status.is(successStatus))
.check(css("span.Mrphs-hierarchy--siteName","title").is("${site._1}"))
.check(css("a.Mrphs-hierarchy--toolName > span[class*='${tool._1}'].Mrphs-breadcrumb--icon").exists)
.check(css("form[name='optionsForm']").exists))
.exec(session => { session.remove("annc_options") })
}
}
}
35 changes: 35 additions & 0 deletions src/test/scala/computerdatabase/plugins/SakaiResourcesPlugin.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package plugins

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class SakaiResourcesPlugin extends SakaiSimulationPlugin {

def name(): String = { "resources-options" }

def description(): String = { "List options in resources" }

def toolid(): String = { "sakai-resources" }

def getSimulationChain =
group("ResourcesListOptions") {
exec(http("Resources")
.get("${tool._2}")
.headers(headers)
.check(status.is(successStatus))
.check(css("span.Mrphs-hierarchy--siteName","title").is("${site._1}"))
.check(css("a.Mrphs-hierarchy--toolName > span[class*='${tool._1}'].Mrphs-breadcrumb--icon").exists)
.check(css("a[href*='doOptions']","href").optional.saveAs("resources_options")))
.doIf("${resources_options.exists()}") {
exec(http("GetOptions")
.get("${annc_options}")
.headers(headers)
.check(status.is(successStatus))
.check(css("span.Mrphs-hierarchy--siteName","title").is("${site._1}"))
.check(css("a.Mrphs-hierarchy--toolName > span[class*='${tool._1}'].Mrphs-breadcrumb--icon").exists)
.check(css("form[name='optionsForm']").exists))
.exec(session => { session.remove("resources_options") })
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package plugins

import io.gatling.core.Predef._
import io.gatling.core.structure._

trait SakaiSimulationPlugin {

val headers = Map(
"Accept" -> "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Encoding" -> "gzip, deflate, sdch, br",
"Accept-Language" -> "es-ES,es;q=0.8,en;q=0.6",
"Cache-Control" -> "max-age=0",
"Connection" -> "keep-alive",
"Upgrade-Insecure-Requests" -> "1")

val successStatus: Int = 200

def name: String
def description: String
def toolid: String
def getSimulationChain: ChainBuilder
}

0 comments on commit a267021

Please sign in to comment.