Search in sources :

Example 6 with LogMetric

use of com.google.logging.v2.LogMetric 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)

Example 7 with LogMetric

use of com.google.logging.v2.LogMetric in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method listLogMetricsTest.

@Test
@SuppressWarnings("all")
public void listLogMetricsTest() {
    String nextPageToken = "";
    LogMetric metricsElement = LogMetric.newBuilder().build();
    List<LogMetric> metrics = Arrays.asList(metricsElement);
    ListLogMetricsResponse expectedResponse = ListLogMetricsResponse.newBuilder().setNextPageToken(nextPageToken).addAllMetrics(metrics).build();
    mockMetricsServiceV2.addResponse(expectedResponse);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
    ListLogMetricsPagedResponse pagedListResponse = client.listLogMetrics(parent);
    List<LogMetric> resources = Lists.newArrayList(pagedListResponse.iterateAll());
    Assert.assertEquals(1, resources.size());
    Assert.assertEquals(expectedResponse.getMetricsList().get(0), resources.get(0));
    List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    ListLogMetricsRequest actualRequest = (ListLogMetricsRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
}
Also used : LogMetric(com.google.logging.v2.LogMetric) ListLogMetricsResponse(com.google.logging.v2.ListLogMetricsResponse) ListLogMetricsPagedResponse(com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse) ParentNameOneof(com.google.logging.v2.ParentNameOneof) ListLogMetricsRequest(com.google.logging.v2.ListLogMetricsRequest) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 8 with LogMetric

use of com.google.logging.v2.LogMetric in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method createLogMetricTest.

@Test
@SuppressWarnings("all")
public void createLogMetricTest() {
    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);
    ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
    LogMetric metric = LogMetric.newBuilder().build();
    LogMetric actualResponse = client.createLogMetric(parent, metric);
    Assert.assertEquals(expectedResponse, actualResponse);
    List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests();
    Assert.assertEquals(1, actualRequests.size());
    CreateLogMetricRequest actualRequest = (CreateLogMetricRequest) actualRequests.get(0);
    Assert.assertEquals(parent, actualRequest.getParentAsParentNameOneof());
    Assert.assertEquals(metric, actualRequest.getMetric());
}
Also used : LogMetric(com.google.logging.v2.LogMetric) CreateLogMetricRequest(com.google.logging.v2.CreateLogMetricRequest) ParentNameOneof(com.google.logging.v2.ParentNameOneof) GeneratedMessageV3(com.google.protobuf.GeneratedMessageV3) Test(org.junit.Test)

Example 9 with LogMetric

use of com.google.logging.v2.LogMetric in project google-cloud-java by GoogleCloudPlatform.

the class MetricsClientTest method createLogMetricExceptionTest.

@Test
@SuppressWarnings("all")
public void createLogMetricExceptionTest() throws Exception {
    StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
    mockMetricsServiceV2.addException(exception);
    try {
        ParentNameOneof parent = ParentNameOneof.from(ProjectName.create("[PROJECT]"));
        LogMetric metric = LogMetric.newBuilder().build();
        client.createLogMetric(parent, 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) ParentNameOneof(com.google.logging.v2.ParentNameOneof) StatusRuntimeException(io.grpc.StatusRuntimeException) ApiException(com.google.api.gax.grpc.ApiException) Test(org.junit.Test)

Example 10 with LogMetric

use of com.google.logging.v2.LogMetric in project google-cloud-java by GoogleCloudPlatform.

the class LoggingImplTest method testGetMetricAsync.

@Test
public void testGetMetricAsync() throws ExecutionException, InterruptedException {
    LogMetric sinkPb = METRIC_INFO.toPb();
    ApiFuture<LogMetric> response = ApiFutures.immediateFuture(sinkPb);
    GetLogMetricRequest request = GetLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).build();
    EasyMock.expect(loggingRpcMock.get(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Metric sink = logging.getMetricAsync(METRIC_NAME).get();
    assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), sink);
}
Also used : LogMetric(com.google.logging.v2.LogMetric) GetLogMetricRequest(com.google.logging.v2.GetLogMetricRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Aggregations

LogMetric (com.google.logging.v2.LogMetric)14 Test (org.junit.Test)14 GetLogMetricRequest (com.google.logging.v2.GetLogMetricRequest)5 GeneratedMessageV3 (com.google.protobuf.GeneratedMessageV3)4 CreateLogMetricRequest (com.google.logging.v2.CreateLogMetricRequest)3 MetricNameOneof (com.google.logging.v2.MetricNameOneof)3 ParentNameOneof (com.google.logging.v2.ParentNameOneof)3 UpdateLogMetricRequest (com.google.logging.v2.UpdateLogMetricRequest)3 ApiException (com.google.api.gax.grpc.ApiException)2 StatusRuntimeException (io.grpc.StatusRuntimeException)2 ListLogMetricsPagedResponse (com.google.cloud.logging.spi.v2.PagedResponseWrappers.ListLogMetricsPagedResponse)1 ListLogMetricsRequest (com.google.logging.v2.ListLogMetricsRequest)1 ListLogMetricsResponse (com.google.logging.v2.ListLogMetricsResponse)1