keycloak-aplcache

Details

diff --git a/testsuite/performance/README.log-tool.md b/testsuite/performance/README.log-tool.md
index 25c85b1..12ae5ff 100644
--- a/testsuite/performance/README.log-tool.md
+++ b/testsuite/performance/README.log-tool.md
@@ -7,7 +7,7 @@ Perform the usual test run:
 mvn verify -Pteardown
 mvn verify -Pprovision
 mvn verify -Pgenerate-data -Ddataset=100users -Dimport.workers=10 -DhashIterations=100
-mvn verify -Ptest -Ddataset=100users -DrunUsers=200 -DrampUpPeriod=10 -DuserThinkTime=0 -DbadLoginAttempts=1 -DrefreshTokenCount=1 -DnumOfIterations=3
+mvn verify -Ptest -Ddataset=100users -DrunUsers=200 -DrampUpPeriod=10 -DuserThinkTime=0 -DbadLoginAttempts=1 -DrefreshTokenCount=1 -DsteadyLoadPeriod=10
 ```
 
 Now analyze the generated simulation.log (adjust LOG_DIR, FROM, and TO):
diff --git a/testsuite/performance/README.md b/testsuite/performance/README.md
index 52e58b1..77a58a9 100644
--- a/testsuite/performance/README.md
+++ b/testsuite/performance/README.md
@@ -27,7 +27,7 @@ mvn clean install
 # Make sure your Docker daemon is running THEN
 mvn verify -Pprovision
 mvn verify -Pgenerate-data -Ddataset=100u -DnumOfWorkers=10 -DhashIterations=100
-mvn verify -Ptest -Ddataset=100u -DrunUsers=200 -DrampUpPeriod=10 -DuserThinkTime=0 -DbadLoginAttempts=1 -DrefreshTokenCount=1 -DnumOfIterations=3
+mvn verify -Ptest -Ddataset=100u -DrunUsers=200 -DrampUpPeriod=10 -DuserThinkTime=0 -DbadLoginAttempts=1 -DrefreshTokenCount=1 -DsteadyLoadPeriod=10
 
 ```
 
@@ -139,7 +139,7 @@ Usage: `mvn verify -Ptest[,cluster] [-DtestParameter=value]`.
 
 | Parameter | Description | Default Value |
 | --- | --- | --- | 
-| `gatling.simulationClass` | Classname of the simulation to be run. | `keycloak.DefaultSimulation`  |
+| `gatling.simulationClass` | Classname of the simulation to be run. | `keycloak.BasicOIDCSimulation`  |
 | `dataset` | Name of the dataset to use. (Individual dataset properties can be overridden with `-Ddataset.property=value`.) | `default` |
 | `runUsers` | Number of users for the simulation run. | `1` |
 | `rampUpPeriod` | Period during which the users will be ramped up. (seconds) | `0` |
@@ -149,7 +149,7 @@ Usage: `mvn verify -Ptest[,cluster] [-DtestParameter=value]`.
 | `userThinkTime` | Pause between individual scenario steps. | `5` |
 | `refreshTokenPeriod`| Period after which token should be refreshed. | `10` |
 
-#### Addtional Parameters of `keycloak.DefaultSimulation`
+#### Addtional Parameters of `keycloak.BasicOIDCSimulation`
 
 | Parameter | Description | Default Value |
 | --- | --- | --- | 
@@ -159,7 +159,7 @@ Usage: `mvn verify -Ptest[,cluster] [-DtestParameter=value]`.
 
 Example:
 
-`mvn verify -Ptest -Dgatling.simulationClass=keycloak.AdminSimulation -Ddataset=100u -DrunUsers=1 -DsteadyLoadPeriod=30 -DuserThinkTime=0 -DrefreshTokenPeriod=15`
+`mvn verify -Ptest -Dgatling.simulationClass=keycloak.AdminConsoleSimulation -Ddataset=100u -DrunUsers=1 -DsteadyLoadPeriod=30 -DuserThinkTime=0 -DrefreshTokenPeriod=15`
 
 
 ## Monitoring
@@ -246,12 +246,16 @@ Thus, it's best to download and install [this SDK version](http://scala-lang.org
 Open Preferences in IntelliJ. Type 'plugins' in the search box. In the right pane click on 'Install JetBrains plugin'.
 Type 'scala' in the search box, and click Install button of the Scala plugin.
 
-#### Run DefaultSimulation from IntelliJ
+#### Run BasicOIDCSimulation from IntelliJ
 
-In ProjectExplorer find Engine object (you can use ctrl-N / cmd-O). Right click on class name and select Run or Debug like for
-JUnit tests.
+Make sure that `performance` maven profile is enabled for IDEA to treat `performance` directory as a project module. 
 
-You'll have to create a test profile, and set 'VM options' with -Dkey=value to override default configuration values in TestConfig class.
+You may also need to rebuild the module in IDEA for scala objects to become available.
+
+Then find Engine object In ProjectExplorer (you can use ctrl-N / cmd-O). Right click on class name and select Run or Debug as if it was
+a JUnit tests.
+
+You'll have to edit a test configuration, and set 'VM options' to a list of -Dkey=value pairs to override default configuration values in TestConfig class.
 
 Make sure to set 'Use classpath of module' to 'performance-test'. 
 
diff --git a/testsuite/performance/tests/pom.xml b/testsuite/performance/tests/pom.xml
index e12cdba..117bd80 100644
--- a/testsuite/performance/tests/pom.xml
+++ b/testsuite/performance/tests/pom.xml
@@ -93,7 +93,7 @@
         <scala-maven-plugin.version>3.2.2</scala-maven-plugin.version>
         <jboss-logging.version>3.3.0.Final</jboss-logging.version>
 
-        <gatling.simulationClass>keycloak.DefaultSimulation</gatling.simulationClass>
+        <gatling.simulationClass>keycloak.BasicOIDCSimulation</gatling.simulationClass>
         <gatling.skip.run>true</gatling.skip.run>
     </properties>
 
diff --git a/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java b/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java
index 4fb33b7..a0fbf2f 100644
--- a/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java
+++ b/testsuite/performance/tests/src/main/java/org/keycloak/performance/TestConfig.java
@@ -68,7 +68,7 @@ public class TestConfig {
     public static final long rampDownPeriodStartTime = simulationStartTime + (rampUpPeriod + steadyLoadPeriod) * 1000;
 
     //
-    // Settings used by DefaultSimulation to control behavior specific to DefaultSimulation
+    // Settings used by BasicOIDCSimulation to control behavior specific to BasicOIDCSimulation
     //
     public static final int badLoginAttempts = Integer.getInteger("badLoginAttempts", 0);
     public static final int refreshTokenCount = Integer.getInteger("refreshTokenCount", 0);
diff --git a/testsuite/performance/tests/src/test/scala/Engine.scala b/testsuite/performance/tests/src/test/scala/Engine.scala
index d71126b..c55af44 100644
--- a/testsuite/performance/tests/src/test/scala/Engine.scala
+++ b/testsuite/performance/tests/src/test/scala/Engine.scala
@@ -4,8 +4,8 @@ import io.gatling.core.config.GatlingPropertiesBuilder
 
 object Engine extends App {
 
-  val sim = classOf[keycloak.DefaultSimulation]
-  //val sim = classOf[keycloak.AdminSimulation]
+  val sim = classOf[keycloak.BasicOIDCSimulation]
+  //val sim = classOf[keycloak.AdminConsoleSimulation]
 
   val props = new GatlingPropertiesBuilder
   props.dataDirectory(IDEPathHelper.dataDirectory.toString)
diff --git a/testsuite/performance/tests/src/test/scala/examples/SimpleExample4.scala b/testsuite/performance/tests/src/test/scala/examples/SimpleExample4.scala
index c829fa4..f15f759 100644
--- a/testsuite/performance/tests/src/test/scala/examples/SimpleExample4.scala
+++ b/testsuite/performance/tests/src/test/scala/examples/SimpleExample4.scala
@@ -24,6 +24,7 @@ class SimpleExample4 extends Simulation {
     .exec(account)
 
   setUp(
+    // rather than starting all 100 users at once, increase the count over a period of 10 seconds
     scn.inject(rampUsers(100) over 10).protocols(httpConf)
   )
 }
diff --git a/testsuite/performance/tests/src/test/scala/keycloak/AdminConsoleSimulation.scala b/testsuite/performance/tests/src/test/scala/keycloak/AdminConsoleSimulation.scala
index d588582..836d97c 100644
--- a/testsuite/performance/tests/src/test/scala/keycloak/AdminConsoleSimulation.scala
+++ b/testsuite/performance/tests/src/test/scala/keycloak/AdminConsoleSimulation.scala
@@ -1,12 +1,10 @@
 package keycloak
 
 import io.gatling.core.Predef._
-import io.gatling.core.validation.Validation
 import io.gatling.http.Predef._
-import org.jboss.perf.util.Util
+
+import io.gatling.core.validation.Validation
 import org.keycloak.performance.TestConfig
-import org.keycloak.gatling.Utils._
-import SimulationsHelper._
 
 
 /**
@@ -14,6 +12,12 @@ import SimulationsHelper._
   */
 class AdminConsoleSimulation extends Simulation {
 
+  def rampDownPeriodNotReached(): Validation[Boolean] = {
+    System.currentTimeMillis < TestConfig.rampDownPeriodStartTime
+  }
+
+
+
   println()
   println("Target server: " + TestConfig.serverUrisList.get(0))
   println()
@@ -31,91 +35,72 @@ class AdminConsoleSimulation extends Simulation {
     .acceptLanguageHeader("en-US,en;q=0.5")
     .userAgentHeader("Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0")
 
-  val adminSession = exec(s => {
-      val realm = TestConfig.randomRealmsIterator().next()
-      val serverUrl = TestConfig.serverUrisList.get(0)
-      s.setAll(
-        "keycloakServer" -> serverUrl,
-        "keycloakServerUrlEncoded" -> urlencode(serverUrl),
-        "keycloakServerRootEncoded" -> urlEncodedRoot(serverUrl),
-        "state" -> Util.randomUUID(),
-        "nonce" -> Util.randomUUID(),
-        "randomClientId" -> ("client_" + Util.randomUUID()),
-        "realm" -> realm,
-        "username" -> "admin",
-        "password" -> "admin",
-        "clientId" -> "security-admin-console"
-      )
-    })
-
-    .exitHereIfFailed
-    .openAdminConsoleHome()
 
+
+
+  val adminSession = new AdminConsoleScenarioBuilder()
+    .openAdminConsoleHome()
     .thinkPause()
-    .acsim_loginThroughLoginForm()
-    .exitHereIfFailed
+    .loginThroughLoginForm()
+
+    .openRealmSettings()
 
     .thinkPause()
-    .acsim_openClients()
+    .openClients()
 
     .thinkPause()
-    .acsim_openCreateNewClient()
+    .openCreateNewClient()
 
     .thinkPause()
-    .acsim_submitNewClient()
+    .submitNewClient()
 
     .thinkPause()
-    .acsim_updateClient()
+    .updateClient()
 
     .thinkPause()
-    .acsim_openClients()
+    .openClients()
 
     .thinkPause()
-    .acsim_openClientDetails()
+    .openClientDetails()
 
     .thinkPause()
-    .acsim_openUsers()
+    .openUsers()
 
     .thinkPause()
-    .acsim_viewAllUsers()
+    .viewAllUsers()
 
     .thinkPause()
-    .acsim_viewTenPagesOfUsers()
+    .viewTenPagesOfUsers()
 
     .thinkPause()
-    .acsim_find20Users()
+    .find20Users()
 
     .thinkPause()
-    .acsim_findUnlimitedUsers()
+    .findUnlimitedUsers()
 
     .thinkPause()
-    .acsim_findRandomUser()
+    .findRandomUser()
+    .openUser()
 
-    .acsim_openUser()
+    .thinkPause()
+    .openUserCredentials()
 
     .thinkPause()
-    .acsim_openUserCredentials()
+    .setTemporaryPassword()
 
     .thinkPause()
-    .acsim_setTemporaryPassword()
+    .logout()
 
     .thinkPause()
-    .acsim_logOut()
 
 
   val adminScenario = scenario("AdminConsole")
     .asLongAs(s => rampDownPeriodNotReached(), null, TestConfig.rampDownASAP) {
       pace(TestConfig.pace)
-      adminSession
+      adminSession.chainBuilder
     }
 
   setUp(adminScenario
     .inject(rampUsers(TestConfig.runUsers) over TestConfig.rampUpPeriod)
     .protocols(httpProtocol))
-
-  
-  def rampDownPeriodNotReached(): Validation[Boolean] = {
-    System.currentTimeMillis < TestConfig.rampDownPeriodStartTime
-  }
-  
 }
diff --git a/testsuite/performance/tests/src/test/scala/keycloak/BasicOIDCSimulation.scala b/testsuite/performance/tests/src/test/scala/keycloak/BasicOIDCSimulation.scala
new file mode 100644
index 0000000..131de09
--- /dev/null
+++ b/testsuite/performance/tests/src/test/scala/keycloak/BasicOIDCSimulation.scala
@@ -0,0 +1,61 @@
+package keycloak
+
+import io.gatling.core.Predef._
+import io.gatling.http.Predef._
+import keycloak.BasicOIDCScenarioBuilder._
+
+import org.keycloak.performance.TestConfig
+
+
+/**
+  * @author Radim Vansa &lt;rvansa@redhat.com&gt;
+  * @author Marko Strukelj &lt;mstrukel@redhat.com&gt;
+  */
+class BasicOIDCSimulation extends Simulation {
+
+  println()
+  println("Target servers: " + TestConfig.serverUrisList)
+  println()
+
+  println("Using test parameters:\n" + TestConfig.toStringCommonTestParameters);
+  println("  refreshTokenCount: " + TestConfig.refreshTokenCount)
+  println("  badLoginAttempts: " + TestConfig.badLoginAttempts)
+  println()
+  println("Using dataset properties:\n" + TestConfig.toStringDatasetProperties)
+
+
+  val httpDefault = http
+    .acceptHeader("application/json")
+    .disableFollowRedirect
+    .inferHtmlResources
+
+  val userSession = new BasicOIDCScenarioBuilder()
+
+      .browserOpensLoginPage()
+
+      .thinkPause()
+      .browserPostsWrongCredentials()
+      .browserPostsCorrectCredentials()
+
+      // Act as client adapter - exchange code for keys
+      .adapterExchangesCodeForTokens()
+
+      .refreshTokenSeveralTimes()
+
+      .thinkPause()
+      .logout()
+
+      .thinkPause()
+
+
+  val usersScenario = scenario("users")
+    .asLongAs(s => rampDownPeriodNotReached(), null, TestConfig.rampDownASAP) {
+      pace(TestConfig.pace)
+      userSession.chainBuilder
+    }
+
+  setUp(usersScenario
+    .inject(rampUsers(TestConfig.runUsers) over TestConfig.rampUpPeriod)
+    .protocols(httpDefault))
+
+}