org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests Java Examples

The following examples show how to use org.apache.derbyTesting.functionTests.util.PrivilegedFileOpsForTests. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SecureServerTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void setTraceDirectory() throws Exception {
	PrivilegedFileOpsForTests.mkdirs(new File("trace"));
    String  traceDirectoryOutput = runServerCommand( "tracedirectory trace" );
    println( "Output for tracedirectory trace command:\n\n" + traceDirectoryOutput );

    if ( traceDirectoryOutput.indexOf( "Trace directory changed to trace." ) < 0 )
    { fail( "Unexpected output in setting trace directory:" + traceDirectoryOutput ); }

    String pingOutput = runServerCommand( "ping" );

    if (pingOutput.indexOf("Connection obtained for host:") < 0)
    { fail ("Failed ping after changing trace directory: " + pingOutput);}
    assertTrue("Trace file does not exist",
            PrivilegedFileOpsForTests.exists(new File("trace/Server6.trace")));
}
 
Example #2
Source File: SecureServerTest.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
private void setTraceDirectory() throws Exception {
	PrivilegedFileOpsForTests.mkdirs(new File("trace"));
    String  traceDirectoryOutput = runServerCommand( "tracedirectory trace" );
    println( "Output for tracedirectory trace command:\n\n" + traceDirectoryOutput );

    if ( traceDirectoryOutput.indexOf( "Trace directory changed to trace." ) < 0 )
    { fail( "Unexpected output in setting trace directory:" + traceDirectoryOutput ); }

    String pingOutput = runServerCommand( "ping" );

    if (pingOutput.indexOf("Connection obtained for host:") < 0)
    { fail ("Failed ping after changing trace directory: " + pingOutput);}
    assertTrue("Trace file does not exist",
            PrivilegedFileOpsForTests.exists(new File("trace/Server6.trace")));
}
 
Example #3
Source File: 919148_ReplicationRun_0_s.java    From coming with MIT License 4 votes vote down vote up
/**
 * Run the test. Extra logic in addition to BaseTestCase's similar logic,
 * to save derby.log and database files for replication directories if a
 * failure happens.
 */
public void runBare() throws Throwable {
 
    try {
 
        super.runBare();
 
    } catch (Throwable running) {
 
        // Copy the master and slave's derby.log file and databases
        //
        PrintWriter stackOut = null;
 
        try {
            String failPath = PrivilegedFileOpsForTests.
                getAbsolutePath(getFailureFolder());
 
            stackOut = new PrintWriter(
                    PrivilegedFileOpsForTests.getFileOutputStream(
                        new File(failPath, ERRORSTACKTRACEFILE), true));
 
            String[] replPaths = new String[]{masterDbSubPath,
                                              slaveDbSubPath};
 
            for (int i=0; i < 2; i++) {
                // Copy the derby.log file.
                //
                File origLog = new File(replPaths[i], DERBY_LOG);
                File newLog = new File(failPath,
                                       replPaths[i] + "-" + DERBY_LOG);
                PrivilegedFileOpsForTests.copy(origLog, newLog);
 
                // Copy the database.
                //
                String dbName = TestConfiguration.getCurrent().
                    getDefaultDatabaseName();
                File dbDir = new File(replPaths[i], dbName );
                File newDbDir = new File(failPath,
                                         replPaths[i] + "-" + dbName);
                PrivilegedFileOpsForTests.copy(dbDir,newDbDir);
            }
        } 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 db_slave/db_master's " +
                                 DERBY_LOG + " or database failed:");
                ioe.printStackTrace(stackOut);
                stackOut.println();
            }
        } finally {
            if (stackOut != null) {
                stackOut.close();
            }
 
            // Let JUnit take over
            throw running;
        }
    }
}
 
Example #4
Source File: 919148_ReplicationRun_0_t.java    From coming with MIT License 4 votes vote down vote up
/**
 * Run the test. Extra logic in addition to BaseTestCase's similar logic,
 * to save derby.log and database files for replication directories if a
 * failure happens.
 */
public void runBare() throws Throwable {
 
    try {
 
        super.runBare();
 
    } catch (Throwable running) {
 
        // Copy the master and slave's derby.log file and databases
        //
        PrintWriter stackOut = null;
 
        try {
            String failPath = PrivilegedFileOpsForTests.
                getAbsolutePath(getFailureFolder());
 
            stackOut = new PrintWriter(
                    PrivilegedFileOpsForTests.getFileOutputStream(
                        new File(failPath, ERRORSTACKTRACEFILE), true));
 
            String[] replPaths = new String[]{masterDbSubPath,
                                              slaveDbSubPath};
 
            for (int i=0; i < 2; i++) {
                // Copy the derby.log file.
                //
                File origLog = new File(replPaths[i], DERBY_LOG);
                File newLog = new File(failPath,
                                       replPaths[i] + "-" + DERBY_LOG);
                PrivilegedFileOpsForTests.copy(origLog, newLog);
 
                // Copy the database.
                //
                String dbName = TestConfiguration.getCurrent().
                    getDefaultDatabaseName();
                File dbDir = new File(replPaths[i], dbName );
                File newDbDir = new File(failPath,
                                         replPaths[i] + "-" + dbName);
                PrivilegedFileOpsForTests.copy(dbDir,newDbDir);
            }
        } 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 db_slave/db_master's " +
                                 DERBY_LOG + " or database failed:");
                ioe.printStackTrace(stackOut);
                stackOut.println();
            }
        } finally {
            if (stackOut != null) {
                stackOut.close();
            }
 
            // Let JUnit take over
            throw running;
        }
    }
}
 
Example #5
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/**
 * Run the test. Extra logic in addition to BaseTestCase's similar logic,
 * to save derby.log and database files for replication directories if a
 * failure happens.
 */
public void runBare() throws Throwable {
 
    try {
 
        super.runBare();
 
    } catch (Throwable running) {
 
        // Copy the master and slave's derby.log file and databases
        //
        PrintWriter stackOut = null;
 
        try {
            String failPath = PrivilegedFileOpsForTests.
                getAbsolutePath(getFailureFolder());
 
            stackOut = new PrintWriter(
                    PrivilegedFileOpsForTests.getFileOutputStream(
                        new File(failPath, ERRORSTACKTRACEFILE), true));
 
            String[] replPaths = new String[]{masterDbSubPath,
                                              slaveDbSubPath};
 
            for (int i=0; i < 2; i++) {
                // Copy the derby.log file.
                //
                File origLog = new File(replPaths[i], DERBY_LOG);
                File newLog = new File(failPath,
                                       replPaths[i] + "-" + DERBY_LOG);
                PrivilegedFileOpsForTests.copy(origLog, newLog);
 
                // Copy the database.
                //
                String dbName = TestConfiguration.getCurrent().
                    getDefaultDatabaseName();
                File dbDir = new File(replPaths[i], dbName );
                File newDbDir = new File(failPath,
                                         replPaths[i] + "-" + dbName);
                PrivilegedFileOpsForTests.copy(dbDir,newDbDir);
            }
        } 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 db_slave/db_master's " +
                                 DERBY_LOG + " or database failed:");
                ioe.printStackTrace(stackOut);
                stackOut.println();
            }
        } finally {
            if (stackOut != null) {
                stackOut.close();
            }
 
            // Let JUnit take over
            throw running;
        }
    }
}
 
Example #6
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
/**
 * Run the test. Extra logic in addition to BaseTestCase's similar logic,
 * to save derby.log and database files for replication directories if a
 * failure happens.
 */
public void runBare() throws Throwable {
 
    try {
 
        super.runBare();
 
    } catch (Throwable running) {
 
        // Copy the master and slave's derby.log file and databases
        //
        PrintWriter stackOut = null;
 
        try {
            String failPath = PrivilegedFileOpsForTests.
                getAbsolutePath(getFailureFolder());
 
            stackOut = new PrintWriter(
                    PrivilegedFileOpsForTests.getFileOutputStream(
                        new File(failPath, ERRORSTACKTRACEFILE), true));
 
            String[] replPaths = new String[]{masterDbSubPath,
                                              slaveDbSubPath};
 
            for (int i=0; i < 2; i++) {
                // Copy the derby.log file.
                //
                File origLog = new File(replPaths[i], DERBY_LOG);
                File newLog = new File(failPath,
                                       replPaths[i] + "-" + DERBY_LOG);
                PrivilegedFileOpsForTests.copy(origLog, newLog);
 
                // Copy the database.
                //
                String dbName = TestConfiguration.getCurrent().
                    getDefaultDatabaseName();
                File dbDir = new File(replPaths[i], dbName );
                File newDbDir = new File(failPath,
                                         replPaths[i] + "-" + dbName);
                PrivilegedFileOpsForTests.copy(dbDir,newDbDir);
            }
        } 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 db_slave/db_master's " +
                                 DERBY_LOG + " or database failed:");
                ioe.printStackTrace(stackOut);
                stackOut.println();
            }
        } finally {
            if (stackOut != null) {
                stackOut.close();
            }
 
            // Let JUnit take over
            throw running;
        }
    }
}