Search in sources :

Example 1 with ParsedStatement

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

the class SingleUseTransactionTest method createParsedQuery.

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

Example 2 with ParsedStatement

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

the class SingleUseTransactionTest method testExecuteUpdate_Transactional_Valid.

@Test
public void testExecuteUpdate_Transactional_Valid() {
    ParsedStatement update = createParsedUpdate(VALID_UPDATE);
    SingleUseTransaction subject = createSubject();
    long updateCount = get(subject.executeUpdateAsync(update));
    assertThat(updateCount).isEqualTo(VALID_UPDATE_COUNT);
    assertThat(subject.getCommitTimestamp()).isNotNull();
    assertThat(subject.getState()).isEqualTo(com.google.cloud.spanner.connection.UnitOfWork.UnitOfWorkState.COMMITTED);
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 3 with ParsedStatement

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

the class SingleUseTransactionTest method testExecuteUpdate_Partitioned_Valid.

@Test
public void testExecuteUpdate_Partitioned_Valid() {
    ParsedStatement update = createParsedUpdate(VALID_UPDATE);
    SingleUseTransaction subject = createSubject(AutocommitDmlMode.PARTITIONED_NON_ATOMIC);
    long updateCount = get(subject.executeUpdateAsync(update));
    assertThat(updateCount).isEqualTo(VALID_UPDATE_COUNT);
    assertThat(subject.getState()).isEqualTo(com.google.cloud.spanner.connection.UnitOfWork.UnitOfWorkState.COMMITTED);
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) Test(org.junit.Test)

Example 4 with ParsedStatement

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

the class SingleUseTransactionTest method testGetCommitResponseAfterQuery.

@Test
public void testGetCommitResponseAfterQuery() {
    ParsedStatement query = createParsedQuery(VALID_QUERY);
    SingleUseTransaction transaction = createSubject();
    get(transaction.executeQueryAsync(query, AnalyzeMode.NONE));
    try {
        transaction.getCommitResponse();
        fail("missing expected exception");
    } catch (SpannerException e) {
        assertEquals(ErrorCode.FAILED_PRECONDITION, e.getErrorCode());
    }
    assertNull(transaction.getCommitResponseOrNull());
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) SpannerException(com.google.cloud.spanner.SpannerException) Test(org.junit.Test)

Example 5 with ParsedStatement

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

the class SingleUseTransactionTest method testExecuteUpdate_Transactional_Invalid.

@Test
public void testExecuteUpdate_Transactional_Invalid() {
    ParsedStatement update = createParsedUpdate(INVALID_UPDATE);
    SingleUseTransaction subject = createSubject();
    try {
        get(subject.executeUpdateAsync(update));
        fail("missing expected exception");
    } catch (SpannerException e) {
        assertThat(e.getErrorCode()).isEqualTo(ErrorCode.UNKNOWN);
        assertThat(e.getMessage()).contains("invalid update");
    }
}
Also used : ParsedStatement(com.google.cloud.spanner.connection.AbstractStatementParser.ParsedStatement) SpannerException(com.google.cloud.spanner.SpannerException) 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