You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by dj...@apache.org on 2007/02/23 22:57:19 UTC
svn commit: r511126 - in
/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe:
client/Load.java load/SimpleInsert.java run/Populate.java run/Schema.java
Author: djd
Date: Fri Feb 23 13:57:19 2007
New Revision: 511126
URL: http://svn.apache.org/viewvc?view=rev&rev=511126
Log:
Re-factor the Load and SimpleInsert for the oe system test kit to support addition of a multi-threaded loader implementation.
Fix a bug in the Schema.java test that did not report times for the executions.
Modified:
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Load.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java
db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Load.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Load.java?view=diff&rev=511126&r1=511125&r2=511126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Load.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Load.java Fri Feb 23 13:57:19 2007
@@ -83,6 +83,17 @@
* @throws Exception
*/
public void setupLoad(Connection conn, short scale) throws Exception;
+
+ /**
+ * Set the number of total threads the loader is allowed to use
+ * to load data.
+ * If an implementation does not support multiple threads then
+ * the passed in value will be ignored.
+ *
+ * @param threadCount Number of threads to use if loading supports
+ * multiple threading.
+ */
+ public void setThreadCount(int threadCount);
/**
* Follow the initial database population requirements in Section 4.3.3
@@ -93,6 +104,6 @@
*
* @throws SQLException
*/
- public void populateAllTables() throws SQLException;
+ public void populateAllTables() throws Exception;
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java?view=diff&rev=511126&r1=511125&r2=511126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/load/SimpleInsert.java Fri Feb 23 13:57:19 2007
@@ -43,7 +43,7 @@
/**
* Seed value for random number generator.
*/
- private long seed = System.currentTimeMillis();
+ long seed = System.currentTimeMillis();
/**
* Utility to generate random data per the TPC-C requirements
@@ -62,9 +62,7 @@
*/
public void setupLoad(Connection conn, short scale) throws SQLException {
- this.conn = conn;
- conn.setAutoCommit(false);
- conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+ setupConnection(conn, scale);
Statement s = conn.createStatement();
try {
@@ -81,10 +79,38 @@
// Section 2.1.6.1 of TPC-C spec
int loadRandomFactor = random.randomInt(0, 255);
s.execute("INSERT INTO C VALUES(" + loadRandomFactor + ", -1, -1, -1)");
+ s.close();
+ conn.commit();
+
+ setRandomGenerator();
+ }
+
+ /**
+ * Set the connection up to the intended state.
+ * Intended for use by sub-classes.
+ */
+ void setupConnection(Connection conn, short scale) throws SQLException
+ {
+ this.conn = conn;
+ conn.setAutoCommit(false);
+ conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+ this.scale = scale;
+ }
+
+ /**
+ * Setup the random number generator to be used for the load.
+ * @throws SQLException
+ */
+ void setRandomGenerator() throws SQLException
+ {
+ Statement s = conn.createStatement();
+ ResultSet rs = s.executeQuery("SELECT CLOAD FROM C");
+ rs.next();
+ int loadRandomFactor = rs.getInt(1);
+ rs.close();
random = new OERandom(loadRandomFactor, -1, -1, seed);
+ s.close();
conn.commit();
-
- this.scale = scale;
}
/**
@@ -93,27 +119,36 @@
*
* @throws SQLException
*/
- public void populateAllTables() throws SQLException {
+ public void populateAllTables() throws Exception {
// load item table
itemTable(1, Load.ITEM_COUNT);
- // for each row in warehouse table, load the stock,
- // district table. For each row in district table, load
- // the customer table. for each row in customer table, load
- // the history, and order table.
-
for (short w = 1; w <= scale; w++) {
- warehouseTable(w);
- // for each warehouse: load the stock table
- stockTable(1, Load.STOCK_COUNT_W, w);
- for (short d = 1; d <= Load.DISTRICT_COUNT_W; d++) {
- districtTable(w, d);
- customerTable(w, d);
- orderTable(w, d);
- }
+ populateForOneWarehouse(w);
}
}
+
+ /**
+ * Populate all the tables needed for a specific warehouse.
+ * for each row in warehouse table, load the stock,
+ * district table. For each row in district table, load
+ * the customer table. for each row in customer table, load
+ * the customer table. for each row in customer table, load
+ * @param w Warehouse to be populated.
+ * @throws SQLException
+ */
+ void populateForOneWarehouse(short w) throws SQLException
+ {
+ warehouseTable(w);
+ // for each warehouse: load the stock table
+ stockTable(1, Load.STOCK_COUNT_W, w);
+ for (short d = 1; d <= Load.DISTRICT_COUNT_W; d++) {
+ districtTable(w, d);
+ customerTable(w, d);
+ orderTable(w, d);
+ }
+ }
/**
* Populate the ITEM table. See population requirements in section 4.3.3.1
@@ -410,6 +445,12 @@
public void setSeed(long seed) {
this.seed = seed;
+ }
+
+ /**
+ * Ignore, this is a single threaded load.
+ */
+ public void setThreadCount(int threadCount) {
}
}
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java?view=diff&rev=511126&r1=511125&r2=511126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Populate.java Fri Feb 23 13:57:19 2007
@@ -65,7 +65,7 @@
/**
* Warehouse scale factor
*/
- private static short scale = 1;
+ static short scale = 1;
/**
* flag to indicate if we should create constraints before loading data
@@ -81,7 +81,7 @@
/**
* Load implementation used to populate the database
*/
- private Load loader;
+ Load loader;
/**
* Create a test case with the given name.
@@ -126,7 +126,7 @@
* parse arguments.
* @param args arguments to parse
*/
- private static void parseArgs(String[] args) {
+ static void parseArgs(String[] args) {
for (int i = 0; i < args.length; i++) {
String arg = args[i];
if (arg.equals("-scale")) {
@@ -162,7 +162,11 @@
*
* @return the tests to run
*/
- public static Test suite() throws Exception {
+ public static Test suite() {
+ return loaderSuite(Populate.class);
+ }
+
+ static Test loaderSuite(Class loader) {
TestSuite suite = new TestSuite("Order Entry");
// Create Schema
@@ -171,7 +175,7 @@
Schema.addConstraints(suite);
// this will populate db
- suite.addTest(new Populate("testLoad"));
+ suite.addTestSuite(loader);
if (!createConstraintsBeforeLoad)
Schema.addConstraints(suite);
Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java?view=diff&rev=511126&r1=511125&r2=511126
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java Fri Feb 23 13:57:19 2007
@@ -34,6 +34,7 @@
*/
public class Schema extends JDBCPerfTestCase {
+ private String scriptBase;
/**
* Create a test case with the given name.
@@ -42,7 +43,8 @@
* of the test case.
*/
public Schema(String name) {
- super(name);
+ super("testScript");
+ scriptBase = name;
}
/**
@@ -81,11 +83,15 @@
/**
* Run a Order Entry script.
*/
- public void runTest() throws UnsupportedEncodingException,
+ public void testScript() throws UnsupportedEncodingException,
SQLException, PrivilegedActionException, IOException {
- String script = "org/apache/derbyTesting/system/oe/schema/" + getName();
+ String script = "org/apache/derbyTesting/system/oe/schema/" + scriptBase;
int errorCount = runScript(script, "US-ASCII");
assertEquals("Errors in script ", 0, errorCount);
+ }
+
+ public String getName() {
+ return scriptBase;
}
}