|
@@ -7,6 +7,7 @@ import java.sql.ResultSet;
|
|
|
import java.sql.SQLException;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.concurrent.ThreadLocalRandom;
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonGenerator;
|
|
|
import com.fasterxml.jackson.databind.*;
|
|
@@ -17,12 +18,13 @@ import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
|
|
|
* Some common functionality and constants used by the Servlet tests.
|
|
|
*/
|
|
|
public class Common {
|
|
|
+ private static final int DB_ROWS = 10000;
|
|
|
// Constants for setting the content type.
|
|
|
protected static final String HEADER_CONTENT_TYPE = "Content-Type";
|
|
|
protected static final String CONTENT_TYPE_JSON = "application/json";
|
|
|
protected static final String CONTENT_TYPE_TEXT = "text/plain";
|
|
|
protected static final String CONTENT_TYPE_HTML = "text/html";
|
|
|
-
|
|
|
+
|
|
|
// Jackson encoder, reused for each response.
|
|
|
protected static final ObjectMapper MAPPER = new ObjectMapper();
|
|
|
// Jackson encoder with AfterBurner module
|
|
@@ -53,6 +55,7 @@ public class Common {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ // Request parameter checking and normalisation
|
|
|
public static int normalise(String param) {
|
|
|
int count = 1;
|
|
|
try {
|
|
@@ -68,6 +71,7 @@ public class Common {
|
|
|
return count;
|
|
|
}
|
|
|
|
|
|
+ // Preload all the data for the cache query test
|
|
|
public static Map<Integer, CachedWorld> loadAll(Connection connection) throws SQLException{
|
|
|
// Fetch all rows from the database.
|
|
|
final Map<Integer, CachedWorld> worlds = new HashMap<Integer, CachedWorld>();
|
|
@@ -82,4 +86,13 @@ public class Common {
|
|
|
}
|
|
|
return worlds;
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ // Modify the SQL connection settings
|
|
|
+ public static void modifySQLConnectionSettings(Connection connection) throws SQLException {
|
|
|
+ connection.setAutoCommit(true);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getRandom() {
|
|
|
+ return 1 + ThreadLocalRandom.current().nextInt(DB_ROWS);
|
|
|
+ }
|
|
|
+}
|