|
1 | 1 | package cloud.localstack; |
2 | 2 |
|
3 | 3 | import cloud.localstack.docker.annotation.LocalstackDockerProperties; |
| 4 | +import com.amazonaws.auth.AWSStaticCredentialsProvider; |
| 5 | +import com.amazonaws.auth.BasicAWSCredentials; |
| 6 | +import com.amazonaws.client.builder.AwsClientBuilder; |
4 | 7 | import com.amazonaws.services.cloudwatch.AmazonCloudWatch; |
| 8 | +import com.amazonaws.services.cloudwatch.AmazonCloudWatchClientBuilder; |
5 | 9 | import com.amazonaws.services.cloudwatch.model.*; |
6 | 10 | import org.junit.Assert; |
7 | 11 | import org.junit.Test; |
8 | 12 | import org.junit.runner.RunWith; |
9 | 13 |
|
10 | 14 | import java.text.ParseException; |
11 | 15 | import java.text.SimpleDateFormat; |
| 16 | +import java.util.Date; |
12 | 17 |
|
13 | 18 | /** |
14 | 19 | * Test integration of CloudWatch metrics with LocalStack |
@@ -57,4 +62,42 @@ public void testCWMetricsAPIs() throws ParseException { |
57 | 62 | ListMetricsResult metrics = cw.listMetrics(new ListMetricsRequest()); |
58 | 63 | Assert.assertEquals(metrics.getMetrics().size(), 1); |
59 | 64 | } |
| 65 | + |
| 66 | + @Test |
| 67 | + public void testCWGetMetricData() { |
| 68 | + final AmazonCloudWatch cw = TestUtils.getClientCloudWatch(); |
| 69 | + |
| 70 | + Metric metric = new Metric() |
| 71 | + .withNamespace("customNamespace") |
| 72 | + .withMetricName("MaxMemoryUsage") |
| 73 | + .withDimensions( |
| 74 | + new Dimension().withName("id").withValue("specificId"), |
| 75 | + new Dimension().withName("class").withValue("customNamespace"), |
| 76 | + new Dimension().withName("level").withValue("INFO"), |
| 77 | + new Dimension().withName("type").withValue("GAUGE")); |
| 78 | + |
| 79 | + /* List metric work */ |
| 80 | + cw.listMetrics(); |
| 81 | + |
| 82 | + String metricQueryId = "someName"; |
| 83 | + MetricDataQuery metricDataQuery = new MetricDataQuery() |
| 84 | + .withId(metricQueryId) |
| 85 | + .withLabel("someLabel") |
| 86 | + .withReturnData(true) |
| 87 | + .withMetricStat(new MetricStat().withMetric(metric) |
| 88 | + .withStat("Average") |
| 89 | + .withUnit("None") |
| 90 | + .withPeriod(5)); |
| 91 | + |
| 92 | + GetMetricDataRequest getMetricDataRequest = new GetMetricDataRequest() |
| 93 | + .withMetricDataQueries(metricDataQuery) |
| 94 | + .withStartTime(new Date(System.currentTimeMillis() - 3600 * 1000)) |
| 95 | + .withEndTime(new Date(System.currentTimeMillis())) |
| 96 | + .withMaxDatapoints(100); |
| 97 | + |
| 98 | + /* Get metricData work */ |
| 99 | + GetMetricDataResult getMetricDataResult = cw.getMetricData(getMetricDataRequest); |
| 100 | + Assert.assertEquals(getMetricDataResult.getMetricDataResults().size(), 1); |
| 101 | + Assert.assertEquals(getMetricDataResult.getMetricDataResults().get(0).getId(), metricQueryId); |
| 102 | + } |
60 | 103 | } |
0 commit comments