Search in sources :

Example 1 with CloudSpannerXADataSource

use of nl.topicus.jdbc.CloudSpannerXADataSource in project spanner-jdbc by olavloite.

the class CloudSpannerXADataSourceTest method testGetConnection.

@Test
public void testGetConnection() throws SQLException {
    CloudSpannerXADataSource subject = new CloudSpannerXADataSource();
    CloudSpannerDataSourceTest.setCommonDataSourceTestProperties(subject);
    subject.setCreateXATable(false);
    CloudSpannerXAConnection connection = subject.getXAConnection();
    assertNotNull(connection);
    assertNotNull(subject.getDescription());
    Connection con = connection.getConnection();
    Assert.assertTrue(con.isWrapperFor(CloudSpannerConnection.class));
    CloudSpannerConnection cloudSpannerConnection = con.unwrap(CloudSpannerConnection.class);
    CloudSpannerDataSourceTest.testCommonDataSourceTestProperties(cloudSpannerConnection);
}
Also used : CloudSpannerXADataSource(nl.topicus.jdbc.CloudSpannerXADataSource) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Connection(java.sql.Connection) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) UnitTest(nl.topicus.jdbc.test.category.UnitTest) Test(org.junit.Test) CloudSpannerDataSourceTest(nl.topicus.jdbc.CloudSpannerDataSourceTest)

Example 2 with CloudSpannerXADataSource

use of nl.topicus.jdbc.CloudSpannerXADataSource in project spanner-jdbc by olavloite.

the class XATester method testXA.

public void testXA(String projectId, String instanceId, String database, String pvtKeyPath) throws SQLException {
    log.info("Starting XA tests");
    int originalLogLevel = CloudSpannerDriver.getLogLevel();
    CloudSpannerDriver.setLogLevel(CloudSpannerDriver.DEBUG);
    CloudSpannerXADataSource ds = new CloudSpannerXADataSource();
    ds.setProjectId(projectId);
    ds.setInstanceId(instanceId);
    ds.setDatabase(database);
    ds.setPvtKeyPath(pvtKeyPath);
    ds.setAllowExtendedMode(true);
    try (CloudSpannerXAConnection xaConnection = ds.getXAConnection()) {
        testXATransaction(xaConnection, CommitMode.TwoPhase);
        testXARollback(xaConnection);
        deleteTestRow(xaConnection);
        testXARecover(xaConnection);
        deleteTestRow(xaConnection);
    } catch (Exception e) {
        throw new CloudSpannerSQLException("Exception occurred during XA tests", Code.INTERNAL, e);
    } finally {
        CloudSpannerDriver.setLogLevel(originalLogLevel);
    }
    log.info("Finished XA tests");
}
Also used : CloudSpannerXADataSource(nl.topicus.jdbc.CloudSpannerXADataSource) CloudSpannerXAConnection(nl.topicus.jdbc.xa.CloudSpannerXAConnection) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException) CloudSpannerSQLException(nl.topicus.jdbc.exception.CloudSpannerSQLException) SQLException(java.sql.SQLException) XAException(javax.transaction.xa.XAException)

Example 3 with CloudSpannerXADataSource

use of nl.topicus.jdbc.CloudSpannerXADataSource in project spanner-jdbc by olavloite.

the class CloudSpannerXADataSourceTest method testGetConnectionWithUserNameAndPassword.

@Test
public void testGetConnectionWithUserNameAndPassword() throws SQLException {
    CloudSpannerXADataSource subject = new CloudSpannerXADataSource();
    CloudSpannerDataSourceTest.setCommonDataSourceTestProperties(subject);
    subject.setCreateXATable(false);
    CloudSpannerXAConnection connection = subject.getXAConnection("test", "test");
    assertNotNull(connection);
    Connection con = connection.getConnection();
    Assert.assertTrue(con.isWrapperFor(CloudSpannerConnection.class));
    CloudSpannerConnection cloudSpannerConnection = con.unwrap(CloudSpannerConnection.class);
    CloudSpannerDataSourceTest.testCommonDataSourceTestProperties(cloudSpannerConnection);
}
Also used : CloudSpannerXADataSource(nl.topicus.jdbc.CloudSpannerXADataSource) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) Connection(java.sql.Connection) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) UnitTest(nl.topicus.jdbc.test.category.UnitTest) Test(org.junit.Test) CloudSpannerDataSourceTest(nl.topicus.jdbc.CloudSpannerDataSourceTest)

Aggregations

CloudSpannerXADataSource (nl.topicus.jdbc.CloudSpannerXADataSource)3 Connection (java.sql.Connection)2 CloudSpannerConnection (nl.topicus.jdbc.CloudSpannerConnection)2 CloudSpannerDataSourceTest (nl.topicus.jdbc.CloudSpannerDataSourceTest)2 UnitTest (nl.topicus.jdbc.test.category.UnitTest)2 Test (org.junit.Test)2 SQLException (java.sql.SQLException)1 XAException (javax.transaction.xa.XAException)1 CloudSpannerSQLException (nl.topicus.jdbc.exception.CloudSpannerSQLException)1 CloudSpannerXAConnection (nl.topicus.jdbc.xa.CloudSpannerXAConnection)1