com.google.datastore.v1.CommitResponse Java Examples
The following examples show how to use
com.google.datastore.v1.CommitResponse.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DatastoreV1Test.java From beam with Apache License 2.0 | 6 votes |
/** Tests {@link DatastoreWriterFn} with a failed request which is retried. */ @Test public void testDatatoreWriterFnRetriesErrors() throws Exception { List<Mutation> mutations = new ArrayList<>(); int numRpcs = 2; for (int i = 0; i < DatastoreV1.DATASTORE_BATCH_UPDATE_ENTITIES_START * numRpcs; ++i) { mutations.add( makeUpsert(Entity.newBuilder().setKey(makeKey("key" + i, i + 1)).build()).build()); } CommitResponse successfulCommit = CommitResponse.getDefaultInstance(); when(mockDatastore.commit(any(CommitRequest.class))) .thenReturn(successfulCommit) .thenThrow(new DatastoreException("commit", Code.DEADLINE_EXCEEDED, "", null)) .thenReturn(successfulCommit); DatastoreWriterFn datastoreWriter = new DatastoreWriterFn( StaticValueProvider.of(PROJECT_ID), null, mockDatastoreFactory, new FakeWriteBatcher()); DoFnTester<Mutation, Void> doFnTester = DoFnTester.of(datastoreWriter); doFnTester.setCloningBehavior(CloningBehavior.DO_NOT_CLONE); doFnTester.processBundle(mutations); }
Example #2
Source File: DatastoreImpl.java From async-datastore-client with Apache License 2.0 | 6 votes |
private ListenableFuture<MutationResult> executeAsyncMutations(final List<Mutation> mutations, final ListenableFuture<TransactionResult> txn) { final ListenableFuture<Response> httpResponse = Futures.transformAsync(txn, result -> { final CommitRequest.Builder request = CommitRequest.newBuilder(); if (mutations != null) { request.addAllMutations(mutations); } final ByteString transaction = result.getTransaction(); if (transaction != null) { request.setTransaction(transaction); } else { request.setMode(CommitRequest.Mode.NON_TRANSACTIONAL); } final ProtoHttpContent payload = new ProtoHttpContent(request.build()); return ListenableFutureAdapter.asGuavaFuture(prepareRequest("commit", payload).execute()); }, MoreExecutors.directExecutor()); return Futures.transformAsync(httpResponse, response -> { if (!isSuccessful(response.getStatusCode())) { throw new DatastoreException(response.getStatusCode(), response.getResponseBody()); } final CommitResponse commit = CommitResponse.parseFrom(streamResponse(response)); return Futures.immediateFuture(MutationResult.build(commit)); }, MoreExecutors.directExecutor()); }
Example #3
Source File: Datastore.java From google-cloud-datastore with Apache License 2.0 | 5 votes |
public CommitResponse commit(CommitRequest request) throws DatastoreException { try (InputStream is = remoteRpc.call("commit", request)) { return CommitResponse.parseFrom(is); } catch (IOException exception) { throw invalidResponseException("commit", exception); } }
Example #4
Source File: DatastoreTest.java From google-cloud-datastore with Apache License 2.0 | 5 votes |
@Test public void commit() throws Exception { CommitRequest.Builder request = CommitRequest.newBuilder(); request.setTransaction(ByteString.copyFromUtf8("project-id")); CommitResponse.Builder response = CommitResponse.newBuilder(); expectRpc("commit", request.build(), response.build()); }