use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithOneParameterTest method testExecuteSetAutocommit.
@Test
public void testExecuteSetAutocommit() {
ParsedStatement subject = parser.parse(Statement.of("set autocommit = true"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementSetAutocommit(any(Boolean.class))).thenCallRealMethod();
for (Boolean mode : new Boolean[] { Boolean.FALSE, Boolean.TRUE }) {
subject.getClientSideStatement().execute(executor, String.format("set autocommit = %s", mode));
verify(connection, times(1)).setAutocommit(mode);
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithOneParameterTest method testExecuteSetOptimizerVersion.
@Test
public void testExecuteSetOptimizerVersion() {
ParsedStatement subject = parser.parse(Statement.of("set optimizer_version='foo'"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementSetOptimizerVersion(any(String.class))).thenCallRealMethod();
for (String version : new String[] { "1", "200", "", "LATEST" }) {
subject.getClientSideStatement().execute(executor, String.format("set optimizer_version='%s'", version));
verify(connection, times(1)).setOptimizerVersion(version);
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithOneParameterTest method testExecuteSetOptimizerStatisticsPackage.
@Test
public void testExecuteSetOptimizerStatisticsPackage() {
ParsedStatement subject = parser.parse(Statement.of("set optimizer_statistics_package='foo'"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementSetOptimizerStatisticsPackage(any(String.class))).thenCallRealMethod();
for (String statisticsPackage : new String[] { "custom-package", "" }) {
subject.getClientSideStatement().execute(executor, String.format("set optimizer_statistics_package='%s'", statisticsPackage));
verify(connection, times(1)).setOptimizerStatisticsPackage(statisticsPackage);
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithOneParameterTest method testExecuteSetTransaction.
@Test
public void testExecuteSetTransaction() {
ParsedStatement subject = parser.parse(Statement.of("set transaction read_only"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementSetTransactionMode(any(TransactionMode.class))).thenCallRealMethod();
for (TransactionMode mode : TransactionMode.values()) {
subject.getClientSideStatement().execute(executor, String.format("set transaction %s", mode.getStatementString()));
verify(connection, times(1)).setTransactionMode(mode);
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class DdlBatchTest method testGetStateAndIsActive.
@Test
public void testGetStateAndIsActive() {
DdlBatch batch = createSubject();
assertThat(batch.getState(), is(UnitOfWorkState.STARTED));
assertThat(batch.isActive(), is(true));
get(batch.runBatchAsync());
assertThat(batch.getState(), is(UnitOfWorkState.RAN));
assertThat(batch.isActive(), is(false));
batch = createSubject();
assertThat(batch.getState(), is(UnitOfWorkState.STARTED));
assertThat(batch.isActive(), is(true));
batch.abortBatch();
assertThat(batch.getState(), is(UnitOfWorkState.ABORTED));
assertThat(batch.isActive(), is(false));
DdlClient client = mock(DdlClient.class);
SpannerException exception = mock(SpannerException.class);
when(exception.getErrorCode()).thenReturn(ErrorCode.FAILED_PRECONDITION);
doThrow(exception).when(client).executeDdl(anyList());
batch = createSubject(client);
assertThat(batch.getState(), is(UnitOfWorkState.STARTED));
assertThat(batch.isActive(), is(true));
ParsedStatement statement = mock(ParsedStatement.class);
when(statement.getStatement()).thenReturn(Statement.of("CREATE TABLE FOO"));
when(statement.getSqlWithoutComments()).thenReturn("CREATE TABLE FOO");
when(statement.getType()).thenReturn(StatementType.DDL);
batch.executeDdlAsync(statement);
try {
get(batch.runBatchAsync());
fail("Missing expected exception");
} catch (SpannerException e) {
assertThat(e.getErrorCode(), is(equalTo(ErrorCode.FAILED_PRECONDITION)));
}
assertThat(batch.getState(), is(UnitOfWorkState.RUN_FAILED));
assertThat(batch.isActive(), is(false));
}
Aggregations