use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method createParsedQuery.
private ParsedStatement createParsedQuery(String sql) {
ParsedStatement statement = mock(ParsedStatement.class);
when(statement.getType()).thenReturn(StatementType.QUERY);
when(statement.isQuery()).thenReturn(true);
when(statement.getStatement()).thenReturn(Statement.of(sql));
return statement;
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method testExecuteUpdate_Transactional_Valid.
@Test
public void testExecuteUpdate_Transactional_Valid() {
ParsedStatement update = createParsedUpdate(VALID_UPDATE);
SingleUseTransaction subject = createSubject();
long updateCount = get(subject.executeUpdateAsync(update));
assertThat(updateCount).isEqualTo(VALID_UPDATE_COUNT);
assertThat(subject.getCommitTimestamp()).isNotNull();
assertThat(subject.getState()).isEqualTo(com.google.cloud.spanner.connection.UnitOfWork.UnitOfWorkState.COMMITTED);
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method testExecuteUpdate_Partitioned_Valid.
@Test
public void testExecuteUpdate_Partitioned_Valid() {
ParsedStatement update = createParsedUpdate(VALID_UPDATE);
SingleUseTransaction subject = createSubject(AutocommitDmlMode.PARTITIONED_NON_ATOMIC);
long updateCount = get(subject.executeUpdateAsync(update));
assertThat(updateCount).isEqualTo(VALID_UPDATE_COUNT);
assertThat(subject.getState()).isEqualTo(com.google.cloud.spanner.connection.UnitOfWork.UnitOfWorkState.COMMITTED);
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method testGetCommitResponseAfterQuery.
@Test
public void testGetCommitResponseAfterQuery() {
ParsedStatement query = createParsedQuery(VALID_QUERY);
SingleUseTransaction transaction = createSubject();
get(transaction.executeQueryAsync(query, AnalyzeMode.NONE));
try {
transaction.getCommitResponse();
fail("missing expected exception");
} catch (SpannerException e) {
assertEquals(ErrorCode.FAILED_PRECONDITION, e.getErrorCode());
}
assertNull(transaction.getCommitResponseOrNull());
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method testExecuteUpdate_Transactional_Invalid.
@Test
public void testExecuteUpdate_Transactional_Invalid() {
ParsedStatement update = createParsedUpdate(INVALID_UPDATE);
SingleUseTransaction subject = createSubject();
try {
get(subject.executeUpdateAsync(update));
fail("missing expected exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
assertThat(e.getMessage()).contains("invalid update");
}
}
Aggregations