db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r753210 - in /db/derby/code/trunk/java/testing: ./ org/apache/derbyTesting/functionTests/tests/memorydb/
Date Fri, 13 Mar 2009 11:33:12 GMT
Author: kristwaa
Date: Fri Mar 13 11:33:11 2009
New Revision: 753210

URL: http://svn.apache.org/viewvc?rev=753210&view=rev
Log:
DERYB-4085: Improve testing of the in-memory back end.
Added the first basic tests for the in-memory back end.
One test just tries to connect to a non-existing database with the memory
protocol. The other creates a in-memory database, adds a table, creates a
backup, adds another row with the default storage engine (directory) and
finally recreates a in-memory database and reads all rows from the table.
The tests are not enabled as part of any larger suite yet.
Patch file: derby-4085-1b-basic_tests.diff

Added:
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/_Suite.java
  (with props)
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/build.xml
  (with props)
Modified:
    db/derby/code/trunk/java/testing/build.xml

Modified: db/derby/code/trunk/java/testing/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/build.xml?rev=753210&r1=753209&r2=753210&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/build.xml (original)
+++ db/derby/code/trunk/java/testing/build.xml Fri Mar 13 11:33:11 2009
@@ -79,6 +79,7 @@
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/perf"/>

     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/management"/>
     <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/memory"/>
+    <ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/memorydb"/>
   	<ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/multi"/>
   	<ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/upgradeTests"/>

   	<ant dir="${derby.testing.src.dir}/${derby.testing.functest.dir}/tests/replicationTests"/>


Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java?rev=753210&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
Fri Mar 13 11:33:11 2009
@@ -0,0 +1,196 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.memorydb.BasicInMemoryDbTest
+
+       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.functionTests.tests.memorydb;
+
+import java.io.File;
+import java.io.IOException;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests;
+import org.apache.derbyTesting.functionTests.util.streams.CharAlphabet;
+import org.apache.derbyTesting.functionTests.util.streams.LoopingAlphabetReader;
+import org.apache.derbyTesting.junit.BaseJDBCTestCase;
+import org.apache.derbyTesting.junit.JDBC;
+import org.apache.derbyTesting.junit.SupportFilesSetup;
+
+/**
+ * Basic tests of the in-memory db storage back end.
+ */
+public class BasicInMemoryDbTest
+        extends BaseJDBCTestCase {
+
+    public BasicInMemoryDbTest(String name) {
+        super(name);
+    }
+
+    /**
+     * Tries to connect to a non-existing database with the in-memory protocol,
+     * expecting an error saying the database doesn't exist.
+     */
+    public void testFunctionalityPresent() {
+        try {
+            getConnection(); // Make sure the driver is loaded (slight hack).
+            DriverManager.getConnection("jdbc:derby:memory:nonExistingDb");
+        } catch (SQLException e) {
+            // Expect a database not found exception.
+            assertSQLState("XJ004", e);
+        }
+    }
+
+    /**
+     * Performs a cycle to test that the in-memory db is compatible with the
+     * deafult directory protocol.
+     * <p>
+     * <ol> <li>Create an in-memory db and add a table with a few rows.</li>
+     *      <li>Backup to disk.</li>
+     *      <li>Boot the database with the directory (default) protocol.</li>
+     *      <li>Verify content, add a new row, shutdown.</li>
+     *      <li>Use createFrom to restore database from disk into the in-memory
+     *          representation.</li>
+     *      <li>Verify new content.</li>
+     * </ol>
+     *
+     * @throws IOException if something goes wrong
+     * @throws SQLException if something goes wrong
+     */
+    public void testCreateBackupBootRestore()
+            throws IOException, SQLException {
+        // 1. Create the database with the in-memory protocol.
+        Connection memCon = DriverManager.getConnection(
+                "jdbc:derby:memory:newMemDb;create=true");
+        // Make sure the database is newly created.
+        assertNull(memCon.getWarnings());
+        Statement stmt = memCon.createStatement();
+        stmt.executeUpdate("create table toverify(" +
+                "id int, val1 varchar(10), val2 clob, primary key(id))");
+        PreparedStatement ps = memCon.prepareStatement("insert into toverify " +
+                "values (?,?,?)");
+        // The content to insert into the table.
+        String[][] firstContent = new String[][] {
+            {"1", "one", getString(1000, CharAlphabet.modernLatinLowercase())},
+            {"2", "two", getString(10000, CharAlphabet.tamil())},
+            {"3", "three", getString(50000, CharAlphabet.cjkSubset())}
+        };
+        for (int i=0; i < firstContent.length; i++) {
+            ps.setString(1, firstContent[i][0]);
+            ps.setString(2, firstContent[i][1]);
+            ps.setString(3, firstContent[i][2]);
+            ps.executeUpdate();
+        }
+        ResultSet rs = stmt.executeQuery("select * from toverify");
+        JDBC.assertFullResultSet(rs, firstContent);
+        ps.close();
+        stmt.close();
+
+        // 2. Backup the database.
+        String dbPath = SupportFilesSetup.getReadWrite("backedUpDb").getPath();
+        CallableStatement cs = memCon.prepareCall(
+                "CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)");
+        cs.setString(1, dbPath);
+        cs.execute();
+        memCon.close();
+
+        // 3. Open the database with the default protocol.
+        String dbPathBackedUp = PrivilegedFileOpsForTests.getAbsolutePath(
+                new File(dbPath, "newMemDb"));
+        Connection dirCon = DriverManager.getConnection(
+                "jdbc:derby:" + dbPathBackedUp);
+        // 4. Verify content, then add one more row.
+        stmt = dirCon.createStatement();
+        rs = stmt.executeQuery("select * from toverify");
+        JDBC.assertFullResultSet(rs, firstContent);
+        ps = dirCon.prepareStatement("insert into toverify values (?,?,?)");
+        String[] rowToAdd = new String[] {
+            "4", "four", getString(32*1024, CharAlphabet.tamil())};
+        ps.setString(1, rowToAdd[0]);
+        ps.setString(2, rowToAdd[1]);
+        ps.setString(3, rowToAdd[2]);
+        ps.executeUpdate();
+        ps.close();
+        dirCon.close();
+        // Shutdown.
+        try {
+            DriverManager.getConnection(
+                "jdbc:derby:" + dbPathBackedUp + ";shutdown=true");
+        } catch (SQLException sqle) {
+            assertSQLState("08006", sqle);
+        }
+
+        // 5. Restore modified backup into memory.
+        memCon = DriverManager.getConnection("jdbc:derby:memory:newMemDb2" +
+                ";createFrom=" + dbPathBackedUp);
+
+        // 6. Verify the new content, where the original in-memory database was
+        //    backed up and the directory protocol was used to add one more row
+        //    to the backed up database. Now we have restored the on-disk
+        //    modified backup, again representing it as an in-memory database.
+        stmt = memCon.createStatement();
+        rs = stmt.executeQuery("select * from toverify");
+        String[][] secondContent = new String[4][3];
+        System.arraycopy(firstContent, 0, secondContent, 0, 3);
+        System.arraycopy(rowToAdd, 0, secondContent[3], 0, 3);
+        JDBC.assertFullResultSet(rs, secondContent);
+        stmt.close();
+        memCon.close();
+
+        // The data will probably hang around in memory at this point.
+        // How to fix that?
+    }
+
+    public static Test suite() {
+        // Run only in embedded-mode for now.
+        return new SupportFilesSetup(new TestSuite(BasicInMemoryDbTest.class));
+    }
+
+    /**
+     * Generates a string.
+     *
+     * @param length length of the string
+     * @param alphabet the alphabet to use for the content
+     * @return A string.
+     * @throws IOException if reading from the source stream fails
+     */
+    public static String getString(int length, CharAlphabet alphabet)
+            throws IOException {
+        LoopingAlphabetReader reader =
+                new LoopingAlphabetReader(length, alphabet);
+        char[] strChar = new char[length];
+        int read = 0;
+        while (read < length) {
+            int readNow = reader.read(strChar, read, length - read);
+            if (readNow < 1) {
+                fail("Creating string failed, stream returned " + readNow);
+            }
+            read += readNow;
+        }
+        return String.copyValueOf(strChar);
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/BasicInMemoryDbTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/_Suite.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/_Suite.java?rev=753210&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/_Suite.java
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/_Suite.java
Fri Mar 13 11:33:11 2009
@@ -0,0 +1,49 @@
+/*
+
+   Derby - Class org.apache.derbyTesting.functionTests.tests.memorydb._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.functionTests.tests.memorydb;
+
+import org.apache.derbyTesting.junit.BaseTestCase;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+/**
+ * Suite to run all JUnit tests in this package:
+ * org.apache.derbyTesting.functionTests.tests.memorydb
+ */
+
+public class _Suite extends BaseTestCase  {
+
+    /**
+     * Use suite method instead.
+     */
+    private _Suite(String name) {
+        super(name);
+    }
+
+    public static Test suite() {
+
+        TestSuite suite = new TestSuite("In-memory db test suite");
+        suite.addTest(BasicInMemoryDbTest.suite());
+
+        return suite;
+    }
+}

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/_Suite.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/build.xml?rev=753210&view=auto
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/build.xml
(added)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/build.xml
Fri Mar 13 11:33:11 2009
@@ -0,0 +1,104 @@
+<?xml version="1.0"?>
+<!--
+  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.
+-->
+
+<!-- ==================================================================== -->
+<!--                       Derby build file                          -->
+<!-- ==================================================================== -->
+
+<project default="FTOtestsubdir" basedir="../../../../../../../.." >
+
+<!-- ==================================================================== -->
+<!--                           Set properties                             -->
+<!-- ==================================================================== -->
+
+  <!-- User settings -->
+  <property file="${user.home}/ant.properties"/>
+
+  <!-- Set property lib dir -->
+  <property name="properties.dir" value="tools/ant/properties" />
+
+  <!-- Significant dirs -->
+  <property file="${properties.dir}/dirs.properties"/>
+  <property file="${properties.dir}/derbytesting.properties"/>
+
+  <!-- Compiler settings -->
+  <property file="${properties.dir}/sane${sanity}.properties"/>
+  <property file="${properties.dir}/defaultcompiler.properties"/>
+  <property file="${properties.dir}/${build.compiler}.properties"/>
+
+  <!-- Parser properties -->
+  <!--property file="${properties.dir}/parser.properties"/-->
+
+  <!-- Compile-time classpath properties files -->
+  <property file="${properties.dir}/extrapath.properties"/>
+  <property file="${properties.dir}/compilepath.properties"/>
+
+  <!-- Release and Version info -->
+  <property file="${properties.dir}/release.properties"/>
+
+  <!-- derby testing specific properties files -->
+  <property file="${ant.home}/properties/derbytesting.properties"/>
+  <property file="${user.home}/properties/derbytesting.properties"/>
+  <property name="this.dir" value="${derby.testing.functest.dir}/tests/memorydb"/>
+
+<!--             ============ Begin Targets ==============                -->
+
+  <target name="FTOtestsubdir" depends="compile,copy"/>
+
+  <!-- mkdir / init target may not be necessary, just here for reference... -->
+  <target name="init">
+    <mkdir dir="${out.dir}/${derby.testing.functest.dir}/tests/memorydb"/>
+  </target>
+
+  <target name="compile">
+    <javac
+      source="1.4"
+      target="1.4"
+      bootclasspath="${empty}"
+      nowarn="on"
+      debug="true"
+      depend="${depend}"
+      deprecation="${deprecation}"
+      optimize="${optimize}"
+      proceed="${proceed}"
+      verbose="${verbose}"
+      srcdir="${derby.testing.src.dir}"
+      destdir="${out.dir}">
+      <classpath>
+        <!--pathelement location="${oro}"/-->
+        <pathelement path="${compile.classpath}"/>
+        <pathelement path="${junit}"/>
+      </classpath>
+      <include name="${this.dir}/*.java"/>
+      <!--exclude name=""/-->
+    </javac>
+  </target>
+
+  <target name="copy">
+    <copy todir="${out.dir}/${derby.testing.functest.dir}/tests/memorydb">
+      <fileset dir="${derby.testing.src.dir}/${this.dir}"
+               includes="*.sql,*.properties"/>
+    </copy>
+  </target>
+
+<!--             ============= End Targets ==============                -->
+
+<!--             ============= End Project ==============                -->
+
+</project>
+

Propchange: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/memorydb/build.xml
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message