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 2006/11/10 19:26:20 UTC

svn commit: r473413 - in /db/derby/code/trunk/java/testing/org/apache/derbyTesting: junit/BaseJDBCTestCase.java system/oe/run/ system/oe/run/Load.java

Author: djd
Date: Fri Nov 10 10:26:19 2006
New Revision: 473413

URL: http://svn.apache.org/viewvc?view=rev&rev=473413
Log:
DERBY-2055 1) Adds a new class Load.java to execute the schema scripts for OE within the junit framework.
2) Adds a new utility method to BaseJDBCTestCase to take a resource name and execute it using runScript. 
Contributed by  Sunitha Kambhampati ksunithaghm@gmail.com

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Load.java   (with props)
Modified:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java?view=diff&rev=473413&r1=473412&r2=473413
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java (original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/BaseJDBCTestCase.java Fri Nov 10 10:26:19 2006
@@ -26,6 +26,8 @@
 import java.io.PrintStream;
 import java.io.Reader;
 import java.io.UnsupportedEncodingException;
+import java.security.PrivilegedActionException;
+import java.net.URL;
 import java.sql.*;
 
 import junit.framework.AssertionFailedError;
@@ -213,6 +215,33 @@
         // Use the same encoding as the input for the output.    
         return ij.runScript(getConnection(), script, encoding,
                 sink, encoding);       
+    }
+    
+    /**
+     * Run a SQL script through ij discarding the output
+     * using this object's default connection. Intended for
+     * setup scripts.
+     * @return Number of errors executing the script
+     * @throws UnsupportedEncodingException 
+     * @throws PrivilegedActionException
+     * @throws SQLException 
+     */
+    public int runScript(String resource,String encoding)
+        throws UnsupportedEncodingException, SQLException,
+        PrivilegedActionException,IOException
+    {
+        
+        URL sql = getTestResource(resource);
+        assertNotNull("SQL script missing: " + resource, sql);
+        InputStream sqlIn = openTestResource(sql);
+        Connection conn = getConnection();
+        int numErrors = runScript(sqlIn,encoding);
+        sqlIn.close();
+        
+        if (!conn.isClosed() && !conn.getAutoCommit())
+            conn.commit();
+        
+        return numErrors;
     }
     
     /**

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Load.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Load.java?view=auto&rev=473413
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Load.java (added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/system/oe/run/Load.java Fri Nov 10 10:26:19 2006
@@ -0,0 +1,80 @@
+/*
+ * 
+ * Derby - Class Load
+ * 
+ * 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 junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.junit.JDBCPerfTestCase;
+
+
+/**
+ * Driver to do the load phase. (partial)
+ * This class currently only creates the schema. 
+ * After the population code is checked in, one can measure performance
+ * using 1) load data after creating constraints 2) load data and then create
+ * constraints.
+ */ 
+public class Load extends JDBCPerfTestCase{
+    
+    
+    
+    /**
+     * Create a test case with the given name.
+     *
+     * @param name of the test case.
+     */
+    public Load(String name)
+    {
+        super(name);
+    }
+    
+    /**
+     * junit tests to do the OE load.
+     * @return the tests to run
+     */
+    public static Test suite()
+    { 
+        TestSuite suite = new TestSuite("OE_Load");
+        suite.addTest(new Load("createSchemaWithConstraints"));        
+        
+        // more to come. (see DERBY-1987)
+        // need to add the population phase.
+        
+        return suite;
+        
+    }
+    
+    /**
+     * Create tables, primary, foreign key constraints 
+     * and indexes for the OE benchmark
+     */
+    public void createSchemaWithConstraints()
+    throws Exception
+    {
+        int numExceptions = 0;
+        numExceptions += runScript("org/apache/derbyTesting/system/oe/schema/schema.sql","US-ASCII");
+        numExceptions += runScript("org/apache/derbyTesting/system/oe/schema/primarykey.sql","US-ASCII");
+        numExceptions += runScript("org/apache/derbyTesting/system/oe/schema/foreignkey.sql","US-ASCII");
+        numExceptions += runScript("org/apache/derbyTesting/system/oe/schema/index.sql","US-ASCII");
+        assertEquals("Number of sql exceptions ",0,numExceptions);
+    }
+    
+}

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