db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r499116 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe: client/Load.java load/SimpleInsert.java run/Checks.java run/Populate.java run/Schema.java test/LoadTester.java test/OETest.java
Date Tue, 23 Jan 2007 20:10:48 GMT
Author: djd
Date: Tue Jan 23 12:10:43 2007
New Revision: 499116

URL: http://svn.apache.org/viewvc?view=rev&rev=499116
Log:
DERBY-2095 ) Add a new class Checks. This class has fixtures to test for rowcounts, as well
as the consistency checks mentioned in Section 3.3.2.1 to 3.3.2.4 of TPC-C specification.
2) Cleanup Load interface to remove the single table loads
3) Remove LoadTester as it is no longer needed
4) Push fixtures to test the rowcounts to the Checks class from the OETest.OETest as well
as the Populate test call test fixtures from Checks class.
6) Remove SimpleInsert(Connection,short) constructor as it is no longer needed.
7) Changes in SimpleInsert to make all tables 1 based.
8) Add a new Test Class -Schema to load the schema and cleanup code in OETest and Populate.

Contributed by Sunitha Kambhampati - ksunithaghm@gmail.com

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java   (with
props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java   (with
props)
Removed:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/LoadTester.java
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/test/OETest.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=499116&r1=499115&r2=499116
==============================================================================
--- 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 Tue
Jan 23 12:10:43 2007
@@ -29,8 +29,7 @@
  * <OL>
  * <LI> Use the setupLoad to perform any necessary initialization for the load
  * phase
- * <LI> Load data into the tables 
- * <LI> Provide information about cardinality of rows in each table.
+ * <LI> Load data into all the tables 
  * </OL>
  * <P>
  * DECIMAL values are represented as String objects to allow Order Entry to be
@@ -67,12 +66,6 @@
         (ORDERS_COUNT_W - NEWORDERS_COUNT_W)/ DISTRICT_COUNT_W;
 
     /**
-     * Return the warehouse scale factor of the database. 
-     * @return
-     */
-    public short getScale();
-
-    /**
      * Perform the necessary setup before database population.
      * @param conn - database connection 
      * @param scale - scale of the database.  The WAREHOUSE table is 
@@ -84,75 +77,12 @@
     /**
      * Follow the initial database population requirements in Section 4.3.3 
      * and populate all the required tables.
+     * BE CAREFUL to use the correct starting identifiers for the data in
+     * the tables. In the specification, identifiers start at 1 (one), 
+     * e.g. 1-10 for a district and is not zero based.
+     * 
      * @throws SQLException
      */
     public void populateAllTables() throws SQLException;
-
-    /**
-     * Return the number of rows in the table. 
-     * A simple select count(*) from tableName 
-     * @param tableName - name of the table
-     * @throws SQLException
-     */
-    public int rowsInTable(String tableName) throws SQLException;
-
-    /**
-     * Populate the ITEM table 
-     * See population requirements in section 4.3.3.1
-     * <BR>
-     * @param itemStart insert item information starting from this Item id (ITEM.I_ID) 
-     * @param itemEnd  last Item id (ITEM.I_ID) for inserting information for
-     * @throws SQLException
-     */
-    public void itemTable(int itemStart, int itemEnd) throws SQLException;
-
-    /**
-     * Populate the WAREHOUSE table for a given warehouse.
-     * See population requirements in section 4.3.3.1
-     * @param w WAREHOUSE ID (W_ID)
-     * @throws SQLException
-     */
-    public void warehouseTable(short w) throws SQLException;
-
-    /**
-     * Populate the STOCK table for a given warehouse.
-     * See population requirements in section 4.3.3.1
-     * <BR>
-     * @param itemStart insert stocks of items from this Item id (ITEM.I_ID) 
-     * @param itemEnd  last Item id (ITEM.I_ID) to insert stocks of times for.
-     * @param w WAREHOUSE id (W_ID) for which the stock is populated.
-     * @throws SQLException
-     */
-    public void stockTable(int itemStart, int itemEnd, short w)
-    throws SQLException;
-
-    /**
-     * Populate the DISTRICT table for a given warehouse.
-     * See population requirements in section 4.3.3.1
-     * <BR>
-     * @param w - WAREHOUSE id (W_ID)
-     * @param d - DISTRICT id (D_ID)
-     * @throws SQLException
-     */
-    public void districtTable(short w, short d) throws SQLException;
-
-    /**
-     * Populate the CUSTOMER table for a given district for a specific warehouse.
-     * See population requirements in section 4.3.3.1
-     * <BR>
-     * @param w - WAREHOUSE id (W_ID)
-     * @param d - DISTRICT id (D_ID)
-     * @throws SQLException
-     */
-    public void customerTable(short w, short d) throws SQLException;
-
-    /**
-     * Populate the ORDER table 
-     * See population requirements in section 4.3.3.1
-     * @param w - WAREHOUSE id (W_ID)
-     * @param d - DISTRICT id (D_ID)
-     * @throws SQLException
-     */
-    public void orderTable(short w, short d) throws SQLException;
 
 }

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=499116&r1=499115&r2=499116
==============================================================================
--- 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
Tue Jan 23 12:10:43 2007
@@ -46,26 +46,6 @@
     OERandom random;
 
     /**
-     * Create an instance of this implementation. Connection will be set to non
-     * auto commit mode and SERIALIZABLE isolation.
-     */
-    public SimpleInsert(Connection conn, short scale) throws SQLException {
-        this.conn = conn;
-        conn.setAutoCommit(false);
-        conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
-        setupLoad(conn, scale);
-    }
-
-    /**
-     * return the warehouse scale factor
-     * 
-     * @see org.apache.derbyTesting.system.oe.client.Load#getScale()
-     */
-    public short getScale() {
-        return scale;
-    }
-
-    /**
      * Perform the necessary setup before database population.
      * 
      * @param conn -
@@ -76,6 +56,11 @@
      * @throws Exception
      */
     public void setupLoad(Connection conn, short scale) throws SQLException {
+
+        this.conn = conn;
+        conn.setAutoCommit(false);
+        conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+
         Statement s = conn.createStatement();
         try {
             s.execute("DROP TABLE C");
@@ -112,11 +97,11 @@
         // the customer table. for each row in customer table, load
         // the history, and order table.
 
-        for (short w = 0; w < scale; w++) {
+        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 = 0; d < Load.DISTRICT_COUNT_W; d++) {
+            for (short d = 1; d <= Load.DISTRICT_COUNT_W; d++) {
                 districtTable(w, d);
                 customerTable(w, d);
                 orderTable(w, d);
@@ -126,25 +111,6 @@
     }
 
     /**
-     * Return the number of rows in the table. A simple select count(*) from
-     * tableName
-     * 
-     * @param tableName -
-     *            name of the table
-     * @throws SQLException
-     */
-    public int rowsInTable(String table) throws SQLException {
-        Statement stmt = conn.createStatement();
-        ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + table);
-        rs.next();
-        int count = rs.getInt(1);
-        rs.close();
-        stmt.close();
-
-        return count;
-    }
-
-    /**
      * Populate the ITEM table. See population requirements in section 4.3.3.1
      * <BR>
      * 
@@ -380,15 +346,15 @@
         int[] cid = random.randomIntPerm(Load.CUSTOMER_COUNT_W
                 / Load.DISTRICT_COUNT_W);
         
-        for (int o_id = 0; o_id < cid.length; o_id++) {
+        for (int o_id = 1; o_id <= cid.length; o_id++) {
             psO.setInt(1, o_id);
-            psO.setInt(4, cid[o_id]);
+            psO.setInt(4, cid[o_id-1]);
 
             Timestamp o_entry_d = new Timestamp(System.currentTimeMillis());
 
             psO.setTimestamp(5, o_entry_d);
 
-            if (o_id < Load.NEWORDERS_BREAKPOINT)
+            if (o_id <= Load.NEWORDERS_BREAKPOINT)
                 psO.setShort(6, (short) random.randomInt(1, 10));
             else
                 psO.setNull(6, Types.SMALLINT);
@@ -402,7 +368,7 @@
             psOL.setShort(3, w);
             psNO.setShort(2, d);
             psNO.setShort(3, w);
-            for (int ol_number = 0; ol_number < o_ol_cnt; ol_number++) {
+            for (int ol_number = 1; ol_number <= o_ol_cnt; ol_number++) {
 
                 psOL.setInt(1, o_id);
                 psOL.setInt(4, ol_number);
@@ -410,7 +376,7 @@
                 // OL_I_ID random within [1 .. 100,000]
                 psOL.setInt(5, random.randomInt(1, Load.ITEM_COUNT));
                 psOL.setShort(6, w);
-                if (o_id < Load.NEWORDERS_BREAKPOINT) {
+                if (o_id <= Load.NEWORDERS_BREAKPOINT) {
                     psOL.setTimestamp(7, o_entry_d);
                     psOL.setString(9, "0.00");
                 } else {
@@ -421,7 +387,7 @@
                 psOL.setString(10, random.randomAString24());
                 psOL.executeUpdate();
             }
-            if (o_id >= Load.NEWORDERS_BREAKPOINT) {
+            if (o_id > Load.NEWORDERS_BREAKPOINT) {
                 psNO.setInt(1, o_id);
                 psNO.executeUpdate();
             }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java?view=auto&rev=499116
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java Tue
Jan 23 12:10:43 2007
@@ -0,0 +1,379 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.test.Checks
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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.
+ */
+package org.apache.derbyTesting.system.oe.run;
+
+import java.sql.SQLException;
+import java.sql.ResultSet;
+import java.sql.Statement;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.JDBCPerfTestCase;
+import org.apache.derbyTesting.system.oe.client.Load;
+
+/**
+ * Do some checks on the Order Entry database.
+ */
+public class Checks extends JDBCPerfTestCase {
+
+    /**
+     * Warehouse scaling factor
+     */
+    private short scale = 1;
+
+    public Checks(String name) {
+        super(name);
+    }
+
+    /**
+     * @param name -
+     *            test name
+     * @param scale
+     *            -warehouse scale factor
+     */
+    public Checks(String name, short scale) {
+        super(name);
+        this.scale = scale;
+
+    }
+
+    /**
+     * Return suite of tests that checks the row counts for all the tables in
+     * the Order Entry bechmark.
+     * 
+     * @param scale
+     * @return
+     */
+    public static Test checkAllRowCounts(short scale) {
+        TestSuite suite = new TestSuite("Order Entry -Check Row Counts");
+        suite.addTest(new Checks("testWarehouseRows", scale));
+        suite.addTest(new Checks("testStockRows", scale));
+        suite.addTest(new Checks("testItemRows", scale));
+        suite.addTest(new Checks("testCustomerRows", scale));
+        suite.addTest(new Checks("testDistrictRows", scale));
+        suite.addTest(new Checks("testOrdersRows", scale));
+        suite.addTest(new Checks("testNewOrdersRows", scale));
+        suite.addTest(new Checks("testOrderLineRows", scale));
+        suite.addTest(new Checks("testHistoryRows", scale));
+
+        return suite;
+
+    }
+    
+    /**
+     * Consistency checks per Section 3.3.2 of TPC-C spec
+     * @return
+     */
+    public static Test consistencyChecks()
+    {
+        TestSuite suite = new TestSuite("Order Entry -Consistency checks");
+        suite.addTest(new Checks("testCondition1"));
+        suite.addTest(new Checks("testCondition2"));
+        suite.addTest(new Checks("testCondition3"));
+        suite.addTest(new Checks("testCondition4"));
+        
+        return suite;
+    }
+
+    /**
+     * @return suite of tests that perform certain consistency checks on the OE
+     *         database
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("OrderEntry - checks");
+        suite.addTest(checkAllRowCounts((short) 1));
+        suite.addTest(consistencyChecks());
+        
+        return suite;
+    }
+
+    /**
+     * Section 3.3.2.1 of TPC-C specification. Entries in the WAREHOUSE and
+     * DISTRICT tables must satisfy the relationship: W_YTD = sum(D_YTD) for
+     * each warehouse defined by (W_ID = D_W_ID).
+     */
+    public void testCondition1() throws SQLException {
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery("SELECT W.W_ID,W.W_YTD, SUM(D.D_YTD) " +
+                        "from WAREHOUSE W , DISTRICT D where W.W_ID=D.D_W_ID" +
+                        " GROUP BY W.W_ID,W.W_YTD");
+        while (rs.next()) {
+            println("W_ID"+ rs.getShort(1)+ "W_YTD)="
+                    + rs.getString(2)
+                    + "SUM(D_YTD)=" + rs.getString(3));
+            // retrieve decimal values as string.
+            // to allow Order Entry to be
+            // run on J2ME/CDC/Foundation which does not support BigDecimal.
+            Assert.assertEquals(
+                    "Condition#1: W_YTD = sum(D_YTD) not " +
+                    "satisfied for W_ID="+ rs.getShort(1),
+                    rs.getString(2),rs.getString(3));
+        }
+        commit();
+        rs.close();
+        s.close();
+    }
+
+    /**
+     * Section 3.3.2.2 Consistency Condition 2 (TPC-C spec) Entries in the
+     * DISTRICT, ORDER, and NEW-ORDER tables must satisfy the relationship:
+     * D_NEXT_O_ID - 1 = max(O_ID) = max(NO_O_ID) for each district defined by
+     * (D_W_ID = O_W_ID = NO_W_ID) and (D_ID = O_D_ID = NO_D_ID). This condition
+     * does not apply to the NEW-ORDER table for any districts which have no
+     * outstanding new orders (i.e., the number of rows is zero).
+     */
+    public void testCondition2() throws SQLException {
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery("SELECT D.D_ID, D.D_W_ID,D.D_NEXT_O_ID, "+
+                        "MAX(O.O_ID),MAX(N.NO_O_ID) FROM NEWORDERS N, " +
+                        "DISTRICT D, ORDERS O WHERE D.D_W_ID=O.O_W_ID " +
+                        "AND D.D_W_ID = N.NO_W_ID AND D.D_ID = O.O_D_ID " +
+                        "AND D.D_ID = N.NO_D_ID GROUP BY " +
+                        "D.D_ID,D.D_W_ID,D.D_NEXT_O_ID");
+        
+        while ( rs.next() )
+        {
+            println("D_ID="+rs.getShort(1)+"D_W_ID="+rs.getShort(2) +
+                    "D_NEXT_O_ID="+ rs.getInt(3) +"MAX(O.O_ID)="+rs.getInt(4) +
+                    "MAX(N.NO_O_ID)="+rs.getInt(5));
+            Assert.assertEquals("Condition#2 (a), (D_NEXT_O_ID -1) = MAX(O_ID) " +
+                    "not satisfied for D_ID="+rs.getShort(1)+
+                    "D_W_ID="+rs.getShort(2)
+                    , (rs.getInt(3)-1),rs.getInt(4));
+            Assert.assertEquals("Condition#2 (b), (D_NEXT_O_ID -1 = MAX(NO_O_ID) " +
+                    "not satisfied for D_ID="+rs.getShort(1)+
+                    " D_W_ID="+rs.getShort(2)
+                    , (rs.getInt(3)-1),rs.getInt(5));
+            Assert.assertEquals("Condition#2 (c), MAX(O_ID) = MAX(NO_O_ID) " +
+                    " not satisfied for D_ID="+rs.getShort(1)+
+                    " D_W_ID="+rs.getShort(2)
+                    , rs.getInt(4),rs.getInt(5));
+        }
+        commit();
+        rs.close();
+        s.close();
+            
+    }
+
+    /**
+     * 3.3.2.3 Consistency Condition 3 
+     * Entries in the NEW-ORDER table must
+     * satisfy the relationship: max(NO_O_ID) - min(NO_O_ID) + 1 = [number of
+     * rows in the NEW-ORDER table for this district] for each district defined
+     * by NO_W_ID and NO_D_ID. This condition does not apply to any districts
+     * which have no outstanding new orders (i.e., the number of rows is zero).
+     */
+    public void testCondition3() throws SQLException {
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery("SELECT NO_W_ID,NO_D_ID," +
+                        "MAX(NO_O_ID) - MIN(NO_O_ID) +1, COUNT(*)" +
+                        " FROM NEWORDERS GROUP BY NO_W_ID,NO_D_ID");
+        while (rs.next()) {
+            println("NO_W_ID=" + rs.getShort(1) + ",NO_D_ID="
+                    + rs.getShort(2) + "Max(NO_O_ID)-MIN(NO_O_ID)+1 ="
+                    + rs.getInt(3) + " Num_rows_NO for this district="
+                    + rs.getInt(4));
+            Assert.assertEquals(
+                    "Condition#3 (max(NO_O_ID) - min(NO_O_ID) + 1) = [number of"+
+                    " rows in the NEW-ORDER table for district] not satisfied " +
+                    "for NO_W_ID="+rs.getShort(1)+" NO_D_ID="+rs.getShort(2),
+                    rs.getInt(3),rs.getInt(4));
+        }
+        commit();
+        rs.close();
+        s.close();
+
+    }
+    
+   /**
+     * 3.3.2.4 Consistency Condition 4 
+     * Entries in the ORDER and ORDER-LINE
+     * tables must satisfy the relationship: sum(O_OL_CNT) = [number of rows in
+     * the ORDER-LINE table for this district] for each district defined by
+     * (O_W_ID = OL_W_ID) and (O_D_ID = OL_D_ID).
+     */
+    public void testCondition4() throws SQLException {
+        
+        Statement s = createStatement();
+        ResultSet rs = s.executeQuery("SELECT " +
+                        "T1.SUM_OL_CNT,T2.NUM_OL_ROWS, T1.O_W_ID," +
+                        "T1.O_D_ID FROM " +
+                        "(SELECT O.O_W_ID, O.O_D_ID, " +
+                        "SUM(CAST(O.O_OL_CNT AS BIGINT)) AS " +
+                        "SUM_OL_CNT FROM ORDERS " +
+                        "O GROUP BY O.O_W_ID,O.O_D_ID) T1 ," +
+                        "(SELECT OL_W_ID,OL_D_ID,COUNT(*) AS " +
+                        "NUM_OL_ROWS FROM ORDERLINE " +
+                        "OL GROUP BY OL.OL_W_ID,OL.OL_D_ID) T2" +
+                        " WHERE (T1.O_W_ID = T2.OL_W_ID) AND" +
+                        " (T1.O_D_ID = T2.OL_D_ID)");    
+        while(rs.next())
+        {
+            println("Sum of ol_cnt"+ rs.getLong(1) 
+                    +" Num_rows_OL="+rs.getInt(1));
+            Assert.assertEquals("Condition#4 sum(O_OL_CNT) = [number of rows"
+                    +" in the ORDER-LINE table for this district]not satisfied"
+                    +"for O_W_ID="+rs.getShort(3)+",O_D_ID="+rs.getShort(4),
+                    rs.getLong(1),rs.getLong(2));
+        }
+        commit();
+        rs.close();
+        s.close();
+
+    }
+    
+    /**
+     * Test cardinality of WAREHOUSE table
+     * 
+     * @throws Exception
+     */
+    public void testWarehouseRows() throws Exception {
+        checkCountStar("WAREHOUSE", scale);
+    }
+
+    /**
+     * Test cardinality of STOCK table
+     * 
+     * @throws Exception
+     */
+    public void testStockRows() throws Exception {
+        checkCountStar("STOCK", Load.STOCK_COUNT_W * scale);
+    }
+
+    /**
+     * Test cardinality of ORDERS table
+     * 
+     * @throws Exception
+     */
+    public void testOrdersRows() throws Exception {
+        checkCountStar("ORDERS", Load.ORDERS_COUNT_W * scale);
+    }
+
+    /**
+     * Test cardinality of DISTRICT table
+     * 
+     * @throws Exception
+     */
+    public void testDistrictRows() throws Exception {
+        checkCountStar("DISTRICT", Load.DISTRICT_COUNT_W * scale);
+    }
+
+    /**
+     * Test cardinality of CUSTOMER table
+     * 
+     * @throws Exception
+     */
+    public void testCustomerRows() throws Exception {
+        checkCountStar("CUSTOMER", Load.CUSTOMER_COUNT_W * scale);
+    }
+
+    /**
+     * Test cardinality of ITEM table
+     * 
+     * @throws Exception
+     */
+    public void testItemRows() throws Exception {
+        checkCountStar("ITEM", Load.ITEM_COUNT);
+    }
+
+    /**
+     * Test cardinality of NEWORDERS table
+     * 
+     * @throws Exception
+     */
+    public void testNewOrdersRows() throws Exception {
+        checkCountStar("NEWORDERS", Load.NEWORDERS_COUNT_W * scale);
+    }
+
+    /**
+     * Test cardinality of HISTORY table
+     * 
+     * @throws Exception
+     */
+    public void testHistoryRows() throws Exception {
+        checkCountStar("HISTORY", Load.HISTORY_COUNT_W * scale);
+    }
+
+    /**
+     * Test cardinality of ORDERLINE table
+     * 
+     * @throws Exception
+     */
+    public void testOrderLineRows() throws Exception {
+        checkWithinOnePercent("ORDERLINE", Load.ORDERLINE_COUNT_WV * scale);
+    }
+
+    /**
+     * Check if number of rows in table is as expected
+     * 
+     * @param table -
+     *            table on which to execute the query
+     * @param expected -
+     *            expected number of rows
+     * @throws Exception
+     */
+    private void checkCountStar(String table, int expected) throws Exception {
+        Assert.assertEquals("Number of rows loaded for " + table
+                + " not correct", expected, rowsInTable(table));
+
+    }
+
+    /**
+     * Return the number of rows in the table. A simple select count(*) from
+     * tableName
+     * 
+     * @param tableName -
+     *            name of the table
+     * @throws SQLException
+     */
+    private int rowsInTable(String tableName) throws SQLException {
+        Statement stmt = createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
+        rs.next();
+        int count = rs.getInt(1);
+        rs.close();
+        stmt.close();
+
+        return count;
+    }
+
+    /**
+     * Check if number of rows in table is within one percent of expected value
+     * 
+     * @param tableName -
+     *            table on which to execute the query
+     * @param expected -
+     *            expected number of rows
+     * @throws Exception
+     */
+    private void checkWithinOnePercent(String tableName, int expected)
+            throws Exception {
+
+        double count = rowsInTable(tableName);
+        double low = ((double) expected) * 0.99;
+        double high = ((double) expected) * 1.01;
+        Assert.assertEquals("Initial rows" + count + " in " + tableName
+                + " is out of range.[" + low + "-" + high + "]", false,
+                ((count < low) || (count > high)));
+    }
+
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=499116&r1=499115&r2=499116
==============================================================================
--- 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 Tue
Jan 23 12:10:43 2007
@@ -24,15 +24,14 @@
 import java.security.PrivilegedActionException;
 import java.sql.SQLException;
 
-import junit.framework.Assert;
 import junit.framework.Test;
 import junit.framework.TestSuite;
 
 import org.apache.derbyTesting.junit.JDBCPerfTestCase;
-import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.system.oe.client.Load;
 import org.apache.derbyTesting.system.oe.load.SimpleInsert;
-
+import org.apache.derbyTesting.system.oe.run.Checks;
+import org.apache.derbyTesting.system.oe.run.Schema;
 
 /**
  * Driver to do the load phase for the Order Entry benchmark.
@@ -105,7 +104,8 @@
         // different implementations, the loading mechanism will need
         // to be configurable taking an option from the command line
         // arguments.
-       loader = new SimpleInsert(getConnection(), scale);
+       loader = new SimpleInsert();
+       loader.setupLoad(getConnection(), scale);
     }
 
     /**
@@ -166,76 +166,28 @@
         TestSuite suite = new TestSuite("Order Entry");
 
         // Create Schema
-        suite.addTest(new Populate("testSchema"));
+        suite.addTest(new Schema("testSchema"));
         if (createConstraintsBeforeLoad)
-            addConstraints(suite);
+            Schema.addConstraints(suite);
+        
         // this will populate db
         suite.addTest(new Populate("testLoad"));
 
         if (!createConstraintsBeforeLoad)
-            addConstraints(suite);
+            Schema.addConstraints(suite);
 
         if (doChecks)
         {
             //check if cardinality of rows are OK after
             //population phase.
-            suite.addTest(new Populate("testWarehouseRows"));
-            suite.addTest(new Populate("testStockRows"));
-            suite.addTest(new Populate("testItemRows"));
-            suite.addTest(new Populate("testCustomerRows"));
-            suite.addTest(new Populate("testDistrictRows"));
-            suite.addTest(new Populate("testOrdersRows"));
-            suite.addTest(new Populate("testNewOrdersRows"));
-            suite.addTest(new Populate("testOrderLineRows"));
-            suite.addTest(new Populate("testHistoryRows"));
+            suite.addTest(Checks.checkAllRowCounts(scale));
+            // consistency checks.
+            suite.addTest(Checks.consistencyChecks());
         }
         
         return suite;
     }
 
-    /**
-     * Add constraint tests to suite.
-     * 
-     * @param suite
-     */
-    private static void addConstraints(TestSuite suite) {
-        suite.addTest(new Populate("testPrimaryKey"));
-        suite.addTest(new Populate("testForeignKey"));
-        suite.addTest(new Populate("testIndex"));
-
-    }
-
-    /**
-     * Test setting up the base tables.
-     */
-    public void testSchema() throws UnsupportedEncodingException, SQLException,
-    PrivilegedActionException, IOException {
-        script("schema.sql");
-    }
-
-    /**
-     * Test setting up the primary keys.
-     */
-    public void testPrimaryKey() throws UnsupportedEncodingException,
-    SQLException, PrivilegedActionException, IOException {
-        script("primarykey.sql");
-    }
-
-    /**
-     * Test setting up the foreign keys.
-     */
-    public void testForeignKey() throws UnsupportedEncodingException,
-    SQLException, PrivilegedActionException, IOException {
-        script("foreignkey.sql");
-    }
-
-    /**
-     * Test setting up the remaining indexes.
-     */
-    public void testIndex() throws UnsupportedEncodingException, SQLException,
-    PrivilegedActionException, IOException {
-        script("index.sql");
-    }
 
     /**
      * test the initial database load
@@ -251,136 +203,6 @@
         // that is defined in oe.properties
         // One extension would be to have an implementation that 
         // uses bulkinsert vti to load data.
-
-    }
-
-    /**
-     * Test cardinality of WAREHOUSE table
-     * 
-     * @throws Exception
-     */
-    public void testWarehouseRows() throws Exception {
-        checkCountStar("WAREHOUSE", loader.getScale());
-    }
-
-    /**
-     * Test cardinality of STOCK table
-     * 
-     * @throws Exception
-     */
-    public void testStockRows() throws Exception {
-        checkCountStar("STOCK", Load.STOCK_COUNT_W * loader.getScale());
-    }
-
-    /**
-     * Test cardinality of ORDERS table
-     * 
-     * @throws Exception
-     */
-    public void testOrdersRows() throws Exception {
-        checkCountStar("ORDERS", Load.ORDERS_COUNT_W * loader.getScale());
-    }
-
-    /**
-     * Test cardinality of DISTRICT table
-     * 
-     * @throws Exception
-     */
-    public void testDistrictRows() throws Exception {
-        checkCountStar("DISTRICT", Load.DISTRICT_COUNT_W * loader.getScale());
-    }
-
-    /**
-     * Test cardinality of CUSTOMER table
-     * 
-     * @throws Exception
-     */
-    public void testCustomerRows() throws Exception {
-        checkCountStar("CUSTOMER", Load.CUSTOMER_COUNT_W * loader.getScale());
     }
 
-    /**
-     * Test cardinality of ITEM table
-     * 
-     * @throws Exception
-     */
-    public void testItemRows() throws Exception {
-        checkCountStar("ITEM", Load.ITEM_COUNT);
-    }
-
-    /**
-     * Test cardinality of NEWORDERS table
-     * 
-     * @throws Exception
-     */
-    public void testNewOrdersRows() throws Exception {
-        checkCountStar("NEWORDERS", Load.NEWORDERS_COUNT_W * loader.getScale());
-    }
-
-    /**
-     * Test cardinality of HISTORY table
-     * 
-     * @throws Exception
-     */
-    public void testHistoryRows() throws Exception {
-        checkCountStar("HISTORY", Load.HISTORY_COUNT_W * loader.getScale());
-    }
-
-    /**
-     * Test cardinality of ORDERLINE table
-     * 
-     * @throws Exception
-     */
-    public void testOrderLineRows() throws Exception {
-        checkWithinOnePercent("ORDERLINE", Load.ORDERLINE_COUNT_WV
-                * loader.getScale());
-    }
-
-    /**
-     * Check if number of rows in table is as expected
-     * 
-     * @param table -
-     *            table on which to execute the query
-     * @param expected -
-     *            expected number of rows
-     * @throws Exception
-     */
-    private void checkCountStar(String table, int expected) throws Exception {
-        Assert.assertEquals("Number of rows loaded for " + table
-                + " not correct", expected, loader.rowsInTable(table));
-    }
-
-    /**
-     * Check if number of rows in table is within one percent of expected value
-     * 
-     * @param table -
-     *            table on which to execute the query
-     * @param expected -
-     *            expected number of rows
-     * @throws Exception
-     */
-    private void checkWithinOnePercent(String tableName, int expected)
-    throws Exception {
-
-        double count = loader.rowsInTable(tableName);
-
-        double low = ((double) expected) * 0.99;
-        double high = ((double) expected) * 1.01;
-
-        Assert.assertEquals("Initial rows" + count + " in " + tableName
-                + " is out of range.[" + low + "-" + high + "]", false,
-                ((count < low) || (count > high)));
-
-    }
-
-    /**
-     * Run a Order Entry script.
-     */
-    private void script(String name) throws UnsupportedEncodingException,
-    SQLException, PrivilegedActionException, IOException {
-
-        String script = "org/apache/derbyTesting/system/oe/schema/" + name;
-        int errorCount = runScript(script, "US-ASCII");
-        assertEquals("Errors in script ", 0, errorCount);
-    }
 }

Added: 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=auto&rev=499116
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java Tue
Jan 23 12:10:43 2007
@@ -0,0 +1,116 @@
+/*
+ * 
+ * Derby - Class org.apache.derbyTesting.system.oe.run.Schema
+ * 
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. 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.
+ */
+package org.apache.derbyTesting.system.oe.run;
+
+import java.io.IOException;
+import java.io.UnsupportedEncodingException;
+import java.security.PrivilegedActionException;
+import java.sql.SQLException;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.JDBCPerfTestCase;
+
+/**
+ * Load the OE schema
+ */
+public class Schema extends JDBCPerfTestCase {
+
+
+    /**
+     * Create a test case with the given name.
+     * 
+     * @param name
+     *            of the test case.
+     */
+    public Schema(String name) {
+        super(name);
+    }
+
+    /**
+     * junit tests to create schema
+     * 
+     * @return the tests to run
+     */
+    public static Test suite() {
+        TestSuite suite = new TestSuite("Order Entry- Schema");
+
+        // Create Schema
+        suite.addTest(new Schema("testSchema"));
+        addConstraints(suite);
+        return suite;
+    }
+
+    /**
+     * Add constraint tests to suite.
+     * 
+     * @param suite
+     */
+    static void addConstraints(TestSuite suite) {
+        suite.addTest(new Schema("testPrimaryKey"));
+        suite.addTest(new Schema("testForeignKey"));
+        suite.addTest(new Schema("testIndex"));
+
+    }
+
+    /**
+     * Test setting up the base tables.
+     */
+    public void testSchema() throws UnsupportedEncodingException, SQLException,
+    PrivilegedActionException, IOException {
+        script("schema.sql");
+    }
+
+    /**
+     * Test setting up the primary keys.
+     */
+    public void testPrimaryKey() throws UnsupportedEncodingException,
+    SQLException, PrivilegedActionException, IOException {
+        script("primarykey.sql");
+    }
+
+    /**
+     * Test setting up the foreign keys.
+     */
+    public void testForeignKey() throws UnsupportedEncodingException,
+    SQLException, PrivilegedActionException, IOException {
+        script("foreignkey.sql");
+    }
+
+    /**
+     * Test setting up the remaining indexes.
+     */
+    public void testIndex() throws UnsupportedEncodingException, SQLException,
+    PrivilegedActionException, IOException {
+        script("index.sql");
+    }
+
+    /**
+     * Run a Order Entry script.
+     */
+    private void script(String name) throws UnsupportedEncodingException,
+    SQLException, PrivilegedActionException, IOException {
+
+        String script = "org/apache/derbyTesting/system/oe/schema/" + name;
+        int errorCount = runScript(script, "US-ASCII");
+        assertEquals("Errors in script ", 0, errorCount);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Schema.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java?view=diff&rev=499116&r1=499115&r2=499116
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java Tue
Jan 23 12:10:43 2007
@@ -31,201 +31,39 @@
 import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
 import org.apache.derbyTesting.system.oe.direct.Standard;
 import org.apache.derbyTesting.system.oe.client.Operations;
-import org.apache.derbyTesting.system.oe.load.SimpleInsert;
-import org.apache.derbyTesting.system.oe.client.Load;
+import org.apache.derbyTesting.system.oe.run.Checks;
+import org.apache.derbyTesting.system.oe.run.Populate;
+import org.apache.derbyTesting.system.oe.run.Schema;
 
 /**
  * Test the basic functionality of the Order Entry test
- * as a functional test, to ensure that changes to the
+ * using scale 1 as a functional test, to ensure that changes to the
  * database do not break the performance test.
  *
  */
 public class OETest extends BaseJDBCTestCase {
 
-	short scale = 1;
-   	LoadTester tester;
    	
     public OETest(String name) {
         super(name);
     }
     
-    public OETest(String name, short scale)
-    {
-    	super(name);
-    	this.scale=scale;
- 
-    }
-    
+      
     public static Test suite() {
         TestSuite suite = new TestSuite("Order Entry");
         
-        suite.addTest(new OETest("testSchema"));
-        suite.addTest(new OETest("testPrimaryKey"));
-        suite.addTest(new OETest("testForeignKey"));
-        suite.addTest(new OETest("testIndex"));
-        
-        // Test load part and the cardinality after the
-        // population.
-        suite.addTest(new OETest("testInsertStmtLoad",(short)1));
-        suite.addTest(new OETest("testWarehouseRows"));
-        suite.addTest(new OETest("testStockRows"));
-        suite.addTest(new OETest("testItemRows"));
-        suite.addTest(new OETest("testCustomerRows"));
-        suite.addTest(new OETest("testDistrictRows"));
-        suite.addTest(new OETest("testOrdersRows"));
-        suite.addTest(new OETest("testNewOrdersRows"));
-        suite.addTest(new OETest("testOrderLineRows"));
-        suite.addTest(new OETest("testHistoryRows"));
-        
-        
+        suite.addTest(Schema.suite());
+        // Test load part
+        suite.addTest(new Populate("testLoad"));
+        // perform checks tests.
+        suite.addTest(Checks.suite());
+
         suite.addTest(new OETest("testStandardOperations"));
         
         return new CleanDatabaseTestSetup(suite);
     }
-    
-    /**
-     * Test setting up the base tables.
-     */
-    public void testSchema() throws UnsupportedEncodingException, SQLException, PrivilegedActionException,
IOException
-    {
-        script("schema.sql");
-    }
-    /**
-     * Test setting up the primary keys.
-     */
-    public void testPrimaryKey() throws UnsupportedEncodingException, SQLException, PrivilegedActionException,
IOException
-    {
-        script("primarykey.sql");
-    }
-    /**
-     * Test setting up the foreign keys.
-     */
-    public void testForeignKey() throws UnsupportedEncodingException, SQLException, PrivilegedActionException,
IOException
-    {
-        script("foreignkey.sql");
-    }
-    /**
-     * Test setting up the remaining indexes.
-     */
-    public void testIndex() throws UnsupportedEncodingException, SQLException, PrivilegedActionException,
IOException
-    {
-        script("index.sql");
-    }
-    
-    /**
-     * Test the Simple Load 
-     */
-    public void testInsertStmtLoad() throws Exception
-    {
-       loadTest(new SimpleInsert(getConnection(),scale));
-    }
-    
-    /**
-     * Test load part. 
-     * Includes 
-     * 1) populating the tables
-     * 2) Check if the cardinality of all tables is per the 
-     * TPC-C requirement as expected.
-     * @param p  - Implementation of the Load to use for populating the database
-     * @throws Exception
-     */
-    public void loadTest(Load p) throws Exception
-    {
-    	LoadTester tester = new LoadTester(p);
-    	tester.test();
-    }
-    
-    /**
-     * Test cardinality of WAREHOUSE table
-     * 
-     * @throws Exception
-     */
-    public void testWarehouseRows() throws Exception
-    {
-    	getLoadTester().testWarehouseRows();
-    }
-
-    /**
-     * Test cardinality of CUSTOMER table
-     * 
-     * @throws Exception
-     */
-    public void testCustomerRows() throws Exception
-    {
-    	getLoadTester().testCustomerRows();
-    }
-
-    /**
-     * Test cardinality of DISTRICT table
-     * 
-     * @throws Exception
-     */
-    public void testDistrictRows() throws Exception
-    {
-    	getLoadTester().testDistrictRows();
-    }
-    
-    /**
-     * Test cardinality of HISTORY table
-     * 
-     * @throws Exception
-     */
-    public void testHistoryRows() throws Exception
-    {
-    	getLoadTester().testHistoryRows();
-    }
 
     /**
-     * Test cardinality of ITEM table
-     * 
-     * @throws Exception
-     */
-    public void testItemRows() throws Exception
-    {
-    	getLoadTester().testItemRows();
-    }
-    
-    /**
-     * Test cardinality of NEWORDERS table
-     * 
-     * @throws Exception
-     */
-    public void testNewOrdersRows() throws Exception
-    {
-    	getLoadTester().testNewOrdersRows();
-    }
-    
-    /**
-     * Test cardinality of ORDERLINE table
-     * 
-     * @throws Exception
-     */
-    public void testOrderLineRows() throws Exception
-    {
-    	getLoadTester().testOrderLineRows();
-    }
-    
-    /**
-     * Test cardinality of STOCK table
-     * 
-     * @throws Exception
-     */
-    public void testStockRows() throws Exception
-    {
-    	getLoadTester().testStockRows();
-    }
-
-    /**
-     * Test cardinality of ORDERS table
-     * 
-     * @throws Exception
-     */
-    public void testOrdersRows() throws Exception
-    {
-    	getLoadTester().testOrdersRows();
-    }
-    
-    /**
      * Test the Standard implementations of the business transactions.
      */
     public void testStandardOperations() throws Exception
@@ -242,28 +80,6 @@
         tester.test();
     }
     
-    /**
-     * Run a Order Entry script.
-     */
-    private void script(String name) throws UnsupportedEncodingException, SQLException, PrivilegedActionException,
IOException {
-        
-        String script = "org/apache/derbyTesting/system/oe/schema/" + name;
-        int errorCount = runScript(script,"US-ASCII");
-        assertEquals("Errors in script ",0, errorCount);
-    }
-    
-    /**
-     * 
-     * @return LoadTester to test the load part.
-     * @throws SQLException
-     */
-    private LoadTester getLoadTester()
-        throws SQLException
-    {
-    	if (tester != null)
-    		return tester;
-    	
-    	tester = new LoadTester(new SimpleInsert(getConnection(),(short)1));
-    	return tester;
-    }
+
+
 }



Mime
View raw message