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/10/26 01:36:05 UTC

svn commit: r588389 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe: client/MultiThreadSubmitter.java client/Submitter.java direct/Standard.java

Author: djd
Date: Thu Oct 25 16:36:04 2007
New Revision: 588389

URL: http://svn.apache.org/viewvc?rev=588389&view=rev
Log:
Minor improvements in OE test framework.
  - Add a Submitter that executes using multiple threads
  - Add a clear counts method to the Submitter and when reporting only print transaction counts for those transactions that were executed.
  - Fix same bug in Standard transaction implementation for payment and order status by name where the incorrect customer was selected.

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/MultiThreadSubmitter.java   (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java
    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/client/MultiThreadSubmitter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/MultiThreadSubmitter.java?rev=588389&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/MultiThreadSubmitter.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/MultiThreadSubmitter.java Thu Oct 25 16:36:04 2007
@@ -0,0 +1,104 @@
+/*
+ *
+ * Derby - Class org.apache.derbyTesting.system.oe.client.MultiThreadSubmitter
+ *
+ * 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.client;
+
+/**
+ * Execute transactions using multiple threads.
+ * A single thread uses a single submitter,
+ * submitters are created outside of this class.
+ */
+public class MultiThreadSubmitter {
+
+    /**
+     * Execute count transactions per submitter
+     * using a newly created thread for each
+     * submitter. In total (count*submitter.length)
+     * transactions will be executed. The time returned
+     * will be the time to execute all the transactions.
+     * 
+     * @param submitters Submitters to use.
+     * @param displays Displays for each submitter.
+     * If null then null will be passed into each transaction
+     * execution
+     * @param count Number of transactions per thread.
+     * @return Time to excute all of the transactions.
+     */
+    public static long multiRun(
+            Submitter[] submitters,
+            Object[] displays,
+            int count) {
+
+        Thread[] threads = new Thread[submitters.length];
+        for (int i = 0; i < submitters.length; i++) {
+            Object displayData = displays == null ? null : displays[i];
+            threads[i] = newThread(i, submitters[i], displayData, count);
+        }
+
+        // Start all the threads
+        long start = System.currentTimeMillis();
+        for (int i = 0; i < threads.length; i++)
+            threads[i].start();
+
+        // and then wait for them to finish
+        for (int i = 0; i < threads.length; i++) {
+            try {
+                threads[i].join();
+            } catch (InterruptedException e) {
+                e.printStackTrace();
+            }
+        }
+
+        long end = System.currentTimeMillis();
+
+        return end - start;
+    }
+
+    /**
+     * Return a thread that will run count transactions using a submitter.
+     * 
+     * @param threadId
+     *            Number of thread.
+     * @param submitter
+     *            Submitter
+     * @param displayData
+     *            DisplayData for this submitter
+     * @param count
+     *            Number of transactions to run.
+     * 
+     * @return Thread (not started)
+     */
+    private static Thread newThread(final int threadId,
+            final Submitter submitter,
+            final Object displayData, final int count) {
+        Thread t = new Thread("OE_Thread:" + threadId) {
+
+            public void run() {
+                try {
+                    submitter.runTransactions(displayData, count);
+                } catch (Exception e) {
+                    e.printStackTrace();
+                }
+            }
+        };
+
+        return t;
+    }
+
+}

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

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java?rev=588389&r1=588388&r2=588389&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/client/Submitter.java Thu Oct 25 16:36:04 2007
@@ -24,6 +24,7 @@
 import java.sql.Connection;
 import java.sql.ResultSet;
 import java.sql.SQLException;
+import java.util.Arrays;
 
 import org.apache.derbyTesting.system.oe.util.OERandom;
 
@@ -256,6 +257,14 @@
     }
     
     /**
+     * Reset the transaction counts to zero.
+     */
+    public void clearTransactionCount()
+    {
+        Arrays.fill(transactionCount, 0);
+    }
+    
+    /**
      * Run a fixed number of transactions returning the
      * time in milli-seconds required to execute all of them.
      * @param displayData Passed onto Display calls
@@ -488,17 +497,27 @@
         int osCount = transactionCount[ORDER_STATUS_BY_NAME] +
             transactionCount[ORDER_STATUS_BY_ID];
 
-        out.println(transactionCount("New Order         ", noTotal, total));        
-        out.println(transactionCount("Payment           ",  pyCount, total));
-        out.println(transactionCount("    By Name       ",  transactionCount[PAYMENT_BY_NAME], total));
-        out.println(transactionCount("    By Identifier ",  transactionCount[PAYMENT_BY_ID], total));
-        out.println(transactionCount("Order Status      ",  osCount, total));
-        out.println(transactionCount("    By Name       ",  transactionCount[ORDER_STATUS_BY_NAME], total));
-        out.println(transactionCount("    By Identifier ",  transactionCount[ORDER_STATUS_BY_ID], total));
+        if (noTotal != 0)
+            out.println(transactionCount("New Order         ", noTotal, total));
         
-        out.println(transactionCount("Stock Level       ", 
+        if (pyCount != 0) {
+            out.println(transactionCount("Payment           ",  pyCount, total));
+            out.println(transactionCount("    By Name       ",  transactionCount[PAYMENT_BY_NAME], total));
+            out.println(transactionCount("    By Identifier ",  transactionCount[PAYMENT_BY_ID], total));
+        }
+        
+        if (osCount != 0) {
+            out.println(transactionCount("Order Status      ",  osCount, total));
+            out.println(transactionCount("    By Name       ",  transactionCount[ORDER_STATUS_BY_NAME], total));
+            out.println(transactionCount("    By Identifier ",  transactionCount[ORDER_STATUS_BY_ID], total));
+        }
+        
+        if (transactionCount[STOCK_LEVEL] != 0)
+            out.println(transactionCount("Stock Level       ", 
                 transactionCount[STOCK_LEVEL], total));
-        out.println(transactionCount("Schedule Delivery ", 
+        
+        if (transactionCount[DELIVERY_SCHEDULE] != 0)
+            out.println(transactionCount("Schedule Delivery ", 
                 transactionCount[DELIVERY_SCHEDULE], total));
     }
     

Modified: 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?rev=588389&r1=588388&r2=588389&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/direct/Standard.java Thu Oct 25 16:36:04 2007
@@ -206,7 +206,7 @@
             osCustomerByName.setShort(2, d);
             osCustomerByName.setString(3, customerLast);
             ResultSet rs = osCustomerByName.executeQuery();
-            int n = 0;
+
             List list = new ArrayList();
             while (rs.next())
             {
@@ -228,8 +228,8 @@
                         + customerLast);
             
             // Customer to use is midpoint (with round up) (see 2.6.2.2)
-            int mid = n/2;
-            if (n%2 == 1)
+            int mid = list.size()/2;
+            if (list.size()%2 == 1)
                 mid++;
 
 
@@ -373,7 +373,7 @@
             pyCustomerByName.setShort(2, cd);
             pyCustomerByName.setString(3, customerLast);
             ResultSet rs = pyCustomerByName.executeQuery();
-            int n = 0;
+
             List list = new ArrayList();
             while (rs.next())
             {           
@@ -385,8 +385,8 @@
                         + customerLast);
             
             // Customer to use is midpoint (with round up) (see 2.5.2.2)
-            int mid = n/2;
-            if (n%2 == 1)
+            int mid = list.size()/2;
+            if (list.size()%2 == 1)
                 mid++;
             
             int c = ((Integer) list.get(mid)).intValue();