mirror of https://github.com/apache/jclouds.git
fixed CloudWatch.putMetricData
This commit is contained in:
parent
884e0d867e
commit
84de4b30db
|
@ -18,16 +18,17 @@
|
|||
*/
|
||||
package org.jclouds.cloudwatch;
|
||||
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.google.common.collect.Sets;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.jclouds.cloudwatch.domain.ListMetricsResponse;
|
||||
import org.jclouds.cloudwatch.domain.Metric;
|
||||
import org.jclouds.cloudwatch.domain.MetricDatum;
|
||||
import org.jclouds.cloudwatch.features.MetricClient;
|
||||
import org.jclouds.cloudwatch.options.ListMetricsOptions;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import com.google.common.collect.AbstractIterator;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Utilities for using CloudWatch.
|
||||
|
@ -109,20 +110,9 @@ public class CloudWatch {
|
|||
public static void putMetricData(CloudWatchClient cloudWatchClient, String region, Iterable<MetricDatum> metrics,
|
||||
String namespace) {
|
||||
MetricClient metricClient = cloudWatchClient.getMetricClientForRegion(region);
|
||||
Iterator<MetricDatum> mIterator = metrics.iterator();
|
||||
Set<MetricDatum> metricsData = Sets.newLinkedHashSet();
|
||||
|
||||
while (mIterator.hasNext()) {
|
||||
metricsData.add(mIterator.next());
|
||||
if (metricsData.size() == 10 || !mIterator.hasNext()) {
|
||||
// Make the call
|
||||
metricClient.putMetricData(metrics, namespace);
|
||||
|
||||
// Reset the list for subsequent call if necessary
|
||||
if (mIterator.hasNext()) {
|
||||
metricsData = Sets.newLinkedHashSet();
|
||||
}
|
||||
}
|
||||
for (List<MetricDatum> slice : Iterables.partition(metrics, 10)) {
|
||||
metricClient.putMetricData(slice, namespace);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -18,9 +18,13 @@
|
|||
*/
|
||||
package org.jclouds.cloudwatch;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
import static org.easymock.EasyMock.anyObject;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.easymock.EasyMock;
|
||||
import org.jclouds.cloudwatch.domain.ListMetricsResponse;
|
||||
import org.jclouds.cloudwatch.domain.Metric;
|
||||
|
@ -30,18 +34,16 @@ import org.jclouds.cloudwatch.options.ListMetricsOptions;
|
|||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.easymock.EasyMock.anyObject;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code CloudWatch}.
|
||||
*
|
||||
* @author Jeremy Whitlock
|
||||
*/
|
||||
@Test(testName = "CloudWatchTest")
|
||||
public class CloudWatchTest {
|
||||
|
||||
/**
|
||||
|
@ -115,7 +117,7 @@ public class CloudWatchTest {
|
|||
String namespace = "JCLOUDS/Test";
|
||||
|
||||
for (int i = 0; i < 11; i++) {
|
||||
metrics.add(MetricDatum.builder().build());
|
||||
metrics.add(MetricDatum.builder().metricName("foo").build());
|
||||
}
|
||||
|
||||
// Using EasyMock.eq("") because EasyMock makes it impossible to pass null as a String value here
|
||||
|
@ -123,10 +125,9 @@ public class CloudWatchTest {
|
|||
.andReturn(metricClient)
|
||||
.atLeastOnce();
|
||||
|
||||
|
||||
metricClient.putMetricData(metrics, namespace);
|
||||
|
||||
expectLastCall().times(2);
|
||||
for (List<MetricDatum> slice : Iterables.partition(metrics, 10)) {
|
||||
metricClient.putMetricData(slice, namespace);
|
||||
}
|
||||
|
||||
EasyMock.replay(client, metricClient);
|
||||
|
||||
|
|
Loading…
Reference in New Issue