use of com.google.cloud.spanner.connection.RandomResultSetGenerator in project java-spanner-jdbc by googleapis.
the class JdbcAbortedTransactionTest method testTransactionalUpdateWithConcurrentModificationsAborted.
@Test
public void testTransactionalUpdateWithConcurrentModificationsAborted() throws SQLException {
// original attempt.
try (java.sql.Connection connection = createConnection()) {
connection.setAutoCommit(false);
// Set a random answer.
mockSpanner.putStatementResult(StatementResult.query(SELECT_RANDOM, new RandomResultSetGenerator(25).generate()));
try (ResultSet rs = connection.createStatement().executeQuery(SELECT_RANDOM.getSql())) {
// noinspection StatementWithEmptyBody
while (rs.next()) {
}
}
// Set a new random answer that will be returned during the retry.
mockSpanner.putStatementResult(StatementResult.query(SELECT_RANDOM, new RandomResultSetGenerator(25).generate()));
// Abort all transactions (including the current one).
mockSpanner.abortNextStatement();
// This will abort and start an internal retry.
connection.createStatement().executeUpdate(UPDATE_STATEMENT.getSql());
fail("missing expected aborted exception");
} catch (JdbcAbortedDueToConcurrentModificationException e) {
assertThat(retryAbortsInternally).isTrue();
} catch (JdbcAbortedException e) {
assertThat(retryAbortsInternally).isFalse();
}
}
Aggregations