Java Code Examples for org.apache.derby.jdbc.ClientDataSource

The following examples show how to use org.apache.derby.jdbc.ClientDataSource. 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
Source Project: coming   Source 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 2
Source Project: coming   Source File: 919148_ReplicationRun_0_t.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
Source Project: components   Source File: JdbcDatasetRuntimeTest.java    License: Apache License 2.0 6 votes vote down vote up
@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 _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 5
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 6
Source Project: coming   Source File: 919148_ReplicationRun_0_s.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 7
Source Project: coming   Source File: 919148_ReplicationRun_0_s.java    License: MIT License 5 votes vote down vote up
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 8
Source Project: coming   Source File: 919148_ReplicationRun_0_s.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 9
Source Project: coming   Source File: 919148_ReplicationRun_0_s.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 10
Source Project: coming   Source 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 11
Source Project: coming   Source 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 12
Source Project: coming   Source File: 919148_ReplicationRun_0_t.java    License: MIT License 5 votes vote down vote up
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 13
Source Project: coming   Source 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 14
Source Project: coming   Source 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 15
Source Project: coming   Source 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 16
Source Project: components   Source 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 17
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 18
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 19
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 20
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 21
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 22
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 23
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 24
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 25
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 26
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 27
Source Project: DataflowTemplates   Source File: DynamicJdbcIOTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void startDatabase() throws Exception {
  ServerSocket socket = new ServerSocket(0);
  port = socket.getLocalPort();
  socket.close();

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

  // by default, derby uses a lock timeout of 60 seconds. In order to speed up the test
  // and detect the lock faster, we decrease this timeout
  System.setProperty("derby.locks.waitTimeout", "2");
  System.setProperty("derby.stream.error.file", "target/derby.log");

  derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
  StringWriter out = new StringWriter();
  derbyServer.start(new PrintWriter(out));
  boolean started = false;
  int count = 0;
  // Use two different methods to detect when server is started:
  // 1) Check the server stdout for the "started" string
  // 2) wait up to 15 seconds for the derby server to start based on a ping
  // on faster machines and networks, this may return very quick, but on slower
  // networks where the DNS lookups are slow, this may take a little time
  while (!started && count < 30) {
    if (out.toString().contains("started")) {
      started = true;
    } else {
      count++;
      TimeUnit.MILLISECONDS.sleep(500);
      try {
        derbyServer.ping();
        started = true;
      } catch (Throwable t) {
        // ignore, still trying to start
      }
    }
  }

  if (!started) {
    // Server has not started in the expected time frame
    throw new IllegalStateException("Derby server failed to start.");
  }

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

  readTableName = getTestTableName("UT_READ");

  createTable(dataSource, readTableName);
  addInitialData(dataSource, readTableName);
}
 
Example 28
Source Project: beam   Source File: JdbcIOTest.java    License: Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  port = NetworkTestHelper.getAvailableLocalPort();
  LOG.info("Starting Derby database on {}", port);

  // by default, derby uses a lock timeout of 60 seconds. In order to speed up the test
  // and detect the lock faster, we decrease this timeout
  System.setProperty("derby.locks.waitTimeout", "2");
  System.setProperty("derby.stream.error.file", "target/derby.log");

  derbyServer = new NetworkServerControl(InetAddress.getByName("localhost"), port);
  StringWriter out = new StringWriter();
  derbyServer.start(new PrintWriter(out));
  boolean started = false;
  int count = 0;
  // Use two different methods to detect when server is started:
  // 1) Check the server stdout for the "started" string
  // 2) wait up to 15 seconds for the derby server to start based on a ping
  // on faster machines and networks, this may return very quick, but on slower
  // networks where the DNS lookups are slow, this may take a little time
  while (!started && count < 30) {
    if (out.toString().contains("started")) {
      started = true;
    } else {
      count++;
      Thread.sleep(500);
      try {
        derbyServer.ping();
        started = true;
      } catch (Throwable t) {
        // ignore, still trying to start
      }
    }
  }

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

  readTableName = DatabaseTestHelper.getTestTableName("UT_READ");

  DatabaseTestHelper.createTable(dataSource, readTableName);
  addInitialData(dataSource, readTableName);
}
 
Example 29
Source Project: beam   Source File: JdbcIOTest.java    License: Apache License 2.0 4 votes vote down vote up
@Test
public void testDataSourceConfigurationDataSourceWithoutPool() {
  assertTrue(
      JdbcIO.DataSourceConfiguration.create(dataSource).buildDatasource()
          instanceof ClientDataSource);
}
 
Example 30
Source Project: coming   Source File: 919148_ReplicationRun_0_s.java    License: MIT License 4 votes vote down vote up
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);
    
}