Search in sources :

Example 11 with TestConfiguration

use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.

the class HarnessJavaTest method decorate.

/**
 * Decorate a HarnessJavaTest test. Any sub-class must
 * call this decorator when adding a test to a suite.
 * This sets up the ij system properties to setup
 * the default connection to be to the default database.
 * The lock timeouts are also shortened and the test
 * will start in a clean database.
 */
protected static Test decorate(HarnessJavaTest test) {
    Test dtest = new SystemPropertyTestSetup(test, new Properties()) {

        protected void setUp() throws java.lang.Exception {
            TestConfiguration config = TestConfiguration.getCurrent();
            // With JDBC 3 connect using a JDBC URL
            if (JDBC.vmSupportsJDBC3()) {
                newValues.setProperty("ij.database", config.getJDBCUrl());
            }
            super.setUp();
        }
    };
    dtest = DatabasePropertyTestSetup.setLockTimeouts(dtest, 4, 6);
    dtest = new CleanDatabaseTestSetup(dtest);
    return dtest;
}
Also used : Test(junit.framework.Test) CleanDatabaseTestSetup(org.apache.derbyTesting.junit.CleanDatabaseTestSetup) SystemPropertyTestSetup(org.apache.derbyTesting.junit.SystemPropertyTestSetup) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) Properties(java.util.Properties)

Example 12 with TestConfiguration

use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.

the class Test_6661 method test_01.

// /////////////////////////////////////////////////////////////////////////////////
// 
// TESTS
// 
// /////////////////////////////////////////////////////////////////////////////////
public void test_01() throws Exception {
    Connection conn = getConnection();
    // 
    // Create and verify a number of constraints.
    // 
    goodStatement(conn, "create table tprim6661_vanilla\n" + "(\n" + "    keyCol  int not null,\n" + "    constraint tprim6661_vanilla primary key( keyCol )\n" + ")\n");
    goodStatement(conn, "create table tprim6661_init_deferred\n" + "(\n" + "    keyCol  int not null,\n" + "    constraint tprim6661_init_deferred primary key( keyCol ) deferrable initially deferred\n" + ")\n");
    goodStatement(conn, "create table tprim6661_init_immediate\n" + "(\n" + "    keyCol  int not null,\n" + "    constraint tprim6661_init_immediate primary key( keyCol ) deferrable\n" + ")\n");
    goodStatement(conn, "create table tunique6661_vanilla\n" + "(\n" + "    keyCol  int not null,\n" + "    constraint tunique6661_vanilla primary key( keyCol )\n" + ")\n");
    goodStatement(conn, "create table tunique6661_init_deferred\n" + "(\n" + "    keyCol  int not null,\n" + "    constraint tunique6661_init_deferred primary key( keyCol ) deferrable initially deferred\n" + ")\n");
    goodStatement(conn, "create table tunique6661_init_immediate\n" + "(\n" + "    keyCol  int not null,\n" + "    constraint tunique6661_init_immediate primary key( keyCol ) deferrable\n" + ")\n");
    goodStatement(conn, "create table tref6661\n" + "(\n" + "    tref6661_vanilla int,\n" + "    tref6661_init_deferred int,\n" + "    tref6661_init_immediate int,\n" + "\n" + "    constraint tref6661_vanilla foreign key( tref6661_vanilla ) references tprim6661_vanilla( keyCol ),\n" + "    constraint tref6661_init_deferred foreign key( tref6661_init_deferred ) references tprim6661_vanilla( keyCol ) deferrable initially deferred,\n" + "    constraint tref6661_init_immediate foreign key( tref6661_init_immediate ) references tprim6661_vanilla( keyCol ) deferrable\n" + ")\n");
    goodStatement(conn, "create table tcheck6661\n" + "(\n" + "    a int,\n" + "\n" + "    constraint check6661_vanilla check( a > 0 ),\n" + "    constraint check6661_init_deferred check( a > 10 ) deferrable initially deferred,\n" + "    constraint check6661_init_immediate check( a > 100 ) deferrable\n" + ")\n");
    String query = "select constraintname, state from sys.sysconstraints order by constraintname";
    assertResults(conn, query, EXPECTED_CONSTRAINT_STATE, true);
    // 
    // Create a dblook script.
    // 
    TestConfiguration config = getTestConfiguration();
    String dbName = config.getPhysicalDatabaseName(config.getDefaultDatabaseName());
    new dblook(new String[] { "-d", "jdbc:derby:" + dbName, "-o", DBLOOK_OUTPUT });
    // 
    // Drop the schema objects.
    // 
    goodStatement(conn, "drop table tcheck6661");
    goodStatement(conn, "drop table tref6661");
    goodStatement(conn, "drop table tunique6661_init_immediate");
    goodStatement(conn, "drop table tunique6661_init_deferred");
    goodStatement(conn, "drop table tunique6661_vanilla");
    goodStatement(conn, "drop table tprim6661_init_immediate");
    goodStatement(conn, "drop table tprim6661_init_deferred");
    goodStatement(conn, "drop table tprim6661_vanilla");
    assertResults(conn, query, new String[][] {}, true);
    // 
    // Now run the script created by dblook and verify that the
    // deferred constraints were re-created correctly.
    // 
    dblook_test.runDDL(conn, DBLOOK_OUTPUT);
    assertResults(conn, query, EXPECTED_CONSTRAINT_STATE, true);
}
Also used : org.apache.derby.tools.dblook(org.apache.derby.tools.dblook) Connection(java.sql.Connection) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration)

Example 13 with TestConfiguration

use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.

the class DatabaseMetaDataTest method testGetURL.

/**
 * getURL() method. Note that this method
 * is the only JDBC 3 DatabaseMetaData method
 * that is dropped in JSR169.
 *
 * @throws java.sql.SQLException
 */
public void testGetURL() throws SQLException {
    DatabaseMetaData dmd = getDMD();
    String url;
    try {
        url = dmd.getURL();
    } catch (NoSuchMethodError e) {
        // JSR 169 - method must not be there!
        assertTrue("getURL not supported", JDBC.vmSupportsJSR169());
        assertFalse("getURL not supported", JDBC.vmSupportsJDBC3());
        return;
    }
    assertFalse("getURL is supported!", JDBC.vmSupportsJSR169());
    assertTrue("getURL is supported!", JDBC.vmSupportsJDBC3());
    TestConfiguration config = getTestConfiguration();
    String expectedURL = config.getJDBCUrl();
    // client returns the URL with connection attributes.
    if (usingDerbyNetClient()) {
        List<String> urlComponents = Arrays.asList(url.split(";"));
        // Only compare whatever comes before the first semi-colon with
        // the expected URL. Check connection attributes separately.
        url = urlComponents.get(0);
        // Put each actual connection attribute in a HashSet for easy
        // comparison.
        HashSet<String> attrs = new HashSet<String>(urlComponents.subList(1, urlComponents.size()));
        // Put each expected connection attribute in a HashSet.
        HashSet<String> expectedAttrs = new HashSet<String>();
        Properties ca = config.getConnectionAttributes();
        for (String key : ca.stringPropertyNames()) {
            expectedAttrs.add(key + '=' + ca.getProperty(key));
        }
        // Verify that the actual connection attributes match the
        // expected attributes. Order is irrelevant.
        assertEquals("Connection attributes don't match", expectedAttrs, attrs);
    }
    assertEquals("getURL match", expectedURL, url);
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) DatabaseMetaData(java.sql.DatabaseMetaData) Properties(java.util.Properties) HashSet(java.util.HashSet)

Example 14 with TestConfiguration

use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.

the class ConcurrentAutoloadTest method testConcurrentAutoloading.

public void testConcurrentAutoloading() throws Exception {
    if (!TestConfiguration.loadingFromJars()) {
        // Autoloading only happens when running from jars.
        return;
    }
    if (!JDBC.vmSupportsJDBC41()) {
        // in multiple threads at once. See DERBY-4480.
        return;
    }
    TestConfiguration tc = getTestConfiguration();
    final String url = tc.getJDBCUrl() + ";create=true";
    final String user = tc.getUserName();
    final String pw = tc.getUserPassword();
    final List<Throwable> errors = Collections.synchronizedList(new ArrayList<Throwable>());
    Runnable r = new Runnable() {

        public void run() {
            try {
                DriverManager.getConnection(url, user, pw);
                println("Successfully connected!");
            } catch (Throwable t) {
                println("Failed to connect!");
                errors.add(t);
            }
        }
    };
    Thread t1 = new Thread(r);
    Thread t2 = new Thread(r);
    t1.start();
    t2.start();
    t1.join();
    t2.join();
    if (!errors.isEmpty()) {
        if (errors.size() > 1) {
            // print all stack traces if we have multiple errors.
            for (int i = 0; i < errors.size(); i++) {
                printStackTrace((Throwable) errors.get(i));
            }
        }
        fail("Thread failed", (Throwable) errors.get(0));
    }
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration)

Example 15 with TestConfiguration

use of org.apache.derbyTesting.junit.TestConfiguration in project derby by apache.

the class RawDBReaderTest method test_001_rawDBReader.

// /////////////////////////////////////////////////////////////////////////////////
// 
// TESTS
// 
// /////////////////////////////////////////////////////////////////////////////////
/**
 * <p>
 * Test the
 * </p>
 */
public void test_001_rawDBReader() throws Exception {
    // create and populate the corrupt database
    Connection dboConnection = openUserConnection(TEST_DBO);
    populateCorruptDB(dboConnection);
    TestConfiguration tc = getTestConfiguration();
    // shutdown the database
    tc.shutdownDatabase();
    String dbName = tc.getDefaultDatabaseName();
    File systemDir = new File("system");
    _dbDir = new File(systemDir, dbName);
    String databaseName = _dbDir.getPath();
    Connection newDBConn = DriverManager.getConnection(MEMORY_DB + ";create=true");
    // verify that the tool hasn't created any schema objects
    vetUnloaded(newDBConn);
    // load the tool to recover the corrupt database
    String dboPassword = tc.getPassword(TEST_DBO);
    goodStatement(newDBConn, "call syscs_util.syscs_register_tool\n" + "(\n" + "  'rawDBReader',\n" + "  true,\n" + "  '" + RECOVERY_SCRIPT + "',\n" + "  'CONTROL11',\n" + "  'RAW11_',\n" + "  '" + databaseName + "',\n" + "  'bootPassword=" + BOOT_PASSWORD + "',\n" + "  '" + TEST_DBO + "',\n" + "  '" + dboPassword + "'\n" + ")\n");
    // verify that the expected schema objects have been created
    vetLoaded(newDBConn);
    runRecoveryScript(newDBConn);
    // now verify that we siphoned the data out of the corrupt database
    vetSiphoning(newDBConn);
    // drop the tables holding the data we siphoned out of the corrupt database
    dropSiphonedData(newDBConn);
    // unload the tool
    goodStatement(newDBConn, "call syscs_util.syscs_register_tool\n" + "(\n" + "  'rawDBReader',\n" + "  false,\n" + "  'CONTROL11',\n" + "  'RAW11_'\n" + ")\n");
    vetUnloaded(newDBConn);
    shutdownInMemoryDB();
}
Also used : Connection(java.sql.Connection) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) File(java.io.File)

Aggregations

TestConfiguration (org.apache.derbyTesting.junit.TestConfiguration)21 File (java.io.File)7 Connection (java.sql.Connection)5 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 DataSource (javax.sql.DataSource)2 JDBCDataSource (org.apache.derbyTesting.junit.JDBCDataSource)2 PrintStream (java.io.PrintStream)1 PrintWriter (java.io.PrintWriter)1 Socket (java.net.Socket)1 UnknownHostException (java.net.UnknownHostException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 Driver (java.sql.Driver)1 PreparedStatement (java.sql.PreparedStatement)1 Statement (java.sql.Statement)1 HashSet (java.util.HashSet)1 Test (junit.framework.Test)1 org.apache.derby.tools.dblook (org.apache.derby.tools.dblook)1