/** * Updates current metric. If the metric does not exist, it is created. * * <p>Example of updating the metric's information. * * <pre>{@code * Metric updatedMetric = metric.toBuilder() * .setDescription("A more detailed description") * .build() * .update(); * }</pre> * * @return a {@code Metric} object with updated information * @throws LoggingException upon failure */ public Metric update() { return logging.update(this); }
/** * Updates current sink. If the sink does not exist, it is created. * * <p>Example of updating the sink's information. * * <pre>{@code * Sink updatedSink = sink.toBuilder() * .setFilter("severity<=ERROR") * .build() * .update(); * }</pre> * * @return a {@code Sink} object with updated information * @throws LoggingException upon failure */ public Sink update() { return logging.update(this); }
/** Example of updating a metric. */ // [TARGET update(MetricInfo)] // [VARIABLE "my_metric_name"] public Metric updateMetric(String metricName) { // [START updateMetric] MetricInfo metricInfo = MetricInfo.newBuilder(metricName, "severity>=ERROR") .setDescription("new description") .build(); Metric metric = logging.update(metricInfo); // [END updateMetric] return metric; }
/** Example of updating a sink. */ // [TARGET update(SinkInfo)] // [VARIABLE "my_sink_name"] // [VARIABLE "my_dataset"] public Sink updateSink(String sinkName, String datasetName) { // [START logging_update_sink] SinkInfo sinkInfo = SinkInfo.newBuilder(sinkName, DatasetDestination.of(datasetName)) .setVersionFormat(SinkInfo.VersionFormat.V2) .setFilter("severity>=ERROR") .build(); Sink sink = logging.update(sinkInfo); // [END logging_update_sink] return sink; }
@Test public void testUpdate() { initializeExpectedSink(2); SinkInfo updatedInfo = SINK_INFO.toBuilder().setFilter(NEW_FILTER).build(); Sink expectedSink = new Sink(serviceMockReturnsOptions, new SinkInfo.BuilderImpl(updatedInfo)); expect(logging.getOptions()).andReturn(mockOptions).times(2); expect(logging.update(expectedSink)).andReturn(expectedSink); replay(logging); initializeSink(); Sink updatedSink = sink.toBuilder().setFilter(NEW_FILTER).build().update(); compareSink(expectedSink, updatedSink); }
@Test public void testUpdate() { 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).times(2); expect(logging.update(expectedMetric)).andReturn(expectedMetric); replay(logging); initializeMetric(); Metric updatedMetric = metric.toBuilder().setFilter(NEW_FILTER).build().update(); compareMetric(expectedMetric, updatedMetric); }
@Test public void testUpdateMetric() { LogMetric sinkPb = METRIC_INFO.toPb(); ApiFuture<LogMetric> response = ApiFutures.immediateFuture(sinkPb); UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).setMetric(sinkPb).build(); EasyMock.expect(loggingRpcMock.update(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Metric sink = logging.update(METRIC_INFO); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), sink); }
@Test public void testUpdateSink() { LogSink sinkPb = SINK_INFO.toPb(PROJECT); ApiFuture<LogSink> response = ApiFutures.immediateFuture(sinkPb); UpdateSinkRequest request = UpdateSinkRequest.newBuilder().setSinkName(SINK_NAME_PB).setSink(sinkPb).build(); EasyMock.expect(loggingRpcMock.update(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Sink sink = logging.update(SINK_INFO); assertEquals(new Sink(logging, new SinkInfo.BuilderImpl(SINK_INFO)), sink); }
@Test public void testUpdateNonExistingSink() { String name = formatForTest("test-update-non-existing-sink"); SinkInfo sinkInfo = SinkInfo.newBuilder(name, DatasetDestination.of("dataset")) .setFilter("severity>=ERROR") .setVersionFormat(SinkInfo.VersionFormat.V2) .build(); assertNull(logging().getSink(name)); thrown.expect(LoggingException.class); thrown.expectMessage("NOT_FOUND"); logging().update(sinkInfo); }
@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()); }
/** * Updates current metric. If the metric does not exist, it is created. * * <p>Example of updating the metric's information. * * <pre>{@code * Metric updatedMetric = metric.toBuilder() * .setDescription("A more detailed description") * .build() * .update(); * }</pre> * * @return a {@code Metric} object with updated information * @throws LoggingException upon failure */ public Metric update() { return logging.update(this); }
/** * Updates current sink. If the sink does not exist, it is created. * * <p>Example of updating the sink's information. * * <pre>{@code * Sink updatedSink = sink.toBuilder() * .setFilter("severity<=ERROR") * .build() * .update(); * }</pre> * * @return a {@code Sink} object with updated information * @throws LoggingException upon failure */ public Sink update() { return logging.update(this); }