db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r506748 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe: run/Checks.java run/DriverUtility.java util/OEChecks.java
Date Mon, 12 Feb 2007 23:43:02 GMT
Author: djd
Date: Mon Feb 12 15:43:01 2007
New Revision: 506748

URL: http://svn.apache.org/viewvc?view=rev&rev=506748
Log:
DERBY-2278 Adds a new class OEChecks that does the cardinality checks in order to separate
out the OE code
logic into its own class and separating it out from the junit test framework that we have.
This leads to modification in implementation of the fixtures in the Checks.java to appropriately
call
the methods from the OEChecks.
Adds a new class - DriverUtility that can be used to populate the OE database given the drivername
and 
the database connection url and then perform checks on it.

Assumption is that the schema is already loaded into the database.
Contributed by Sunitha Kambhampati  -- ksunithaghm@gmail.com

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/DriverUtility.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OEChecks.java
  (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java

Modified: 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=diff&rev=506748&r1=506747&r2=506748
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Checks.java Mon
Feb 12 15:43:01 2007
@@ -29,6 +29,7 @@
 
 import org.apache.derbyTesting.junit.JDBCPerfTestCase;
 import org.apache.derbyTesting.system.oe.client.Load;
+import org.apache.derbyTesting.system.oe.util.OEChecks;
 
 /**
  * Do some checks on the Order Entry database.
@@ -39,11 +40,16 @@
      * Warehouse scaling factor
      */
     private short scale = 1;
-
-    public Checks(String name) {
+    
+    /**
+     * Run checks on OE database
+     */
+    private OEChecks check = null;
+    
+    public Checks(String name)
+    {
         super(name);
     }
-
     /**
      * @param name -
      *            test name
@@ -56,6 +62,11 @@
 
     }
 
+    public void setUp() throws Exception
+    {
+        this.check = new OEChecks();
+        check.initialize(getConnection(),scale);
+    }
     /**
      * Return suite of tests that checks the row counts for all the tables in
      * the Order Entry bechmark.
@@ -247,7 +258,7 @@
      * @throws Exception
      */
     public void testWarehouseRows() throws Exception {
-        checkCountStar("WAREHOUSE", scale);
+        check.testWarehouseRows();
     }
 
     /**
@@ -256,7 +267,7 @@
      * @throws Exception
      */
     public void testStockRows() throws Exception {
-        checkCountStar("STOCK", Load.STOCK_COUNT_W * scale);
+        check.testStockRows();
     }
 
     /**
@@ -265,7 +276,7 @@
      * @throws Exception
      */
     public void testOrdersRows() throws Exception {
-        checkCountStar("ORDERS", Load.ORDERS_COUNT_W * scale);
+        check.testOrdersRows();
     }
 
     /**
@@ -274,7 +285,7 @@
      * @throws Exception
      */
     public void testDistrictRows() throws Exception {
-        checkCountStar("DISTRICT", Load.DISTRICT_COUNT_W * scale);
+        check.testDistrictRows();
     }
 
     /**
@@ -283,7 +294,7 @@
      * @throws Exception
      */
     public void testCustomerRows() throws Exception {
-        checkCountStar("CUSTOMER", Load.CUSTOMER_COUNT_W * scale);
+        check.testCustomerRows();
     }
 
     /**
@@ -292,7 +303,7 @@
      * @throws Exception
      */
     public void testItemRows() throws Exception {
-        checkCountStar("ITEM", Load.ITEM_COUNT);
+        check.testItemRows();
     }
 
     /**
@@ -301,7 +312,7 @@
      * @throws Exception
      */
     public void testNewOrdersRows() throws Exception {
-        checkCountStar("NEWORDERS", Load.NEWORDERS_COUNT_W * scale);
+        check.testNewOrdersRows();
     }
 
     /**
@@ -310,7 +321,7 @@
      * @throws Exception
      */
     public void testHistoryRows() throws Exception {
-        checkCountStar("HISTORY", Load.HISTORY_COUNT_W * scale);
+        check.testHistoryRows();
     }
 
     /**
@@ -319,61 +330,6 @@
      * @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.testOrderLineRows();
     }
-
-    /**
-     * 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)));
-    }
-
 }

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/DriverUtility.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/DriverUtility.java?view=auto&rev=506748
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/DriverUtility.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/DriverUtility.java
Mon Feb 12 15:43:01 2007
@@ -0,0 +1,203 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.run.DriverUtility
+ *
+ * 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.DriverManager;
+import java.sql.Connection;
+import org.apache.derbyTesting.system.oe.client.Load;
+import org.apache.derbyTesting.system.oe.load.SimpleInsert;
+import org.apache.derbyTesting.system.oe.util.OEChecks;
+
+/**
+ * Driver to do the load phase for the Order Entry benchmark.
+ *
+ * This class takes in following arguments currently:
+ * Usage: java org.apache.derbyTesting.system.oe.run.DriverUtility options
+ * Options:
+ * <OL>
+ * <LI>-scale warehouse scaling factor. Takes a short value. If not specified 
+ * defaults to 1
+ * <LI>-doChecks check consistency of data, takes a boolean value. If not specified,
defaults to true
+ * <LI>-driver jdbc driver class to use
+ * <LI>-dbUrl  database connection url 
+ * <LI>-help prints usage
+ * </OL>
+ *
+ * To load database with scale of 2
+ * and to not do any checks, the command to run the test is as follows:
+ * <BR>
+ * java org.apache.derbyTesting.system.oe.run.DriverUtility -driver org.apache.derby.jdbc.ClientDriver
-dbUrl 'jdbc:derby://localhost:1527/db' -scale 2 -doChecks false
+ * <BR>
+ */
+public class DriverUtility {
+
+    /**
+     * Database connection
+     */
+    private Connection conn = null;
+    /**
+     * Warehouse scale factor
+     */
+    private static short scale = 1;
+
+    /**
+     * Database connection url
+     */
+    private static String dbUrl = "jdbc:derby:wombat;create=true";
+
+    /**
+     * JDBC Driver class
+     */
+    private static String driver = "org.apache.derby.jdbc.EmbeddedDriver";
+
+    /**
+     * flag to indicate if we should perform consistency, cardinality checks
+     * after the load
+     */
+    private static boolean doChecks = true;
+
+    /**
+     * Create a test case with the given name.
+     *
+     * @param name
+     *            of the test case.
+     */
+    public DriverUtility() {
+
+        try {
+            Class.forName(driver);
+        } catch (Exception e) {
+            e.printStackTrace();
+            System.exit(1);
+        }
+    }
+
+    /**
+     * Run OE load
+     * @param args supply arguments for benchmark.
+     * @throws Exception
+     */
+    public static void main(String[] args) throws Exception {
+        parseArgs(args);
+        DriverUtility oe = new DriverUtility();
+        oe.populate();
+        if ( doChecks )
+            oe.allChecks();
+        oe.cleanup();
+    }
+
+    /**
+     * @return the connection
+     * @throws SQLException
+     */
+    public Connection getConnection() throws SQLException {
+        if ( conn == null)
+        {
+            System.out.println("dbUrl="+dbUrl);
+            conn = DriverManager.getConnection(dbUrl);
+        }
+        return conn;
+    }
+
+    /**
+     * Populate the OE database.
+     * Assumption is that the schema is already loaded
+     * in the database.
+     */
+    public void populate() throws Exception {
+        // Use simple insert statements to insert data.
+        // currently only this form of load is present, once we have
+        // different implementations, the loading mechanism will need
+        // to be configurable taking an option from the command line
+        // arguments.
+        Load loader = new SimpleInsert();
+        loader.setupLoad(getConnection(), scale);
+        long start = System.currentTimeMillis();
+        loader.populateAllTables();
+        long stop = System.currentTimeMillis();
+        System.out.println("Time to load (ms)=" + (stop - start));
+    }
+
+    /**
+     * Do the necessary checks to see if database is in consistent state
+     */
+    public void allChecks() throws Exception {
+        OEChecks checks = new OEChecks();
+        checks.initialize(getConnection(), scale);
+        long start = System.currentTimeMillis();
+        checks.checkAllRowCounts();
+        long stop = System.currentTimeMillis();
+        System.out.println("Time to do checks (ms)=" + (stop - start));
+    }
+
+    /**
+     * parse arguments.
+     * @param args arguments to parse
+     */
+    private static void parseArgs(String[] args) {
+        for (int i = 0; i < args.length; i++) {
+            String arg = args[i];
+            if (arg.equals("-scale")) {
+                scale = Short.parseShort(args[++i]);
+            } else if (arg.equals("-driver")) {
+                driver = args[++i];
+            } else if (arg.equals("-dbUrl")) {
+                dbUrl = args[++i];
+            } else if (arg.equals("-doChecks")) {
+                doChecks = (args[++i].equals("false")? false:true);
+            } else if (arg.equals("-help")) {
+                printUsage();
+                System.exit(0);
+            } else {
+                System.err.println("Invalid option: " + args[i]);
+                System.exit(1);
+            }
+        }
+    }
+
+    /**
+     * prints the usage
+     */
+    private static void printUsage() {
+        System.out.println("Usage: java org.apache.derbyTesting.system.oe." +
+                        "run.DriverUtility options");
+        System.out.println();
+        System.out.println("Options:");
+        System.out.println("  -scale warehouse scaling factor. " +
+                        "Takes a short value. If not specified defaults to 1");
+        System.out.println("  -doChecks  should consistency checks be run" +
+                        " on the database. Takes a boolean value");
+        System.out.println("  -driver  the class of the jdbc driver");
+        System.out.println("  -dbUrl  the database connection url");
+        System.out.println("  -help prints usage");
+        System.out.println();
+    }
+
+    /**
+     * cleanup resources. 
+     * @throws SQLException
+     */
+    public void cleanup() throws SQLException {
+        if (conn != null)
+            conn.close();
+    }
+
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OEChecks.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OEChecks.java?view=auto&rev=506748
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OEChecks.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/util/OEChecks.java
Mon Feb 12 15:43:01 2007
@@ -0,0 +1,207 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.util.OEChecks
+ *
+ * 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.util;
+
+import java.sql.SQLException;
+import java.sql.ResultSet;
+import java.sql.Statement;
+import java.sql.Connection;
+
+import org.apache.derbyTesting.system.oe.client.Load;
+
+/**
+ * Do some OEChecks on the Order Entry database.
+ */
+public class OEChecks  {
+
+    /**
+     * Warehouse scaling factor
+     */
+    private short scale = 1;
+
+    private Connection conn = null;
+
+    public void initialize(Connection conn, short scale)
+    throws Exception
+    {
+        this.conn = conn;
+        conn.setAutoCommit(false);
+        this.scale = scale;
+    }
+    
+    /**
+     * Return suite of tests that OEChecks the row counts for all the tables in
+     * the Order Entry bechmark.
+     * 
+     * @param scale
+     * @return
+     */
+    public void checkAllRowCounts() throws Exception {
+        testWarehouseRows();
+        testStockRows();
+        testItemRows();
+        testCustomerRows();
+        testDistrictRows();
+        testOrdersRows();
+        testNewOrdersRows();
+        testOrderLineRows();
+        testHistoryRows();
+    }
+    
+    /**
+     * 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 {
+        if( expected != rowsInTable(table))
+            System.out.println("ERROR:Number of rows loaded for " + table +
+                    " not correct, expected="+expected +" rows found="+ 
+                    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 = conn.createStatement();
+        ResultSet rs = stmt.executeQuery("SELECT COUNT(*) FROM " + tableName);
+        rs.next();
+        int count = rs.getInt(1);
+        conn.commit();
+        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;
+        if ( (count < low) || (count >high))
+            System.out.println("ERROR! Initial rows" + count + " in " + 
+                tableName + " is out of range.[" + low + "-" + high + "]");
+        
+    }
+    
+}

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



Mime
View raw message