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; }
@Override public void onSuccess(PublishResponse result) { try { if (result.getMessageIdsCount() != outstandingBatch.size()) { Throwable t = new IllegalStateException( String.format( "The publish result count %s does not match " + "the expected %s results. Please contact Cloud Pub/Sub support " + "if this frequently occurs", result.getMessageIdsCount(), outstandingBatch.size())); for (OutstandingPublish oustandingMessage : outstandingBatch.outstandingPublishes) { oustandingMessage.publishResult.setException(t); } return; } Iterator<OutstandingPublish> messagesResultsIt = outstandingBatch.outstandingPublishes.iterator(); for (String messageId : result.getMessageIdsList()) { messagesResultsIt.next().publishResult.set(messageId); } } finally { messagesWaiter.incrementPendingMessages(-outstandingBatch.size()); } }
void awaitCompletion() throws Throwable { try { completionFuture.get(10, TimeUnit.MINUTES); } catch (ExecutionException e) { throw e.getCause(); } }
String dlpJobName = dlpJob.getName(); final SettableApiFuture<Boolean> done = SettableApiFuture.create(); && pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) { done.set(true); ackReplyConsumer.ack(); done.get(1, TimeUnit.MINUTES); Thread.sleep(500); // Wait for the job to become available } catch (TimeoutException e) {
private void runWatchTest(final TestDefinition.ListenTest testCase) throws ExecutionException, InterruptedException { final SettableApiFuture<Void> testCaseStarted = SettableApiFuture.create(); final SettableApiFuture<Void> testCaseFinished = SettableApiFuture.create(); testCaseStarted.get(); testCaseFinished.get(); registration.remove();
@Override public void onError(Throwable t) { errorFuture.setException(t); }
@Override public void nack() { response.set(AckReply.NACK); } };
@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); }
@Override public void onEvent(@Nullable QuerySnapshot snapshots, @Nullable FirestoreException e) { if (e != null) { System.err.println("Listen failed:" + e); return; } List<String> cities = new ArrayList<>(); for (DocumentSnapshot doc : snapshots) { if (doc.get("name") != null) { cities.add(doc.getString("name")); } } System.out.println("Current cites in CA: " + cities); // [START_EXCLUDE silent] if (!future.isDone()) { future.set(cities); } // [END_EXCLUDE] } });
callable.call("request", watchdog.watch(downstreamObserver1, waitTime, idleTime)); MockServerStreamingCall<String, String> call1 = callable.popLastCall(); downstreamObserver1.controller.get().request(1); callable.call("req2", watchdog.watch(downstreamObserver2, waitTime, idleTime)); MockServerStreamingCall<String, String> call2 = callable.popLastCall(); downstreamObserver2.controller.get().request(1); Truth.assertThat(downstreamObserver1.done.isDone()).isFalse(); Throwable error = null; try { downstreamObserver2.done.get(); } catch (ExecutionException t) { error = t.getCause();
public boolean isDone() { return done.isDone(); } }
String dlpJobName = dlpJob.getName(); final SettableApiFuture<Boolean> done = SettableApiFuture.create(); && pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) { done.set(true); ackReplyConsumer.ack(); done.get(1, TimeUnit.MINUTES); Thread.sleep(500); // Wait for the job to become available } catch (TimeoutException e) {
/** * 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); }
@Override public void onError(Throwable throwable) { result.setException(throwable); }
@Override public void ack() { response.set(AckReply.ACK); }
@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] } });
public boolean isCancelled() { return cancelFuture.isDone(); }
String dlpJobName = dlpJob.getName(); final SettableApiFuture<Boolean> done = SettableApiFuture.create(); && pubsubMessage.getAttributesMap().get("DlpJobName").equals(dlpJobName)) { done.set(true); ackReplyConsumer.ack(); done.get(1, TimeUnit.MINUTES); Thread.sleep(500); // Wait for the job to become available } catch (TimeoutException e) {