usergrid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sfeld...@apache.org
Subject [3/6] git commit: new setup methodology
Date Thu, 06 Nov 2014 15:27:48 GMT
new setup methodology


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

Branch: refs/heads/key-row-sharding
Commit: cb43d8173fcbf36b436c6f2c0c0570f0835188ac
Parents: 1c0f931
Author: Shawn Feldman <sfeldman@apache.org>
Authored: Wed Nov 5 17:21:06 2014 -0700
Committer: Shawn Feldman <sfeldman@apache.org>
Committed: Wed Nov 5 17:21:06 2014 -0700

----------------------------------------------------------------------
 .../org/apache/usergrid/helpers/Setup.scala     | 96 +++++++++++++-------
 .../scenarios/NotificationScenarios.scala       |  5 +-
 .../usergrid/scenarios/UserScenarios.scala      |  3 -
 .../org/apache/usergrid/settings/Settings.scala |  3 +
 .../PushNotificationTargetUserSimulation.scala  |  2 +-
 5 files changed, 68 insertions(+), 41 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb43d817/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Setup.scala
----------------------------------------------------------------------
diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Setup.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Setup.scala
index 8072be8..bb1ae51 100644
--- a/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Setup.scala
+++ b/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Setup.scala
@@ -20,8 +20,10 @@
 
 package org.apache.usergrid.helpers
 
+import java.util
+
 import com.fasterxml.jackson.databind.ObjectMapper
-import com.ning.http.client.AsyncHttpClient
+import com.ning.http.client.{ListenableFuture, AsyncHttpClient,Response}
 import io.gatling.core.Predef._
 import io.gatling.http.Predef._
 import io.gatling.http.request.StringBody
@@ -29,26 +31,28 @@ import io.gatling.jsonpath.JsonPath
 import org.apache.usergrid.datagenerators.FeederGenerator
 import org.apache.usergrid.settings.{Settings, Headers}
 
+import scala.collection.mutable.ArrayBuffer
+
 /**
  * Classy class class.
  */
 object Setup {
   var token:String = null
+  val client = new AsyncHttpClient()
+
   def setupOrg(): Integer = {
-    val client = new AsyncHttpClient()
 
     val createOrgPost = client
       .preparePost(Settings.baseUrl + "/management/organizations")
-      .setBody("{\"organization\":\"" + Settings.org + "\",\"username\":\"" + Settings.admin
+ "\",\"name\":\"" + Settings.admin + "\",\"email\":\"" + Settings.admin + "@apigee.com\",\"password\":\""
+ Settings.password + "\"}")
-      .setHeader("Cache-Control", "no-cache")
+       .setHeader("Cache-Control", "no-cache")
       .setHeader("Content-Type", "application/json; charset=UTF-8")
-
-    val orgResponse = createOrgPost.execute().get();
-
+      .setBody("{\"organization\":\"" + Settings.org + "\",\"username\":\"" + Settings.admin
+ "\",\"name\":\"" + Settings.admin + "\",\"email\":\"" + Settings.admin + "@apigee.com\",\"password\":\""
+ Settings.password + "\"}")
+    .build()
+    val orgResponse = client.executeRequest(createOrgPost).get()
+    printResponse("POST ORG",orgResponse.getStatusCode,orgResponse.getResponseBody())
     return orgResponse.getStatusCode
   }
   def setupApplication():Integer = {
-    val client = new AsyncHttpClient()
 
     val authToken = getManagementToken()
     val createAppPost = client
@@ -57,16 +61,15 @@ object Setup {
       .setHeader("Cache-Control", "no-cache")
       .setHeader("Content-Type", "application/json; charset=UTF-8")
       .setHeader("Authorization","Bearer "+authToken)
+      .build()
 
-
-    val appResponse = createAppPost.execute().get();
-
+    val appResponse = client.executeRequest(createAppPost).get();
+    printResponse("POST Application",appResponse.getStatusCode, appResponse.getResponseBody())
 
     return appResponse.getStatusCode
   }
 
   def setupNotifier():Integer = {
-    val client = new AsyncHttpClient()
 
     val authToken = getManagementToken()
     val createNotifier = client
@@ -75,57 +78,82 @@ object Setup {
       .setHeader("Cache-Control", "no-cache")
       .setHeader("Content-Type", "application/json; charset=UTF-8")
       .setHeader("Authorization","Bearer "+authToken)
+      .build()
 
-    val notifierResponse = createNotifier.execute().get();
+    val notifierResponse = client.executeRequest(createNotifier).get();
+    printResponse("POST Notifier", notifierResponse.getStatusCode ,notifierResponse.getResponseBody())
 
     return notifierResponse.getStatusCode
   }
 
   def getManagementToken():String = {
-//    if(token==null) {
-
-      val client = new AsyncHttpClient()
+    if(token == null) {
       val getToken = client
         .preparePost(Settings.baseUrl + "/management/token")
         .setBody("{\"username\":\"" + Settings.admin + "\",\"password\":\"" + Settings.password
+ "\",\"grant_type\":\"password\"}")
         .setHeader("Cache-Control", "no-cache")
         .setHeader("Content-Type", "application/json; charset=UTF-8")
-      val body = getToken.execute().get().getResponseBody()
+        .build()
+      val response = client.executeRequest(getToken).get()
       val omapper = new ObjectMapper();
-      val tree = omapper.readTree(body)
+      val tree = omapper.readTree(response.getResponseBody())
       val node = tree.get("access_token");
-      token = node.toString
-//    }
+      token = node.asText()
+      println("Token is "+token)
+    }
     return token
   }
 
   def setupUsers() = {
-    val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers
*  Settings.duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude)
+    val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers
* Settings.duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude)
+    val list:ArrayBuffer[ListenableFuture[Response]] = new ArrayBuffer[ListenableFuture[Response]]
     userFeeder.foreach(user => {
-      setupUser(user);
+      list += setupUser(user);
     });
+    list.foreach(f => {
+      val response = f.get()
+      printResponse("Post user",response.getStatusCode,response.getResponseBody())
+    })
 
   }
 
-  def setupUser(user:Map[String,String]):Integer = {
-
-    val client = new AsyncHttpClient()
+  def setupUser(user:Map[String,String]):ListenableFuture[Response] = {
+
+    val latitude = user.get("latitude").get
+    val longitude = user.get("longitude").get
+    val username = user.get("username").get
+    val displayName = user.get("displayName").get
+    val age = user.get("age").get
+    val seen = user.get("seen").get
+    val weight = user.get("weight").get
+    val height = user.get("height").get
+    val aboutMe = user.get("aboutMe").get
+    val profileId = user.get("profileId").get
+    val headline = user.get("headline").get
+    val showAge = user.get("showAge").get
+    val relationshipStatus = user.get("relationshipStatus").get
+    val ethnicity = user.get("ethnicity").get
+    val password= user.get("password").get
+    val body = s"""{"location":{"latitude":"$latitude","longitude":"$longitude"},"username":"$username",
+      "displayName":"$displayName","age":"$age","seen":"$seen","weight":"$weight",
+      "height":"$height","aboutMe":"$aboutMe","profileId":"$profileId","headline":"$headline",
+      "showAge":"$showAge","relationshipStatus":"$relationshipStatus","ethnicity":"$ethnicity","password":"$password"}"""
 
     val authToken = getManagementToken()
     val createUser = client
       .preparePost(Settings.baseAppUrl + "/users")
-      .setBody("{\"location\":{\"latitude\":\"" + user.get("latitude") + "\",\"longitude\":\""
+ user.get("longitude") + "\"},\"username\":\"" + user.get("username") + "\"," +
-      "\"displayName\":\""+user.get("displayName")+"\",\"age\":\""+user.get("age")+"\",\"seen\":\""+user.get("seen")+"\",\"weight\":\""+user.get("weight")+"\","
+
-      "\"height\":\""+user.get("height")+"\",\"aboutMe\":\""+user.get("aboutMe")+"\",\"profileId\":\""+user.get("profileId")+"\",\"headline\":\""+user.get("headline")+"\","
+
-      "\"showAge\":\""+user.get("showAge")+"\",\"relationshipStatus\":\""+user.get("relationshipStatus")+"\",\"ethnicity\":\""+user.get("ethnicity")+"\",\"password\":\""+user.get("password")+"\"}"
-      )
-      .setHeader("Cache-Control", "no-cache")
-      .setHeader("Content-Type", "application/json; charset=UTF-8")
+      .setBody(body)
+      .setBodyEncoding("UTF-8")
       .setHeader("Authorization","Bearer "+authToken)
+      .build()
+
+    return client.executeRequest(createUser)
 
-    val createUserResponse = createUser.execute().get();
 
-    return createUserResponse.getStatusCode
+  }
+
+  def printResponse(caller:String, status:Int, body:String) = {
+    println(caller + ": status: "+status.toString+" body:"+body)
 
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb43d817/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 40f5085..b248260 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
@@ -68,13 +68,12 @@ object NotificationScenarios {
   )
 
   val numEntities:Int = Settings.numUsers * 3 * Settings.duration
-
-  val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers *
 Settings.duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude)
+  val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers, Settings.userLocationRadius,
Settings.centerLatitude, Settings.centerLongitude)
 
   val createScenario = scenario("Create Push Notification")
     .feed(userFeeder)
-    .exec( UserScenarios.getUserByUsername)
     .exec(TokenScenarios.getUserToken)
+    .exec( UserScenarios.getUserByUsername)
     .repeat(2){
     feed(FeederGenerator.generateEntityNameFeeder("device", numEntities))
       .exec( DeviceScenarios.postDeviceWithNotifier)

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb43d817/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 7a557e5..86d1f78 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
@@ -62,8 +62,5 @@ import io.gatling.core.Predef._
      .doIf("${userStatus}", "400") {
      exec(getUserByUsername)
    }
-   val numEntities:Int = Settings.numEntities
-
-   val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers *
 Settings.duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude)
 
  }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb43d817/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 5c7852b..90dd41d 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
@@ -18,6 +18,7 @@ package org.apache.usergrid.settings
 
 import io.gatling.core.Predef._
 import io.gatling.http.Predef._
+import org.apache.usergrid.datagenerators.FeederGenerator
 import scala.concurrent.duration._
 
 object Settings {
@@ -50,4 +51,6 @@ object Settings {
   val pushNotifier = System.getProperty("pushNotifier")
   val pushProvider = System.getProperty("pushProvider")
 
+  val constantUsers:Int = Settings.numUsers/Settings.duration
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/cb43d817/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 4c1de29..510cee1 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
@@ -35,7 +35,7 @@ class PushNotificationTargetUserSimulation extends Simulation {
   }
   setUp(
     NotificationScenarios.createScenario
-      .inject(constantUsersPerSec(Settings.numUsers) during (Settings.duration)) // wait
for 15 seconds so create org can finish, need to figure out coordination
+      .inject(constantUsersPerSec(Settings.constantUsers) during (Settings.duration)) //
wait for 15 seconds so create org can finish, need to figure out coordination
       .throttle(reachRps(Settings.throttle) in ( Settings.rampTime.seconds))
       .protocols( Settings.httpConf.acceptHeader("application/json"))
   )


Mime
View raw message