org.apache.derbyTesting.junit.BaseTestCase Java Examples

The following examples show how to use org.apache.derbyTesting.junit.BaseTestCase. 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: SURDataModelSetup.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a datamodel for testing Scrollable Updatable ResultSets
 * and populates the database model with data.
 * @param model enumerator for which model to use
 * @param con connection to database
 * @param records number of records in the data model
 */
public static void createDataModel(SURDataModel model, Connection con,
                                   int records) 
    throws SQLException
{
    
    BaseJDBCTestCase.dropTable(con, "T1");
    
    Statement statement = con.createStatement();     
    
    /** Create the table */
    statement.execute(model.getCreateTableStatement());
    BaseTestCase.println(model.getCreateTableStatement());
    
    /** Create secondary index */
    if (model.hasSecondaryKey()) {
        statement.execute("create index a_on_t on t1(a)");
        BaseTestCase.println("create index a_on_t on t1(a)");
    }
    
    /** Populate with data */
    PreparedStatement ps = con.
        prepareStatement("insert into t1 values (?,?,?,?)");
    
    for (int i=0; i<records; i++) {
        ps.setInt(1, i);
        ps.setInt(2, i);
        ps.setInt(3, i*2 + 17);
        ps.setString(4, "Tuple " +i);
        ps.addBatch();
    }
    ps.executeBatch();
    ps.close();
    statement.close();
    con.commit();
}
 
Example #2
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private void failOver_ij(String jvmVersion,
        String dbPath, String dbSubPath, String dbName,
        String host,  // Where the db is run.
        int serverPort,
        
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
            
    String URL = masterURL(dbName)
            +";failover=true";
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( host.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.failover=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "failOver_ij ");
    util.DEBUG(results);
}
 
Example #3
Source File: 919148_ReplicationRun_0_s.java    From coming with MIT License 5 votes vote down vote up
private void failOver_ij(String jvmVersion,
        String dbPath, String dbSubPath, String dbName,
        String host,  // Where the db is run.
        int serverPort,
        
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
            
    String URL = masterURL(dbName)
            +";failover=true";
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( host.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.failover=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "failOver_ij ");
    util.DEBUG(results);
}
 
Example #4
Source File: 919148_ReplicationRun_0_t.java    From coming with MIT License 5 votes vote down vote up
private void failOver_ij(String jvmVersion,
        String dbPath, String dbSubPath, String dbName,
        String host,  // Where the db is run.
        int serverPort,
        
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
            
    String URL = masterURL(dbName)
            +";failover=true";
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( host.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.failover=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "failOver_ij ");
    util.DEBUG(results);
}
 
Example #5
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 5 votes vote down vote up
private void failOver_ij(String jvmVersion,
        String dbPath, String dbSubPath, String dbName,
        String host,  // Where the db is run.
        int serverPort,
        
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
            
    String URL = masterURL(dbName)
            +";failover=true";
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( host.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.failover=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "failOver_ij ");
    util.DEBUG(results);
}
 
Example #6
Source File: SURDataModelSetup.java    From gemfirexd-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a datamodel for testing Scrollable Updatable ResultSets
 * and populates the database model with data.
 * @param model enumerator for which model to use
 * @param con connection to database
 * @param records number of records in the data model
 */
public static void createDataModel(SURDataModel model, Connection con,
                                   int records) 
    throws SQLException
{
    
    BaseJDBCTestCase.dropTable(con, "T1");
    
    Statement statement = con.createStatement();     
    
    /** Create the table */
    statement.execute(model.getCreateTableStatement());
    BaseTestCase.println(model.getCreateTableStatement());
    
    /** Create secondary index */
    if (model.hasSecondaryKey()) {
        statement.execute("create index a_on_t on t1(a)");
        BaseTestCase.println("create index a_on_t on t1(a)");
    }
    
    /** Populate with data */
    PreparedStatement ps = con.
        prepareStatement("insert into t1 values (?,?,?,?)");
    
    for (int i=0; i<records; i++) {
        ps.setInt(1, i);
        ps.setInt(2, i);
        ps.setInt(3, i*2 + 17);
        ps.setString(4, "Tuple " +i);
        ps.addBatch();
    }
    ps.executeBatch();
    ps.close();
    statement.close();
    con.commit();
}
 
Example #7
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void runTestOnSlave(String replicationTest,
        String clientVM,
        String testClientHost,
        String serverHost, int serverPort,
        String dbName)
        throws Exception
{
    util.DEBUG("runTestOnSlave(" + replicationTest
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + serverHost
            + ", " + serverPort
            + ", " + dbName
            + ") "
            );
    
    
    String URL = slaveURL(dbName);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    if ( replicationTest == null ) 
    {
        util.DEBUG("No replicationTest specified. Exitting.");
        return;
    } 
    
    if ( serverHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
        testingClassPath = classPath;
    }
    util.DEBUG("replicationTest: " + replicationTest);
    if ( replicationTest.indexOf(".sql") >= 0 )
    {
        command = clientJvm
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + replicationTest
                ;
    }
    else
    { // JUnit
        if ( testClientHost.equals("localhost") ) 
        {
            testingClassPath = classPath; // Using the complete classpath
        }
        command = clientJvm
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\""  // Now using noSecurityManager decorator
                + " -Dtest.serverHost=" + serverHost  // Tell the test what server
                + " -Dtest.serverPort=" + serverPort  // and port to connect to.
                + " -Dtest.inserts=" + tuplesToInsertPerf // for SimplePerfTest
                + " -Dtest.commitFreq=" +  commitFreq // for SimplePerfTest
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + replicationTest
                ;
    }
    
    long startTime = System.currentTimeMillis();
    String results = null;
    if ( testClientHost.equalsIgnoreCase("localhost") )
    {
        runUserCommandLocally(command, userDir+FS+slaveDbSubPath, "runTestOnSlave ");
    }
    else
    {
        command = "cd "+ userDir +";" // Must be positioned where the properties file is located.
                + command;
        results = runUserCommandRemotely(command, testClientHost, testUser,
                "runTestOnSlave ");
    }
    util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0);
    
}
 
Example #8
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void runLoad(String load,
        String clientVM,
        String testClientHost,
        String masterHost, int masterPort,
        String dbSubPath) // FIXME? Should we allow extra URL options?
        throws Exception
{
    util.DEBUG("runLoad(" + load
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + masterHost
            + ", " + masterPort
            + ", " + dbSubPath
            + ") "
            );
    
    
    String URL = masterLoadURL(dbSubPath);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            // Needed for 'run resource 'createTestProcedures.subsql';' cases?
            // Nope? what is 'resource'?
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
        testingClassPath = classPath;
    }
    util.DEBUG("load: " + load);
    if ( load.indexOf(".sql") >= 0 )
    {
        command = clientJvm // "java"
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + load
                ;
    }
    else
    {
        /* BEGIN For junit: */
        command = clientJvm // "java"
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\""  // Now using noSecurityManager decorator
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + load //
                // + " org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationTestRun"
                ;
        /* END */
    }
    
    /* String results = */
    if ( testClientHost.equalsIgnoreCase("localhost") )
    {
        runUserCommandInThread(command,  testUser, dbSubPath,
                "runLoad["+dbSubPath+"] ");
    }
    else
    {
        runUserCommandInThreadRemotely(command,
                testClientHost, testUser, dbSubPath,
                "runLoad["+dbSubPath+"] ");
    }
    
}
 
Example #9
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void runStateTest(String stateTest,
        String clientVM,
        String testClientHost,
        String masterHost, int masterPort, // serverHost?, serverPort?
        String dbSubPath) // FIXME? Should we allow extra URL options?
        throws Exception
{
    util.DEBUG("runStateTest(" + stateTest
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + masterHost
            + ", " + masterPort
            + ", " + dbSubPath
            + ") "
            );
    
    
    String URL = masterLoadURL(dbSubPath);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            // Needed for 'run resource 'createTestProcedures.subsql';' cases?
            // Nope? what is 'resource'?
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
        testingClassPath = classPath;
    }
    util.DEBUG("stateTest: " + stateTest);
    if ( stateTest.indexOf(".sql") >= 0 )
    {
        command = clientJvm 
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + stateTest
                ;
    }
    else
    {
        /* BEGIN For junit: */
        command = "cd "+ userDir +";" // Must be positioned where the properties file is located.
                + clientJvm 
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\""  // Now using noSecurityManager decorator
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + stateTest
                ;
        /* END */
    }
    
    /* String results = */
    runUserCommandRemotely(command,
            testClientHost, // masterHost,
            testUser,
            // dbSubPath,
            "runStateTest "); // ["+dbSubPath+"]
    
}
 
Example #10
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void startLoad(String load,
        String dbSubPath,
        String database,
        boolean existingDB,
        String testClientHost,
        String serverHost,
        int serverPort)
        throws Exception
{
    util.DEBUG("run load " + load
            + " on client " + testClientHost
            + " against server " + serverHost + ":" + serverPort
            + " using DB  " + database + "["+existingDB+"]"
            );
    if ( load == null )
    {
        util.DEBUG("No load supplied!");
        return;
    }
    if ( !existingDB )
    {
        // Create it!
        String URL = masterURL(database)
                +";create=true"; // Creating! No need for encryption here?
        String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
                + PS + derbyVersion +FS+ "derbyTesting.jar"
                + PS + derbyVersion +FS+ "derbytools.jar";
    if ( serverHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
        String clientJvm = BaseTestCase.getJavaExecutableName();
        String command = "rm -rf /"+masterDatabasePath+FS+dbSubPath+FS+database+";" // FIXME! for slave load!
                + clientJvm // "java"
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.create"+database+"=\"" + URL + "\""
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + sqlLoadInit // FIXME! Should be load specific!
                ;
        String results =
                runUserCommandRemotely(command,
                testClientHost,
                testUser,
                "Create_"+database);
        
    }
    
    // Must run in separate thread!:
    runLoad(load,
            jvmVersion,
            testClientHost,
            serverHost, serverPort,
            dbSubPath+FS+database);
    
    // FIXME! How to join and cleanup....
    
}
 
Example #11
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startMaster_CLI(String clientVM,
        String dbName,
        String masterHost,  // Where the command is to be executed.
        int masterServerPort, // master server interface accepting client requests
        String slaveClientInterface, // Will be = slaveReplInterface = slaveHost if only one interface card used.
        int slaveServerPort, // masterPort, // Not used since slave don't accept client requests
        String slaveReplInterface, // slaveHost,
        int slaveReplPort) // slavePort)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        masterClassPath = classPath;
    }
    /* java -classpath ${MASTER_LIB}/derbynet.jar \
     *       org.apache.derby.drda.NetworkServerControl startreplication test \
     *       -slavehost ${SLAVEREPLINTERFACE} -slaveport ${SLAVEREPLPORT} \
     *       -h ${SLAVECLIENTINTERFACE} -p ${SLAVESERVERPORT}?? \
     *       -noSecurityManager
     */
    String command = clientJvm
            + " -classpath " + masterClassPath
            + " " + networkServerControl
            + " startreplication" // startmaster!
            + " " + dbName
            + " -slavehost " + /*slaveHost*/ slaveReplInterface + " -slaveport " + /*slavePort*/ slaveReplPort
            + " -h " + /*masterHost*/ slaveClientInterface + " -p " + masterServerPort /*masterPort*/ /* see comment above slaveServerPort */
            + " -noSecurityManager"
            ;
    
    util.DEBUG("Executing '" + command + "' on " + masterHost);
    
    // Do rsh/ssh to masterHost and execute the command there.
    
    // runUserCommandRemotely(command, // FIXME?! Should NOT be in sep. thread? Wait for it to complete!?
    runUserCommandInThreadRemotely(command, //
            masterHost,
            testUser,
            masterDbSubPath+FS+dbName,
            "startMaster_CLI ");
    
}
 
Example #12
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startMaster_ij(String dbName,
        String masterHost,
        int masterServerPort,  // Where the master db is run.
        String slaveReplInterface, // master server interface accepting client requests
        
        int slaveReplPort, // slaveHost,
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        masterClassPath = classPath;
    }
            
    String URL = masterURL(dbName)
            +";startMaster=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.startMaster=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "startMaster_ij ");
    util.DEBUG(results);
}
 
Example #13
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startSlave_CLI(String clientVM,
        String dbName,
        String slaveClientInterface, // slaveHost, // Where the command is to be executed.
        int slaveServerPort,
        String slaveReplInterface,
        int slaveReplPort)
        throws InterruptedException
{
    
    String slaveClassPath = derbySlaveVersion +FS+ "derbynet.jar";
    if ( slaveClientInterface.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        slaveClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    /*
     * java -classpath ${SLAVE_LIB}/derbynet.jar org.apache.derby.drda.NetworkServerControl \
     *       startslave test -slavehost ${SLAVEREPLINTERFACE}  -slaveport ${SLAVEREPLPORT} \
     *       -h ${SLAVECLIENTINTERFACE} -p ${SLAVESERVERPORT}??  \
     *       -noSecurityManager
     */
    String command = clientJvm
            + " -classpath " + slaveClassPath
            + " " + networkServerControl
            + " startslave"
            + " " + dbName
            + " -slavehost " + slaveReplInterface + " -slaveport " + slaveReplPort
            + " -h " + slaveClientInterface + " -p " + slaveServerPort
            + " -noSecurityManager"
            ;
    
    util.DEBUG("Executing  '" + command + "' on " + slaveClientInterface); // slaveHost
    
    runUserCommandInThreadRemotely(command,
            slaveClientInterface, // slaveHost,
            testUser,
            slaveDbSubPath+FS+dbName,
            "startSlave_CLI ");
    
}
 
Example #14
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startSlave_ij(String jvmVersion,
        String dbName,
        String slaveHost,  // Where the slave db is run.
        int slaveServerPort, // slave server interface accepting client requests
        
        String slaveReplInterface, // slaveHost,
        int slaveReplPort, // slavePort)
        
        String testClientHost)
        throws Exception
{
    
    String slaveClassPath = derbySlaveVersion +FS+ "derbynet.jar";
    if ( slaveHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        slaveClassPath = classPath;
    }
    String URL = slaveURL(dbName)
            +";startSlave=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( slaveHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.startSlave=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    /* String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "startSlave_ij ");
    util.DEBUG(results); */
    // 618220 + failover_impl_3205_v3.diff + derby-3361-1a.diff :
    runUserCommandInThreadRemotely(command,
            testClientHost,
            testUser,
            slaveDbSubPath+FS+dbName,
            "startSlave_ij ");
    
}
 
Example #15
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void runTest(String replicationTest,
        String clientVM,
        String testClientHost,
        String serverHost, int serverPort,
        String dbName)
        throws Exception
{
    util.DEBUG("runTest(" + replicationTest
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + serverHost
            + ", " + serverPort
            + ", " + dbName
            + ") "
            );
    
    if ( replicationTest == null ) 
    {
        util.DEBUG("No replicationTest specified. Exitting.");
        return;
    } 
    
    if ( simpleLoad )
    {
        _testInsertUpdateDeleteOnMaster(serverHost, serverPort,
            dbName, simpleLoadTuples);
        return;
    }
    
    String URL = masterURL(dbName);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    util.DEBUG("replicationTest: " + replicationTest);
    if ( replicationTest.indexOf(".sql") >= 0 )
    {
        command = clientJvm
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + replicationTest
                ;
    }
    else
    { // JUnit
        if ( testClientHost.equals("localhost") )
        {
            testingClassPath = classPath; // Using the complete classpath
        }
        command = clientJvm
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\"" // Now using noSecurityManager decorator
                + " -Dtest.serverHost=" + serverHost  // Tell the test what server
                + " -Dtest.serverPort=" + serverPort  // and port to connect to.
                + " -Dtest.inserts=" + tuplesToInsertPerf // for SimplePerfTest
                + " -Dtest.commitFreq=" +  commitFreq // for SimplePerfTest
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + replicationTest
                ;
    }
    
    long startTime = System.currentTimeMillis();
    String results = null;
    if ( testClientHost.equalsIgnoreCase("localhost") )
    {
        runUserCommandLocally(command, userDir+FS+masterDbSubPath, "runTest ");
    }
    else
    {
        command = "cd "+ userDir +";" // Must be positioned where the properties file is located.
                + command;
        results = runUserCommandRemotely(command, testClientHost, testUser,
                "runTest ");
    }
    util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0);
    
}
 
Example #16
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void stopMaster_ij(String jvmVersion,
        String dbName,
        String masterHost,  // Where the master db is run.
        int masterServerPort,
        
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        masterClassPath = classPath;
    }
            
    String URL = masterURL(dbName)
            +";stopMaster=true"; 
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.stopMaster=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "stopMaster_ij ");
    util.DEBUG(results);
}
 
Example #17
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void stopServer(String serverVM, String serverVersion,
        String serverHost, int serverPort)
{
    util.DEBUG("");
    final String debugId = "stopServer@" + serverHost + ":" + serverPort + " ";
    util.DEBUG("+++ stopServer " + serverVM + " / " + serverVersion
            + " " + debugId);
    
    String serverJvm = BaseTestCase.getJavaExecutableName();
    String serverClassPath = serverVersion + FS+"derby.jar"
            + PS + serverVersion + FS+"derbynet.jar";
    if ( serverHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        serverClassPath = classPath;
    }
    
    String command = "shutdown";
    int port = serverPort;
    
    final String[] commandElements = {serverJvm
            , " -Dderby.infolog.append=true"
            , " -cp ", serverClassPath
            , " " + networkServerControl
            , " " + command
            , " -h " + serverHost // FIXME! interfacesToListenOn
            , " -p ", serverPort+""
            // , " " + securityOption
            };
    String[] envElements = {"CLASS_PATH="+serverClassPath
            , "PATH="+serverVM+FS+".."+FS+"bin"
            };
    if ( serverHost.equals("localhost") )
    {
        envElements =null;
    }
    
    String workingDirName = System.getProperty("user.dir"); // Means we will do the shutdown wherever we are
    util.DEBUG(debugId+"user.dir: " + workingDirName);
    
    String tmp ="";
    for ( int i=0;i<commandElements.length;i++)
    {tmp = tmp + commandElements[i];}
    util.DEBUG(debugId+"commandElements: " + tmp);
    
    final String fullCmd = tmp;
    tmp ="";
    if ( envElements != null )
    {
        for ( int i=0;i<envElements.length;i++)
        {tmp = tmp + envElements[i] + " ";}
    }
    util.DEBUG(debugId+"envElements: " + tmp);
    
    final File workingDir = new File(workingDirName);
    
    String shellCmd = null;
    
    if ( serverHost.equalsIgnoreCase("localhost") )
    {
        util.DEBUG(debugId+"Stopping server on localhost "+ serverHost);
        shellCmd = fullCmd;
    }
    else
    {
        util.DEBUG(debugId+"Stopping server on non-local host "+ serverHost);
        
        String[] shEnvElements = {"setenv CLASS_PATH "+serverClassPath
                , "setenv PATH "+serverVM+FS+".."+FS+"bin:${PATH}"
                };
        String shellEnv = "";
        for ( int i=0;i<shEnvElements.length;i++)
        {shellEnv = shellEnv + shEnvElements[i] + ";";}
        util.DEBUG(debugId+"shellEnv: " + shellEnv);
        
        shellCmd = "pwd;" + shellEnv + ";"  + fullCmd;
        util.DEBUG(debugId+"shellCmd: " + shellCmd);
        
        shellCmd = remoteShell + " "
                + "-l " + testUser + " -n " + serverHost + " "
                + shellCmd;
    }
    
    {
        final String localCommand = shellCmd;
        util.DEBUG(debugId+"localCommand: " + localCommand);
        
        try
        {
            Process proc = Runtime.getRuntime().exec(localCommand,envElements,workingDir);
            processDEBUGOutput(debugId+"pDo ", proc);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    util.DEBUG(debugId+"--- stopServer ");
    util.DEBUG("");
    
}
 
Example #18
Source File: 919148_ReplicationRun_0_s.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void startLoad(String load,
        String dbSubPath,
        String database,
        boolean existingDB,
        String testClientHost,
        String serverHost,
        int serverPort)
        throws Exception
{
    util.DEBUG("run load " + load
            + " on client " + testClientHost
            + " against server " + serverHost + ":" + serverPort
            + " using DB  " + database + "["+existingDB+"]"
            );
    if ( load == null )
    {
        util.DEBUG("No load supplied!");
        return;
    }
    if ( !existingDB )
    {
        // Create it!
        String URL = masterURL(database)
                +";create=true"; // Creating! No need for encryption here?
        String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
                + PS + derbyVersion +FS+ "derbyTesting.jar"
                + PS + derbyVersion +FS+ "derbytools.jar";
    if ( serverHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
        String clientJvm = BaseTestCase.getJavaExecutableName();
        String command = "rm -rf /"+masterDatabasePath+FS+dbSubPath+FS+database+";" // FIXME! for slave load!
                + clientJvm // "java"
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.create"+database+"=\"" + URL + "\""
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + sqlLoadInit // FIXME! Should be load specific!
                ;
        String results =
                runUserCommandRemotely(command,
                testClientHost,
                testUser,
                "Create_"+database);
        
    }
    
    // Must run in separate thread!:
    runLoad(load,
            jvmVersion,
            testClientHost,
            serverHost, serverPort,
            dbSubPath+FS+database);
    
    // FIXME! How to join and cleanup....
    
}
 
Example #19
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;
        }
    }
}
 
Example #20
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void runTest(String replicationTest,
        String clientVM,
        String testClientHost,
        String serverHost, int serverPort,
        String dbName)
        throws Exception
{
    util.DEBUG("runTest(" + replicationTest
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + serverHost
            + ", " + serverPort
            + ", " + dbName
            + ") "
            );
    
    if ( replicationTest == null ) 
    {
        util.DEBUG("No replicationTest specified. Exitting.");
        return;
    } 
    
    if ( simpleLoad )
    {
        _testInsertUpdateDeleteOnMaster(serverHost, serverPort,
            dbName, simpleLoadTuples);
        return;
    }
    
    String URL = masterURL(dbName);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    util.DEBUG("replicationTest: " + replicationTest);
    if ( replicationTest.indexOf(".sql") >= 0 )
    {
        command = clientJvm
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + replicationTest
                ;
    }
    else
    { // JUnit
        if ( testClientHost.equals("localhost") )
        {
            testingClassPath = classPath; // Using the complete classpath
        }
        command = clientJvm
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\"" // Now using noSecurityManager decorator
                + " -Dtest.serverHost=" + serverHost  // Tell the test what server
                + " -Dtest.serverPort=" + serverPort  // and port to connect to.
                + " -Dtest.inserts=" + tuplesToInsertPerf // for SimplePerfTest
                + " -Dtest.commitFreq=" +  commitFreq // for SimplePerfTest
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + replicationTest
                ;
    }
    
    long startTime = System.currentTimeMillis();
    String results = null;
    if ( testClientHost.equalsIgnoreCase("localhost") )
    {
        runUserCommandLocally(command, userDir+FS+masterDbSubPath, "runTest ");
    }
    else
    {
        command = "cd "+ userDir +";" // Must be positioned where the properties file is located.
                + command;
        results = runUserCommandRemotely(command, testClientHost, testUser,
                "runTest ");
    }
    util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0);
    
}
 
Example #21
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void runTestOnSlave(String replicationTest,
        String clientVM,
        String testClientHost,
        String serverHost, int serverPort,
        String dbName)
        throws Exception
{
    util.DEBUG("runTestOnSlave(" + replicationTest
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + serverHost
            + ", " + serverPort
            + ", " + dbName
            + ") "
            );
    
    
    String URL = slaveURL(dbName);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    if ( replicationTest == null ) 
    {
        util.DEBUG("No replicationTest specified. Exitting.");
        return;
    } 
    
    if ( serverHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
        testingClassPath = classPath;
    }
    util.DEBUG("replicationTest: " + replicationTest);
    if ( replicationTest.indexOf(".sql") >= 0 )
    {
        command = clientJvm
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + replicationTest
                ;
    }
    else
    { // JUnit
        if ( testClientHost.equals("localhost") ) 
        {
            testingClassPath = classPath; // Using the complete classpath
        }
        command = clientJvm
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\""  // Now using noSecurityManager decorator
                + " -Dtest.serverHost=" + serverHost  // Tell the test what server
                + " -Dtest.serverPort=" + serverPort  // and port to connect to.
                + " -Dtest.inserts=" + tuplesToInsertPerf // for SimplePerfTest
                + " -Dtest.commitFreq=" +  commitFreq // for SimplePerfTest
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + replicationTest
                ;
    }
    
    long startTime = System.currentTimeMillis();
    String results = null;
    if ( testClientHost.equalsIgnoreCase("localhost") )
    {
        runUserCommandLocally(command, userDir+FS+slaveDbSubPath, "runTestOnSlave ");
    }
    else
    {
        command = "cd "+ userDir +";" // Must be positioned where the properties file is located.
                + command;
        results = runUserCommandRemotely(command, testClientHost, testUser,
                "runTestOnSlave ");
    }
    util.DEBUG("Time: " + (System.currentTimeMillis() - startTime) / 1000.0);
    
}
 
Example #22
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void runLoad(String load,
        String clientVM,
        String testClientHost,
        String masterHost, int masterPort,
        String dbSubPath) // FIXME? Should we allow extra URL options?
        throws Exception
{
    util.DEBUG("runLoad(" + load
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + masterHost
            + ", " + masterPort
            + ", " + dbSubPath
            + ") "
            );
    
    
    String URL = masterLoadURL(dbSubPath);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            // Needed for 'run resource 'createTestProcedures.subsql';' cases?
            // Nope? what is 'resource'?
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
        testingClassPath = classPath;
    }
    util.DEBUG("load: " + load);
    if ( load.indexOf(".sql") >= 0 )
    {
        command = clientJvm // "java"
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + load
                ;
    }
    else
    {
        /* BEGIN For junit: */
        command = clientJvm // "java"
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\""  // Now using noSecurityManager decorator
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + load //
                // + " org.apache.derbyTesting.functionTests.tests.replicationTests.ReplicationTestRun"
                ;
        /* END */
    }
    
    /* String results = */
    if ( testClientHost.equalsIgnoreCase("localhost") )
    {
        runUserCommandInThread(command,  testUser, dbSubPath,
                "runLoad["+dbSubPath+"] ");
    }
    else
    {
        runUserCommandInThreadRemotely(command,
                testClientHost, testUser, dbSubPath,
                "runLoad["+dbSubPath+"] ");
    }
    
}
 
Example #23
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void runStateTest(String stateTest,
        String clientVM,
        String testClientHost,
        String masterHost, int masterPort, // serverHost?, serverPort?
        String dbSubPath) // FIXME? Should we allow extra URL options?
        throws Exception
{
    util.DEBUG("runStateTest(" + stateTest
            + ", " + clientVM
            + ", " + testClientHost
            + ", " + masterHost
            + ", " + masterPort
            + ", " + dbSubPath
            + ") "
            );
    
    
    String URL = masterLoadURL(dbSubPath);
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbyTesting.jar"
            // Needed for 'run resource 'createTestProcedures.subsql';' cases?
            // Nope? what is 'resource'?
            + PS + derbyVersion +FS+ "derbytools.jar";
    String testingClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbynet.jar" // WHY IS THIS NEEDED?
            // See TestConfiguration: startNetworkServer and stopNetworkServer
            + PS + test_jars;
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = null;
    
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
        testingClassPath = classPath;
    }
    util.DEBUG("stateTest: " + stateTest);
    if ( stateTest.indexOf(".sql") >= 0 )
    {
        command = clientJvm 
                + " -Dij.driver=" + DRIVER_CLASS_NAME
                + " -Dij.connection.startTestClient=" + URL
                + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
                + " " + stateTest
                ;
    }
    else
    {
        /* BEGIN For junit: */
        command = "cd "+ userDir +";" // Must be positioned where the properties file is located.
                + clientJvm 
                + " -Dderby.tests.trace=true"
                // + " -Djava.security.policy=\"<NONE>\""  // Now using noSecurityManager decorator
                + " -classpath " + testingClassPath
                + " junit.textui.TestRunner"
                + " " + stateTest
                ;
        /* END */
    }
    
    /* String results = */
    runUserCommandRemotely(command,
            testClientHost, // masterHost,
            testUser,
            // dbSubPath,
            "runStateTest "); // ["+dbSubPath+"]
    
}
 
Example #24
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startMaster_CLI(String clientVM,
        String dbName,
        String masterHost,  // Where the command is to be executed.
        int masterServerPort, // master server interface accepting client requests
        String slaveClientInterface, // Will be = slaveReplInterface = slaveHost if only one interface card used.
        int slaveServerPort, // masterPort, // Not used since slave don't accept client requests
        String slaveReplInterface, // slaveHost,
        int slaveReplPort) // slavePort)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        masterClassPath = classPath;
    }
    /* java -classpath ${MASTER_LIB}/derbynet.jar \
     *       org.apache.derby.drda.NetworkServerControl startreplication test \
     *       -slavehost ${SLAVEREPLINTERFACE} -slaveport ${SLAVEREPLPORT} \
     *       -h ${SLAVECLIENTINTERFACE} -p ${SLAVESERVERPORT}?? \
     *       -noSecurityManager
     */
    String command = clientJvm
            + " -classpath " + masterClassPath
            + " " + networkServerControl
            + " startreplication" // startmaster!
            + " " + dbName
            + " -slavehost " + /*slaveHost*/ slaveReplInterface + " -slaveport " + /*slavePort*/ slaveReplPort
            + " -h " + /*masterHost*/ slaveClientInterface + " -p " + masterServerPort /*masterPort*/ /* see comment above slaveServerPort */
            + " -noSecurityManager"
            ;
    
    util.DEBUG("Executing '" + command + "' on " + masterHost);
    
    // Do rsh/ssh to masterHost and execute the command there.
    
    // runUserCommandRemotely(command, // FIXME?! Should NOT be in sep. thread? Wait for it to complete!?
    runUserCommandInThreadRemotely(command, //
            masterHost,
            testUser,
            masterDbSubPath+FS+dbName,
            "startMaster_CLI ");
    
}
 
Example #25
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startMaster_ij(String dbName,
        String masterHost,
        int masterServerPort,  // Where the master db is run.
        String slaveReplInterface, // master server interface accepting client requests
        
        int slaveReplPort, // slaveHost,
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        masterClassPath = classPath;
    }
            
    String URL = masterURL(dbName)
            +";startMaster=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.startMaster=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "startMaster_ij ");
    util.DEBUG(results);
}
 
Example #26
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startSlave_CLI(String clientVM,
        String dbName,
        String slaveClientInterface, // slaveHost, // Where the command is to be executed.
        int slaveServerPort,
        String slaveReplInterface,
        int slaveReplPort)
        throws InterruptedException
{
    
    String slaveClassPath = derbySlaveVersion +FS+ "derbynet.jar";
    if ( slaveClientInterface.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        slaveClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    /*
     * java -classpath ${SLAVE_LIB}/derbynet.jar org.apache.derby.drda.NetworkServerControl \
     *       startslave test -slavehost ${SLAVEREPLINTERFACE}  -slaveport ${SLAVEREPLPORT} \
     *       -h ${SLAVECLIENTINTERFACE} -p ${SLAVESERVERPORT}??  \
     *       -noSecurityManager
     */
    String command = clientJvm
            + " -classpath " + slaveClassPath
            + " " + networkServerControl
            + " startslave"
            + " " + dbName
            + " -slavehost " + slaveReplInterface + " -slaveport " + slaveReplPort
            + " -h " + slaveClientInterface + " -p " + slaveServerPort
            + " -noSecurityManager"
            ;
    
    util.DEBUG("Executing  '" + command + "' on " + slaveClientInterface); // slaveHost
    
    runUserCommandInThreadRemotely(command,
            slaveClientInterface, // slaveHost,
            testUser,
            slaveDbSubPath+FS+dbName,
            "startSlave_CLI ");
    
}
 
Example #27
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void startSlave_ij(String jvmVersion,
        String dbName,
        String slaveHost,  // Where the slave db is run.
        int slaveServerPort, // slave server interface accepting client requests
        
        String slaveReplInterface, // slaveHost,
        int slaveReplPort, // slavePort)
        
        String testClientHost)
        throws Exception
{
    
    String slaveClassPath = derbySlaveVersion +FS+ "derbynet.jar";
    if ( slaveHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        slaveClassPath = classPath;
    }
    String URL = slaveURL(dbName)
            +";startSlave=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( slaveHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.startSlave=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    /* String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "startSlave_ij ");
    util.DEBUG(results); */
    // 618220 + failover_impl_3205_v3.diff + derby-3361-1a.diff :
    runUserCommandInThreadRemotely(command,
            testClientHost,
            testUser,
            slaveDbSubPath+FS+dbName,
            "startSlave_ij ");
    
}
 
Example #28
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
private void stopMaster_ij(String jvmVersion,
        String dbName,
        String masterHost,  // Where the master db is run.
        int masterServerPort,
        
        String testClientHost)
        throws Exception
{
    
    String masterClassPath = derbyMasterVersion +FS+ "derbynet.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        masterClassPath = classPath;
    }
            
    String URL = masterURL(dbName)
            +";stopMaster=true"; 
    String ijClassPath = derbyVersion +FS+ "derbyclient.jar"
            + PS + derbyVersion +FS+ "derbytools.jar";
    if ( masterHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        ijClassPath = classPath;
    }
    
    String clientJvm = BaseTestCase.getJavaExecutableName();
    
    String command = clientJvm // "java"
            + " -Dij.driver=" + DRIVER_CLASS_NAME
            + " -Dij.connection.stopMaster=\"" + URL + "\""
            + " -classpath " + ijClassPath + " org.apache.derby.tools.ij"
            + " " + "/home/os136789/Replication/testing/exit.sql"
            ;
    
    // Execute the ij command on the testClientHost as testUser
    String results =
            runUserCommandRemotely(command,
            testClientHost,
            testUser,
            "stopMaster_ij ");
    util.DEBUG(results);
}
 
Example #29
Source File: 919148_ReplicationRun_0_t.java    From gumtree-spoon-ast-diff with Apache License 2.0 4 votes vote down vote up
void stopServer(String serverVM, String serverVersion,
        String serverHost, int serverPort)
{
    util.DEBUG("");
    final String debugId = "stopServer@" + serverHost + ":" + serverPort + " ";
    util.DEBUG("+++ stopServer " + serverVM + " / " + serverVersion
            + " " + debugId);
    
    String serverJvm = BaseTestCase.getJavaExecutableName();
    String serverClassPath = serverVersion + FS+"derby.jar"
            + PS + serverVersion + FS+"derbynet.jar";
    if ( serverHost.equals("localhost") )
    { // Use full classpath when running locally. Can not vary server versions!
        serverClassPath = classPath;
    }
    
    String command = "shutdown";
    int port = serverPort;
    
    final String[] commandElements = {serverJvm
            , " -Dderby.infolog.append=true"
            , " -cp ", serverClassPath
            , " " + networkServerControl
            , " " + command
            , " -h " + serverHost // FIXME! interfacesToListenOn
            , " -p ", serverPort+""
            // , " " + securityOption
            };
    String[] envElements = {"CLASS_PATH="+serverClassPath
            , "PATH="+serverVM+FS+".."+FS+"bin"
            };
    if ( serverHost.equals("localhost") )
    {
        envElements =null;
    }
    
    String workingDirName = System.getProperty("user.dir"); // Means we will do the shutdown wherever we are
    util.DEBUG(debugId+"user.dir: " + workingDirName);
    
    String tmp ="";
    for ( int i=0;i<commandElements.length;i++)
    {tmp = tmp + commandElements[i];}
    util.DEBUG(debugId+"commandElements: " + tmp);
    
    final String fullCmd = tmp;
    tmp ="";
    if ( envElements != null )
    {
        for ( int i=0;i<envElements.length;i++)
        {tmp = tmp + envElements[i] + " ";}
    }
    util.DEBUG(debugId+"envElements: " + tmp);
    
    final File workingDir = new File(workingDirName);
    
    String shellCmd = null;
    
    if ( serverHost.equalsIgnoreCase("localhost") )
    {
        util.DEBUG(debugId+"Stopping server on localhost "+ serverHost);
        shellCmd = fullCmd;
    }
    else
    {
        util.DEBUG(debugId+"Stopping server on non-local host "+ serverHost);
        
        String[] shEnvElements = {"setenv CLASS_PATH "+serverClassPath
                , "setenv PATH "+serverVM+FS+".."+FS+"bin:${PATH}"
                };
        String shellEnv = "";
        for ( int i=0;i<shEnvElements.length;i++)
        {shellEnv = shellEnv + shEnvElements[i] + ";";}
        util.DEBUG(debugId+"shellEnv: " + shellEnv);
        
        shellCmd = "pwd;" + shellEnv + ";"  + fullCmd;
        util.DEBUG(debugId+"shellCmd: " + shellCmd);
        
        shellCmd = remoteShell + " "
                + "-l " + testUser + " -n " + serverHost + " "
                + shellCmd;
    }
    
    {
        final String localCommand = shellCmd;
        util.DEBUG(debugId+"localCommand: " + localCommand);
        
        try
        {
            Process proc = Runtime.getRuntime().exec(localCommand,envElements,workingDir);
            processDEBUGOutput(debugId+"pDo ", proc);
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
        }
    }
    
    util.DEBUG(debugId+"--- stopServer ");
    util.DEBUG("");
    
}
 
Example #30
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;
        }
    }
}