001: /*
002: * $Id: TestForElmar.java,v 1.4 2005/03/15 05:37:33 ahimanikya Exp $
003: * =======================================================================
004: * Copyright (c) 2004 Axion Development Team. All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions
008: * are met:
009: *
010: * 1. Redistributions of source code must retain the above
011: * copyright notice, this list of conditions and the following
012: * disclaimer.
013: *
014: * 2. Redistributions in binary form must reproduce the above copyright
015: * notice, this list of conditions and the following disclaimer in
016: * the documentation and/or other materials provided with the
017: * distribution.
018: *
019: * 3. The names "Tigris", "Axion", nor the names of its contributors may
020: * not be used to endorse or promote products derived from this
021: * software without specific prior written permission.
022: *
023: * 4. Products derived from this software may not be called "Axion", nor
024: * may "Tigris" or "Axion" appear in their names without specific prior
025: * written permission.
026: *
027: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
028: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
029: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
030: * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
031: * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
032: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
033: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
034: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
035: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
036: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
037: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
038: * =======================================================================
039: */
040:
041: package org.axiondb.functional;
042:
043: import java.io.File;
044: import java.sql.Connection;
045: import java.sql.DriverManager;
046: import java.sql.ResultSet;
047: import java.sql.Statement;
048:
049: import junit.framework.Test;
050: import junit.framework.TestSuite;
051:
052: /**
053: * @version $Revision: 1.4 $ $Date: 2005/03/15 05:37:33 $
054: * @author Rodney Waldhoff
055: */
056: public class TestForElmar extends AbstractFunctionalTest {
057:
058: //------------------------------------------------------------ Conventional
059:
060: public TestForElmar(String testName) {
061: super (testName);
062: }
063:
064: public static Test suite() {
065: return new TestSuite(TestForElmar.class);
066: }
067:
068: protected File getDatabaseDirectory() {
069: return new File("testdb2");
070: }
071:
072: protected String getConnectString() {
073: return "jdbc:axiondb:testdb2:testdb2";
074: }
075:
076: //------------------------------------------------------------------- Tests
077:
078: public void testElmarsExample() throws Exception {
079: // first, create the database and table
080: {
081: Connection conn = DriverManager
082: .getConnection("jdbc:axiondb:testdb2:testdb2");
083: assertNotNull(conn);
084: Statement stmt = conn.createStatement();
085: stmt.execute("create table foo ( id integer )");
086: stmt.execute("insert into foo values ( 0 )");
087: stmt.close();
088: conn.close();
089: }
090:
091: // now following Elmar's example:
092:
093: // 1) for each table, I create a database connection, execute a query to see if
094: // the table exists and close the connection again. [But not the statement]
095: {
096: Connection conn = DriverManager
097: .getConnection("jdbc:axiondb:testdb2:testdb2");
098: assertNotNull(conn);
099: Statement stmt = conn.createStatement();
100: ResultSet rset = stmt
101: .executeQuery("select count(*) from foo");
102: assertTrue(rset.next());
103: assertEquals(1, rset.getInt(1));
104: rset.close();
105: // stmt.close(); // note statement not closed
106: conn.close();
107: }
108:
109: // 2) The application seems to perform fine, no exceptions or other complaints,
110: // even when saving to the database and issuing a checkpoint.
111: {
112: Connection conn = DriverManager
113: .getConnection("jdbc:axiondb:testdb2:testdb2");
114: assertNotNull(conn);
115: Statement stmt = conn.createStatement();
116: stmt.execute("insert into foo values ( 1 )");
117: stmt.close();
118: conn.close();
119: }
120: {
121: Connection conn = DriverManager
122: .getConnection("jdbc:axiondb:testdb2:testdb2");
123: assertNotNull(conn);
124: Statement stmt = conn.createStatement();
125: stmt.execute("insert into foo values ( 2 )");
126: // stmt.close(); // note statement not closed
127: conn.close();
128: }
129: {
130: Connection conn = DriverManager
131: .getConnection("jdbc:axiondb:testdb2:testdb2");
132: assertNotNull(conn);
133: Statement stmt = conn.createStatement();
134: stmt.execute("insert into foo values ( 3 )");
135: stmt.close();
136: conn.close();
137: }
138:
139: {
140: Connection conn = DriverManager
141: .getConnection("jdbc:axiondb:testdb2:testdb2");
142: assertNotNull(conn);
143: Statement stmt = conn.createStatement();
144: ResultSet rset = stmt
145: .executeQuery("select count(*) from foo");
146: assertTrue(rset.next());
147: assertEquals(4, rset.getInt(1));
148: rset.close();
149: stmt.close();
150: conn.close();
151: }
152:
153: // 3) Upon shutdown I receive the exception shown above and none of the data
154: // produced during the session actually made it to Disk.
155: {
156: Connection conn = DriverManager
157: .getConnection("jdbc:axiondb:testdb2:testdb2");
158: assertNotNull(conn);
159: Statement stmt = conn.createStatement();
160: stmt.execute("shutdown");
161: stmt.close();
162: conn.close();
163: }
164:
165: {
166: Connection conn = DriverManager
167: .getConnection("jdbc:axiondb:testdb2:testdb2");
168: assertNotNull(conn);
169: Statement stmt = conn.createStatement();
170: ResultSet rset = stmt
171: .executeQuery("select count(*) from foo");
172: assertTrue(rset.next());
173: assertEquals(4, rset.getInt(1));
174: rset.close();
175: stmt.close();
176: conn.close();
177: }
178: }
179:
180: }
|