use of com.google.monitoring.v3.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method createTimeSeriesTest.
@Test
@SuppressWarnings("all")
public void createTimeSeriesTest() {
Empty expectedResponse = Empty.newBuilder().build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
client.createTimeSeries(name, timeSeries);
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
CreateTimeSeriesRequest actualRequest = (CreateTimeSeriesRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
Assert.assertEquals(timeSeries, actualRequest.getTimeSeriesList());
}
use of com.google.monitoring.v3.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClient method createTimeSeries.
// AUTO-GENERATED DOCUMENTATION AND METHOD
/**
* Creates or adds data to one or more time series. The response is empty if all time series in
* the request were written. If any time series could not be written, a corresponding failure
* message is included in the error response.
*
* <p>Sample code:
*
* <pre><code>
* try (MetricServiceClient metricServiceClient = MetricServiceClient.create()) {
* ProjectName name = ProjectName.create("[PROJECT]");
* List<TimeSeries> timeSeries = new ArrayList<>();
* metricServiceClient.createTimeSeries(name, timeSeries);
* }
* </code></pre>
*
* @param name The project on which to execute the request. The format is
* `"projects/{project_id_or_number}"`.
* @param timeSeries The new data to be added to a list of time series. Adds at most one data
* point to each of several time series. The new data point must be more recent than any other
* point in its time series. Each `TimeSeries` value must fully specify a unique time series
* by supplying all label values for the metric and the monitored resource.
* @throws com.google.api.gax.grpc.ApiException if the remote call fails
*/
public final void createTimeSeries(ProjectName name, List<TimeSeries> timeSeries) {
CreateTimeSeriesRequest request = CreateTimeSeriesRequest.newBuilder().setNameWithProjectName(name).addAllTimeSeries(timeSeries).build();
createTimeSeries(request);
}
use of com.google.monitoring.v3.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method createTimeSeriesExceptionTest.
@Test
@SuppressWarnings("all")
public void createTimeSeriesExceptionTest() throws Exception {
StatusRuntimeException exception = new StatusRuntimeException(Status.INVALID_ARGUMENT);
mockMetricService.addException(exception);
try {
ProjectName name = ProjectName.create("[PROJECT]");
List<TimeSeries> timeSeries = new ArrayList<>();
client.createTimeSeries(name, timeSeries);
Assert.fail("No exception raised");
} catch (ApiException e) {
Assert.assertEquals(Status.INVALID_ARGUMENT.getCode(), e.getStatusCode());
}
}
use of com.google.monitoring.v3.TimeSeries in project google-cloud-java by GoogleCloudPlatform.
the class MetricServiceClientTest method listTimeSeriesTest.
@Test
@SuppressWarnings("all")
public void listTimeSeriesTest() {
String nextPageToken = "";
TimeSeries timeSeriesElement = TimeSeries.newBuilder().build();
List<TimeSeries> timeSeries = Arrays.asList(timeSeriesElement);
ListTimeSeriesResponse expectedResponse = ListTimeSeriesResponse.newBuilder().setNextPageToken(nextPageToken).addAllTimeSeries(timeSeries).build();
mockMetricService.addResponse(expectedResponse);
ProjectName name = ProjectName.create("[PROJECT]");
String filter = "filter-1274492040";
TimeInterval interval = TimeInterval.newBuilder().build();
ListTimeSeriesRequest.TimeSeriesView view = ListTimeSeriesRequest.TimeSeriesView.FULL;
ListTimeSeriesPagedResponse pagedListResponse = client.listTimeSeries(name, filter, interval, view);
List<TimeSeries> resources = Lists.newArrayList(pagedListResponse.iterateAll());
Assert.assertEquals(1, resources.size());
Assert.assertEquals(expectedResponse.getTimeSeriesList().get(0), resources.get(0));
List<GeneratedMessageV3> actualRequests = mockMetricService.getRequests();
Assert.assertEquals(1, actualRequests.size());
ListTimeSeriesRequest actualRequest = (ListTimeSeriesRequest) actualRequests.get(0);
Assert.assertEquals(name, actualRequest.getNameAsProjectName());
Assert.assertEquals(filter, actualRequest.getFilter());
Assert.assertEquals(interval, actualRequest.getInterval());
Assert.assertEquals(view, actualRequest.getView());
}
Aggregations