Added support for get-users-count and create-available-users into PerfTools

This commit is contained in:
mposolda committed 2014-06-27 15:51:02 +02:00
1 parent 4ebc575afc
commit 9ebe2ff45e
3 files changed
+47 -4

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
Adding users
------------
Adding 1000 new users (will start from last added user, so you don't need to explicitly check how many users to create are needed:
http://localhost:8081/keycloak-tools/perf/perf-realm/create-available-users?prefix=user&count=1000&batch=100&roles=user
Checking users count:
http://localhost:8081/keycloak-tools/perf/perf-realm/get-users-count?prefix=user
Switching to Mongo
------------------
Start with: (TODO)
-Dkeycloak.model.provider=mongo -Dkeycloak.model.mongo.db=keycloak-perf
@@ -16,9 +16,9 @@
},
"users" : [
{
"username" : "test-user@localhost",
"username" : "test@localhost",
"enabled": true,
"email" : "test-user@localhost",
"email" : "test@localhost",
"credentials" : [
{ "type" : "password",
"value" : "password" }
@@ -37,7 +37,7 @@
],
"roleMappings": [
{
"username": "test-user@localhost",
"username": "test@localhost",
"roles": ["user"]
}
],
@@ -92,7 +92,7 @@
"applicationRoleMappings": {
"perf-app": [
{
"username": "test-user@localhost",
"username": "test@localhost",
"roles": ["customer-user"]
}
]
@@ -17,9 +17,12 @@ import javax.ws.rs.QueryParam;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.atomic.AtomicInteger;
@@ -99,6 +102,33 @@ public class PerfTools {
}
}
@GET
@Path("{realm}/get-users-count")
public Response getUsersCountReq(@PathParam("realm") String realmName, @QueryParam("prefix") String prefix) {
int usersCount = getUsersCount(realmName, prefix);
return Response.ok(String.valueOf(usersCount)).build();
}
// Same as createUsers, but dynamically compute "start" (Next available user)
@GET
@Path("{realm}/create-available-users")
public Response createAvailableUsers(@PathParam("realm") String realmName, @QueryParam("count") Integer count, @QueryParam("batch") Integer batch, @QueryParam("prefix") String prefix, @QueryParam("roles") String roles) throws InterruptedException {
int start = getUsersCount(realmName, prefix);
return createUsers(realmName, count, batch, start, prefix, roles);
}
private int getUsersCount(String realmName, String prefix) {
RealmModel realm = session.getRealmByName(realmName);
// TODO: method for count on model
if (prefix == null) {
return realm.getUsers().size();
} else {
return realm.searchForUser(prefix).size();
}
}
@GET
@Path("export")
public void export(@QueryParam("dir") String dir) {