use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method createParsedUpdate.
private ParsedStatement createParsedUpdate(String sql) {
ParsedStatement statement = mock(ParsedStatement.class);
when(statement.getType()).thenReturn(StatementType.UPDATE);
when(statement.isUpdate()).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_FailedCommit.
@Test
public void testExecuteUpdate_Transactional_Valid_FailedCommit() {
ParsedStatement update = createParsedUpdate(VALID_UPDATE);
SingleUseTransaction subject = createSubject(CommitBehavior.FAIL);
try {
get(subject.executeUpdateAsync(update));
fail("missing expected exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
assertThat(e.getMessage()).contains("commit failed");
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method testGetCommitResponseAfterUpdate.
@Test
public void testGetCommitResponseAfterUpdate() {
ParsedStatement update = createParsedUpdate(VALID_UPDATE);
SingleUseTransaction transaction = createSubject();
get(transaction.executeUpdateAsync(update));
assertNotNull(transaction.getCommitResponse());
assertNotNull(transaction.getCommitResponseOrNull());
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteCommit.
@Test
public void testExecuteCommit() {
ParsedStatement subject = parser.parse(Statement.of("commit"));
for (String statement : subject.getClientSideStatement().getExampleStatements()) {
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementCommit()).thenCallRealMethod();
subject.getClientSideStatement().execute(executor, statement);
verify(connection, times(1)).commit();
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetAutocommitDmlMode.
@Test
public void testExecuteGetAutocommitDmlMode() {
ParsedStatement statement = parser.parse(Statement.of("show variable autocommit_dml_mode"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowAutocommitDmlMode()).thenCallRealMethod();
when(connection.getAutocommitDmlMode()).thenReturn(AutocommitDmlMode.TRANSACTIONAL);
statement.getClientSideStatement().execute(executor, "show variable autocommit_dml_mode");
verify(connection, times(1)).getAutocommitDmlMode();
}
Aggregations