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());
}
}
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());
}
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());
}
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());
}
}
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);
}
Aggregations