Search in sources :

Example 1 with MetricDescriptorName

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());
}
Also used : Empty(com.google.protobuf.Empty) MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName) DeleteMetricDescriptorRequest(com.google.monitoring.v3.DeleteMetricDescriptorRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 2 with MetricDescriptorName

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());
}
Also used : GetMetricDescriptorRequest(com.google.monitoring.v3.GetMetricDescriptorRequest) MetricDescriptor(com.google.api.MetricDescriptor) MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 3 with MetricDescriptorName

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);
}
Also used : DeleteMetricDescriptorRequest(com.google.monitoring.v3.DeleteMetricDescriptorRequest)

Example 4 with MetricDescriptorName

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());
    }
}
Also used : MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 5 with MetricDescriptorName

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());
    }
}
Also used : MetricDescriptorName(com.google.monitoring.v3.MetricDescriptorName) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

MetricDescriptorName (com.google.monitoring.v3.MetricDescriptorName)4 Test (org.junit.Test)4 ApiException (com.google.api.gax.grpc.ApiException)2 DeleteMetricDescriptorRequest (com.google.monitoring.v3.DeleteMetricDescriptorRequest)2 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 MetricDescriptor (com.google.api.MetricDescriptor)1 GetMetricDescriptorRequest (com.google.monitoring.v3.GetMetricDescriptorRequest)1 Empty (com.google.protobuf.Empty)1