usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From toddn...@apache.org
Subject [10/50] git commit: working push tests with authentication
Date Thu, 06 Nov 2014 00:14:56 GMT
working push tests with authentication


Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/73c67503
Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/73c67503
Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/73c67503

Branch: refs/heads/two-dot-o
Commit: 73c67503656ee13e402e4c98edc0223a8350c45d
Parents: c02e77e
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Fri Oct 31 17:08:47 2014 -0600
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Fri Oct 31 17:08:47 2014 -0600

----------------------------------------------------------------------
 .../scenarios/ConnectionScenarios.scala         | 10 +++++---
 .../usergrid/scenarios/DeviceScenarios.scala    |  8 ++++---
 .../usergrid/scenarios/GeoScenarios.scala       |  6 ++++-
 .../scenarios/NotificationScenarios.scala       |  4 +++-
 .../usergrid/scenarios/NotifierScenarios.scala  |  6 +++--
 .../scenarios/OrganizationScenarios.scala       | 17 ++++++++++----
 .../usergrid/scenarios/TokenScenarios.scala     | 22 ++----------------
 .../usergrid/scenarios/UserScenarios.scala      | 14 ++++++++++--
 .../org/apache/usergrid/settings/Settings.scala |  3 ++-
 .../PushNotificationTargetUserSimulation.scala  | 24 ++++++++++++--------
 10 files changed, 67 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/ConnectionScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/ConnectionScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/ConnectionScenarios.scala
index 4a5e2ae..8037ade 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/ConnectionScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/ConnectionScenarios.scala
@@ -18,19 +18,23 @@
 
 import io.gatling.core.Predef._
 import io.gatling.http.Predef._
+ import org.apache.usergrid.settings.Headers
 
-object ConnectionScenarios {
+ object ConnectionScenarios {
 
   val postConnection = exec(
     http("POST connection")
     .post("/users/${user1}/likes/users/${user2}")
-    .check(status.is(200))
+      .headers(Headers.jsonAuthorized)
+
+      .check(status.is(200))
   )
 
   val postUserToDeviceConnection = exec(
     http("Connect user with device")
     .post("/users/${username}/devices/${deviceId}")
-    .check(status.is(200))
+      .headers(Headers.jsonAuthorized)
+      .check(status.is(200))
   )
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/DeviceScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/DeviceScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/DeviceScenarios.scala
index 5737e24..ad1b821 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/DeviceScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/DeviceScenarios.scala
@@ -19,7 +19,7 @@ package org.apache.usergrid.scenarios
 import io.gatling.core.Predef._
 import io.gatling.http.Predef.StringBody
 import io.gatling.http.Predef._
-import org.apache.usergrid.settings.Settings
+import org.apache.usergrid.settings.{Headers, Settings}
 
 /**
  *
@@ -46,6 +46,7 @@ object DeviceScenarios {
    */
   val postDeviceWithNotifier = exec(http("Create device with notifier")
     .post("/devices")
+    .headers(Headers.jsonAuthorized)
     .body(StringBody("""{"deviceModel":"Fake Device",
     "deviceOSVerion":"Negative Version",
     """" + notifier + """.notifier.id":"${entityName}"}"""))
@@ -54,6 +55,7 @@ object DeviceScenarios {
 
   val postDeviceWithNotifier400ok = exec(http("Create device with notifier")
     .post("/devices")
+    .headers(Headers.jsonAuthorized)
     .body(StringBody("""{"name":"${entityName}",
     "deviceModel":"Fake Device",
     "deviceOSVerion":"Negative Version",
@@ -66,13 +68,13 @@ object DeviceScenarios {
    */
   val maybeCreateDevice = exec(
     //try to do a GET on device name, if it 404's create it
-    http("Check and create device").get("/devices/${entityName}").check(status.not(404).saveAs("deviceExists")))
+    http("Check and create device").get("/devices/${entityName}").headers(Headers.jsonAuthorized).check(status.not(404).saveAs("deviceExists")))
     //create the device if we got a 404
     .doIf("${deviceExists}", "404") {
 
     exec(
 
-      http("Create device and save deviceId").post("/devices").body(StringBody(
+      http("Create device and save deviceId").post("/devices").headers(Headers.jsonAuthorized).body(StringBody(
         """{"name":"${entityName}",
           "deviceModel":"Fake Device",
           "deviceOSVerion":"Negative Version",

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/GeoScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/GeoScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/GeoScenarios.scala
index 2954abd..d5ce7c7 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/GeoScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/GeoScenarios.scala
@@ -18,19 +18,22 @@
 
 import io.gatling.core.Predef._
 import io.gatling.http.Predef._
- import org.apache.usergrid.settings.{Utils, Settings}
+ import org.apache.usergrid.settings.{Headers, Utils, Settings}
 
  object GeoScenarios {
 
   val getGeolocation = exec(
       http("GET geolocated user")
         .get("/users?ql=location%20within%20" + Settings.geosearchRadius + "%20of%20${latitude},${longitude}")
+        .headers(Headers.jsonAuthorized)
+
         .check(status.is(200))
     )
 
   val getGeolocationWithQuery = exec(
       http("GET geolocated user with query")
         .get("/users?ql=${queryParams}%20AND%20location%20within%20" + Settings.geosearchRadius
+ "%20of%20${latitude},${longitude}")
+        .headers(Headers.jsonAuthorized)
         .check(status.is(200))
     )
 
@@ -38,6 +41,7 @@ import io.gatling.http.Predef._
     http("PUT user location")
       .put("/users/user" + Utils.generateRandomInt(1, Settings.numUsers))
       .body(StringBody("{\"location\":{\"latitude\":\"${latitude}\",\"longitude\":\"${longitude}\"}}"))
+      .headers(Headers.jsonAuthorized)
       .check(status.is(200))
   )
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotificationScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotificationScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotificationScenarios.scala
index 2ac8995..f17e6d0 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotificationScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotificationScenarios.scala
@@ -25,7 +25,7 @@ import scala.concurrent.duration._
 
 import scala.io.Source
 
-import org.apache.usergrid.settings.Settings
+import org.apache.usergrid.settings.{Headers, Settings}
 
 /**
  *
@@ -55,12 +55,14 @@ object NotificationScenarios {
   val sendNotification = exec(http("Send Single Notification")
       .post("/devices/${entityName}/notifications")
       .body(StringBody("{\"payloads\":{\"" + notifier + "\":\"testmessage\"}}"))
+      .headers(Headers.jsonAuthorized)
       .check(status.is(200))
     )
 
   val sendNotificationToUser= exec(http("Send Notification to All Devices")
     .post("/users/${userId}/notifications")
     .body(StringBody("{\"payloads\":{\"" + notifier + "\":\"testmessage\"}}"))
+    .headers(Headers.jsonAuthorized)
     .check(status.is(200))
   )
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotifierScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotifierScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotifierScenarios.scala
index 00cdd71..37070a7 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotifierScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/NotifierScenarios.scala
@@ -18,7 +18,7 @@
 
 import io.gatling.core.Predef._
 import io.gatling.http.Predef._
- import org.apache.usergrid.settings.Settings
+ import org.apache.usergrid.settings.{Headers, Settings}
  import scala.concurrent.duration._
 
 /**
@@ -41,6 +41,8 @@ object NotifierScenarios {
   
   val notifier = Settings.pushNotifier
   val provider = Settings.pushProvider
+  val org = Settings.org
+  val app = Settings.app
 
   /**
    * Create a notifier
@@ -53,7 +55,7 @@ object NotifierScenarios {
     )
 
     .exec(http("Create Notifier")
-    .post("/notifiers")
+    .post(Settings.baseAppUrl+"/notifiers")
     .body(StringBody("{\"name\":\"" + notifier + "\",\"provider\":\"" + provider + "\"}"))
     //remnants of trying to upload an apple certificate
 //    .param("name", "${notifierName}")

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/OrganizationScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/OrganizationScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/OrganizationScenarios.scala
index f79efd6..8326d70 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/OrganizationScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/OrganizationScenarios.scala
@@ -35,9 +35,18 @@ object OrganizationScenarios {
 
   //register the org with the randomly generated org
   val createOrgAndAdmin = exec(http("Create Organization")
-  .post("/management/organizations")
-  .headers(Headers.jsonAnonymous)
-  .body(StringBody("{\"organization\":\"" + Settings.org + "\",\"username\":\"${entityName}\",\"name\":\"${entityName}\",\"email\":\"${entityName}@apigee.com\",\"password\":\"test\"}"))
-  .check(status.is(200)))
+    .post(Settings.baseUrl+"/management/organizations")
+    .headers(Headers.jsonAnonymous)
+    .body(StringBody("{\"organization\":\"" + Settings.org + "\",\"username\":\"" + Settings.org
+ "\",\"name\":\"${entityName}\",\"email\":\"${entityName}@apigee.com\",\"password\":\"test\"}"))
+    .check(status.in(200 to 400))
+  )
+
+  val getManagementToken = exec(http("POST Org Token")
+    .post(Settings.baseUrl+"/management/token")
+    .headers(Headers.jsonAnonymous)
+    //pass in the the username and password, store the "access_token" json response element
as the var "authToken" in the session
+    .body(StringBody("{\"username\":\"" + Settings.org + "\",\"password\":\"test\",\"grant_type\":\"password\"}"))
+    .check(jsonPath("$.access_token").find(0).saveAs("authToken"))
+  )
 
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/TokenScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/TokenScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/TokenScenarios.scala
index 3508d6f..a08701b 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/TokenScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/TokenScenarios.scala
@@ -19,6 +19,8 @@
 import io.gatling.core.Predef._
 import io.gatling.http.Predef._
  import org.apache.usergrid.settings.Headers
+ import org.apache.usergrid.settings.Settings
+
  import scala.concurrent.duration._
 
 /**
@@ -37,24 +39,4 @@ import io.gatling.http.Predef._
 
 object TokenScenarios {
 
-
-  val getManagementToken =
-    exec(
-      http("POST Org Token")
-        .post("/management/token")
-        .headers(Headers.jsonAnonymous)
-        //pass in the the username and password, store the "access_token" json response element
as the var "authToken" in the session
-        .body(StringBody("{\"username\":\"${username}\",\"password\":\"${password}\",\"grant_type\":\"password\"}"))
-        .check(jsonPath("access_token")
-        .saveAs("authToken"))
-    )
-
-  val getUserToken =
-    exec(
-      http("POST user token")
-        .post("/token")
-        .body(StringBody("{\"grant_type\":\"password\",\"username\":\"${user1}\",\"password\":\"password\"}"))
-        .check(status.is(200))
-    )
-
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/UserScenarios.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/UserScenarios.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/UserScenarios.scala
index a2fa227..596b411 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/UserScenarios.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/scenarios/UserScenarios.scala
@@ -17,28 +17,30 @@
  package org.apache.usergrid.scenarios
 
 import io.gatling.core.Predef._
- import io.gatling.http.Predef.StringBody
  import io.gatling.http.Predef._
  import io.gatling.http.request.StringBody
- import org.apache.usergrid.settings.{Settings, Utils}
+ import org.apache.usergrid.settings.{Headers, Settings, Utils}
 
  object UserScenarios {
 
   val getRandomUser = exec(
     http("GET user")
       .get("/users/user" + Utils.generateRandomInt(1, Settings.numEntities))
+      .headers(Headers.jsonAuthorized)
       .check(status.is(200))
   )
 
    val getUserByUsername = exec(
      http("GET user")
        .get("/users/${username}")
+       .headers(Headers.jsonAuthorized)
        .check(status.is(200), jsonPath("$..entities[0].uuid").saveAs("userId"))
    )
 
   val postUser = exec(
     http("POST geolocated Users")
       .post("/users")
+      .headers(Headers.jsonAuthorized)
       .body(new StringBody("""{"location":{"latitude":"${latitude}","longitude":"${longitude}"},"username":"${username}",
       "displayName":"${displayName}","age":"${age}","seen":"${seen}","weight":"${weight}",
       "height":"${height}","aboutMe":"${aboutMe}","profileId":"${profileId}","headline":"${headline}",
@@ -47,4 +49,12 @@ import io.gatling.core.Predef._
     .doIf ("${userStatus}", "400") {
       exec(getUserByUsername)
     }
+
+   val getUserToken =
+     exec(
+       http("POST user token")
+         .post("/token")
+         .body(StringBody("{\"grant_type\":\"password\",\"username\":\"${username}\",\"password\":\"password\"}"))
+         .check(status.is(200),jsonPath("$..access_token").exists,jsonPath("$..access_token").saveAs("authToken"))
+     )
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala
index bb82100..1f3add5 100755
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/settings/Settings.scala
@@ -26,7 +26,8 @@ object Settings {
   val org = System.getProperty("org")
   val app = System.getProperty("app")
   val baseUrl = System.getProperty("baseurl")
-  val httpConf = http.baseURL(baseUrl + "/" + org + "/" + app)
+  val baseAppUrl = baseUrl + "/" + org + "/" + app
+  val httpConf = http.baseURL(baseAppUrl)
 
   // Simulation settings
   val numUsers:Int = Integer.getInteger("numUsers", 10).toInt

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/73c67503/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/PushNotificationTargetUserSimulation.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/PushNotificationTargetUserSimulation.scala
b/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/PushNotificationTargetUserSimulation.scala
index af95f8b..dc2dc9c 100644
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/PushNotificationTargetUserSimulation.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/PushNotificationTargetUserSimulation.scala
@@ -42,6 +42,10 @@ class PushNotificationTargetUserSimulation extends Simulation {
   val createOrg = OrganizationScenarios.createOrgAndAdmin
   val connectUserToDevice = ConnectionScenarios.postUserToDeviceConnection
 
+  val getManagementToken = OrganizationScenarios.getManagementToken;
+
+  val getUserToken = UserScenarios.getUserToken
+
   val deviceNameFeeder = FeederGenerator.generateEntityNameFeeder("device", numEntities)
   val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(numUsersPerSecond *
duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude)
   val orgFeeder = FeederGenerator.generateRandomEntityNameFeeder("org", 1)
@@ -49,24 +53,24 @@ class PushNotificationTargetUserSimulation extends Simulation {
   val scnCreateOrg = scenario("Create org")
     .feed(orgFeeder)
     .exec(createOrg)
-
-  val scnCreateNotifier = scenario("Create notifier")
+    .exec(getManagementToken)
     .exec(createNotifier)
 
   val scnToRun = scenario("Create Push Notification")
+    .exec(getManagementToken)
     .feed(userFeeder)
     .exec(createUser)
+    .exec(getUserToken)
     .repeat(2){
       feed(deviceNameFeeder)
-      .exec(createDevice)
-      .exec(connectUserToDevice)
-    }
+        .exec(createDevice)
+        .exec(connectUserToDevice)
+      }
     .exec(sendNotification)
 
-
-
-  setUp(scnCreateOrg.inject(atOnceUsers(1)).protocols(http.baseURL(Settings.baseUrl)),
-    scnCreateNotifier.inject(nothingFor(5), atOnceUsers(1)).protocols(httpConf),
-    scnToRun.inject(nothingFor(7), constantUsersPerSec(numUsersPerSecond) during (duration)).throttle(reachRps(throttle)
in (rampTime.seconds)).protocols(httpConf))
+  setUp(
+    scnCreateOrg.inject(atOnceUsers(1)).protocols(http.baseURL(Settings.baseUrl)),
+    scnToRun.inject(nothingFor(30), constantUsersPerSec(numUsersPerSecond) during (duration))
+      .throttle(reachRps(throttle) in (rampTime.seconds)).protocols(httpConf))
 
 }


Mime
View raw message