/** * Fetches current metric's latest information. Returns {@code null} if the metric does not exist. * * <p>Example of getting the metric's latest information. * * <pre>{@code * Metric latestMetric = metric.reload(); * if (latestMetric == null) { * // the metric was not found * } * }</pre> * * @return a {@code Metric} object with latest information or {@code null} if not found * @throws LoggingException upon failure */ public Metric reload() { return logging.getMetric(getName()); }
/** * 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()); }
/** * Sends a request to fetch current metric's latest information. This method returns a {@code * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a {@code Metric} * object with latest information or {@code null} if not found. * * <p>Example of asynchronously getting the metric's latest information. * * <pre>{@code * ApiFuture<Metric> future = metric.reloadAsync(); * // ... * Metric latestMetric = future.get(); * if (latestMetric == null) { * // the metric was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Metric> reloadAsync() { return logging.getMetricAsync(getName()); }
/** * 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()); }
private void compareMetric(Metric expected, Metric value) { assertEquals(expected, value); assertEquals(expected.getName(), value.getName()); assertEquals(expected.getDescription(), value.getDescription()); assertEquals(expected.getFilter(), value.getFilter()); assertEquals(expected.hashCode(), value.hashCode()); assertEquals(expected.toString(), value.toString()); } }
@Test public void testBuilder() { initializeExpectedMetric(2); replay(logging); Metric builtMetric = expectedMetric .toBuilder() .setName(NEW_NAME) .setFilter(NEW_FILTER) .setDescription(NEW_DESCRIPTION) .build(); assertEquals(NEW_NAME, builtMetric.getName()); assertEquals(NEW_DESCRIPTION, builtMetric.getDescription()); assertEquals(NEW_FILTER, builtMetric.getFilter()); assertSame(serviceMockReturnsOptions, builtMetric.getLogging()); }
@Test public void testUpdateNonExistingMetric() { String name = formatForTest("test-update-non-existing-metric"); MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR").setDescription("description").build(); assertNull(logging().getMetric(name)); Metric metric = logging().update(metricInfo); assertEquals(name, metric.getName()); assertEquals("severity>=ERROR", metric.getFilter()); assertEquals("description", metric.getDescription()); assertTrue(metric.delete()); }
@Test public void testCreateGetUpdateAndDeleteMetric() { String name = formatForTest("test-create-get-update-metric"); MetricInfo metricInfo = MetricInfo.newBuilder(name, "severity>=ERROR").setDescription("description").build(); Metric metric = logging().create(metricInfo); assertEquals(name, metric.getName()); assertEquals("severity>=ERROR", metric.getFilter()); assertEquals("description", metric.getDescription()); assertEquals(metric, logging().getMetric(name)); metric = metric .toBuilder() .setDescription("newDescription") .setFilter("severity>=WARNING") .build() .update(); assertEquals(name, metric.getName()); assertEquals("severity>=WARNING", metric.getFilter()); assertEquals("newDescription", metric.getDescription()); assertTrue(metric.delete()); assertFalse(metric.delete()); }
/** * Fetches current metric's latest information. Returns {@code null} if the metric does not exist. * * <p>Example of getting the metric's latest information. * * <pre>{@code * Metric latestMetric = metric.reload(); * if (latestMetric == null) { * // the metric was not found * } * }</pre> * * @return a {@code Metric} object with latest information or {@code null} if not found * @throws LoggingException upon failure */ public Metric reload() { return logging.getMetric(getName()); }
/** * 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()); }
/** * Sends a request to fetch current metric's latest information. This method returns a {@code * ApiFuture} object to consume the result. {@link ApiFuture#get()} returns a {@code Metric} * object with latest information or {@code null} if not found. * * <p>Example of asynchronously getting the metric's latest information. * * <pre>{@code * ApiFuture<Metric> future = metric.reloadAsync(); * // ... * Metric latestMetric = future.get(); * if (latestMetric == null) { * // the metric was not found * } * }</pre> * * @throws LoggingException upon failure */ public ApiFuture<Metric> reloadAsync() { return logging.getMetricAsync(getName()); }
/** * 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()); }