@Override public LogMetric apply(MetricInfo metricInfo) { return metricInfo.toPb(); } };
@Override public ApiFuture<Metric> createAsync(MetricInfo metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() .setParent(ProjectName.of(getOptions().getProjectId()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.create(request), Metric.fromPbFunction(this)); }
@Test public void testGetMetric() { 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.getMetric(METRIC_NAME); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), sink); }
@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 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); }
@Test public void testCreateMetric() { 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.create(METRIC_INFO); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), metric); }
@Test public void testUpdateMetric() { LogMetric sinkPb = METRIC_INFO.toPb(); ApiFuture<LogMetric> response = ApiFutures.immediateFuture(sinkPb); UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).setMetric(sinkPb).build(); EasyMock.expect(loggingRpcMock.update(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Metric sink = logging.update(METRIC_INFO); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), sink); }
@Test public void testUpdateMetricAsync() throws ExecutionException, InterruptedException { LogMetric sinkPb = METRIC_INFO.toPb(); ApiFuture<LogMetric> response = ApiFutures.immediateFuture(sinkPb); UpdateLogMetricRequest request = UpdateLogMetricRequest.newBuilder().setMetricName(METRIC_NAME_PB).setMetric(sinkPb).build(); EasyMock.expect(loggingRpcMock.update(request)).andReturn(response); EasyMock.replay(rpcFactoryMock, loggingRpcMock); logging = options.getService(); Metric sink = logging.updateAsync(METRIC_INFO).get(); assertEquals(new Metric(logging, new MetricInfo.BuilderImpl(METRIC_INFO)), sink); }
@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); }
@Override public ApiFuture<Metric> createAsync(MetricInfo metric) { CreateLogMetricRequest request = CreateLogMetricRequest.newBuilder() .setParent(ProjectName.of(getOptions().getProjectId()).toString()) .setMetric(metric.toPb()) .build(); return transform(rpc.create(request), Metric.fromPbFunction(this)); }
@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)); }