use of com.google.logging.v2.MetricNameOneof in project google-cloud-java by GoogleCloudPlatform.
the class MetricsClient method deleteLogMetric.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes a logs-based metric.
*
* <p>Sample code:
*
* <pre><code>
* try (MetricsClient metricsClient = MetricsClient.create()) {
* MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
* metricsClient.deleteLogMetric(metricName);
* }
* </code></pre>
*
* @param metricName The resource name of the metric to delete:
* <p>"projects/[PROJECT_ID]/metrics/[METRIC_ID]"
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void deleteLogMetric(MetricNameOneof metricName) {
DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder().setMetricNameWithMetricNameOneof(metricName).build();
deleteLogMetric(request);
}
use of com.google.logging.v2.MetricNameOneof in project google-cloud-java by GoogleCloudPlatform.
the class MetricsClientTest method deleteLogMetricTest.
@Test
@SuppressWarnings("all")
public void deleteLogMetricTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockMetricsServiceV2.addResponse(expectedResponse);
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
client.deleteLogMetric(metricName);
List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteLogMetricRequest actualRequest = (DeleteLogMetricRequest) actualRequests.get(0);
Assert.assertEquals(metricName, actualRequest.getMetricNameAsMetricNameOneof());
}
use of com.google.logging.v2.MetricNameOneof in project google-cloud-java by GoogleCloudPlatform.
the class MetricsClientTest method updateLogMetricTest.
@Test
@SuppressWarnings("all")
public void updateLogMetricTest() {
String name = "name3373707";
String description = "description-1724546052";
String filter = "filter-1274492040";
LogMetric expectedResponse = LogMetric.newBuilder().setName(name).setDescription(description).setFilter(filter).build();
mockMetricsServiceV2.addResponse(expectedResponse);
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric metric = LogMetric.newBuilder().build();
LogMetric actualResponse = client.updateLogMetric(metricName, metric);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateLogMetricRequest actualRequest = (UpdateLogMetricRequest) actualRequests.get(0);
Assert.assertEquals(metricName, actualRequest.getMetricNameAsMetricNameOneof());
Assert.assertEquals(metric, actualRequest.getMetric());
}
use of com.google.logging.v2.MetricNameOneof in project google-cloud-java by GoogleCloudPlatform.
the class MetricsClientTest method getLogMetricTest.
@Test
@SuppressWarnings("all")
public void getLogMetricTest() {
String name = "name3373707";
String description = "description-1724546052";
String filter = "filter-1274492040";
LogMetric expectedResponse = LogMetric.newBuilder().setName(name).setDescription(description).setFilter(filter).build();
mockMetricsServiceV2.addResponse(expectedResponse);
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric actualResponse = client.getLogMetric(metricName);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetLogMetricRequest actualRequest = (GetLogMetricRequest) actualRequests.get(0);
Assert.assertEquals(metricName, actualRequest.getMetricNameAsMetricNameOneof());
}
use of com.google.logging.v2.MetricNameOneof in project google-cloud-java by GoogleCloudPlatform.
the class MetricsClientTest method updateLogMetricExceptionTest.
@Test
@SuppressWarnings("all")
public void updateLogMetricExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricsServiceV2.addException(exception);
try {
MetricNameOneof metricName = MetricNameOneof.from(MetricName.create("[PROJECT]", "[METRIC]"));
LogMetric metric = LogMetric.newBuilder().build();
client.updateLogMetric(metricName, metric);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
Aggregations