Search in sources :

Example 1 with MetricNameOneof

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);
}
Also used : DeleteLogMetricRequest(com.google.logging.v2.DeleteLogMetricRequest)

Example 2 with MetricNameOneof

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());
}
Also used : Empty(com.google.protobuf.Empty) MetricNameOneof(com.google.logging.v2.MetricNameOneof) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) DeleteLogMetricRequest(com.google.logging.v2.DeleteLogMetricRequest) Test(org.junit.Test)

Example 3 with MetricNameOneof

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());
}
Also used : UpdateLogMetricRequest(com.google.logging.v2.UpdateLogMetricRequest) LogMetric(com.google.logging.v2.LogMetric) MetricNameOneof(com.google.logging.v2.MetricNameOneof) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 4 with MetricNameOneof

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());
}
Also used : LogMetric(com.google.logging.v2.LogMetric) MetricNameOneof(com.google.logging.v2.MetricNameOneof) GetLogMetricRequest(com.google.logging.v2.GetLogMetricRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 5 with MetricNameOneof

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());
    }
}
Also used : LogMetric(com.google.logging.v2.LogMetric) MetricNameOneof(com.google.logging.v2.MetricNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Aggregations

MetricNameOneof (com.google.logging.v2.MetricNameOneof)6 Test (org.junit.Test)6 ApiException (com.google.api.gax.grpc.ApiException)3 LogMetric (com.google.logging.v2.LogMetric)3 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 DeleteLogMetricRequest (com.google.logging.v2.DeleteLogMetricRequest)2 GetLogMetricRequest (com.google.logging.v2.GetLogMetricRequest)1 UpdateLogMetricRequest (com.google.logging.v2.UpdateLogMetricRequest)1 Empty (com.google.protobuf.Empty)1