Repository: incubator-usergrid Updated Branches: refs/heads/two-dot-o 795874e37 -> 2a0ed717a
moving user creation to setup Project: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/commit/60055e47 Tree: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/tree/60055e47 Diff: http://git-wip-us.apache.org/repos/asf/incubator-usergrid/diff/60055e47 Branch: refs/heads/two-dot-o Commit: 60055e47ee1d02dfdc8667fb7ccdb39424229909 Parents: e351179 Author: Shawn Feldman <[email protected]> Authored: Wed Nov 5 14:30:45 2014 -0700 Committer: Shawn Feldman <[email protected]> Committed: Wed Nov 5 14:30:45 2014 -0700 ---------------------------------------------------------------------- .../datagenerators/EntityDataGenerator.scala | 5 +- .../org/apache/usergrid/helpers/Setup.scala | 132 +++++++++++++++++++ .../scenarios/NotificationScenarios.scala | 8 +- .../usergrid/scenarios/UserScenarios.scala | 18 ++- .../simulations/GeoProfileSimulation.scala | 33 +++++ .../PushNotificationTargetUserSimulation.scala | 22 ++-- 6 files changed, 200 insertions(+), 18 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60055e47/stack/loadtests/src/main/scala/org/apache/usergrid/datagenerators/EntityDataGenerator.scala ---------------------------------------------------------------------- diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/datagenerators/EntityDataGenerator.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/datagenerators/EntityDataGenerator.scala index b0a4771..6917930 100755 --- a/stack/loadtests/src/main/scala/org/apache/usergrid/datagenerators/EntityDataGenerator.scala +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/datagenerators/EntityDataGenerator.scala @@ -43,7 +43,7 @@ object EntityDataGenerator { def generateUser(userId: Int): Map[String,String] = { - return Map("username" -> "user".concat(userId.toString).concat(UUID.randomUUID().toString), + return Map("username" -> "user".concat(userId.toString), "profileId" -> Utils.generateRandomInt(10000, 1000000).toString, "displayName" -> Utils.generateRandomInt(10000, 1000000).toString, "showAge" -> Utils.generateRandomInt(0, 1).toString, @@ -54,7 +54,8 @@ object EntityDataGenerator { "age" -> Utils.generateRandomInt(18, 65).toString, "height" -> Utils.generateRandomInt(48, 84).toString, "weight" -> Utils.generateRandomInt(120, 350).toString, - "seen" -> Utils.generateRandomInt(50, 100000).toString + "seen" -> Utils.generateRandomInt(50, 100000).toString, + "password" -> "password" ) } http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60055e47/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 new file mode 100644 index 0000000..8072be8 --- /dev/null +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/helpers/Setup.scala @@ -0,0 +1,132 @@ +/* + * + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. The ASF licenses this file to You + * * under the Apache License, Version 2.0 (the "License"); you may not + * * use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. For additional information regarding + * * copyright in this work, please see the NOTICE file in the top level + * * directory of this distribution. + * + */ + +package org.apache.usergrid.helpers + +import com.fasterxml.jackson.databind.ObjectMapper +import com.ning.http.client.AsyncHttpClient +import io.gatling.core.Predef._ +import io.gatling.http.Predef._ +import io.gatling.http.request.StringBody +import io.gatling.jsonpath.JsonPath +import org.apache.usergrid.datagenerators.FeederGenerator +import org.apache.usergrid.settings.{Settings, Headers} + +/** + * Classy class class. + */ +object Setup { + var token:String = null + 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("Content-Type", "application/json; charset=UTF-8") + + val orgResponse = createOrgPost.execute().get(); + + return orgResponse.getStatusCode + } + def setupApplication():Integer = { + val client = new AsyncHttpClient() + + val authToken = getManagementToken() + val createAppPost = client + .preparePost(Settings.baseUrl + "/management/organizations/"+Settings.org+"/applications") + .setBody("{\"name\":\"" + Settings.app + "\"}") + .setHeader("Cache-Control", "no-cache") + .setHeader("Content-Type", "application/json; charset=UTF-8") + .setHeader("Authorization","Bearer "+authToken) + + + val appResponse = createAppPost.execute().get(); + + + return appResponse.getStatusCode + } + + def setupNotifier():Integer = { + val client = new AsyncHttpClient() + + val authToken = getManagementToken() + val createNotifier = client + .preparePost(Settings.baseAppUrl + "/notifiers") + .setBody("{\"name\":\"" + Settings.pushNotifier + "\",\"provider\":\"" + Settings.pushProvider + "\"}") + .setHeader("Cache-Control", "no-cache") + .setHeader("Content-Type", "application/json; charset=UTF-8") + .setHeader("Authorization","Bearer "+authToken) + + val notifierResponse = createNotifier.execute().get(); + + return notifierResponse.getStatusCode + } + + def getManagementToken():String = { +// if(token==null) { + + val client = new AsyncHttpClient() + 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() + val omapper = new ObjectMapper(); + val tree = omapper.readTree(body) + val node = tree.get("access_token"); + token = node.toString +// } + return token + } + + def setupUsers() = { + val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers * Settings.duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude) + userFeeder.foreach(user => { + setupUser(user); + }); + + } + + def setupUser(user:Map[String,String]):Integer = { + + val client = new AsyncHttpClient() + + 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") + .setHeader("Authorization","Bearer "+authToken) + + val createUserResponse = createUser.execute().get(); + + return createUserResponse.getStatusCode + + } + +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60055e47/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 8556845..40f5085 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 @@ -72,14 +72,8 @@ object NotificationScenarios { val userFeeder = FeederGenerator.generateUserWithGeolocationFeeder(Settings.numUsers * Settings.duration, Settings.userLocationRadius, Settings.centerLatitude, Settings.centerLongitude) val createScenario = scenario("Create Push Notification") - .asLongAs(session=>session.get("applicationStatus")!="200" && session.get("notifierStatus")!="200"){ - exec(TokenScenarios.getManagementToken) - .exec(ApplicationScenarios.checkApplication) - .exec(NotifierScenarios.checkNotifier) - .exec(session=>{session.remove("authToken")}) - } .feed(userFeeder) - .exec( UserScenarios.postUser) + .exec( UserScenarios.getUserByUsername) .exec(TokenScenarios.getUserToken) .repeat(2){ feed(FeederGenerator.generateEntityNameFeeder("device", numEntities)) http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60055e47/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 ae756dc..7a557e5 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 @@ -19,6 +19,7 @@ import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.gatling.http.request.StringBody + import org.apache.usergrid.datagenerators.FeederGenerator import org.apache.usergrid.settings.{Headers, Settings, Utils} object UserScenarios { @@ -49,5 +50,20 @@ import io.gatling.core.Predef._ exec(getUserByUsername) } + val putUser = exec( + http("POST geolocated Users") + .put("/users") + .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}", + "showAge":"${showAge}","relationshipStatus":"${relationshipStatus}","ethnicity":"${ethnicity}","password":"password"}""")) + .check(status.is(200), status.saveAs("userStatus"), jsonPath("$..entities[0].uuid").saveAs("userId")) + ) + .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/60055e47/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/GeoProfileSimulation.scala ---------------------------------------------------------------------- diff --git a/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/GeoProfileSimulation.scala b/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/GeoProfileSimulation.scala new file mode 100644 index 0000000..b8b8839 --- /dev/null +++ b/stack/loadtests/src/main/scala/org/apache/usergrid/simulations/GeoProfileSimulation.scala @@ -0,0 +1,33 @@ +/* + * + * * Licensed to the Apache Software Foundation (ASF) under one or more + * * contributor license agreements. The ASF licenses this file to You + * * under the Apache License, Version 2.0 (the "License"); you may not + * * use this file except in compliance with the License. + * * You may obtain a copy of the License at + * * + * * http://www.apache.org/licenses/LICENSE-2.0 + * * + * * Unless required by applicable law or agreed to in writing, software + * * distributed under the License is distributed on an "AS IS" BASIS, + * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * * See the License for the specific language governing permissions and + * * limitations under the License. For additional information regarding + * * copyright in this work, please see the NOTICE file in the top level + * * directory of this distribution. + * + */ + +package org.apache.usergrid.simulations + +import io.gatling.core.Predef._ +import io.gatling.http.Predef._ +import org.apache.usergrid.scenarios.{OrganizationScenarios, UserScenarios} +import org.apache.usergrid.settings.Settings + +/** + * Classy class class. + */ +class GeoProfileSimulation extends Simulation { + +} http://git-wip-us.apache.org/repos/asf/incubator-usergrid/blob/60055e47/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 67447e0..4c1de29 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 @@ -16,22 +16,28 @@ */ package org.apache.usergrid.simulations +import com.ning.http.client.AsyncHttpClient import io.gatling.core.Predef._ import io.gatling.http.Predef._ import org.apache.usergrid.scenarios._ import org.apache.usergrid.settings.Settings import scala.concurrent.duration._ +import org.apache.usergrid.helpers.Setup class PushNotificationTargetUserSimulation extends Simulation { - val scnToRun = NotificationScenarios.createScenario - .inject(constantUsersPerSec(Settings.numUsers) 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")) - val createOrg = OrganizationScenarios.createOrgScenario - .inject(atOnceUsers(1)) - .protocols(http.baseURL(Settings.baseUrl)) - setUp(createOrg,scnToRun) + before{ + Setup.setupOrg() + Setup.setupApplication() + Setup.setupNotifier() + Setup.setupUsers() + } + setUp( + NotificationScenarios.createScenario + .inject(constantUsersPerSec(Settings.numUsers) 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")) + ) }
