Search in sources :

Example 1 with SessionNotFoundException

use of com.google.cloud.spanner.SessionNotFoundException in project java-spanner by googleapis.

the class ITClosedSessionTest method testTransactionManagerNoRecreation.

@Test
public void testTransactionManagerNoRecreation() {
    client.setAllowSessionReplacing(false);
    client.invalidateNextSession();
    try (TransactionManager manager = client.transactionManager()) {
        TransactionContext txn = manager.begin();
        while (true) {
            try (ResultSet rs = txn.executeQuery(Statement.of("SELECT 1"))) {
                rs.next();
                fail("Expected exception");
            }
        }
    } catch (SessionNotFoundException ex) {
        assertNotNull(ex.getMessage());
    }
}
Also used : TransactionManager(com.google.cloud.spanner.TransactionManager) TransactionContext(com.google.cloud.spanner.TransactionContext) ResultSet(com.google.cloud.spanner.ResultSet) SessionNotFoundException(com.google.cloud.spanner.SessionNotFoundException) ParallelIntegrationTest(com.google.cloud.spanner.ParallelIntegrationTest) Test(org.junit.Test)

Example 2 with SessionNotFoundException

use of com.google.cloud.spanner.SessionNotFoundException in project java-spanner by googleapis.

the class ITClosedSessionTest method testReadWriteTransactionNoRecreation.

@Test
public void testReadWriteTransactionNoRecreation() {
    client.setAllowSessionReplacing(false);
    client.invalidateNextSession();
    try {
        TransactionRunner txn = client.readWriteTransaction();
        txn.run(transaction -> {
            try (ResultSet rs = transaction.executeQuery(Statement.of("SELECT 1"))) {
                rs.next();
                fail("Expected exception");
            }
            return null;
        });
        fail("Expected exception");
    } catch (SessionNotFoundException ex) {
        assertNotNull(ex.getMessage());
    }
}
Also used : TransactionRunner(com.google.cloud.spanner.TransactionRunner) ResultSet(com.google.cloud.spanner.ResultSet) SessionNotFoundException(com.google.cloud.spanner.SessionNotFoundException) ParallelIntegrationTest(com.google.cloud.spanner.ParallelIntegrationTest) Test(org.junit.Test)

Example 3 with SessionNotFoundException

use of com.google.cloud.spanner.SessionNotFoundException in project java-spanner by googleapis.

the class ITClosedSessionTest method testReadOnlyTransactionNoRecreation.

@Test
public void testReadOnlyTransactionNoRecreation() {
    client.setAllowSessionReplacing(false);
    client.invalidateNextSession();
    try (ReadOnlyTransaction txn = client.readOnlyTransaction()) {
        try (ResultSet rs = txn.executeQuery(Statement.of("SELECT 1"))) {
            rs.next();
            fail("Expected exception");
        }
        fail("Expected exception");
    } catch (SessionNotFoundException ex) {
        assertNotNull(ex.getMessage());
    }
}
Also used : ReadOnlyTransaction(com.google.cloud.spanner.ReadOnlyTransaction) ResultSet(com.google.cloud.spanner.ResultSet) SessionNotFoundException(com.google.cloud.spanner.SessionNotFoundException) ParallelIntegrationTest(com.google.cloud.spanner.ParallelIntegrationTest) Test(org.junit.Test)

Example 4 with SessionNotFoundException

use of com.google.cloud.spanner.SessionNotFoundException in project java-spanner by googleapis.

the class ITClosedSessionTest method testSingleUseNoRecreation.

@Test
public void testSingleUseNoRecreation() {
    // This should trigger an exception with code NOT_FOUND and the text 'Session not found'.
    client.setAllowSessionReplacing(false);
    client.invalidateNextSession();
    try (ResultSet rs = Statement.of("SELECT 1").executeQuery(client.singleUse())) {
        rs.next();
        fail("Expected exception");
    } catch (SessionNotFoundException ex) {
        assertNotNull(ex.getMessage());
    }
}
Also used : ResultSet(com.google.cloud.spanner.ResultSet) SessionNotFoundException(com.google.cloud.spanner.SessionNotFoundException) ParallelIntegrationTest(com.google.cloud.spanner.ParallelIntegrationTest) Test(org.junit.Test)

Aggregations

ParallelIntegrationTest (com.google.cloud.spanner.ParallelIntegrationTest)4 ResultSet (com.google.cloud.spanner.ResultSet)4 SessionNotFoundException (com.google.cloud.spanner.SessionNotFoundException)4 Test (org.junit.Test)4 ReadOnlyTransaction (com.google.cloud.spanner.ReadOnlyTransaction)1 TransactionContext (com.google.cloud.spanner.TransactionContext)1 TransactionManager (com.google.cloud.spanner.TransactionManager)1 TransactionRunner (com.google.cloud.spanner.TransactionRunner)1