use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetStatementTimeout.
@Test
public void testExecuteGetStatementTimeout() {
ParsedStatement statement = parser.parse(Statement.of("show variable statement_timeout"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowStatementTimeout()).thenCallRealMethod();
when(connection.hasStatementTimeout()).thenReturn(true);
when(connection.getStatementTimeout(TimeUnit.NANOSECONDS)).thenReturn(1L);
statement.getClientSideStatement().execute(executor, "show variable statement_timeout");
verify(connection, times(2)).getStatementTimeout(TimeUnit.NANOSECONDS);
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteBegin.
@Test
public void testExecuteBegin() {
ParsedStatement subject = parser.parse(Statement.of("begin"));
for (String statement : subject.getClientSideStatement().getExampleStatements()) {
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementBeginTransaction()).thenCallRealMethod();
subject.getClientSideStatement().execute(executor, statement);
verify(connection, times(1)).beginTransaction();
}
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetCommitTimestamp.
@Test
public void testExecuteGetCommitTimestamp() {
ParsedStatement statement = parser.parse(Statement.of("show variable commit_timestamp"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowCommitTimestamp()).thenCallRealMethod();
when(connection.getCommitTimestampOrNull()).thenReturn(Timestamp.now());
statement.getClientSideStatement().execute(executor, "show variable commit_timestamp");
verify(connection, times(1)).getCommitTimestampOrNull();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithNoParametersTest method testExecuteGetOptimizerVersion.
@Test
public void testExecuteGetOptimizerVersion() {
ParsedStatement statement = parser.parse(Statement.of("show variable optimizer_version"));
ConnectionImpl connection = mock(ConnectionImpl.class);
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.getConnection()).thenReturn(connection);
when(executor.statementShowOptimizerVersion()).thenCallRealMethod();
when(connection.getOptimizerVersion()).thenReturn("1");
statement.getClientSideStatement().execute(executor, "show variable optimizer_version");
verify(connection, times(1)).getOptimizerVersion();
}
use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.
the class ConnectionStatementWithOneParameterTest method testExecuteSetStatementTimeout.
@Test
public void testExecuteSetStatementTimeout() {
ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
when(executor.statementSetStatementTimeout(any(Duration.class))).thenCallRealMethod();
ConnectionImpl connection = mock(ConnectionImpl.class);
when(executor.getConnection()).thenReturn(connection);
for (TimeUnit unit : ReadOnlyStalenessUtil.SUPPORTED_UNITS) {
for (Long val : new Long[] { 1L, 100L, 999L }) {
ParsedStatement subject = parser.parse(Statement.of(String.format("set statement_timeout='%d%s'", val, ReadOnlyStalenessUtil.getTimeUnitAbbreviation(unit))));
subject.getClientSideStatement().execute(executor, String.format("set statement_timeout='%d%s'", val, ReadOnlyStalenessUtil.getTimeUnitAbbreviation(unit)));
verify(connection, times(1)).setStatementTimeout(val, unit);
}
}
ParsedStatement subject = parser.parse(Statement.of("set statement_timeout=null"));
subject.getClientSideStatement().execute(executor, "set statement_timeout=null");
verify(connection, times(1)).clearStatementTimeout();
}
Aggregations