Skip to content

Commit 4c41828

Browse files
committed
Update testcontainers to 2.0.2
1 parent 0080ade commit 4c41828

File tree

3 files changed

+21
-22
lines changed

3 files changed

+21
-22
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ testing {
7878
implementation(libs.awaitility)
7979
implementation(libs.aws.sdkv2.cloudwatch)
8080
implementation(libs.hivemq.mqttClient)
81+
implementation(libs.testcontainers)
8182
implementation(libs.testcontainers.hivemq)
8283
implementation(libs.testcontainers.junitJupiter)
8384
implementation(libs.testcontainers.localstack)

gradle/libs.versions.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jetbrains-annotations = "26.0.2-1"
1111
junit-jupiter = "5.10.0"
1212
logback = "1.5.21"
1313
mockito = "5.20.0"
14-
testcontainers = "1.21.3"
14+
testcontainers = "2.0.2"
1515

1616
[libraries]
1717
awaitility = { module = "org.awaitility:awaitility", version.ref = "awaitility" }
@@ -24,9 +24,10 @@ jaxb-impl = { module = "com.sun.xml.bind:jaxb-impl", version.ref = "jaxb-impl" }
2424
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains-annotations" }
2525
logback-classic = { module = "ch.qos.logback:logback-classic", version.ref = "logback" }
2626
mockito = { module = "org.mockito:mockito-core", version.ref = "mockito" }
27-
testcontainers-hivemq = { module = "org.testcontainers:hivemq", version.ref = "testcontainers" }
28-
testcontainers-junitJupiter = { module = "org.testcontainers:junit-jupiter", version.ref = "testcontainers" }
29-
testcontainers-localstack = { module = "org.testcontainers:localstack", version.ref = "testcontainers" }
27+
testcontainers = { module = "org.testcontainers:testcontainers", version.ref = "testcontainers" }
28+
testcontainers-hivemq = { module = "org.testcontainers:testcontainers-hivemq", version.ref = "testcontainers" }
29+
testcontainers-junitJupiter = { module = "org.testcontainers:testcontainers-junit-jupiter", version.ref = "testcontainers" }
30+
testcontainers-localstack = { module = "org.testcontainers:testcontainers-localstack", version.ref = "testcontainers" }
3031

3132
[plugins]
3233
defaults = { id = "io.github.sgtsilvio.gradle.defaults", version = "0.2.0" }

src/integrationTest/java/com/hivemq/extensions/aws/cloudwatch/EndToEndIT.java

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.hivemq.extensions.aws.cloudwatch;
1717

18-
import com.hivemq.client.mqtt.mqtt5.Mqtt5BlockingClient;
1918
import com.hivemq.client.mqtt.mqtt5.Mqtt5Client;
2019
import io.github.sgtsilvio.gradle.oci.junit.jupiter.OciImages;
2120
import org.awaitility.Durations;
@@ -25,9 +24,8 @@
2524
import org.junit.jupiter.api.Test;
2625
import org.junit.jupiter.api.Timeout;
2726
import org.testcontainers.containers.Network;
28-
import org.testcontainers.containers.localstack.LocalStackContainer;
29-
import org.testcontainers.containers.localstack.LocalStackContainer.Service;
3027
import org.testcontainers.hivemq.HiveMQContainer;
28+
import org.testcontainers.localstack.LocalStackContainer;
3129
import org.testcontainers.utility.MountableFile;
3230
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
3331
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
@@ -42,7 +40,6 @@
4240
import java.time.Instant;
4341
import java.util.Collections;
4442
import java.util.List;
45-
import java.util.OptionalDouble;
4643
import java.util.concurrent.TimeUnit;
4744

4845
import 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

Comments
 (0)