use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class SingleUseTransactionTest method testExecuteUpdate_Partitioned_Invalid.
@Test
public void testExecuteUpdate_Partitioned_Invalid() {
ParsedStatement update = createParsedUpdate(INVALID_UPDATE);
SingleUseTransaction subject = createSubject(AutocommitDmlMode.PARTITIONED_NON_ATOMIC);
try {
get(subject.executeUpdateAsync(update));
fail("missing expected exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
assertThat(e.getMessage()).contains("invalid update");
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ReadOnlyTransactionTest method testPlanQuery.
@Test
public void testPlanQuery() {
for (TimestampBound staleness : getTestTimestampBounds()) {
ParsedStatement parsedStatement = mock(ParsedStatement.class);
when(parsedStatement.getType()).thenReturn(StatementType.QUERY);
when(parsedStatement.isQuery()).thenReturn(true);
Statement statement = Statement.of("SELECT * FROM FOO");
when(parsedStatement.getStatement()).thenReturn(statement);
when(parsedStatement.getSqlWithoutComments()).thenReturn(statement.getSql());
ReadOnlyTransaction transaction = createSubject(staleness);
ResultSet rs = get(transaction.executeQueryAsync(parsedStatement, AnalyzeMode.PLAN));
assertThat(rs, is(notNullValue()));
// get all results and then get the stats
while (rs.next()) {
// do nothing
}
assertThat(rs.getStats(), is(notNullValue()));
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ReadOnlyTransactionTest method testExecuteQueryWithOptionsTest.
@Test
public void testExecuteQueryWithOptionsTest() {
String sql = "SELECT * FROM FOO";
QueryOption option = Options.prefetchChunks(10000);
ParsedStatement parsedStatement = mock(ParsedStatement.class);
when(parsedStatement.getType()).thenReturn(StatementType.QUERY);
when(parsedStatement.isQuery()).thenReturn(true);
Statement statement = Statement.of(sql);
when(parsedStatement.getStatement()).thenReturn(statement);
when(parsedStatement.getSqlWithoutComments()).thenReturn(statement.getSql());
DatabaseClient client = mock(DatabaseClient.class);
com.google.cloud.spanner.ReadOnlyTransaction tx = mock(com.google.cloud.spanner.ReadOnlyTransaction.class);
ResultSet resWithOptions = mock(ResultSet.class);
ResultSet resWithoutOptions = mock(ResultSet.class);
when(tx.executeQuery(Statement.of(sql), option)).thenReturn(resWithOptions);
when(tx.executeQuery(Statement.of(sql))).thenReturn(resWithoutOptions);
when(client.readOnlyTransaction(TimestampBound.strong())).thenReturn(tx);
ReadOnlyTransaction transaction = ReadOnlyTransaction.newBuilder().setDatabaseClient(client).setReadOnlyStaleness(TimestampBound.strong()).withStatementExecutor(new StatementExecutor()).build();
ResultSet expectedWithOptions = DirectExecuteResultSet.ofResultSet(resWithOptions);
assertThat(get(transaction.executeQueryAsync(parsedStatement, AnalyzeMode.NONE, option)), is(equalTo(expectedWithOptions)));
ResultSet expectedWithoutOptions = DirectExecuteResultSet.ofResultSet(resWithoutOptions);
assertThat(get(transaction.executeQueryAsync(parsedStatement, AnalyzeMode.NONE)), is(equalTo(expectedWithoutOptions)));
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ReadOnlyTransactionTest method testExecuteDdl.
@Test
public void testExecuteDdl() {
ParsedStatement ddl = mock(ParsedStatement.class);
when(ddl.getType()).thenReturn(StatementType.DDL);
try {
createSubject().executeDdlAsync(ddl);
fail("Expected exception");
} catch (SpannerException ex) {
assertEquals(ErrorCode.FAILED_PRECONDITION, ex.getErrorCode());
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ReadWriteTransactionTest method testExecuteQuery.
@Test
public void testExecuteQuery() {
ParsedStatement parsedStatement = mock(ParsedStatement.class);
when(parsedStatement.getType()).thenReturn(StatementType.QUERY);
when(parsedStatement.isQuery()).thenReturn(true);
Statement statement = Statement.of("SELECT * FROM FOO");
when(parsedStatement.getStatement()).thenReturn(statement);
ReadWriteTransaction transaction = createSubject();
ResultSet rs = get(transaction.executeQueryAsync(parsedStatement, AnalyzeMode.NONE));
assertThat(rs, is(notNullValue()));
assertThat(rs.getStats(), is(nullValue()));
}
Aggregations