/** Example of asynchronously getting the metric's latest information. */ // [TARGET reloadAsync()] public Metric reloadAsync() throws ExecutionException, InterruptedException { // [START reloadAsync] Future<Metric> future = metric.reloadAsync(); // ... Metric latestMetric = future.get(); if (latestMetric == null) { // the metric was not found } // [END reloadAsync] return latestMetric; }
@Test public void testReloadAsyncNull() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.getMetricAsync(NAME)).andReturn(ApiFutures.<Metric>immediateFuture(null)); replay(logging); initializeMetric(); assertNull(metric.reloadAsync().get()); }
@Test public void testReloadAsync() throws ExecutionException, InterruptedException { initializeExpectedMetric(2); MetricInfo updatedInfo = METRIC_INFO.toBuilder().setFilter(NEW_FILTER).build(); Metric expectedMetric = new Metric(serviceMockReturnsOptions, new MetricInfo.BuilderImpl(updatedInfo)); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.getMetricAsync(NAME)).andReturn(ApiFutures.immediateFuture(expectedMetric)); replay(logging); initializeMetric(); Metric updatedMetric = metric.reloadAsync().get(); compareMetric(expectedMetric, updatedMetric); }