1515 */
1616package com .hivemq .extensions .aws .cloudwatch ;
1717
18- import com .hivemq .client .mqtt .mqtt5 .Mqtt5BlockingClient ;
1918import com .hivemq .client .mqtt .mqtt5 .Mqtt5Client ;
2019import io .github .sgtsilvio .gradle .oci .junit .jupiter .OciImages ;
2120import org .awaitility .Durations ;
2524import org .junit .jupiter .api .Test ;
2625import org .junit .jupiter .api .Timeout ;
2726import org .testcontainers .containers .Network ;
28- import org .testcontainers .containers .localstack .LocalStackContainer ;
29- import org .testcontainers .containers .localstack .LocalStackContainer .Service ;
3027import org .testcontainers .hivemq .HiveMQContainer ;
28+ import org .testcontainers .localstack .LocalStackContainer ;
3129import org .testcontainers .utility .MountableFile ;
3230import software .amazon .awssdk .auth .credentials .AwsBasicCredentials ;
3331import software .amazon .awssdk .auth .credentials .StaticCredentialsProvider ;
4240import java .time .Instant ;
4341import java .util .Collections ;
4442import java .util .List ;
45- import java .util .OptionalDouble ;
4643import java .util .concurrent .TimeUnit ;
4744
4845import static org .awaitility .Awaitility .await ;
@@ -52,18 +49,19 @@ class EndToEndIT {
5249 private final @ NotNull Network network = org .testcontainers .containers .Network .newNetwork ();
5350
5451 private final @ NotNull LocalStackContainer localStack =
55- new LocalStackContainer (OciImages .getImageName ("localstack/localstack" )).withServices (Service . CLOUDWATCH )
52+ new LocalStackContainer (OciImages .getImageName ("localstack/localstack" )).withServices ("cloudwatch" )
5653 .withNetwork (network )
5754 .withNetworkAliases ("localstack" );
5855
5956 private final @ NotNull HiveMQContainer hivemq =
6057 new HiveMQContainer (OciImages .getImageName ("hivemq/extensions/hivemq-aws-cloudwatch-extension" )
61- .asCompatibleSubstituteFor ("hivemq/hivemq4" )). withCopyToContainer ( MountableFile . forClasspathResource (
62- "extension-config.xml" ),
58+ .asCompatibleSubstituteFor ("hivemq/hivemq4" )) //
59+ . withCopyToContainer ( MountableFile . forClasspathResource ( "extension-config.xml" ),
6360 "/opt/hivemq/extensions/hivemq-aws-cloudwatch-extension/extension-config.xml" )
6461 .withEnv ("AWS_REGION" , localStack .getRegion ())
6562 .withEnv ("AWS_ACCESS_KEY_ID" , localStack .getAccessKey ())
6663 .withEnv ("AWS_SECRET_ACCESS_KEY" , localStack .getSecretKey ())
64+ .withEnv ("HIVEMQ_DISABLE_STATISTICS" , "true" )
6765 .withLogConsumer (outputFrame -> System .out .println ("HIVEMQ: " +
6866 outputFrame .getUtf8StringWithoutLineEnding ()))
6967 .withNetwork (network );
@@ -84,13 +82,13 @@ void tearDown() {
8482 @ Test
8583 @ Timeout (value = 5 , unit = TimeUnit .MINUTES )
8684 void endToEnd () {
87- final StaticCredentialsProvider credentialsProvider =
85+ final var credentialsProvider =
8886 StaticCredentialsProvider .create (AwsBasicCredentials .create (localStack .getAccessKey (),
8987 localStack .getSecretKey ()));
9088
91- final CloudWatchClient cloudWatchClient = CloudWatchClient .builder ()
89+ final var cloudWatchClient = CloudWatchClient .builder ()
9290 .credentialsProvider (credentialsProvider )
93- .endpointOverride (localStack .getEndpointOverride ( Service . CLOUDWATCH ))
91+ .endpointOverride (localStack .getEndpoint ( ))
9492 .region (Region .of (localStack .getRegion ()))
9593 .build ();
9694
@@ -100,17 +98,16 @@ void endToEnd() {
10098 .stream ()
10199 .anyMatch (metric -> "com.hivemq.messages.incoming.publish.count" .equals (metric .metricName ())));
102100
103- final Metric metric = Metric .builder ()
101+ final var metric = Metric .builder ()
104102 .namespace ("hivemq-metrics" )
105103 .metricName ("com.hivemq.messages.incoming.publish.count" )
106104 .dimensions (Collections .emptyList ())
107105 .build ();
108106
109- final MetricStat metricStat =
107+ final var metricStat =
110108 MetricStat .builder ().stat (Statistic .MAXIMUM .toString ()).period (60 ).metric (metric ).build ();
111109
112- final MetricDataQuery metricDataQuery =
113- MetricDataQuery .builder ().id ("m1" ).metricStat (metricStat ).returnData (true ).build ();
110+ final var metricDataQuery = MetricDataQuery .builder ().id ("m1" ).metricStat (metricStat ).returnData (true ).build ();
114111
115112 await ().timeout (Durations .FIVE_MINUTES ).until (() -> {
116113 final GetMetricDataRequest request = GetMetricDataRequest .builder ()
@@ -119,27 +116,27 @@ void endToEnd() {
119116 .metricDataQueries (List .of (metricDataQuery ))
120117 .build ();
121118 final var response = cloudWatchClient .getMetricData (request );
122- final OptionalDouble maxValue = response .metricDataResults ()
119+ final var maxValue = response .metricDataResults ()
123120 .stream ()
124121 .flatMap (result -> result .values ().stream ())
125122 .mapToDouble (Double ::doubleValue )
126123 .max ();
127124 return maxValue .isPresent () && maxValue .getAsDouble () == 0.0 ;
128125 });
129126
130- final Mqtt5BlockingClient mqttClient =
127+ final var mqttClient =
131128 Mqtt5Client .builder ().serverHost (hivemq .getHost ()).serverPort (hivemq .getMqttPort ()).buildBlocking ();
132129 mqttClient .connect ();
133130 mqttClient .publishWith ().topic ("wabern" ).send ();
134131
135132 await ().timeout (Durations .FIVE_MINUTES ).until (() -> {
136- final GetMetricDataRequest request = GetMetricDataRequest .builder ()
133+ final var request = GetMetricDataRequest .builder ()
137134 .startTime (Instant .now ().minusSeconds (3600 ))
138135 .endTime (Instant .now ())
139136 .metricDataQueries (List .of (metricDataQuery ))
140137 .build ();
141138 final var response = cloudWatchClient .getMetricData (request );
142- final OptionalDouble maxValue = response .metricDataResults ()
139+ final var maxValue = response .metricDataResults ()
143140 .stream ()
144141 .flatMap (result -> result .values ().stream ())
145142 .mapToDouble (Double ::doubleValue )
0 commit comments