Search in sources :

Example 71 with ParsedStatement

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);
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 72 with ParsedStatement

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();
    }
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 73 with ParsedStatement

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();
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 74 with ParsedStatement

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();
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 75 with ParsedStatement

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();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Duration(com.google.protobuf.Duration) ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Aggregations

ParsedStatement (com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement)75 Test (org.junit.Test)61 Statement (com.google.cloud.spanner.Statement)23 SpannerException (com.google.cloud.spanner.SpannerException)20 ResultSet (com.google.cloud.spanner.ResultSet)12 AsyncResultSet (com.google.cloud.spanner.AsyncResultSet)6 DatabaseClient (com.google.cloud.spanner.DatabaseClient)6 TimestampBound (com.google.cloud.spanner.TimestampBound)6 LinkedList (java.util.LinkedList)3 Mockito.anyString (org.mockito.Mockito.anyString)3 AbortedException (com.google.cloud.spanner.AbortedException)2 QueryOption (com.google.cloud.spanner.Options.QueryOption)2 Mutation (com.google.cloud.spanner.Mutation)1 ReadContext (com.google.cloud.spanner.ReadContext)1 TransactionContext (com.google.cloud.spanner.TransactionContext)1 TransactionManager (com.google.cloud.spanner.TransactionManager)1 ImmutableList (com.google.common.collect.ImmutableList)1 Duration (com.google.protobuf.Duration)1 BigDecimal (java.math.BigDecimal)1 TimeUnit (java.util.concurrent.TimeUnit)1