Search in sources :

Example 6 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testAsyncTransactionManagerCommitWithPriority.

@Test
public void testAsyncTransactionManagerCommitWithPriority() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    try (AsyncTransactionManager manager = client.transactionManagerAsync(Options.priority(RpcPriority.HIGH))) {
        TransactionContextFuture transaction = manager.beginAsync();
        get(transaction.then((txn, input) -> {
            txn.buffer(Mutation.delete("TEST", KeySet.all()));
            return ApiFutures.immediateFuture(null);
        }, executor).commitAsync());
    }
    List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(requests).hasSize(1);
    CommitRequest request = requests.get(0);
    assertNotNull(request.getRequestOptions());
    assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) TransactionContextFuture(com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture) Test(org.junit.Test)

Example 7 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testWrite.

@Test
public void testWrite() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    Timestamp timestamp = client.write(Collections.singletonList(Mutation.newInsertBuilder("FOO").set("ID").to(1L).set("NAME").to("Bar").build()));
    assertNotNull(timestamp);
    List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(commitRequests).hasSize(1);
    CommitRequest commit = commitRequests.get(0);
    assertNotNull(commit.getRequestOptions());
    assertEquals(Priority.PRIORITY_UNSPECIFIED, commit.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Example 8 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class DatabaseClientImplTest method testAsyncRunnerCommitWithPriority.

@Test
public void testAsyncRunnerCommitWithPriority() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    AsyncRunner runner = client.runAsync(Options.priority(RpcPriority.HIGH));
    get(runner.runAsync(txn -> {
        txn.buffer(Mutation.delete("TEST", KeySet.all()));
        return ApiFutures.immediateFuture(null);
    }, executor));
    List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(requests).hasSize(1);
    CommitRequest request = requests.get(0);
    assertNotNull(request.getRequestOptions());
    assertEquals(Priority.PRIORITY_HIGH, request.getRequestOptions().getPriority());
}
Also used : LocalChannelProvider(com.google.api.gax.grpc.testing.LocalChannelProvider) Context(io.grpc.Context) QueryAnalyzeMode(com.google.cloud.spanner.ReadContext.QueryAnalyzeMode) NoCredentials(com.google.cloud.NoCredentials) Timestamp(com.google.cloud.Timestamp) SettableFuture(com.google.common.util.concurrent.SettableFuture) StatementResult(com.google.cloud.spanner.MockSpannerServiceImpl.StatementResult) ReadRequest(com.google.spanner.v1.ReadRequest) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) After(org.junit.After) Status(io.grpc.Status) READ_ONE_KEY_VALUE_RESULTSET(com.google.cloud.spanner.MockSpannerTestUtil.READ_ONE_KEY_VALUE_RESULTSET) AfterClass(org.junit.AfterClass) ApiFutures(com.google.api.core.ApiFutures) SpannerApiFutures.get(com.google.cloud.spanner.SpannerApiFutures.get) READ_COLUMN_NAMES(com.google.cloud.spanner.MockSpannerTestUtil.READ_COLUMN_NAMES) DeleteSessionRequest(com.google.spanner.v1.DeleteSessionRequest) Set(java.util.Set) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) Logger(java.util.logging.Logger) Executors(java.util.concurrent.Executors) ApiFuture(com.google.api.core.ApiFuture) Duration(org.threeten.bp.Duration) List(java.util.List) ExecuteSqlRequest(com.google.spanner.v1.ExecuteSqlRequest) ResourceNotFoundException(com.google.cloud.spanner.SpannerException.ResourceNotFoundException) QueryMode(com.google.spanner.v1.ExecuteSqlRequest.QueryMode) Mockito.mock(org.mockito.Mockito.mock) Priority(com.google.spanner.v1.RequestOptions.Priority) TransactionOption(com.google.cloud.spanner.Options.TransactionOption) BeforeClass(org.junit.BeforeClass) READ_TABLE_NAME(com.google.cloud.spanner.MockSpannerTestUtil.READ_TABLE_NAME) Stopwatch(com.google.common.base.Stopwatch) Assert.assertThrows(org.junit.Assert.assertThrows) RunWith(org.junit.runner.RunWith) Function(java.util.function.Function) InProcessServerBuilder(io.grpc.inprocess.InProcessServerBuilder) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) RetrySettings(com.google.api.gax.retrying.RetrySettings) CommitRequest(com.google.spanner.v1.CommitRequest) PooledSessionFuture(com.google.cloud.spanner.SessionPool.PooledSessionFuture) ImmutableList(com.google.common.collect.ImmutableList) GrpcStreamIterator(com.google.cloud.spanner.AbstractResultSet.GrpcStreamIterator) Server(io.grpc.Server) SimulatedExecutionTime(com.google.cloud.spanner.MockSpannerServiceImpl.SimulatedExecutionTime) ExecutorService(java.util.concurrent.ExecutorService) READ_ONE_KEY_VALUE_STATEMENT(com.google.cloud.spanner.MockSpannerTestUtil.READ_ONE_KEY_VALUE_STATEMENT) Before(org.junit.Before) QueryOptions(com.google.spanner.v1.ExecuteSqlRequest.QueryOptions) TransactionContextFuture(com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture) CallbackResponse(com.google.cloud.spanner.AsyncResultSet.CallbackResponse) AbstractMessage(com.google.protobuf.AbstractMessage) SpannerCallContextTimeoutConfigurator(com.google.cloud.spanner.SpannerOptions.SpannerCallContextTimeoutConfigurator) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) JUnit4(org.junit.runners.JUnit4) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.verify(org.mockito.Mockito.verify) StatusRuntimeException(io.grpc.StatusRuntimeException) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) Assert.assertNull(org.junit.Assert.assertNull) RpcPriority(com.google.cloud.spanner.Options.RpcPriority) SELECT1(com.google.cloud.spanner.MockSpannerTestUtil.SELECT1) ExecuteBatchDmlRequest(com.google.spanner.v1.ExecuteBatchDmlRequest) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 9 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class PgNumericTest method testMutation.

@Test
public void testMutation() {
    final List<Mutation> mutations = Collections.singletonList(Mutation.newInsertBuilder("Table").set("PgNumeric").to("1.23").set("PgNumericNull").to((String) null).set("PgNumericNaN").to("NaN").set("PgNumericValue").to(Value.pgNumeric("2.34")).set("PgNumericArray").toStringArray(Arrays.asList("2.34", null, "3.45")).set("PgNumericArrayNull").toStringArray(null).build());
    final List<com.google.spanner.v1.Mutation> expectedMutations = new ArrayList<>();
    Mutation.toProto(mutations, expectedMutations);
    databaseClient.readWriteTransaction().run(transaction -> {
        transaction.buffer(mutations);
        return null;
    });
    final List<CommitRequest> requests = mockSpanner.getRequestsOfType(CommitRequest.class);
    final CommitRequest request = requests.get(0);
    assertEquals(1, requests.size());
    assertEquals(expectedMutations, request.getMutationsList());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 10 with CommitRequest

use of com.google.firestore.v1beta1.CommitRequest in project java-spanner by googleapis.

the class SessionImplTest method writeAtLeastOnce.

@Test
public void writeAtLeastOnce() throws ParseException {
    String timestampString = "2015-10-01T10:54:20.021Z";
    ArgumentCaptor<CommitRequest> commit = ArgumentCaptor.forClass(CommitRequest.class);
    CommitResponse response = CommitResponse.newBuilder().setCommitTimestamp(Timestamps.parse(timestampString)).build();
    Mockito.when(rpc.commit(commit.capture(), Mockito.eq(options))).thenReturn(response);
    Timestamp timestamp = session.writeAtLeastOnce(Collections.singletonList(Mutation.newInsertBuilder("T").set("C").to("x").build()));
    assertThat(timestamp.getSeconds()).isEqualTo(utcTimeSeconds(2015, Calendar.OCTOBER, 1, 10, 54, 20));
    assertThat(timestamp.getNanos()).isEqualTo(TimeUnit.MILLISECONDS.toNanos(21));
    CommitRequest request = commit.getValue();
    assertThat(request.getSingleUseTransaction()).isNotNull();
    assertThat(request.getSingleUseTransaction().getReadWrite()).isNotNull();
    com.google.spanner.v1.Mutation mutation = com.google.spanner.v1.Mutation.newBuilder().setInsert(Write.newBuilder().setTable("T").addColumns("C").addValues(ListValue.newBuilder().addValues(com.google.protobuf.Value.newBuilder().setStringValue("x")))).build();
    assertThat(request.getMutationsList()).containsExactly(mutation);
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) CommitResponse(com.google.spanner.v1.CommitResponse) ByteString(com.google.protobuf.ByteString) Timestamp(com.google.cloud.Timestamp) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)85 CommitRequest (com.google.spanner.v1.CommitRequest)47 CommitRequest (com.google.firestore.v1.CommitRequest)40 CommitResponse (com.google.firestore.v1.CommitResponse)40 ArrayList (java.util.ArrayList)26 Connection (java.sql.Connection)23 ByteString (com.google.protobuf.ByteString)14 ExecuteSqlRequest (com.google.spanner.v1.ExecuteSqlRequest)12 SQLException (java.sql.SQLException)12 Statement (java.sql.Statement)12 CopyManager (org.postgresql.copy.CopyManager)11 BaseConnection (org.postgresql.core.BaseConnection)11 ExecuteBatchDmlRequest (com.google.spanner.v1.ExecuteBatchDmlRequest)10 ArrayValue (com.google.firestore.v1.ArrayValue)9 MapValue (com.google.firestore.v1.MapValue)9 Value (com.google.firestore.v1.Value)9 Write (com.google.firestore.v1.Write)9 StringReader (java.io.StringReader)9 HashMap (java.util.HashMap)9 AbstractMessage (com.google.protobuf.AbstractMessage)8