use of com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.JdbcAbortedException in project java-spanner-jdbc by googleapis.
the class JdbcAbortedTransactionTest method testTransactionalUpdateAborted.
@Test
public void testTransactionalUpdateAborted() throws SQLException {
// off.
try (java.sql.Connection connection = createConnection()) {
connection.setAutoCommit(false);
mockSpanner.abortNextStatement();
int updateCount = connection.createStatement().executeUpdate(UPDATE_STATEMENT.getSql());
if (!retryAbortsInternally) {
fail("missing expected exception");
}
assertThat(updateCount).isEqualTo(UPDATE_COUNT);
assertThat(getRetryCount(connection)).isEqualTo(1);
} catch (JdbcAbortedException e) {
assertThat(retryAbortsInternally).isFalse();
}
}
use of com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.JdbcAbortedException in project java-spanner-jdbc by googleapis.
the class JdbcAbortedTransactionTest method testTransactionalUpdateWithErrorOnOriginalAndNotOnRetry.
@Test
public void testTransactionalUpdateWithErrorOnOriginalAndNotOnRetry() throws SQLException {
final String sql = "UPDATE SOMETHING SET OTHER=1";
mockSpanner.putStatementResult(StatementResult.exception(Statement.of(sql), Status.INVALID_ARGUMENT.withDescription("test").asRuntimeException()));
try (java.sql.Connection connection = createConnection()) {
connection.setAutoCommit(false);
try (ResultSet rs = connection.createStatement().executeQuery(SELECT1.getSql())) {
while (rs.next()) {
assertThat(rs.getLong(1)).isEqualTo(1L);
}
}
try {
connection.createStatement().executeUpdate(sql);
fail("missing 'test' exception");
} catch (SQLException e) {
// ignore
}
// Set the update statement to return a result next time (i.e. during retry).
mockSpanner.putStatementResult(StatementResult.update(Statement.of(sql), 1L));
mockSpanner.abortNextStatement();
connection.commit();
fail("missing expected aborted exception");
} catch (JdbcAbortedDueToConcurrentModificationException e) {
assertThat(retryAbortsInternally).isTrue();
assertThat(e.getDatabaseErrorDuringRetry()).isNull();
} catch (JdbcAbortedException e) {
assertThat(retryAbortsInternally).isFalse();
}
}
use of com.google.cloud.spanner.jdbc.JdbcSqlExceptionFactory.JdbcAbortedException in project java-spanner-jdbc by googleapis.
the class JdbcAbortedTransactionTest method testTransactionalSelectAborted.
@Test
public void testTransactionalSelectAborted() throws SQLException {
try (java.sql.Connection connection = createConnection()) {
connection.setAutoCommit(false);
mockSpanner.abortNextStatement();
try (ResultSet rs = connection.createStatement().executeQuery(SELECT1.getSql())) {
while (rs.next()) {
if (!retryAbortsInternally) {
fail("missing expected exception");
}
assertThat(rs.getLong(1)).isEqualTo(1L);
}
}
assertThat(getRetryCount(connection)).isEqualTo(1);
} catch (JdbcAbortedException e) {
assertThat(retryAbortsInternally).isFalse();
}
}
Aggregations