Search in sources :

Example 6 with TestConfiguration

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

the class Derby6396Test method testTempNotReadable.

public void testTempNotReadable() throws SQLException {
    final TestConfiguration config = TestConfiguration.getCurrent();
    // First make sure the database exists and is not booted.
    getConnection().close();
    config.shutdownDatabase();
    // Now make sure the database has a tmp directory that cannot be read.
    tmpDir = new File(config.getDatabasePath(config.getDefaultDatabaseName()), "tmp");
    assertTrue(PrivilegedFileOpsForTests.mkdir(tmpDir));
    PrivilegedFileOpsForTests.setReadable(tmpDir, false, true);
    // Booting the database used to fail with a NullPointerException.
    // Should succeed now.
    getConnection().close();
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) File(java.io.File)

Example 7 with TestConfiguration

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

the class ErrorStreamTest method runBareOverridable.

/**
 * <p>
 * Run the bare test, including {@code setUp()} and {@code tearDown()}.
 * </p>
 *
 * <p>
 * This is overriding BaseJDBCTestCase.runBareOverridable and thereby
 * BaseJDBCTestCase.runBare(), so we can copy any log files created by this
 * test if any of the fixtures fail.
 * </p>
 */
public void runBareOverridable() throws Throwable {
    PrintStream out = System.out;
    TestConfiguration config = getTestConfiguration();
    boolean stopAfterFirstFail = config.stopAfterFirstFail();
    try {
        super.runBareOverridable();
    }// the database of the failed test.
     catch (Throwable running) {
        PrintWriter stackOut = null;
        try {
            copyFileToFail(LOGFILESDIR);
            nullFields();
            deleteFile(LOGFILESDIR);
            // copy files from testStyleRollingFile:
            copyFileToFail("derby-0.log");
            copyFileToFail("derby-0.log.lck");
            // copy files from the testDefaultRollingUserConfig test
            for (int i = 0; i < 3; i++) {
                copyFileToFail("db-" + i + ".log");
                deleteFile("db-" + i + ".log");
            }
        } catch (IOException ioe) {
            // We need to throw the original exception so if there
            // is an exception saving the db or derby.log we will print it
            // and additionally try to log it to file.
            BaseTestCase.printStackTrace(ioe);
            if (stackOut != null) {
                stackOut.println("Copying derby.log or database failed:");
                ioe.printStackTrace(stackOut);
                stackOut.println();
            }
        } finally {
            if (stackOut != null) {
                stackOut.close();
            }
            if (stopAfterFirstFail) {
                // if run with -Dderby.tests.stopAfterFirstFail=true
                // exit after reporting failure. Useful for debugging
                // cascading failures or errors that lead to hang.
                running.printStackTrace(out);
                System.exit(1);
            } else
                throw running;
        }
    } finally {
        // attempt to clean up
        // first ensure we have the engine shutdown, or some
        // files cannot be cleaned up.
        getTestConfiguration().shutdownEngine();
        File origLogFilesDir = new File(DEFAULT_DB_DIR, LOGFILESDIR);
        nullFields();
        removeDirectory(origLogFilesDir);
        deleteFile("derby-0.log.lck");
        deleteFile("derby-0.log");
        deleteFile("derby.log");
    }
}
Also used : PrintStream(java.io.PrintStream) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) IOException(java.io.IOException) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 8 with TestConfiguration

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

the class ShutdownWithoutDeregisterPermissionTest method testShutdownWithoutPermission.

public void testShutdownWithoutPermission() throws SQLException {
    // First get a connection to make sure the engine is booted.
    getConnection().close();
    // Shut down the engine. This used to fail with an
    // AccessControlException on Java 8 before DERBY-6224.
    TestConfiguration config = TestConfiguration.getCurrent();
    config.shutdownEngine();
    // Test whether shutdown deregistered the driver. On versions prior
    // to Java 8/JDBC 4.2, we expect the driver to be deregistered even
    // though the permission is missing, and the call to getDrivers()
    // should not return any instance of AutoloadedDriver.
    // On Java 8/JDBC 4.2 and higher, we expect AutoloadedDriver to
    // be in the list of registered drivers.
    Enumeration<Driver> drivers = DriverManager.getDrivers();
    Driver found = null;
    while (found == null && drivers.hasMoreElements()) {
        Driver driver = drivers.nextElement();
        if (driver.getClass().getName().startsWith("org.apache.derby.iapi.jdbc.AutoloadedDriver")) {
            found = driver;
        }
    }
    if (JDBC.vmSupportsJDBC42()) {
        assertNotNull("Expected driver to be registered", found);
    } else {
        assertNull("Expected driver to be deregistered", found);
    }
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) Driver(java.sql.Driver)

Example 9 with TestConfiguration

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

the class Changes10_9 method verifyNewLocations.

private void verifyNewLocations(int noOfObjects) throws SQLException {
    TestConfiguration tc = TestConfiguration.getCurrent();
    String dbPath = tc.getPhysicalDatabaseName(tc.getDefaultDatabaseName());
    String jarDirName = "system" + File.separator + dbPath + File.separator + "jar";
    File jarDir = new File(jarDirName);
    assertTrue(jarDir.isDirectory());
    File[] contents = jarDir.listFiles();
    // <db>/jar should now contain this no of files, none of which are
    // directories
    assertEquals(noOfObjects, contents.length);
    // assert that all the old style directories are gone
    for (int i = 0; i < contents.length; i++) {
        File f = contents[i];
        assertTrue(f.isFile());
        assertFileNameShape(f.getName());
    }
}
Also used : TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration) File(java.io.File)

Example 10 with TestConfiguration

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

the class Changes10_10 method testReadMeFiles.

/**
 * DERBY-5996(Create readme files (cautioning users against modifying
 *  database files) at database hard upgrade time)
 * Simple test to make sure readme files are getting created
 */
public void testReadMeFiles() throws SQLException, IOException {
    Statement s = createStatement();
    s.close();
    TestConfiguration currentConfig = TestConfiguration.getCurrent();
    String dbPath = currentConfig.getDatabasePath(currentConfig.getDefaultDatabaseName());
    switch(getPhase()) {
        case PH_CREATE:
        case PH_SOFT_UPGRADE:
        case PH_POST_SOFT_UPGRADE:
            // DERBY-5995 Pre 10.10 databases would not have readme files
            lookForReadmeFile(dbPath, false);
            lookForReadmeFile(dbPath + File.separator + "seg0", false);
            lookForReadmeFile(dbPath + File.separator + "log", false);
            break;
        case PH_HARD_UPGRADE:
        case PH_POST_HARD_UPGRADE:
            // DERBY-5995 Hard upgrade to 10.10 will create readme files
            lookForReadmeFile(dbPath, true);
            lookForReadmeFile(dbPath + File.separator + "seg0", true);
            lookForReadmeFile(dbPath + File.separator + "log", true);
            break;
    }
}
Also used : Statement(java.sql.Statement) PreparedStatement(java.sql.PreparedStatement) TestConfiguration(org.apache.derbyTesting.junit.TestConfiguration)

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