Set<MetricDatum> metrics = Sets.newLinkedHashSet();
for (int i = 0; i < 11; i++) {
metrics.add(MetricDatum.builder()
.metricName(metricName + "_" + i)
.dimension(new Dimension("BaseMetricName", metricName))
.unit(Unit.COUNT)
.timestamp(metricTimestamp)
.value((double) i)
.build());
}
CloudWatch.putMetricData(api, null, metrics, namespace);
ListMetricsOptions lmo = ListMetricsOptions.Builder.namespace(namespace)
.dimension(new Dimension("BaseMetricName", metricName));
boolean success = retry(new Predicate<ListMetricsOptions>() {
public boolean apply(ListMetricsOptions options) {
return Iterables.size(CloudWatch.listMetrics(api, null, options)) == 11;
}
}, 20, 1, MINUTES).apply(lmo);