public static ProjectMetricName parse(String formattedString) { if (formattedString.isEmpty()) { return null; } Map<String, String> matchMap = PATH_TEMPLATE.validatedMatch( formattedString, "ProjectMetricName.parse: formattedString not in valid format"); return of(matchMap.get("project"), matchMap.get("metric")); }
public static String format(String project, String metric) { return newBuilder().setProject(project).setMetric(metric).build().toString(); }
public ProjectMetricName build() { return new ProjectMetricName(this); } }
public static MetricName parse(String resourceNameString) { if (ProjectMetricName.isParsableFrom(resourceNameString)) { return ProjectMetricName.parse(resourceNameString); } return UntypedMetricName.parse(resourceNameString); } }
@Override public ApiFuture<Boolean> deleteMetricAsync(String metric) { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder() .setMetricName(ProjectMetricName.of(getOptions().getProjectId(), metric).toString()) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); }
public static List<String> toStringList(List<ProjectMetricName> values) { List<String> list = new ArrayList<String>(values.size()); for (ProjectMetricName value : values) { if (value == null) { list.add(""); } else { list.add(value.toString()); } } return list; }
public String getFieldValue(String fieldName) { return getFieldValuesMap().get(fieldName); }
public static List<ProjectMetricName> parseList(List<String> formattedStrings) { List<ProjectMetricName> list = new ArrayList<>(formattedStrings.size()); for (String formattedString : formattedStrings) { list.add(parse(formattedString)); } return list; }
public static ProjectMetricName of(String project, String metric) { return newBuilder().setProject(project).setMetric(metric).build(); }
@Override public ApiFuture<Metric> updateAsync(MetricInfo metric) { UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder() .setMetricName( ProjectMetricName.of(getOptions().getProjectId(), metric.getName()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.update(request), Metric.fromPbFunction(this)); }
@Test @SuppressWarnings("all") public void getLogMetricExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockMetricsServiceV2.addException(exception); try { MetricName metricName = ProjectMetricName.of("[PROJECT]", "[METRIC]"); client.getLogMetric(metricName); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Override public ApiFuture<Boolean> deleteMetricAsync(String metric) { DeleteLogMetricRequest request = DeleteLogMetricRequest.newBuilder() .setMetricName(ProjectMetricName.of(getOptions().getProjectId(), metric).toString()) .build(); return transform(rpc.delete(request), EMPTY_TO_BOOLEAN_FUNCTION); }
@Test @SuppressWarnings("all") public void deleteLogMetricExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockMetricsServiceV2.addException(exception); try { MetricName metricName = ProjectMetricName.of("[PROJECT]", "[METRIC]"); client.deleteLogMetric(metricName); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } } }
@Test @SuppressWarnings("all") public void updateLogMetricExceptionTest() throws Exception { StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT); mockMetricsServiceV2.addException(exception); try { MetricName metricName = ProjectMetricName.of("[PROJECT]", "[METRIC]"); LogMetric metric = LogMetric.newBuilder().build(); client.updateLogMetric(metricName, metric); Assert.fail("No exception raised"); } catch (InvalidArgumentException e) { // Expected exception } }
@Override public ApiFuture<Metric> updateAsync(MetricInfo metric) { UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder() .setMetricName( ProjectMetricName.of(getOptions().getProjectId(), metric.getName()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.update(request), Metric.fromPbFunction(this)); }
@Test @SuppressWarnings("all") public void getLogMetricTest() { MetricName name = ProjectMetricName.of("[PROJECT]", "[METRIC]"); String description = "description-1724546052"; String filter = "filter-1274492040"; String valueExtractor = "valueExtractor2047672534"; LogMetric expectedResponse = LogMetric.newBuilder() .setName(name.toString()) .setDescription(description) .setFilter(filter) .setValueExtractor(valueExtractor) .build(); mockMetricsServiceV2.addResponse(expectedResponse); MetricName metricName = ProjectMetricName.of("[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, MetricNames.parse(actualRequest.getMetricName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void deleteLogMetricTest() { Empty expectedResponse = Empty.newBuilder().build(); mockMetricsServiceV2.addResponse(expectedResponse); MetricName metricName = ProjectMetricName.of("[PROJECT]", "[METRIC]"); client.deleteLogMetric(metricName); List<GeneratedMessageV3> actualRequests = mockMetricsServiceV2.getRequests(); Assert.assertEquals(1, actualRequests.size()); DeleteLogMetricRequest actualRequest = (DeleteLogMetricRequest) actualRequests.get(0); Assert.assertEquals(metricName, MetricNames.parse(actualRequest.getMetricName())); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void updateLogMetricTest() { MetricName name = ProjectMetricName.of("[PROJECT]", "[METRIC]"); String description = "description-1724546052"; String filter = "filter-1274492040"; String valueExtractor = "valueExtractor2047672534"; LogMetric expectedResponse = LogMetric.newBuilder() .setName(name.toString()) .setDescription(description) .setFilter(filter) .setValueExtractor(valueExtractor) .build(); mockMetricsServiceV2.addResponse(expectedResponse); MetricName metricName = ProjectMetricName.of("[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, MetricNames.parse(actualRequest.getMetricName())); Assert.assertEquals(metric, actualRequest.getMetric()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }