/** Example of deleting a metric. */ // [TARGET deleteMetric(String)] // [VARIABLE "my_metric_name"] public boolean deleteMetric(String metricName) { // [START deleteMetric] boolean deleted = logging.deleteMetric(metricName); if (deleted) { // the metric was deleted } else { // the metric was not found } // [END deleteMetric] return deleted; }
@Override public void run(Logging logging, String metric) { logging.deleteMetric(metric); System.out.printf("Deleted metric %s%n", metric); } }
/** * Deletes this metric. * * <p>Example of deleting the metric. * * <pre>{@code * boolean deleted = metric.delete(); * if (deleted) { * // the metric was deleted * } else { * // the metric was not found * } * }</pre> * * @return {@code true} if the metric was deleted, {@code false} if it was not found * @throws LoggingException upon failure */ public boolean delete() { return logging.deleteMetric(getName()); }
@Test public void testDeleteTrue() { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteMetric(NAME)).andReturn(true); replay(logging); initializeMetric(); assertTrue(metric.delete()); }
@Test public void testDeleteFalse() { initializeExpectedMetric(1); expect(logging.getOptions()).andReturn(mockOptions); expect(logging.deleteMetric(NAME)).andReturn(false); replay(logging); initializeMetric(); assertFalse(metric.delete()); }
@Test public void testDeleteMetric_Null() { 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.deleteMetric(METRIC_NAME)); }
@Test public void testDeleteMetric() { 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.deleteMetric(METRIC_NAME)); }
/** * Deletes this metric. * * <p>Example of deleting the metric. * * <pre>{@code * boolean deleted = metric.delete(); * if (deleted) { * // the metric was deleted * } else { * // the metric was not found * } * }</pre> * * @return {@code true} if the metric was deleted, {@code false} if it was not found * @throws LoggingException upon failure */ public boolean delete() { return logging.deleteMetric(getName()); }