private SettableApiFuture<T> invokeUserCallback() { // Execute the user callback on the provided executor. final SettableApiFuture<T> callbackResult = SettableApiFuture.create(); userCallbackExecutor.execute( new Runnable() { @Override public void run() { try { callbackResult.set(transactionCallback.updateCallback(transaction)); } catch (Throwable t) { callbackResult.setException(t); } } }); return callbackResult; }
@Nonnull @Override public <T> ApiFuture<T> runTransaction( @Nonnull final Transaction.Function<T> updateFunction, @Nonnull TransactionOptions transactionOptions) { SettableApiFuture<T> resultFuture = SettableApiFuture.create(); runTransaction(updateFunction, resultFuture, transactionOptions); return resultFuture; }
ApiFuture<QuerySnapshot> get(@Nullable ByteString transactionId) { final SettableApiFuture<QuerySnapshot> result = SettableApiFuture.create(); stream( new QuerySnapshotObserver() { List<QueryDocumentSnapshot> documentSnapshots = new ArrayList<>(); @Override public void onNext(QueryDocumentSnapshot documentSnapshot) { documentSnapshots.add(documentSnapshot); } @Override public void onError(Throwable throwable) { result.setException(throwable); } @Override public void onCompleted() { QuerySnapshot querySnapshot = QuerySnapshot.withDocuments(Query.this, this.getReadTime(), documentSnapshots); result.set(querySnapshot); } }, transactionId); return result; }
@SuppressWarnings("unchecked") @Before public void setUp() { innerCallable = Mockito.mock(UnaryCallable.class); innerMutation = ArgumentCaptor.forClass(MutateRowRequest.class); innerResult = SettableApiFuture.create(); Mockito.when( innerCallable.futureCall(innerMutation.capture(), Mockito.any(ApiCallContext.class))) .thenReturn(innerResult); }
@SuppressWarnings("unchecked") @Before public void setUp() { innerCallable = Mockito.mock(UnaryCallable.class); innerQuery = ArgumentCaptor.forClass(Query.class); innerResult = SettableApiFuture.create(); Mockito.when(innerCallable.futureCall(innerQuery.capture(), Mockito.any(ApiCallContext.class))) .thenReturn(innerResult); }
final SettableApiFuture<AckReply> response = SettableApiFuture.create(); final AckReplyConsumer consumer = new AckReplyConsumer() {
SettableApiFuture<String> publishResult = SettableApiFuture.<String>create(); final OutstandingPublish outstandingPublish = new OutstandingPublish(publishResult, message); messagesBatchLock.lock();
@Test public void proxyBulkMutationsBatchingSendTest() { BulkMutationBatcher batcher = bigtableDataClient.newBulkMutationBatcher(); RowMutation request = RowMutation.create("fake-table", "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); SettableApiFuture<Void> innerResult = SettableApiFuture.create(); Mockito.when(mockBulkMutateRowsBatchingCallable.futureCall(request)).thenReturn(innerResult); ApiFuture<Void> actualResult = batcher.add(request); assertThat(actualResult).isSameAs(innerResult); }
private void initialize() { final SettableApiFuture<Void> errorFuture = SettableApiFuture.create(); final ResponseObserver<StreamingPullResponse> responseObserver = new StreamingPullResponseObserver(errorFuture);
@Test public void testFlush() throws InterruptedException { SettableApiFuture<WriteLogEntriesResponse> mockRpcResponse = SettableApiFuture.create(); replay(rpcFactoryMock); logging = options.getService();
@Test public void testFlushStress() throws InterruptedException { SettableApiFuture<WriteLogEntriesResponse> mockRpcResponse = SettableApiFuture.create(); mockRpcResponse.set(null); replay(rpcFactoryMock);
@Nullable FieldMask fieldMask, @Nullable ByteString transactionId) { final SettableApiFuture<List<DocumentSnapshot>> futureList = SettableApiFuture.create(); final Map<DocumentReference, DocumentSnapshot> resultMap = new HashMap<>();
@Test public void testWriteLogEntriesDoesnotEnableFlushByDefault() { WriteLogEntriesRequest request = WriteLogEntriesRequest.newBuilder() .addAllEntries( Iterables.transform( ImmutableList.of( LOG_ENTRY1, LOG_ENTRY2.toBuilder().setSeverity(Severity.EMERGENCY).build()), LogEntry.toPbFunction(PROJECT))) .build(); ApiFuture<WriteLogEntriesResponse> apiFuture = SettableApiFuture.create(); EasyMock.expect(loggingRpcMock.write(request)).andReturn(apiFuture); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); logging.write( ImmutableList.of( LOG_ENTRY1, LOG_ENTRY2.toBuilder().setSeverity(Severity.EMERGENCY).build())); }
@Test public void bulkMutationsBatchingFailureTest() throws Exception { BulkMutationBatcher batcher = bigtableDataClient.newBulkMutationBatcher(); RowMutation request = RowMutation.create("fake-table", "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); SettableApiFuture<Void> innerResult = SettableApiFuture.create(); Mockito.when(mockBulkMutateRowsBatchingCallable.futureCall(request)).thenReturn(innerResult); ApiException innerError = new ApiException(null, GrpcStatusCode.of(Code.INTERNAL), false); batcher.add(request); innerResult.setException(innerError); Throwable outerError = null; try { batcher.close(Duration.ofMillis(10)); } catch (Throwable t) { outerError = t; } assertThat(outerError).isInstanceOf(BulkMutationFailure.class); }
@Test public void bulkMutationsBatchingCloseTest() throws Exception { BulkMutationBatcher batcher = bigtableDataClient.newBulkMutationBatcher(); RowMutation request = RowMutation.create("fake-table", "some-key") .setCell("some-family", "fake-qualifier", "fake-value"); SettableApiFuture<Void> innerResult = SettableApiFuture.create(); Mockito.when(mockBulkMutateRowsBatchingCallable.futureCall(request)).thenReturn(innerResult); batcher.add(request); // Close will timeout while the request is outstanding. Throwable error = null; try { batcher.close(Duration.ofMillis(20)); } catch (Throwable t) { error = t; } assertThat(error).isInstanceOf(TimeoutException.class); // Resolve the request innerResult.set(null); // Now, close will promptly finish batcher.close(Duration.ofMillis(20)); }
/** * Listen to a single document, returning data after the first snapshot. */ Map<String, Object> listenToDocument() throws Exception { final SettableApiFuture<Map<String, Object>> future = SettableApiFuture.create(); // [START listen_to_document] DocumentReference docRef = db.collection("cities").document("SF"); docRef.addSnapshotListener(new EventListener<DocumentSnapshot>() { @Override public void onEvent(@Nullable DocumentSnapshot snapshot, @Nullable FirestoreException e) { if (e != null) { System.err.println("Listen failed: " + e); return; } if (snapshot != null && snapshot.exists()) { System.out.println("Current data: " + snapshot.getData()); } else { System.out.print("Current data: null"); } // [START_EXCLUDE silent] if (!future.isDone()) { future.set(snapshot.getData()); } // [END_EXCLUDE] } }); // [END listen_to_document] return future.get(TIMEOUT_SECONDS, TimeUnit.SECONDS); }
final SettableApiFuture<List<String>> future = SettableApiFuture.create();
SettableApiFuture<List<DocumentChange>> future = SettableApiFuture.create();
String dlpJobName = dlpJob.getName(); final SettableApiFuture<Boolean> done = SettableApiFuture.create();