Browse Source

Need to distinguish single query apart from multiple queries (even if with a count of 1)

denka 10 years ago
parent
commit
ef293760b5

+ 1 - 1
frameworks/Java/grizzly-jersey/benchmark_config.json

@@ -4,7 +4,7 @@
     "default": {
     "default": {
       "setup_file": "setup",
       "setup_file": "setup",
       "json_url": "/json",
       "json_url": "/json",
-      "db_url": "/db",
+      "db_url": "/db?single=true",
       "query_url": "/db?queries=",
       "query_url": "/db?queries=",
       "fortune_url": "/fortunes",
       "fortune_url": "/fortunes",
       "port": 8080,
       "port": 8080,

+ 4 - 16
frameworks/Java/grizzly-jersey/src/main/java/hello/DbResource.java

@@ -11,6 +11,7 @@ import java.util.concurrent.ExecutionException;
 import java.util.concurrent.Future;
 import java.util.concurrent.Future;
 import java.util.concurrent.ThreadLocalRandom;
 import java.util.concurrent.ThreadLocalRandom;
 
 
+import javax.ws.rs.DefaultValue;
 import javax.ws.rs.GET;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
 import javax.ws.rs.Produces;
@@ -33,10 +34,10 @@ public class DbResource {
   
   
   @GET
   @GET
   @Produces(APPLICATION_JSON + "; charset=utf-8")
   @Produces(APPLICATION_JSON + "; charset=utf-8")
-  public Object db(@QueryParam("queries") String queriesParam)
+  public Object db(@QueryParam("queries") @DefaultValue("1") int queryNumber, @QueryParam("single") boolean isSingle)
       throws ExecutionException, InterruptedException {
       throws ExecutionException, InterruptedException {
 
 
-    final int queries = getQueries(queriesParam);
+    final int queries = Math.min(500, Math.max(1, queryNumber));
     final World[] worlds = new World[queries];
     final World[] worlds = new World[queries];
     final Random random = ThreadLocalRandom.current();
     final Random random = ThreadLocalRandom.current();
 
 
@@ -59,19 +60,6 @@ public class DbResource {
       worlds[i] = futureWorlds.get(i).get();
       worlds[i] = futureWorlds.get(i).get();
     }
     }
 
 
-    return queries == 1 ? worlds[0] : worlds;
-  }
-
-  private int getQueries(String proto) {
-    int result = 1;
-    try {
-      if (proto != null && !proto.trim().isEmpty()) {
-        result = Integer.parseInt(proto);
-      }
-    } catch (NumberFormatException e) {
-      throw new IllegalArgumentException(e);
-    }
-
-    return Math.min(500, Math.max(1, result));
+    return isSingle ? worlds[0] : worlds;
   }
   }
 }
 }