Search in sources :

Example 66 with ParsedStatement

use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.

the class SingleUseTransactionTest method createParsedUpdate.

private ParsedStatement createParsedUpdate(String sql) {
    ParsedStatement statement = mock(ParsedStatement.class);
    when(statement.getType()).thenReturn(StatementType.UPDATE);
    when(statement.isUpdate()).thenReturn(true);
    when(statement.getStatement()).thenReturn(Statement.of(sql));
    return statement;
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement)

Example 67 with ParsedStatement

use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.

the class SingleUseTransactionTest method testExecuteUpdate_Transactional_Valid_FailedCommit.

@Test
public void testExecuteUpdate_Transactional_Valid_FailedCommit() {
    ParsedStatement update = createParsedUpdate(VALID_UPDATE);
    SingleUseTransaction subject = createSubject(CommitBehavior.FAIL);
    try {
        get(subject.executeUpdateAsync(update));
        fail("missing expected exception");
    } catch (SpannerException e) {
        assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
        assertThat(e.getMessage()).contains("commit failed");
    }
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) SpannerException(com.google.cloud.spanner.SpannerException) Test(org.junit.Test)

Example 68 with ParsedStatement

use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.

the class SingleUseTransactionTest method testGetCommitResponseAfterUpdate.

@Test
public void testGetCommitResponseAfterUpdate() {
    ParsedStatement update = createParsedUpdate(VALID_UPDATE);
    SingleUseTransaction transaction = createSubject();
    get(transaction.executeUpdateAsync(update));
    assertNotNull(transaction.getCommitResponse());
    assertNotNull(transaction.getCommitResponseOrNull());
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 69 with ParsedStatement

use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.

the class ConnectionStatementWithNoParametersTest method testExecuteCommit.

@Test
public void testExecuteCommit() {
    ParsedStatement subject = parser.parse(Statement.of("commit"));
    for (String statement : subject.getClientSideStatement().getExampleStatements()) {
        ConnectionImpl connection = mock(ConnectionImpl.class);
        ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
        when(executor.getConnection()).thenReturn(connection);
        when(executor.statementCommit()).thenCallRealMethod();
        subject.getClientSideStatement().execute(executor, statement);
        verify(connection, times(1)).commit();
    }
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 70 with ParsedStatement

use of com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement in project java-spanner by googleapis.

the class ConnectionStatementWithNoParametersTest method testExecuteGetAutocommitDmlMode.

@Test
public void testExecuteGetAutocommitDmlMode() {
    ParsedStatement statement = parser.parse(Statement.of("show variable autocommit_dml_mode"));
    ConnectionImpl connection = mock(ConnectionImpl.class);
    ConnectionStatementExecutorImpl executor = mock(ConnectionStatementExecutorImpl.class);
    when(executor.getConnection()).thenReturn(connection);
    when(executor.statementShowAutocommitDmlMode()).thenCallRealMethod();
    when(connection.getAutocommitDmlMode()).thenReturn(AutocommitDmlMode.TRANSACTIONAL);
    statement.getClientSideStatement().execute(executor, "show variable autocommit_dml_mode");
    verify(connection, times(1)).getAutocommitDmlMode();
}
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