Search in sources :

Example 1 with GemFireTransactionDataSource

use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.

the class TransactionTimeOutJUnitTest method test8CommitAfterTimeOut.

@Test
public void test8CommitAfterTimeOut() throws Exception {
    Context ctx = cache.getJNDIContext();
    DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
    ds2.getConnection();
    GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
    UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
    utx.begin();
    Connection conn = ds.getConnection();
    String sql = "create table newTable2 (id integer)";
    Statement sm = conn.createStatement();
    sm.execute(sql);
    utx.setTransactionTimeout(30);
    sql = "insert into newTable2  values (1)";
    sm.execute(sql);
    sql = "select * from newTable2 where id = 1";
    ResultSet rs = sm.executeQuery(sql);
    if (!rs.next()) {
        fail("Transaction not committed");
    }
    sql = "drop table newTable2";
    sm.execute(sql);
    sm.close();
    conn.close();
    utx.setTransactionTimeout(1);
    Thread.sleep(3000);
    try {
        utx.commit();
        fail("exception did not occur on commit although transaction timed out");
    } catch (Exception expected) {
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) DataSource(javax.sql.DataSource) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Example 2 with GemFireTransactionDataSource

use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.

the class TransactionTimeOutDUnitTest method runTest10.

public static void runTest10() {
    try {
        boolean exceptionOccurred = false;
        Context ctx = cache.getJNDIContext();
        DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
        ds2.getConnection();
        GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
        UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        utx.begin();
        Connection conn = ds.getConnection();
        String sql = "create table newTable3 (id integer)";
        Statement sm = conn.createStatement();
        sm.execute(sql);
        utx.setTransactionTimeout(30);
        sql = "insert into newTable3  values (1)";
        sm.execute(sql);
        sql = "select * from newTable3 where id = 1";
        ResultSet rs = sm.executeQuery(sql);
        if (!rs.next())
            fail("Transaction not committed");
        sql = "drop table newTable3";
        sm.execute(sql);
        sm.close();
        conn.close();
        utx.setTransactionTimeout(1);
        Thread.sleep(3000);
        try {
            utx.rollback();
        } catch (Exception e) {
            exceptionOccurred = true;
        }
        if (!exceptionOccurred) {
            fail("exception did not occur on rollback although transaction timed out");
        }
    } catch (Exception e) {
        fail("Exception occurred in test Commit due to ", e);
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) DataSource(javax.sql.DataSource) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource)

Example 3 with GemFireTransactionDataSource

use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.

the class TransactionTimeOutDUnitTest method runTest8.

public static void runTest8() {
    try {
        Context ctx = cache.getJNDIContext();
        DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
        ds2.getConnection();
        GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
        UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        utx.begin();
        Connection conn = ds.getConnection();
        String sql = "create table newTable1 (id integer)";
        Statement sm = conn.createStatement();
        sm.execute(sql);
        utx.setTransactionTimeout(30);
        Thread.sleep(5000);
        utx.setTransactionTimeout(20);
        utx.setTransactionTimeout(10);
        sql = "insert into newTable1  values (1)";
        sm.execute(sql);
        utx.commit();
        sql = "select * from newTable1 where id = 1";
        ResultSet rs = sm.executeQuery(sql);
        if (!rs.next())
            fail("Transaction not committed");
        sql = "drop table newTable1";
        sm.execute(sql);
        sm.close();
        conn.close();
    } catch (Exception e) {
        fail("Exception occurred in test Commit due to ", e);
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) DataSource(javax.sql.DataSource) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource)

Example 4 with GemFireTransactionDataSource

use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.

the class TransactionTimeOutDUnitTest method runTest9.

public static void runTest9() {
    try {
        boolean exceptionOccurred = false;
        Context ctx = cache.getJNDIContext();
        DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
        ds2.getConnection();
        GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
        UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
        utx.begin();
        Connection conn = ds.getConnection();
        String sql = "create table newTable2 (id integer)";
        Statement sm = conn.createStatement();
        sm.execute(sql);
        utx.setTransactionTimeout(30);
        sql = "insert into newTable2  values (1)";
        sm.execute(sql);
        sql = "select * from newTable2 where id = 1";
        ResultSet rs = sm.executeQuery(sql);
        if (!rs.next())
            fail("Transaction not committed");
        sql = "drop table newTable2";
        sm.execute(sql);
        sm.close();
        conn.close();
        utx.setTransactionTimeout(1);
        Thread.sleep(3000);
        try {
            utx.commit();
        } catch (Exception e) {
            exceptionOccurred = true;
        }
        if (!exceptionOccurred) {
            fail("exception did not occur on commit although transaction timed out");
        }
    } catch (Exception e) {
        fail("Exception occurred in test Commit due to ", e);
    }
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IOException(java.io.IOException) DataSource(javax.sql.DataSource) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource)

Example 5 with GemFireTransactionDataSource

use of org.apache.geode.internal.datasource.GemFireTransactionDataSource in project geode by apache.

the class TransactionTimeOutJUnitTest method test7Commit.

@Test
public void test7Commit() throws Exception {
    Context ctx = cache.getJNDIContext();
    DataSource ds2 = (DataSource) ctx.lookup("java:/SimpleDataSource");
    ds2.getConnection();
    GemFireTransactionDataSource ds = (GemFireTransactionDataSource) ctx.lookup("java:/XAPooledDataSource");
    UserTransaction utx = (UserTransaction) ctx.lookup("java:/UserTransaction");
    utx.begin();
    Connection conn = ds.getConnection();
    String sql = "create table newTable1 (id integer)";
    Statement sm = conn.createStatement();
    sm.execute(sql);
    utx.setTransactionTimeout(30);
    Thread.sleep(5000);
    utx.setTransactionTimeout(20);
    utx.setTransactionTimeout(10);
    sql = "insert into newTable1  values (1)";
    sm.execute(sql);
    utx.commit();
    sql = "select * from newTable1 where id = 1";
    ResultSet rs = sm.executeQuery(sql);
    if (!rs.next()) {
        fail("Transaction not committed");
    }
    sql = "drop table newTable1";
    sm.execute(sql);
    sm.close();
    conn.close();
}
Also used : Context(javax.naming.Context) UserTransaction(javax.transaction.UserTransaction) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Statement(java.sql.Statement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) DataSource(javax.sql.DataSource) GemFireTransactionDataSource(org.apache.geode.internal.datasource.GemFireTransactionDataSource) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

Context (javax.naming.Context)8 GemFireTransactionDataSource (org.apache.geode.internal.datasource.GemFireTransactionDataSource)8 Connection (java.sql.Connection)6 ResultSet (java.sql.ResultSet)6 Statement (java.sql.Statement)6 DataSource (javax.sql.DataSource)6 UserTransaction (javax.transaction.UserTransaction)6 IOException (java.io.IOException)5 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)5 Test (org.junit.Test)5 SQLException (java.sql.SQLException)2 RollbackException (javax.transaction.RollbackException)2