use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class WriteBatchTest method deleteDocument.
@Test
public void deleteDocument() throws Exception {
doReturn(commitResponse(2, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
List<Write> writes = new ArrayList<>();
batch.delete(documentReference);
writes.add(delete());
batch.delete(documentReference, Precondition.updatedAt(Timestamp.ofTimeSecondsAndNanos(1, 2)));
com.google.firestore.v1.Precondition.Builder precondition = com.google.firestore.v1.Precondition.newBuilder();
precondition.getUpdateTimeBuilder().setSeconds(1).setNanos(2);
writes.add(delete(precondition.build()));
assertEquals(2, batch.getMutationsSize());
List<WriteResult> writeResults = batch.commit().get();
for (int i = 0; i < writeResults.size(); ++i) {
assertEquals(Timestamp.ofTimeSecondsAndNanos(i, i), writeResults.get(i).getUpdateTime());
}
CommitRequest commitRequest = commitCapture.getValue();
assertEquals(commit(writes.toArray(new Write[] {})), commitRequest);
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project java-firestore by googleapis.
the class FirestoreTest method arrayUnionWithPojo.
@Test
public void arrayUnionWithPojo() throws ExecutionException, InterruptedException {
doReturn(commitResponse(1, 0)).when(firestoreMock).sendRequest(commitCapture.capture(), Matchers.<UnaryCallable<CommitRequest, CommitResponse>>any());
DocumentReference doc = firestoreMock.document("coll/doc");
doc.update("array", FieldValue.arrayUnion(SINGLE_FIELD_OBJECT)).get();
CommitRequest expectedRequest = commit(update(Collections.emptyMap(), new ArrayList<>()), transform("array", arrayUnion(SINGLE_FIELD_VALUE)));
CommitRequest actualRequest = commitCapture.getValue();
assertEquals(expectedRequest, actualRequest);
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project appengine-java-standard by GoogleCloudPlatform.
the class AsyncCloudDatastoreV1ServiceImplTest method testCommitTriggersGetOnAllFutures.
@Test
public void testCommitTriggersGetOnAllFutures() throws Exception {
// This test will have 2 Put calls and 1 Get call within a transaction.
Entity putEntity1 = new Entity("Foo1");
putEntity1.setProperty("aString", "test1");
Entity putEntity2 = new Entity("Foo2");
putEntity1.setProperty("aString", "test2");
Key getKey1 = KeyFactory.createKey("Foo3", "name1");
Entity expectedGetEntity = new Entity(getKey1);
expectedGetEntity.setProperty("aString", "test3");
ByteString remoteTxn = expectBeginTransaction();
AllocateIdsRequest expectedAllocIdsReq1 = createAllocateIdsRequest(putEntity1);
AllocateIdsRequest expectedAllocIdsReq2 = createAllocateIdsRequest(putEntity2);
LookupRequest expectedLookupRequest = createLookupRequest(remoteTxn, getKey1).build();
// Use TrackingFutures to allow us to assert exactly when Future.get is called.
TrackingFuture<AllocateIdsResponse> trackingAllocIdRespFuture1 = new TrackingFuture<>(createAllocateIdsResponse(expectedAllocIdsReq1, 11L));
TrackingFuture<AllocateIdsResponse> trackingAllocIdRespFuture2 = new TrackingFuture<>(createAllocateIdsResponse(expectedAllocIdsReq2, 22L));
CommitRequest expectedPutRequest = createPutCommitRequest(remoteTxn, copyWithNewId(putEntity2, 22L), copyWithNewId(putEntity1, 11L)).build();
CommitResponse expectedPutResponse = CommitResponse.newBuilder().addMutationResults(MutationResult.getDefaultInstance()).addMutationResults(MutationResult.getDefaultInstance()).build();
TrackingFuture<CommitResponse> trackingPutResponseFuture = new TrackingFuture<>(expectedPutResponse);
TrackingFuture<LookupResponse> trackingLookupResponseFuture = new TrackingFuture<>(createLookupResponse(expectedGetEntity));
expectAllocateIds(expectedAllocIdsReq1, trackingAllocIdRespFuture1);
expectAllocateIds(expectedAllocIdsReq2, trackingAllocIdRespFuture2);
expectLookup(expectedLookupRequest, trackingLookupResponseFuture);
expectCommitRequest(expectedPutRequest, trackingPutResponseFuture);
replay();
AsyncCloudDatastoreV1ServiceImpl ads = newAsyncDatastoreService();
// Begin a transaction.
Transaction txn = ads.beginTransaction().get();
// Issue the async calls.
Future<Key> putFuture1 = ads.put(putEntity1);
Future<Key> putFuture2 = ads.put(putEntity2);
Future<Entity> getFuture = ads.get(getKey1);
// Nothing should have triggered the Future.get calls yet.
assertThat(trackingAllocIdRespFuture1.getNumCallsToGet()).isEqualTo(0);
assertThat(trackingAllocIdRespFuture2.getNumCallsToGet()).isEqualTo(0);
assertThat(trackingPutResponseFuture.getNumCallsToGet()).isEqualTo(0);
assertThat(trackingLookupResponseFuture.getNumCallsToGet()).isEqualTo(0);
// Simulate user code getting one of the Futures.
Key putResult2 = putFuture2.get();
assertThat(putResult2.getId()).isEqualTo(22L);
// That should be the only one of the four underlying Futures that had get() called.
assertThat(trackingAllocIdRespFuture1.getNumCallsToGet()).isEqualTo(0);
assertThat(trackingAllocIdRespFuture2.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingPutResponseFuture.getNumCallsToGet()).isEqualTo(0);
assertThat(trackingLookupResponseFuture.getNumCallsToGet()).isEqualTo(0);
// Commit the transaction. This should trigger the other underlying Futures.
txn.commit();
assertThat(trackingAllocIdRespFuture1.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingAllocIdRespFuture2.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingPutResponseFuture.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingLookupResponseFuture.getNumCallsToGet()).isEqualTo(1);
// User code gets the remaining results after the commit.
Key putResult1 = putFuture1.get();
assertThat(putResult1.getId()).isEqualTo(11L);
Entity getResult = getFuture.get();
assertThat(getResult).isEqualTo(expectedGetEntity);
// This triggers an additional call on the getFuture, but no additional calls to the
// CloudDatastoreV1Proxy.
assertThat(trackingAllocIdRespFuture1.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingAllocIdRespFuture2.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingPutResponseFuture.getNumCallsToGet()).isEqualTo(1);
assertThat(trackingLookupResponseFuture.getNumCallsToGet()).isEqualTo(2);
verify();
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project appengine-java-standard by GoogleCloudPlatform.
the class CloudDatastoreV1ServiceImplTest method putAndReturnError.
private void putAndReturnError(Code code) throws Exception {
Entity golden = new Entity("Foo");
golden.setProperty("aString", "test");
golden.setProperty("anInteger", 42);
golden.setProperty("aFloat", 62.3);
golden.getKey().simulatePutForTesting(12345L);
ByteString remoteTxn = maybeExpectBeginTransaction();
CommitRequest putRequest = createPutCommitRequest(remoteTxn, golden).build();
expectCommit(putRequest, code);
replay();
newDatastoreService().put(golden);
throw new AssertionError("should have thrown an exception");
}
use of com.swiftmq.impl.routing.single.smqpr.v942.CommitRequest in project grpc-gcp-java by GoogleCloudPlatform.
the class DataStoreChecksumClient method commitTransaction.
private static void commitTransaction(DatastoreBlockingStub stub, String projectId) {
int transactionBytes = 2000;
String payload = new String(new char[transactionBytes]).replace('\0', 'x');
Key key = Key.newBuilder().addPath(PathElement.newBuilder().setKind("Data").setName("data1").build()).build();
Entity entity = Entity.newBuilder().setKey(key).putProperties("2kb", Value.newBuilder().setExcludeFromIndexes(true).setStringValue(payload).build()).build();
Mutation mutation = Mutation.newBuilder().setUpdate(entity).build();
CommitRequest commitRequest = CommitRequest.newBuilder().setProjectId(projectId).setMode(Mode.NON_TRANSACTIONAL).addMutations(mutation).build();
CommitResponse commitResponse = stub.commit(commitRequest);
System.out.println("index updates: " + commitResponse.getIndexUpdates());
}
Aggregations