db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r481602 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe: direct/ direct/Standard.java test/ test/OETest.java test/OperationsTester.java test/_Suite.java
Date Sat, 02 Dec 2006 18:50:27 GMT
Author: djd
Date: Sat Dec  2 10:50:26 2006
New Revision: 481602

URL: http://svn.apache.org/viewvc?view=rev&rev=481602
Log:
DERBY-2094 (partial) Initial partial implementation of the order entry test transactions using
the
defined behaviour from the appendix TPC-C specification. Only stock level added.
Also added a JUnit testing frame work to test the functionality of the operations.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java  
(with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/_Suite.java  
(with props)

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java?view=auto&rev=481602
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java
Sat Dec  2 10:50:26 2006
@@ -0,0 +1,206 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.direct.Standard
+ *
+ * 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.direct;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+import org.apache.derbyTesting.system.oe.client.Display;
+import org.apache.derbyTesting.system.oe.client.Operations;
+
+/**
+ * Implement the transactions following the TPC-C specification
+ * using client side prepared statements. Thus all the logic
+ * is contained within this class. The client, through this
+ * object, holds onto PreparedStatements for all the SQL
+ * for its lifetime.
+ * <P>
+ * This standard implementation is based upon the sample
+ * programs in the appendix of the TPC-C specification.
+ * <P>
+ * More specific direct (client side) implementations
+ * could extend this class overriding methods as needed.
+ */
+public class Standard implements Operations {
+    
+    private final Connection conn;
+
+    /**
+     * Create an instance of this implementation.
+     * Connection will be set to non auto commit
+     * mode and SERIZIALZABLE isolation.
+     */
+    public Standard(Connection conn) throws SQLException
+    {
+        this.conn = conn;
+        conn.setAutoCommit(false);
+        conn.setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
+    }
+    
+    /**
+     * Prepare all statements as forward-only, read-only, close at commit.
+     */
+    PreparedStatement prepare(String sql) throws SQLException
+    {
+        return conn.prepareStatement(sql,
+                ResultSet.TYPE_FORWARD_ONLY,
+                ResultSet.CONCUR_READ_ONLY,
+                ResultSet.CLOSE_CURSORS_AT_COMMIT);
+    }
+    
+    /*
+     *  Stock Level transaction.
+     *  Described in section 2.8.2.
+     *  SQL based upon sample prgram in appendix A.5.
+     */
+    
+    private PreparedStatement sl1;
+    private PreparedStatement sl2;
+    
+    public void setupStockLevel() throws Exception {
+        sl1 = prepare(
+            "SELECT D_NEXT_O_ID FROM DISTRICT WHERE D_W_ID = ? AND D_ID = ?");
+        
+        sl2 = prepare(
+            "SELECT COUNT(DISTINCT(S_I_ID)) FROM ORDERLINE, STOCK " +
+            "WHERE OL_W_ID = ? AND OL_D_ID = ? " +
+            "AND OL_O_ID < ? AND OL_O_ID >= ? " +
+            "AND S_W_ID = ? AND S_I_ID = OL_I_ID AND S_QUANTITY < ?");
+    }
+    
+    public void stockLevel(Display display, Object displayData, short w,
+            short d, int threshold) throws Exception {
+        
+        int isolation = conn.getTransactionIsolation();
+
+        int level;
+        try {
+
+            try {
+
+                conn.setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
+                         
+                sl1.setShort(1, w);
+                sl1.setShort(2, d);
+
+                sl2.setShort(1, w);
+                sl2.setShort(2, d);
+
+                sl2.setShort(5, w);
+                sl2.setInt(6, threshold);
+
+                ResultSet rs = sl1.executeQuery();
+
+                rs.next();
+                int nextOrder = rs.getInt(1);
+                rs.close();
+
+                sl2.setInt(3, nextOrder);
+                sl2.setInt(4, nextOrder - 20);
+
+                rs = sl2.executeQuery();
+                rs.next();
+                level = rs.getInt(1);
+                rs.close();
+
+                conn.commit();
+            } finally {
+                conn.setTransactionIsolation(isolation);
+            }
+
+        } catch (SQLException sqle) {
+
+            conn.rollback();
+            throw sqle;
+        }
+
+        if (display != null)
+            display.displayStockLevel(displayData, w, d, threshold, level);
+    }
+    
+    /*
+     * Order Status transaction.
+     */
+
+    public void setupOrderStatus() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    public void orderStatus(Display display, Object displayData, short w,
+            short d, String customerLast) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void orderStatus(Display display, Object displayData, short w,
+            short d, int c) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void setupPayment() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void payment(Display display, Object displayData, short w, short d,
+            short cw, short cd, String customerLast, String amount)
+            throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+
+    public void payment(Display display, Object displayData, short w, short d,
+            short cw, short cd, int c, String amount) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    
+    public void setupNewOrder() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    public void newOrder(Display display, Object displayData, short w, short d,
+            int c, int[] items, short[] quantities, short[] supplyW)
+            throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    public void setupScheduleDelivery() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    public void scheduleDelivery(Display display, Object displayData, short w,
+            short carrier) throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    
+    public void setupDelivery() throws Exception {
+        // TODO Auto-generated method stub
+
+    }
+    public int delivery() throws Exception {
+        // TODO Auto-generated method stub
+        return 0;
+    }
+}

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

Added: 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=auto&rev=481602
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OETest.java Sat
Dec  2 10:50:26 2006
@@ -0,0 +1,115 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.test.OETest
+ *
+ * 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.test;
+
+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.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.CleanDatabaseTestSetup;
+import org.apache.derbyTesting.system.oe.client.Operations;
+import org.apache.derbyTesting.system.oe.direct.Standard;
+
+/**
+ * Test the basic functionality of the Order Entry test
+ * as a functional test, to ensure that changes to the
+ * database do not break the performance test.
+ *
+ */
+public class OETest extends BaseJDBCTestCase {
+
+    public OETest(String name) {
+        super(name);
+    }
+    
+    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"));
+        
+        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 Standard implementations of the business transactions.
+     */
+    public void testStandardOperations() throws Exception
+    {
+        operationsTest(new Standard(getConnection()));
+    }
+    /**
+     * Run a standard set of tests against an implementation
+     * of Operations using the OperationsTester class.
+     */
+    private static void operationsTest(Operations ops) throws Exception
+    {
+        OperationsTester tester = new OperationsTester(ops);
+        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);
+    }
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java?view=auto&rev=481602
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/OperationsTester.java
Sat Dec  2 10:50:26 2006
@@ -0,0 +1,72 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.test.OperationsTester
+ *
+ * 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.test;
+
+import org.apache.derbyTesting.system.oe.client.Operations;
+
+/**
+ * Test an implementation of Operations.
+ * Currently just tests the setup but as more
+ * code is added the implemetations of the transactions
+ * will be added.
+ */
+class OperationsTester  {
+
+    private final Operations ops;
+    
+    OperationsTester(Operations ops) {
+        this.ops = ops;
+    }
+    
+    void test() throws Exception
+    {
+        testStockLevel();
+        testOrderStatus();
+        testPayment();
+        testNewOrder();
+        testScheduleDelivery();
+        testDelivery();
+    }
+    
+    private void testStockLevel() throws Exception
+    {
+        ops.setupStockLevel();
+    }
+    private void testOrderStatus() throws Exception
+    {
+        ops.setupOrderStatus();
+    }
+    private void testPayment() throws Exception
+    {
+        ops.setupPayment();
+    }
+    private void testNewOrder() throws Exception
+    {
+        ops.setupNewOrder();
+    }
+    private void testScheduleDelivery() throws Exception
+    {
+        ops.setupScheduleDelivery();
+    }
+    private void testDelivery() throws Exception
+    {
+        ops.setupDelivery();
+    }
+}

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

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/_Suite.java?view=auto&rev=481602
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/_Suite.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/test/_Suite.java Sat
Dec  2 10:50:26 2006
@@ -0,0 +1,44 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.test._Suite
+ *
+ * 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.test;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.BaseTestCase;
+
+public class _Suite extends BaseTestCase  {
+
+    /**
+     * Use suite method instead.
+     */
+    private _Suite(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+
+        TestSuite suite = new TestSuite("oe");
+        
+        suite.addTest(OETest.suite());
+        
+        return suite;
+    }
+}

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



Mime
View raw message