mirror of https://github.com/apache/jclouds.git
Follow up to f06d273
that addresses pull request comments.
* Adds region to the listMetrics and getMetricStatisticsV2 * Fixed hashCode implementations * Fixed typo in Datapoint.equals()
This commit is contained in:
parent
f06d273764
commit
13d80f7d3a
|
@ -36,18 +36,19 @@ public class CloudWatch {
|
||||||
* List metrics based on the criteria in the {@link ListMetricsOptions} passed in.
|
* List metrics based on the criteria in the {@link ListMetricsOptions} passed in.
|
||||||
*
|
*
|
||||||
* @param cloudWatchClient the CloudWatch client
|
* @param cloudWatchClient the CloudWatch client
|
||||||
|
* @param region the region to list metrics in
|
||||||
* @param options the options describing the ListMetrics request
|
* @param options the options describing the ListMetrics request
|
||||||
*
|
*
|
||||||
* @return iterable of metrics fitting the criteria
|
* @return iterable of metrics fitting the criteria
|
||||||
*/
|
*/
|
||||||
public static Iterable<Metric> listMetrics(final CloudWatchClient cloudWatchClient,
|
public static Iterable<Metric> listMetrics(final CloudWatchClient cloudWatchClient,
|
||||||
final ListMetricsOptions options) {
|
final String region, final ListMetricsOptions options) {
|
||||||
return new Iterable<Metric>() {
|
return new Iterable<Metric>() {
|
||||||
public Iterator<Metric> iterator() {
|
public Iterator<Metric> iterator() {
|
||||||
return new AbstractIterator<Metric>() {
|
return new AbstractIterator<Metric>() {
|
||||||
|
|
||||||
private ListMetricsOptions lastOptions = options;
|
private ListMetricsOptions lastOptions = options;
|
||||||
private ListMetricsResponse response = cloudWatchClient.listMetrics(lastOptions);
|
private ListMetricsResponse response = cloudWatchClient.listMetrics(region, lastOptions);
|
||||||
private Iterator<Metric> iterator = response.getMetrics().iterator();
|
private Iterator<Metric> iterator = response.getMetrics().iterator();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -63,7 +64,7 @@ public class CloudWatch {
|
||||||
.namespace(lastOptions.getNamespace())
|
.namespace(lastOptions.getNamespace())
|
||||||
.nextToken(response.getNextToken())
|
.nextToken(response.getNextToken())
|
||||||
.build();
|
.build();
|
||||||
response = cloudWatchClient.listMetrics(lastOptions);
|
response = cloudWatchClient.listMetrics(region, lastOptions);
|
||||||
iterator = response.getMetrics().iterator();
|
iterator = response.getMetrics().iterator();
|
||||||
}
|
}
|
||||||
if (iterator.hasNext()) {
|
if (iterator.hasNext()) {
|
||||||
|
|
|
@ -79,21 +79,25 @@ public interface CloudWatchAsyncClient {
|
||||||
GetMetricStatisticsOptions... options);
|
GetMetricStatisticsOptions... options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CloudWatchClient#listMetrics(org.jclouds.cloudwatch.options.ListMetricsOptions)
|
* @see CloudWatchClient#listMetrics(String, org.jclouds.cloudwatch.options.ListMetricsOptions)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(ListMetricsResponseHandler.class)
|
@XMLResponseParser(ListMetricsResponseHandler.class)
|
||||||
@FormParams(keys = "Action", values = "ListMetrics")
|
@FormParams(keys = "Action", values = "ListMetrics")
|
||||||
ListenableFuture<? extends ListMetricsResponse> listMetrics(ListMetricsOptions options);
|
ListenableFuture<? extends ListMetricsResponse> listMetrics(
|
||||||
|
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||||
|
ListMetricsOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see CloudWatchClient#getMetricStatistics(org.jclouds.cloudwatch.options.GetMetricStatisticsOptionsV2)
|
* @see CloudWatchClient#getMetricStatistics(String, org.jclouds.cloudwatch.options.GetMetricStatisticsOptionsV2)
|
||||||
*/
|
*/
|
||||||
@POST
|
@POST
|
||||||
@Path("/")
|
@Path("/")
|
||||||
@XMLResponseParser(GetMetricStatisticsResponseHandlerV2.class)
|
@XMLResponseParser(GetMetricStatisticsResponseHandlerV2.class)
|
||||||
@FormParams(keys = "Action", values = "GetMetricStatistics")
|
@FormParams(keys = "Action", values = "GetMetricStatistics")
|
||||||
ListenableFuture<? extends GetMetricStatisticsResponse> getMetricStatistics(GetMetricStatisticsOptionsV2 options);
|
ListenableFuture<? extends GetMetricStatisticsResponse> getMetricStatistics(
|
||||||
|
@EndpointParam(parser = RegionToEndpointOrProviderIfNull.class) @Nullable String region,
|
||||||
|
GetMetricStatisticsOptionsV2 options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,21 +92,23 @@ public interface CloudWatchClient {
|
||||||
* <h3>Note</h3> Up to 500 results are returned for any one call. To retrieve further results, use returned
|
* <h3>Note</h3> Up to 500 results are returned for any one call. To retrieve further results, use returned
|
||||||
* NextToken ({@link org.jclouds.cloudwatch.domain.ListMetricsResponse#getNextToken()})
|
* NextToken ({@link org.jclouds.cloudwatch.domain.ListMetricsResponse#getNextToken()})
|
||||||
* value with subsequent calls .To retrieve all available metrics with one call, use
|
* value with subsequent calls .To retrieve all available metrics with one call, use
|
||||||
* {@link CloudWatch#listMetrics(CloudWatchClient, org.jclouds.cloudwatch.options.ListMetricsOptions)}.
|
* {@link CloudWatch#listMetrics(CloudWatchClient, String, org.jclouds.cloudwatch.options.ListMetricsOptions)}.
|
||||||
*
|
*
|
||||||
|
* @param region the region to query metrics in
|
||||||
* @param options the options describing the metrics query
|
* @param options the options describing the metrics query
|
||||||
*
|
*
|
||||||
* @return the response object
|
* @return the response object
|
||||||
*/
|
*/
|
||||||
ListMetricsResponse listMetrics(ListMetricsOptions options);
|
ListMetricsResponse listMetrics(@Nullable String region, ListMetricsOptions options);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets statistics for the specified metric.
|
* Gets statistics for the specified metric.
|
||||||
*
|
*
|
||||||
|
* @param region the region to gather metrics in
|
||||||
* @param options the options describing the metric statistics query
|
* @param options the options describing the metric statistics query
|
||||||
*
|
*
|
||||||
* @return the response object
|
* @return the response object
|
||||||
*/
|
*/
|
||||||
GetMetricStatisticsResponse getMetricStatistics(GetMetricStatisticsOptionsV2 options);
|
GetMetricStatisticsResponse getMetricStatistics(@Nullable String region, GetMetricStatisticsOptionsV2 options);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ public class Datapoint {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(super.hashCode(), average, customUnit, maximum, minimum, samples, sum, timestamp, unit);
|
return Objects.hashCode(average, customUnit, maximum, minimum, samples, sum, timestamp, unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -132,7 +132,7 @@ public class Datapoint {
|
||||||
return false;
|
return false;
|
||||||
Datapoint other = (Datapoint) obj;
|
Datapoint other = (Datapoint) obj;
|
||||||
return Objects.equal(this.average, other.average) &&
|
return Objects.equal(this.average, other.average) &&
|
||||||
Objects.equal(this.customUnit, other.maximum) &&
|
Objects.equal(this.customUnit, other.customUnit) &&
|
||||||
Objects.equal(this.maximum, other.maximum) &&
|
Objects.equal(this.maximum, other.maximum) &&
|
||||||
Objects.equal(this.minimum, other.minimum) &&
|
Objects.equal(this.minimum, other.minimum) &&
|
||||||
Objects.equal(this.samples, other.samples) &&
|
Objects.equal(this.samples, other.samples) &&
|
||||||
|
|
|
@ -54,7 +54,7 @@ public class Dimension {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(super.hashCode(), name, value);
|
return Objects.hashCode(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -62,7 +62,7 @@ public class GetMetricStatisticsResponse {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(super.hashCode(), datapoints, label);
|
return Objects.hashCode(datapoints, label);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -64,7 +64,7 @@ public class ListMetricsResponse {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(super.hashCode(), metrics, nextToken);
|
return Objects.hashCode(metrics, nextToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class Metric {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(super.hashCode(), dimensions, metricName, namespace);
|
return Objects.hashCode(dimensions, metricName, namespace);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -69,7 +69,7 @@ import static org.testng.Assert.assertEquals;
|
||||||
public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsyncClient> {
|
public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsyncClient> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that {@link CloudWatchAsyncClient#getMetricStatistics(org.jclouds.cloudwatch.options.GetMetricStatisticsOptionsV2)}
|
* Tests that {@link CloudWatchAsyncClient#getMetricStatistics(String, org.jclouds.cloudwatch.options.GetMetricStatisticsOptionsV2)}
|
||||||
* works as expected.
|
* works as expected.
|
||||||
*
|
*
|
||||||
* @throws Exception if anything goes wrong
|
* @throws Exception if anything goes wrong
|
||||||
|
@ -97,8 +97,9 @@ public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsy
|
||||||
.statistic(statistic1)
|
.statistic(statistic1)
|
||||||
.statistic(statistic2)
|
.statistic(statistic2)
|
||||||
.unit(unit).build();
|
.unit(unit).build();
|
||||||
Method method = CloudWatchAsyncClient.class.getMethod("getMetricStatistics", GetMetricStatisticsOptionsV2.class);
|
Method method = CloudWatchAsyncClient.class.getMethod("getMetricStatistics", String.class,
|
||||||
HttpRequest request = processor.createRequest(method, goodOptions);
|
GetMetricStatisticsOptionsV2.class);
|
||||||
|
HttpRequest request = processor.createRequest(method, null, goodOptions);
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
||||||
|
@ -122,17 +123,17 @@ public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsy
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that {@link CloudWatchAsyncClient#listMetrics(org.jclouds.cloudwatch.options.ListMetricsOptions)} works
|
* Tests that {@link CloudWatchAsyncClient#listMetrics(String, org.jclouds.cloudwatch.options.ListMetricsOptions)} works
|
||||||
* as expected.
|
* as expected.
|
||||||
*
|
*
|
||||||
* @throws Exception if anything goes wrong
|
* @throws Exception if anything goes wrong
|
||||||
*/
|
*/
|
||||||
public void testListMetrics() throws Exception {
|
public void testListMetrics() throws Exception {
|
||||||
Method method = CloudWatchAsyncClient.class.getMethod("listMetrics", ListMetricsOptions.class);
|
Method method = CloudWatchAsyncClient.class.getMethod("listMetrics", String.class, ListMetricsOptions.class);
|
||||||
HttpRequest request;
|
HttpRequest request;
|
||||||
|
|
||||||
// Test an empty request
|
// Test an empty request
|
||||||
request = processor.createRequest(method, ListMetricsOptions.builder().build());
|
request = processor.createRequest(method, null, ListMetricsOptions.builder().build());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
||||||
|
@ -147,12 +148,12 @@ public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsy
|
||||||
String metricName = EC2Constants.MetricName.CPU_UTILIZATION;
|
String metricName = EC2Constants.MetricName.CPU_UTILIZATION;
|
||||||
String nextToken = "SOMENEXTTOKEN";
|
String nextToken = "SOMENEXTTOKEN";
|
||||||
String namespace = Namespaces.EC2;
|
String namespace = Namespaces.EC2;
|
||||||
request = processor.createRequest(method, ListMetricsOptions.builder()
|
request = processor.createRequest(method, null, ListMetricsOptions.builder()
|
||||||
.dimension(dimension1)
|
.dimension(dimension1)
|
||||||
.metricName(metricName)
|
.metricName(metricName)
|
||||||
.namespace(namespace)
|
.namespace(namespace)
|
||||||
.nextToken(nextToken)
|
.nextToken(nextToken)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
||||||
|
@ -167,12 +168,12 @@ public class CloudWatchAsyncClientTest extends BaseAsyncClientTest<CloudWatchAsy
|
||||||
|
|
||||||
// Test a request with multiple dimensions and no NextToken
|
// Test a request with multiple dimensions and no NextToken
|
||||||
Dimension dimension2 = new Dimension(EC2Constants.Dimension.INSTANCE_TYPE, "t1.micro");
|
Dimension dimension2 = new Dimension(EC2Constants.Dimension.INSTANCE_TYPE, "t1.micro");
|
||||||
request = processor.createRequest(method, ListMetricsOptions.builder()
|
request = processor.createRequest(method, null, ListMetricsOptions.builder()
|
||||||
.dimension(dimension1)
|
.dimension(dimension1)
|
||||||
.dimension(dimension2)
|
.dimension(dimension2)
|
||||||
.metricName(metricName)
|
.metricName(metricName)
|
||||||
.namespace(namespace)
|
.namespace(namespace)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
assertRequestLineEquals(request, "POST https://monitoring.us-east-1.amazonaws.com/ HTTP/1.1");
|
||||||
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
assertNonPayloadHeadersEqual(request, "Host: monitoring.us-east-1.amazonaws.com\n");
|
||||||
|
|
|
@ -66,7 +66,7 @@ public class CloudWatchClientLiveTest extends BaseContextLiveTest<RestContext<Cl
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
protected void testGetMetricStatisticsV2() {
|
protected void testGetMetricStatisticsV2() {
|
||||||
ListMetricsResponse metricsResponse = client.listMetrics(ListMetricsOptions.builder().build());
|
ListMetricsResponse metricsResponse = client.listMetrics(null, ListMetricsOptions.builder().build());
|
||||||
|
|
||||||
// Walk through all datapoints in all metrics until we find a metric datapoint that returns statistics
|
// Walk through all datapoints in all metrics until we find a metric datapoint that returns statistics
|
||||||
if (metricsResponse.getMetrics().size() > 0) {
|
if (metricsResponse.getMetrics().size() > 0) {
|
||||||
|
@ -91,7 +91,7 @@ public class CloudWatchClientLiveTest extends BaseContextLiveTest<RestContext<Cl
|
||||||
.statistics(ImmutableSet.of(Statistics.MAXIMUM,
|
.statistics(ImmutableSet.of(Statistics.MAXIMUM,
|
||||||
Statistics.MINIMUM))
|
Statistics.MINIMUM))
|
||||||
.unit(Unit.PERCENT).build();
|
.unit(Unit.PERCENT).build();
|
||||||
GetMetricStatisticsResponse response = client.getMetricStatistics(options);
|
GetMetricStatisticsResponse response = client.getMetricStatistics(null, options);
|
||||||
|
|
||||||
if (response.getDatapoints().size() > 0) {
|
if (response.getDatapoints().size() > 0) {
|
||||||
checkNotNull(response.getLabel());
|
checkNotNull(response.getLabel());
|
||||||
|
@ -123,7 +123,7 @@ public class CloudWatchClientLiveTest extends BaseContextLiveTest<RestContext<Cl
|
||||||
String testDimensionValue = "t1.micro";
|
String testDimensionValue = "t1.micro";
|
||||||
|
|
||||||
// Test an empty request (pulls all stored metric options across all products)
|
// Test an empty request (pulls all stored metric options across all products)
|
||||||
response = client.listMetrics(ListMetricsOptions.builder().build());
|
response = client.listMetrics(null, ListMetricsOptions.builder().build());
|
||||||
|
|
||||||
performDefaultMetricsTests(response);
|
performDefaultMetricsTests(response);
|
||||||
|
|
||||||
|
@ -157,12 +157,12 @@ public class CloudWatchClientLiveTest extends BaseContextLiveTest<RestContext<Cl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test with a NextToken, even if it's null
|
// Test with a NextToken, even if it's null
|
||||||
response = client.listMetrics(ListMetricsOptions.builder().nextToken(response.getNextToken()).build());
|
response = client.listMetrics(null, ListMetricsOptions.builder().nextToken(response.getNextToken()).build());
|
||||||
|
|
||||||
performDefaultMetricsTests(response);
|
performDefaultMetricsTests(response);
|
||||||
|
|
||||||
// Test with a Namespace
|
// Test with a Namespace
|
||||||
response = client.listMetrics(ListMetricsOptions.builder().namespace(testNamespace).build());
|
response = client.listMetrics(null, ListMetricsOptions.builder().namespace(testNamespace).build());
|
||||||
|
|
||||||
performDefaultMetricsTests(response);
|
performDefaultMetricsTests(response);
|
||||||
|
|
||||||
|
@ -172,7 +172,7 @@ public class CloudWatchClientLiveTest extends BaseContextLiveTest<RestContext<Cl
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test with a MetricName
|
// Test with a MetricName
|
||||||
response = client.listMetrics(ListMetricsOptions.builder().metricName(testMetricName).build());
|
response = client.listMetrics(null, ListMetricsOptions.builder().metricName(testMetricName).build());
|
||||||
|
|
||||||
performDefaultMetricsTests(response);
|
performDefaultMetricsTests(response);
|
||||||
|
|
||||||
|
@ -185,8 +185,7 @@ public class CloudWatchClientLiveTest extends BaseContextLiveTest<RestContext<Cl
|
||||||
if (testDimensionName != null) {
|
if (testDimensionName != null) {
|
||||||
Dimension testDimension = new Dimension(testDimensionName, testDimensionValue);
|
Dimension testDimension = new Dimension(testDimensionName, testDimensionValue);
|
||||||
|
|
||||||
response = client.listMetrics(ListMetricsOptions.builder()
|
response = client.listMetrics(null, ListMetricsOptions.builder().dimension(testDimension).build());
|
||||||
.dimension(testDimension).build());
|
|
||||||
|
|
||||||
performDefaultMetricsTests(response);
|
performDefaultMetricsTests(response);
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ public class CloudWatchLiveTest extends BaseContextLiveTest<RestContext<CloudWat
|
||||||
@Test
|
@Test
|
||||||
protected void testCloudWatchListMetrics() {
|
protected void testCloudWatchListMetrics() {
|
||||||
// Just make sure there is at least one metric returned (Much better if the account you use has more than 500)
|
// Just make sure there is at least one metric returned (Much better if the account you use has more than 500)
|
||||||
checkArgument(CloudWatch.listMetrics(client, ListMetricsOptions.builder().build()).iterator().hasNext());
|
checkArgument(CloudWatch.listMetrics(client, null, ListMetricsOptions.builder().build()).iterator().hasNext());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,8 +39,8 @@ import static org.easymock.EasyMock.expect;
|
||||||
public class CloudWatchTest {
|
public class CloudWatchTest {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link CloudWatch#listMetrics(CloudWatchClient, org.jclouds.cloudwatch.options.ListMetricsOptions)} where a
|
* Tests {@link CloudWatch#listMetrics(CloudWatchClient, String, org.jclouds.cloudwatch.options.ListMetricsOptions)}
|
||||||
* single response returns all results.
|
* where a single response returns all results.
|
||||||
*
|
*
|
||||||
* @throws Exception if anything goes wrong
|
* @throws Exception if anything goes wrong
|
||||||
*/
|
*/
|
||||||
|
@ -50,18 +50,18 @@ public class CloudWatchTest {
|
||||||
ListMetricsOptions options = ListMetricsOptions.builder().build();
|
ListMetricsOptions options = ListMetricsOptions.builder().build();
|
||||||
ListMetricsResponse response = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), null);
|
ListMetricsResponse response = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), null);
|
||||||
|
|
||||||
expect(client.listMetrics(options))
|
expect(client.listMetrics(null, options))
|
||||||
.andReturn(response)
|
.andReturn(response)
|
||||||
.once();
|
.once();
|
||||||
|
|
||||||
EasyMock.replay(client);
|
EasyMock.replay(client);
|
||||||
|
|
||||||
Assert.assertEquals(1, Iterables.size(CloudWatch.listMetrics(client, options)));
|
Assert.assertEquals(1, Iterables.size(CloudWatch.listMetrics(client, null, options)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests {@link CloudWatch#listMetrics(CloudWatchClient, org.jclouds.cloudwatch.options.ListMetricsOptions)} where
|
* Tests {@link CloudWatch#listMetrics(CloudWatchClient, String, org.jclouds.cloudwatch.options.ListMetricsOptions)}
|
||||||
* retrieving all results requires multiple requests.
|
* where retrieving all results requires multiple requests.
|
||||||
*
|
*
|
||||||
* @throws Exception if anything goes wrong
|
* @throws Exception if anything goes wrong
|
||||||
*/
|
*/
|
||||||
|
@ -72,16 +72,17 @@ public class CloudWatchTest {
|
||||||
ListMetricsResponse response1 = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), "NEXTTOKEN");
|
ListMetricsResponse response1 = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), "NEXTTOKEN");
|
||||||
ListMetricsResponse response2 = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), null);
|
ListMetricsResponse response2 = new ListMetricsResponse(ImmutableSet.of(createMock(Metric.class)), null);
|
||||||
|
|
||||||
expect(client.listMetrics(anyObject(ListMetricsOptions.class)))
|
// Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here
|
||||||
|
expect(client.listMetrics(EasyMock.eq(""), anyObject(ListMetricsOptions.class)))
|
||||||
.andReturn(response1)
|
.andReturn(response1)
|
||||||
.once();
|
.once();
|
||||||
expect(client.listMetrics(anyObject(ListMetricsOptions.class)))
|
expect(client.listMetrics(EasyMock.eq(""), anyObject(ListMetricsOptions.class)))
|
||||||
.andReturn(response2)
|
.andReturn(response2)
|
||||||
.once();
|
.once();
|
||||||
|
|
||||||
EasyMock.replay(client);
|
EasyMock.replay(client);
|
||||||
|
|
||||||
Assert.assertEquals(2, Iterables.size(CloudWatch.listMetrics(client, options)));
|
Assert.assertEquals(2, Iterables.size(CloudWatch.listMetrics(client, "", options)));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue