use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class DdlBatchTest method testCancel.
@Test
public void testCancel() {
ParsedStatement statement = mock(ParsedStatement.class);
when(statement.getType()).thenReturn(StatementType.DDL);
when(statement.getStatement()).thenReturn(Statement.of("CREATE TABLE FOO"));
when(statement.getSqlWithoutComments()).thenReturn("CREATE TABLE FOO");
DdlClient client = createDefaultMockDdlClient(10000L);
final DdlBatch batch = createSubject(client);
batch.executeDdlAsync(statement);
Executors.newSingleThreadScheduledExecutor().schedule(batch::cancel, 100, TimeUnit.MILLISECONDS);
try {
get(batch.runBatchAsync());
fail("expected CANCELLED");
} catch (SpannerException e) {
assertEquals(ErrorCode.CANCELLED, e.getErrorCode());
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetReadOnlyStaleness.
@Test
public void testExecuteGetReadOnlyStaleness() {
ParsedStatement statement = parser.parse(Statement.of("show variable read_only_staleness"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowReadOnlyStaleness()).thenCallRealMethod();
when(connection.getReadOnlyStaleness()).thenReturn(TimestampBound.strong());
statement.getClientSideStatement().execute(executor, "show variable read_only_staleness");
verify(connection, times(1)).getReadOnlyStaleness();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteRollback.
@Test
public void testExecuteRollback() {
ParsedStatement subject = parser.parse(Statement.of("rollback"));
for (String statement : subject.getClientSideStatement().getExampleStatements()) {
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementRollback()).thenCallRealMethod();
subject.getClientSideStatement().execute(executor, statement);
verify(connection, times(1)).rollback();
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetOptimizerStatisticsPackage.
@Test
public void testExecuteGetOptimizerStatisticsPackage() {
ParsedStatement statement = parser.parse(Statement.of("show variable optimizer_statistics_package"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowOptimizerStatisticsPackage()).thenCallRealMethod();
when(connection.getOptimizerStatisticsPackage()).thenReturn("custom-package");
statement.getClientSideStatement().execute(executor, "show variable optimizer_statistics_package");
verify(connection, times(1)).getOptimizerStatisticsPackage();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetReadOnly.
@Test
public void testExecuteGetReadOnly() {
ParsedStatement statement = parser.parse(Statement.of("show variable readonly"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowReadOnly()).thenCallRealMethod();
statement.getClientSideStatement().execute(executor, "show variable readonly");
verify(connection, times(1)).isReadOnly();
}
Aggregations