use of com.google.monitoring.v3.MetricDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method deleteMetricDescriptorTest.
@Test
@SuppressWarnings("all")
public void deleteMetricDescriptorTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockMetricService.addResponse(expectedResponse);
MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
client.deleteMetricDescriptor(name);
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
DeleteMetricDescriptorRequest actualRequest = (DeleteMetricDescriptorRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsMetricDescriptorName());
}
use of com.google.monitoring.v3.MetricDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method getMetricDescriptorTest.
@Test
@SuppressWarnings("all")
public void getMetricDescriptorTest() {
String name2 = "name2-1052831874";
String type = "type3575610";
String unit = "unit3594628";
String description = "description-1724546052";
String displayName = "displayName1615086568";
MetricDescriptor expectedResponse = MetricDescriptor.newBuilder().setName(name2).setType(type).setUnit(unit).setDescription(description).setDisplayName(displayName).build();
mockMetricService.addResponse(expectedResponse);
MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
MetricDescriptor actualResponse = client.getMetricDescriptor(name);
Assert.assertEquals(expectedResponse, actualResponse);
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
GetMetricDescriptorRequest actualRequest = (GetMetricDescriptorRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsMetricDescriptorName());
}
use of com.google.monitoring.v3.MetricDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClient method deleteMetricDescriptor.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Deletes a metric descriptor. Only user-created [custom metrics](/monitoring/custom-metrics) can
* be deleted.
*
* <p>Sample code:
*
* <pre><code>
* try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
* MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
* metricServiceClient.deleteMetricDescriptor(name);
* }
* </code></pre>
*
* @param name The metric descriptor on which to execute the request. The format is
* `"projects/{project_id_or_number}/metricDescriptors/{metric_id}"`. An example of
* `{metric_id}` is: `"custom.googleapis.com/my_test_metric"`.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void deleteMetricDescriptor(MetricDescriptorName name) {
DeleteMetricDescriptorRequest request = DeleteMetricDescriptorRequest.newBuilder().setNameWithMetricDescriptorName(name).build();
deleteMetricDescriptor(request);
}
use of com.google.monitoring.v3.MetricDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method getMetricDescriptorExceptionTest.
@Test
@SuppressWarnings("all")
public void getMetricDescriptorExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
client.getMetricDescriptor(name);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.monitoring.v3.MetricDescriptorName in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method deleteMetricDescriptorExceptionTest.
@Test
@SuppressWarnings("all")
public void deleteMetricDescriptorExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
MetricDescriptorName name = MetricDescriptorName.create("[PROJECT]", "[METRIC_DESCRIPTOR]");
client.deleteMetricDescriptor(name);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
Aggregations