Java Code Examples for org.apache.derby.jdbc.ClientDataSource#setPortNumber()

The following examples show how to use org.apache.derby.jdbc.ClientDataSource#setPortNumber() . These examples are extracted from open source projects. 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
void _verifyDatabase(String serverHost, 
        int serverPort,
        String dbPath,
        int _noTuplesInserted)
    throws SQLException
{
    util.DEBUG("_verifyDatabase: "+serverHost+":"+serverPort+"/"+dbPath);
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(dbPath);
    ds.setServerName(serverHost);
    ds.setPortNumber(serverPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
    
    _verify(conn,_noTuplesInserted);
    
    conn.close();
}
 
Example 2
Source Project: coming   File: 919148_ReplicationRun_0_s.java    License: MIT License 6 votes vote down vote up
void _verifyDatabase(String serverHost, 
        int serverPort,
        String dbPath,
        int _noTuplesInserted)
    throws SQLException
{
    util.DEBUG("_verifyDatabase: "+serverHost+":"+serverPort+"/"+dbPath);
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(dbPath);
    ds.setServerName(serverHost);
    ds.setPortNumber(serverPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
    
    _verify(conn,_noTuplesInserted);
    
    conn.close();
}
 
Example 3
@BeforeClass
public static void startDatabase() throws Exception {
    ServerSocket socket = new ServerSocket(0);
    port = socket.getLocalPort();
    socket.close();

    JDBC_URL = "jdbc:derby://localhost:" + port + "/target/tcomp";

    System.setProperty("derby.stream.error.file", "target/derby.log");

    derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
    derbyServer.start(null);

    dataSource = new ClientDataSource();
    dataSource.setCreateDatabase("create");
    dataSource.setDatabaseName("target/tcomp");
    dataSource.setServerName("localhost");
    dataSource.setPortNumber(port);

    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate("create table " + TABLE_IN + "(id INT, name VARCHAR(500))");
            statement.executeUpdate("create table " + TABLE_OUT + "(id INT, name VARCHAR(500))");
        }
    }
}
 
Example 4
void waitForConnect(long sleepTime, int tries,
        String fullDbPath, 
        String serverHost, int serverPort)
    throws Exception
{
    int count = 0;
    String msg = null;
    while ( count++ <= tries )
    {
        try
        {
            ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
            ds.setDatabaseName(fullDbPath);
            ds.setServerName(serverHost);
            ds.setPortNumber(serverPort);
            ds.setConnectionAttributes(useEncryption(false));
            Connection conn = ds.getConnection();
            util.DEBUG("Got connection after " 
                    + (count-1) +" * "+ sleepTime + " ms.");
            conn.close();
            return;
        }
        catch ( SQLException se )
        {
            msg = se.getErrorCode() + "' '" + se.getSQLState()
                    + "' '" + se.getMessage();
            util.DEBUG(count  + " got '" + msg +"'.");
            Thread.sleep(sleepTime); // ms. Sleep and try again...
        }
    }        
    assertTrue(msg + ": Could NOT connect in "
            + tries+"*"+sleepTime + "ms.",false);
}
 
Example 5
void verifyMaster()
throws Exception
{
    util.DEBUG("BEGIN verifyMaster " + masterServerHost + ":"
            +masterServerPort+"/"+masterDatabasePath+FS+masterDbSubPath+FS+replicatedDb);
    
    if ( (replicationTest != null)  // If 'replicationTest==null' no table was created/filled
            && simpleLoad )
    {
        _verifyDatabase(masterServerHost, masterServerPort, 
                masterDatabasePath+FS+masterDbSubPath+FS+replicatedDb,
                simpleLoadTuples);
        // return;
    }
 
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(masterDatabasePath + FS + masterDbSubPath + FS +
                       replicatedDb);
    ds.setServerName(masterServerHost);
    ds.setPortNumber(masterServerPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
        
    simpleVerify(conn);
    conn.close();
    /*
    runMasterVerificationCLient(jvmVersion,
            testClientHost,
            replicatedDb,
            masterServerHost, masterServerPort);
    */
    util.DEBUG("END   verifyMaster");
}
 
Example 6
Source Project: components   File: JDBCBeamRuntimeTest.java    License: Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void startDatabase() throws Exception {
    ServerSocket socket = new ServerSocket(0);
    port = socket.getLocalPort();
    socket.close();

    LOGGER.info("Starting Derby database on {}", port);

    JDBC_URL = "jdbc:derby://localhost:" + port + "/target/tcomp";

    System.setProperty("derby.stream.error.file", "target/derby.log");

    derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
    derbyServer.start(null);

    dataSource = new ClientDataSource();
    dataSource.setCreateDatabase("create");
    dataSource.setDatabaseName("target/tcomp");
    dataSource.setServerName("localhost");
    dataSource.setPortNumber(port);

    try (Connection connection = dataSource.getConnection()) {
        try (Statement statement = connection.createStatement()) {
            statement.executeUpdate("create table " + TABLE_IN + "(id INT, name VARCHAR(500))");
            statement.executeUpdate("create table " + TABLE_OUT + "(id INT, name VARCHAR(500))");
        }
    }
}
 
Example 7
void _testInsertUpdateDeleteOnMaster(String serverHost, 
        int serverPort,
        String dbPath,
        int _noTuplesToInsert)
    throws SQLException
{
    util.DEBUG("_testInsertUpdateDeleteOnMaster: " + serverHost + ":" +
               serverPort + "/" + dbPath + " " + _noTuplesToInsert);
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(dbPath);
    ds.setServerName(serverHost);
    ds.setPortNumber(serverPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
    
    PreparedStatement ps = conn.prepareStatement("create table t(i integer primary key, s varchar(64))");
    
    ps.execute();
    
    ps = conn.prepareStatement("insert into t values (?,?)");
    for (int i = 0; i< _noTuplesToInsert; i++)
    {
        ps.setInt(1,i);
        ps.setString(2,"dilldall"+i);
        ps.execute();
        if ( (i % 10000) == 0 ) conn.commit();
    }
    
    _verify(conn, _noTuplesToInsert);
    
    conn.close();
}
 
Example 8
Source Project: coming   File: 919148_ReplicationRun_0_s.java    License: MIT License 5 votes vote down vote up
void _testInsertUpdateDeleteOnMaster(String serverHost, 
        int serverPort,
        String dbPath,
        int _noTuplesToInsert)
    throws SQLException
{
    util.DEBUG("_testInsertUpdateDeleteOnMaster: " + serverHost + ":" +
               serverPort + "/" + dbPath + " " + _noTuplesToInsert);
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(dbPath);
    ds.setServerName(serverHost);
    ds.setPortNumber(serverPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
    
    PreparedStatement ps = conn.prepareStatement("create table t(i integer primary key, s varchar(64))");
    
    ps.execute();
    
    ps = conn.prepareStatement("insert into t values (?,?)");
    for (int i = 0; i< _noTuplesToInsert; i++)
    {
        ps.setInt(1,i);
        ps.setString(2,"dilldall"+i);
        ps.execute();
        if ( (i % 10000) == 0 ) conn.commit();
    }
    
    _verify(conn, _noTuplesToInsert);
    
    conn.close();
}
 
Example 9
Source Project: coming   File: 919148_ReplicationRun_0_t.java    License: MIT License 5 votes vote down vote up
String showCurrentState(String ID, long waitTime,
        String fullDbPath, 
        String serverHost, int serverPort)
    throws Exception
{
    int errCode = 0;
    String sState = "CONNECTED";
    String msg = null;
    Thread.sleep(waitTime); // .... until stable...
    try
    {
        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
        ds.setDatabaseName(fullDbPath);
        ds.setServerName(serverHost);
        ds.setPortNumber(serverPort);
        ds.setConnectionAttributes(useEncryption(false));
        Connection conn = ds.getConnection();
        conn.close();
    }
    catch ( SQLException se )
    {
        errCode = se.getErrorCode();
        msg = se.getMessage();
        sState = se.getSQLState();
    }
    util.DEBUG(ID+": ["+serverHost+":"+serverPort+"/"+fullDbPath+"] "
            + errCode + " " + sState + " " + msg);
    return sState;
}
 
Example 10
void verifySlave()
throws Exception
{
    util.DEBUG("BEGIN verifySlave "+slaveServerHost+":"
            +slaveServerPort+"/"+slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb);
    
    if ( (replicationTest != null) // If 'replicationTest==null' no table was created/filled
            && simpleLoad )
    {
        _verifyDatabase(slaveServerHost, slaveServerPort, 
                slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb,
                simpleLoadTuples);
        // return;
    }
 
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(slaveDatabasePath + FS + slaveDbSubPath + FS +
                       replicatedDb);
    ds.setServerName(slaveServerHost);
    ds.setPortNumber(slaveServerPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
        
    simpleVerify(conn);
    conn.close();
    /*
    runSlaveVerificationCLient(jvmVersion,
            testClientHost,
            replicatedDb,
            slaveServerHost, slaveServerPort);
    */
    util.DEBUG("END   verifySlave");
}
 
Example 11
String showCurrentState(String ID, long waitTime,
        String fullDbPath, 
        String serverHost, int serverPort)
    throws Exception
{
    int errCode = 0;
    String sState = "CONNECTED";
    String msg = null;
    Thread.sleep(waitTime); // .... until stable...
    try
    {
        ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
        ds.setDatabaseName(fullDbPath);
        ds.setServerName(serverHost);
        ds.setPortNumber(serverPort);
        ds.setConnectionAttributes(useEncryption(false));
        Connection conn = ds.getConnection();
        conn.close();
    }
    catch ( SQLException se )
    {
        errCode = se.getErrorCode();
        msg = se.getMessage();
        sState = se.getSQLState();
    }
    util.DEBUG(ID+": ["+serverHost+":"+serverPort+"/"+fullDbPath+"] "
            + errCode + " " + sState + " " + msg);
    return sState;
}
 
Example 12
Source Project: coming   File: 919148_ReplicationRun_0_t.java    License: MIT License 5 votes vote down vote up
void verifySlave()
throws Exception
{
    util.DEBUG("BEGIN verifySlave "+slaveServerHost+":"
            +slaveServerPort+"/"+slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb);
    
    if ( (replicationTest != null) // If 'replicationTest==null' no table was created/filled
            && simpleLoad )
    {
        _verifyDatabase(slaveServerHost, slaveServerPort, 
                slaveDatabasePath+FS+slaveDbSubPath+FS+replicatedDb,
                simpleLoadTuples);
        // return;
    }
 
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(slaveDatabasePath + FS + slaveDbSubPath + FS +
                       replicatedDb);
    ds.setServerName(slaveServerHost);
    ds.setPortNumber(slaveServerPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
        
    simpleVerify(conn);
    conn.close();
    /*
    runSlaveVerificationCLient(jvmVersion,
            testClientHost,
            replicatedDb,
            slaveServerHost, slaveServerPort);
    */
    util.DEBUG("END   verifySlave");
}
 
Example 13
Source Project: coming   File: 919148_ReplicationRun_0_t.java    License: MIT License 5 votes vote down vote up
void verifyMaster()
throws Exception
{
    util.DEBUG("BEGIN verifyMaster " + masterServerHost + ":"
            +masterServerPort+"/"+masterDatabasePath+FS+masterDbSubPath+FS+replicatedDb);
    
    if ( (replicationTest != null)  // If 'replicationTest==null' no table was created/filled
            && simpleLoad )
    {
        _verifyDatabase(masterServerHost, masterServerPort, 
                masterDatabasePath+FS+masterDbSubPath+FS+replicatedDb,
                simpleLoadTuples);
        // return;
    }
 
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(masterDatabasePath + FS + masterDbSubPath + FS +
                       replicatedDb);
    ds.setServerName(masterServerHost);
    ds.setPortNumber(masterServerPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
        
    simpleVerify(conn);
    conn.close();
    /*
    runMasterVerificationCLient(jvmVersion,
            testClientHost,
            replicatedDb,
            masterServerHost, masterServerPort);
    */
    util.DEBUG("END   verifyMaster");
}
 
Example 14
Source Project: coming   File: 919148_ReplicationRun_0_t.java    License: MIT License 5 votes vote down vote up
void _testInsertUpdateDeleteOnMaster(String serverHost, 
        int serverPort,
        String dbPath,
        int _noTuplesToInsert)
    throws SQLException
{
    util.DEBUG("_testInsertUpdateDeleteOnMaster: " + serverHost + ":" +
               serverPort + "/" + dbPath + " " + _noTuplesToInsert);
    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
    ds.setDatabaseName(dbPath);
    ds.setServerName(serverHost);
    ds.setPortNumber(serverPort);
    ds.setConnectionAttributes(useEncryption(false));
    Connection conn = ds.getConnection();
    
    PreparedStatement ps = conn.prepareStatement("create table t(i integer primary key, s varchar(64))");
    
    ps.execute();
    
    ps = conn.prepareStatement("insert into t values (?,?)");
    for (int i = 0; i< _noTuplesToInsert; i++)
    {
        ps.setInt(1,i);
        ps.setString(2,"dilldall"+i);
        ps.execute();
        if ( (i % 10000) == 0 ) conn.commit();
    }
    
    _verify(conn, _noTuplesToInsert);
    
    conn.close();
}
 
Example 15
private void startMaster_direct(String dbName,
        String masterHost,  // Where the master db is run.
        int masterServerPort, // master server interface accepting client requests
        
        String slaveReplInterface, // slaveHost,
        int slaveReplPort)
        throws Exception
{
    
    String URL = masterURL(dbName)
            +";startMaster=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
            
        util.DEBUG("startMaster_direct getConnection("+URL+")");
        Connection conn = null;
        boolean done = false;
        int count = 0;
        while ( !done )
        {
            try
            {
                /* On 1.5 locking of Drivermanager.class prevents
                 * using DriverManager.getConnection() concurrently
                 * in startMaster and startSlave!
                Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
                conn = DriverManager.getConnection(URL);
                 */
                ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
                ds.setDatabaseName(masterDatabasePath+FS+masterDbSubPath+FS+dbName);
                ds.setServerName(masterHost);
                ds.setPortNumber(masterServerPort);
                ds.setConnectionAttributes("startMaster=true"
                        +";slaveHost="+slaveReplInterface
                        +";slavePort="+slaveReplPort
                        +useEncryption(false));
                conn = ds.getConnection();
                
                done = true;
                conn.close();
                util.DEBUG("startMaster_direct connected in " + count + " * 100ms.");
            }
            catch ( SQLException se )
            {
                int errCode = se.getErrorCode();
                String msg = se.getMessage();
                String sState = se.getSQLState();
                String expectedState = "XRE04";
                util.DEBUG("startMaster Got SQLException: " 
                        + errCode + " " + sState + " " + msg + ". Expected " + expectedState);
                if ( (errCode == -1)
                && (sState.equalsIgnoreCase(expectedState) ) )
                {
                    util.DEBUG("Not ready to startMaster. "
                            +"Beware: Will also report "
                            + "'... got a fatal error for database '...../<dbname>'"
                            + " in master derby.log.");
                    Thread.sleep(100L); // ms.
                }
                else
                {
                    if (REPLICATION_MASTER_TIMED_OUT.equals(sState)) // FIXME! CANNOT_START_MASTER_ALREADY_BOOTED
                    {
                        util.DEBUG("Master already started?");
                    }
                    util.DEBUG("startMaster_direct Got: "
                            +state+" Expected "+expectedState);
                    throw se;
                }
            }
 
            assertTrue("startMaster did not succeed.", count++ < 1200); // 1200*100ms = 120s = 2mins.
        }
        util.DEBUG("startMaster_direct exit.");
}
 
Example 16
void waitForSQLState(String expectedState, 
        long sleepTime, int tries,
        String fullDbPath, 
        String serverHost, int serverPort)
    throws Exception
{
    int count = 0;
    String msg = null;
    while ( count++ <= tries )
    {
        try
        {
            ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
            ds.setDatabaseName(fullDbPath);
            ds.setServerName(serverHost);
            ds.setPortNumber(serverPort);
            ds.setConnectionAttributes(useEncryption(false));
            Connection conn = ds.getConnection();
            // Should never get here!
            conn.close();
            assertTrue("Expected SQLState'"+expectedState
                        + "', but got connection!",
                    false);
        }
        catch ( SQLException se )
        {
            int errCode = se.getErrorCode();
            msg = se.getMessage();
            String sState = se.getSQLState();
            msg = "'" + errCode + "' '" + sState + "' '" + msg +"'";
            util.DEBUG(count 
                    + ": SQLState expected '"+expectedState+"'," +
                    " got " + msg);
            if ( sState.equals(expectedState) )
            {
                util.DEBUG("Reached SQLState '" + expectedState +"' in "
                        + (count-1)+"*"+sleepTime + "ms.");
                return; // Got desired SQLState.
            }
            else
            {
                Thread.sleep(sleepTime); // ms. Sleep and try again...
            }
        }
        
    }
    assertTrue(msg + ": SQLState '"+expectedState+"' was not reached in "
            + tries+"*"+sleepTime + "ms.",false);
    
}
 
Example 17
Source Project: coming   File: 919148_ReplicationRun_0_s.java    License: MIT License 4 votes vote down vote up
private void startSlave_direct(String dbName,
        String slaveHost,  // Where the slave db is run.
        int slaveServerPort, // slave server interface accepting client requests
        String slaveReplInterface,
        int slaveReplPort)
        throws Exception
{
    final String URL = slaveURL(dbName)
            +";startSlave=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    
        util.DEBUG("startSlave_direct getConnection("+URL+")");
        
        final String fDbPath = slaveDatabasePath+FS+slaveDbSubPath+FS+dbName;
        final String fSlaveHost = slaveHost;
        final int fSlaveServerPort = slaveServerPort;
        final String fConnAttrs = "startSlave=true"
                            +";slaveHost="+slaveReplInterface
                            +";slavePort="+slaveReplPort
                            +useEncryption(false);
        Thread connThread = new Thread(
                new Runnable()
        {
            public void run()
            {
                startSlaveException = null;
                Connection conn = null;
                String expectedState = "XRE08";
                try {
                    // NB! WIll hang here until startMaster is executed!
                    /*On 1.5 locking of Drivermanager.class prevents
                     * using DriverManager.getConnection() concurrently
                     * in startMaster and startSlave!
                    Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
                    conn = DriverManager.getConnection(URL);
                     */
                    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
                    ds.setDatabaseName(fDbPath);
                    ds.setServerName(fSlaveHost);
                    ds.setPortNumber(fSlaveServerPort);
                    ds.setConnectionAttributes(fConnAttrs);
                    conn = ds.getConnection();
                    conn.close();
                }
                catch (SQLException se)
                {
                    startSlaveException = se;
                }
                catch (Exception ex)
                {
                    startSlaveException = ex;
                }
            }
        }
        );
        connThread.start();
        util.DEBUG("startSlave_direct exit.");
}
 
Example 18
private void startSlave_direct(String dbName,
        String slaveHost,  // Where the slave db is run.
        int slaveServerPort, // slave server interface accepting client requests
        String slaveReplInterface,
        int slaveReplPort)
        throws Exception
{
    final String URL = slaveURL(dbName)
            +";startSlave=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    
        util.DEBUG("startSlave_direct getConnection("+URL+")");
        
        final String fDbPath = slaveDatabasePath+FS+slaveDbSubPath+FS+dbName;
        final String fSlaveHost = slaveHost;
        final int fSlaveServerPort = slaveServerPort;
        final String fConnAttrs = "startSlave=true"
                            +";slaveHost="+slaveReplInterface
                            +";slavePort="+slaveReplPort
                            +useEncryption(false);
        Thread connThread = new Thread(
                new Runnable()
        {
            public void run()
            {
                startSlaveException = null;
                Connection conn = null;
                String expectedState = "XRE08";
                try {
                    // NB! WIll hang here until startMaster is executed!
                    /*On 1.5 locking of Drivermanager.class prevents
                     * using DriverManager.getConnection() concurrently
                     * in startMaster and startSlave!
                    Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
                    conn = DriverManager.getConnection(URL);
                     */
                    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
                    ds.setDatabaseName(fDbPath);
                    ds.setServerName(fSlaveHost);
                    ds.setPortNumber(fSlaveServerPort);
                    ds.setConnectionAttributes(fConnAttrs);
                    conn = ds.getConnection();
                    conn.close();
                }
                catch (SQLException se)
                {
                    startSlaveException = se;
                }
                catch (Exception ex)
                {
                    startSlaveException = ex;
                }
            }
        }
        );
        connThread.start();
        util.DEBUG("startSlave_direct exit.");
}
 
Example 19
Source Project: coming   File: 919148_ReplicationRun_0_t.java    License: MIT License 4 votes vote down vote up
private void startSlave_direct(String dbName,
        String slaveHost,  // Where the slave db is run.
        int slaveServerPort, // slave server interface accepting client requests
        String slaveReplInterface,
        int slaveReplPort)
        throws Exception
{
    final String URL = slaveURL(dbName)
            +";startSlave=true;slaveHost="+slaveReplInterface
            +";slavePort="+slaveReplPort;
    
        util.DEBUG("startSlave_direct getConnection("+URL+")");
        
        final String fDbPath = slaveDatabasePath+FS+slaveDbSubPath+FS+dbName;
        final String fSlaveHost = slaveHost;
        final int fSlaveServerPort = slaveServerPort;
        final String fConnAttrs = "startSlave=true"
                            +";slaveHost="+slaveReplInterface
                            +";slavePort="+slaveReplPort
                            +useEncryption(false);
        Thread connThread = new Thread(
                new Runnable()
        {
            public void run()
            {
                startSlaveException = null;
                Connection conn = null;
                String expectedState = "XRE08";
                try {
                    // NB! WIll hang here until startMaster is executed!
                    /*On 1.5 locking of Drivermanager.class prevents
                     * using DriverManager.getConnection() concurrently
                     * in startMaster and startSlave!
                    Class.forName(DRIVER_CLASS_NAME); // Needed when running from classes!
                    conn = DriverManager.getConnection(URL);
                     */
                    ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
                    ds.setDatabaseName(fDbPath);
                    ds.setServerName(fSlaveHost);
                    ds.setPortNumber(fSlaveServerPort);
                    ds.setConnectionAttributes(fConnAttrs);
                    conn = ds.getConnection();
                    conn.close();
                }
                catch (SQLException se)
                {
                    startSlaveException = se;
                }
                catch (Exception ex)
                {
                    startSlaveException = ex;
                }
            }
        }
        );
        connThread.start();
        util.DEBUG("startSlave_direct exit.");
}
 
Example 20
void waitForSQLState(String expectedState, 
        long sleepTime, int tries,
        String fullDbPath, 
        String serverHost, int serverPort)
    throws Exception
{
    int count = 0;
    String msg = null;
    while ( count++ <= tries )
    {
        try
        {
            ClientDataSource ds = new org.apache.derby.jdbc.ClientDataSource();
            ds.setDatabaseName(fullDbPath);
            ds.setServerName(serverHost);
            ds.setPortNumber(serverPort);
            ds.setConnectionAttributes(useEncryption(false));
            Connection conn = ds.getConnection();
            // Should never get here!
            conn.close();
            assertTrue("Expected SQLState'"+expectedState
                        + "', but got connection!",
                    false);
        }
        catch ( SQLException se )
        {
            int errCode = se.getErrorCode();
            msg = se.getMessage();
            String sState = se.getSQLState();
            msg = "'" + errCode + "' '" + sState + "' '" + msg +"'";
            util.DEBUG(count 
                    + ": SQLState expected '"+expectedState+"'," +
                    " got " + msg);
            if ( sState.equals(expectedState) )
            {
                util.DEBUG("Reached SQLState '" + expectedState +"' in "
                        + (count-1)+"*"+sleepTime + "ms.");
                return; // Got desired SQLState.
            }
            else
            {
                Thread.sleep(sleepTime); // ms. Sleep and try again...
            }
        }
        
    }
    assertTrue(msg + ": SQLState '"+expectedState+"' was not reached in "
            + tries+"*"+sleepTime + "ms.",false);
    
}