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());
}
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();
}
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");
}
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);
}
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()));
}
Aggregations