use of com.google.logging.v2.LogMetricName in project gapic-generator-java by googleapis.
the class SyncGetLogMetricLogmetricname method syncGetLogMetricLogmetricname.
public static void syncGetLogMetricLogmetricname() throws Exception {
// It may require modifications to work in your environment.
try (MetricsClient metricsClient = MetricsClient.create()) {
LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
LogMetric response = metricsClient.getLogMetric(metricName);
}
}
use of com.google.logging.v2.LogMetricName in project java-logging by googleapis.
the class MetricsClientTest method getLogMetricExceptionTest.
@Test
public void getLogMetricExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(io.grpc.Status.INVALID_ARGUMENT);
mockMetricsServiceV2.addException(exception);
try {
LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
client.getLogMetric(metricName);
Assert.fail("No exception raised");
} catch (InvalidArgumentException e) {
// Expected exception.
}
}
use of com.google.logging.v2.LogMetricName in project java-logging 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.
}
}
use of com.google.logging.v2.LogMetricName in project java-logging by googleapis.
the class MetricsClientTest method updateLogMetricTest.
@Test
public void updateLogMetricTest() throws Exception {
LogMetric expectedResponse = LogMetric.newBuilder().setName(LogMetricName.of("[PROJECT]", "[METRIC]").toString()).setDescription("description-1724546052").setFilter("filter-1274492040").setDisabled(true).setMetricDescriptor(MetricDescriptor.newBuilder().build()).setValueExtractor("valueExtractor-1867420749").putAllLabelExtractors(new HashMap<String, String>()).setBucketOptions(Distribution.BucketOptions.newBuilder().build()).setCreateTime(Timestamp.newBuilder().build()).setUpdateTime(Timestamp.newBuilder().build()).build();
mockMetricsServiceV2.addResponse(expectedResponse);
LogMetricName metricName = LogMetricName.of("[PROJECT]", "[METRIC]");
LogMetric metric = LogMetric.newBuilder().build();
LogMetric actualResponse = client.updateLogMetric(metricName, metric);
Assert.assertEquals(expectedResponse, actualResponse);
List<AbstractMessage> actualRequests = mockMetricsServiceV2.getRequests();
Assert.assertEquals(1, actualRequests.size());
UpdateLogMetricRequest actualRequest = ((UpdateLogMetricRequest) actualRequests.get(0));
Assert.assertEquals(metricName.toString(), actualRequest.getMetricName());
Assert.assertEquals(metric, actualRequest.getMetric());
Assert.assertTrue(channelProvider.isHeaderSent(ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern()));
}
use of com.google.logging.v2.LogMetricName in project java-logging 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()));
}
Aggregations