Search in sources :

Example 1 with LogMetric

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

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

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

the class LoggingImplTest method testCreateMetricAsync.

@Test
public void testCreateMetricAsync() throws ExecutionException, InterruptedException {
    LogMetric metricPb = METRIC_INFO.toPb();
    ApiFuture<LogMetric> response = ApiFutures.immediateFuture(metricPb);
    CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder().setParent(PROJECT_PB).setMetric(metricPb).build();
    EasyMock.expect(loggingRpcMock.create(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    Metric metric = logging.createAsync(METRIC_INFO).get();
    assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), metric);
}
Also used : LogMetric(com.google.logging.v2.LogMetric) CreateLogMetricRequest(com.google.logging.v2.CreateLogMetricRequest) LogMetric(com.google.logging.v2.LogMetric) Test(org.junit.Test)

Example 4 with LogMetric

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

the class LoggingImplTest method testGetMetricAsync_Null.

@Test
public void testGetMetricAsync_Null() throws ExecutionException, InterruptedException {
    ApiFuture<LogMetric> response = ApiFutures.immediateFuture(null);
    GetLogMetricRequest request = GetLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).build();
    EasyMock.expect(loggingRpcMock.get(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    assertNull(logging.getMetricAsync(METRIC_NAME).get());
}
Also used : LogMetric(com.google.logging.v2.LogMetric) GetLogMetricRequest(com.google.logging.v2.GetLogMetricRequest) Test(org.junit.Test)

Example 5 with LogMetric

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

the class LoggingImplTest method testGetMetric_Null.

@Test
public void testGetMetric_Null() {
    ApiFuture<LogMetric> response = ApiFutures.immediateFuture(null);
    GetLogMetricRequest request = GetLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).build();
    EasyMock.expect(loggingRpcMock.get(request)).andReturn(response);
    EasyMock.replay(rpcFactoryMock, loggingRpcMock);
    logging = options.getService();
    assertNull(logging.getMetric(METRIC_NAME));
}
Also used : LogMetric(com.google.logging.v2.LogMetric) GetLogMetricRequest(com.google.logging.v2.GetLogMetricRequest) 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