/** Example of asynchronously deleting a metric. */ // [TARGET deleteMetricAsync(String)] // [VARIABLE "my_metric_name"] public boolean deleteMetricAsync(String metricName) throws ExecutionException, InterruptedException { // [START deleteMetricAsync] Future<Boolean> future = logging.deleteMetricAsync(metricName); // ... boolean deleted = future.get(); if (deleted) { // the metric was deleted } else { // the metric was not found } // [END deleteMetricAsync] return deleted; }
/** * Sends a request for deleting this metric. This method returns a {@code ApiFuture} object to * consume the result. {@link ApiFuture#get()} returns {@code true} if the metric was deleted, * {@code false} if it was not found. * * <p>Example of asynchronously deleting the metric. * * <pre>{@code * ApiFuture<Boolean> future = metric.deleteAsync(); * // ... * boolean deleted = future.get(); * if (deleted) { * // the metric was deleted * } else { * // the metric was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Boolean> deleteAsync() { return logging.deleteMetricAsync(getName()); }
@Test public void testDeleteAsyncFalse() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteMetricAsync(NAME)).andReturn(ApiFutures.immediateFuture(false)); replay(logging); initializeMetric(); assertFalse(metric.deleteAsync().get()); }
@Test public void testDeleteAsyncTrue() throws ExecutionException, InterruptedException { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteMetricAsync(NAME)).andReturn(ApiFutures.immediateFuture(true)); replay(logging); initializeMetric(); assertTrue(metric.deleteAsync().get()); }
@Test public void testDeleteMetricAsync_Null() throws ExecutionException, InterruptedException { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).build(); ApiFuture<Empty> response = ApiFutures.immediateFuture(null); EasyMock.expect(loggingRpcMock.delete(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); assertFalse(logging.deleteMetricAsync(METRIC_NAME).get()); }
@Test public void testDeleteMetricAsync() throws ExecutionException, InterruptedException { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).build(); ApiFuture<Empty> response = ApiFutures.immediateFuture(Empty.getDefaultInstance()); EasyMock.expect(loggingRpcMock.delete(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); assertTrue(logging.deleteMetricAsync(METRIC_NAME).get()); }
/** * Sends a request for deleting this metric. This method returns a {@code ApiFuture} object to * consume the result. {@link ApiFuture#get()} returns {@code true} if the metric was deleted, * {@code false} if it was not found. * * <p>Example of asynchronously deleting the metric. * * <pre>{@code * ApiFuture<Boolean> future = metric.deleteAsync(); * // ... * boolean deleted = future.get(); * if (deleted) { * // the metric was deleted * } else { * // the metric was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Boolean> deleteAsync() { return logging.deleteMetricAsync(getName()); }