Search in sources :

Example 66 with CommitRequest

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

the class DatabaseClientImplTest method testWriteAtLeastOnceWithOptions.

@Test
public void testWriteAtLeastOnceWithOptions() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    client.writeAtLeastOnceWithOptions(Collections.singletonList(Mutation.newInsertBuilder("FOO").set("ID").to(1L).set("NAME").to("Bar").build()), Options.priority(RpcPriority.LOW));
    List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(commitRequests).hasSize(1);
    CommitRequest commit = commitRequests.get(0);
    assertNotNull(commit.getSingleUseTransaction());
    assertTrue(commit.getSingleUseTransaction().hasReadWrite());
    assertNotNull(commit.getRequestOptions());
    assertEquals(Priority.PRIORITY_LOW, commit.getRequestOptions().getPriority());
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 67 with CommitRequest

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

the class DatabaseClientImplTest method writeAtLeastOnceWithTagOptions.

@Test
public void writeAtLeastOnceWithTagOptions() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    client.writeAtLeastOnceWithOptions(Collections.singletonList(Mutation.newInsertBuilder("FOO").set("ID").to(1L).set("NAME").to("Bar").build()), Options.tag("app=spanner,env=test"));
    List<CommitRequest> commitRequests = mockSpanner.getRequestsOfType(CommitRequest.class);
    assertThat(commitRequests).hasSize(1);
    CommitRequest commit = commitRequests.get(0);
    assertNotNull(commit.getSingleUseTransaction());
    assertTrue(commit.getSingleUseTransaction().hasReadWrite());
    assertNotNull(commit.getRequestOptions());
    assertThat(commit.getRequestOptions().getTransactionTag()).isEqualTo("app=spanner,env=test");
    assertThat(commit.getRequestOptions().getRequestTag()).isEmpty();
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) Test(org.junit.Test)

Example 68 with CommitRequest

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

the class DatabaseClientImplTest method testAsyncTransactionManagerCommitWithTag.

@Test
public void testAsyncTransactionManagerCommitWithTag() {
    DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE));
    try (AsyncTransactionManager manager = client.transactionManagerAsync(Options.tag("app=spanner,env=test,action=manager"))) {
        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());
    assertThat(request.getRequestOptions().getRequestTag()).isEmpty();
    assertThat(request.getRequestOptions().getTransactionTag()).isEqualTo("app=spanner,env=test,action=manager");
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) TransactionContextFuture(com.google.cloud.spanner.AsyncTransactionManager.TransactionContextFuture) Test(org.junit.Test)

Example 69 with CommitRequest

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

the class SessionImplTest method writeAtLeastOnceWithOptions.

@Test
public void writeAtLeastOnceWithOptions() throws ParseException {
    String tag = "app=spanner,env=test";
    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);
    session.writeAtLeastOnceWithOptions(Collections.singletonList(Mutation.newInsertBuilder("T").set("C").to("x").build()), Options.tag(tag));
    CommitRequest request = commit.getValue();
    assertThat(request.getRequestOptions().getTransactionTag()).isEqualTo(tag);
    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) Test(org.junit.Test)

Example 70 with CommitRequest

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

the class SpannerClientTest method commitTest3.

@Test
public void commitTest3() throws Exception {
    CommitResponse expectedResponse = CommitResponse.newBuilder().setCommitTimestamp(Timestamp.newBuilder().build()).setCommitStats(CommitResponse.CommitStats.newBuilder().build()).build();
    mockSpanner.addResponse(expectedResponse);
    String session = "session1984987798";
    ByteString transactionId = ByteString.EMPTY;
    List<Mutation> mutations = new ArrayList<>();
    CommitResponse actualResponse = client.commit(session, transactionId, mutations);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<AbstractMessage> actualRequests = mockSpanner.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CommitRequest actualRequest = ((CommitRequest) actualRequests.get(0));
    Assert.assertEquals(session, actualRequest.getSession());
    Assert.assertEquals(transactionId, actualRequest.getTransactionId());
    Assert.assertEquals(mutations, actualRequest.getMutationsList());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : CommitRequest(com.google.spanner.v1.CommitRequest) AbstractMessage(com.google.protobuf.AbstractMessage) ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) CommitResponse(com.google.spanner.v1.CommitResponse) ByteString(com.google.protobuf.ByteString) Mutation(com.google.spanner.v1.Mutation) 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