Search in sources :

Example 26 with ParsedStatement

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

Example 27 with ParsedStatement

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

Example 28 with ParsedStatement

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

Example 29 with ParsedStatement

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

Example 30 with ParsedStatement

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();
}
Also used : 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