Search in sources :

Example 16 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class MetricsClientTest method deleteLogMetricTest.

@Test
public void deleteLogMetricTest() throws Exception {
    Empty expectedResponse = Empty.newBuilder().build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
    client.deleteLogMetric(metricName);
    List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    DeleteLogMetricRequest actualRequest = ((DeleteLogMetricRequest) actualRequests.get(0));
    Assert.assertEquals(metricName.toString(), actualRequest.getMetricName());
    Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
Also used : Empty(com.google.protobuf.Empty) AbstractMessage(com.google.protobuf.AbstractMessage) LogMetricName(com.google.logging.v2.LogMetricName) DeleteLogMetricRequest(com.google.logging.v2.DeleteLogMetricRequest) Test(org.junit.Test)

Example 17 with LogMetricName

use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.

the class MetricsClientTest method updateLogMetricExceptionTest.

@Test
public void updateLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
        LogMetric metric = LogMetric.newBuilder().build();
        client.updateLogMetric(metricName, metric);
        Assert.fail("No exception raised");
    } catch (InvalidArgumentException e) {
    // Expected exception.
    }
}
Also used : InvalidArgumentException(com.google.api.gax.rpc.InvalidArgumentException) LogMetric(com.google.logging.v2.LogMetric) LogMetricName(com.google.logging.v2.LogMetricName) StatusRuntimeException(io.grpc.StatusRuntimeException) Test(org.junit.Test)

Aggregations

LogMetricName (com.google.logging.v2.LogMetricName)15 Test (org.junit.Test)12 LogMetric (com.google.logging.v2.LogMetric)8 InvalidArgumentException (com.google.api.gax.rpc.InvalidArgumentException)6 AbstractMessage (com.google.protobuf.AbstractMessage)6 StatusRuntimeException (io.grpc.StatusRuntimeException)6 DeleteLogMetricRequest (com.google.logging.v2.DeleteLogMetricRequest)4 MetricsClient (com.google.cloud.logging.v2.MetricsClient)3 GetLogMetricRequest (com.google.logging.v2.GetLogMetricRequest)2 UpdateLogMetricRequest (com.google.logging.v2.UpdateLogMetricRequest)2 Empty (com.google.protobuf.Empty)2