Skip to content
This repository was archived by the owner on Oct 25, 2023. It is now read-only.

Commit b9615c5

Browse files
author
yweber
committed
fixed overwriting of exposed ports
1 parent 04ddeaf commit b9615c5

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

core/src/main/java/com/hivemq/testcontainer/core/HiveMQTestContainerCore.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public HiveMQTestContainerCore() {
7676

7777
public HiveMQTestContainerCore(final @NotNull String image, final @NotNull String tag) {
7878
super(image + ":" + tag);
79-
withExposedPorts(MQTT_PORT);
79+
addExposedPort(MQTT_PORT);
8080

8181
waitStrategy.withRegEx("(.*)Started HiveMQ in(.*)");
8282
waitingFor(waitStrategy);
@@ -135,8 +135,8 @@ public HiveMQTestContainerCore(final @NotNull String image, final @NotNull Strin
135135
* @return self
136136
*/
137137
public @NotNull SELF withDebugging(final int debuggingPortHost) {
138-
withExposedPorts(DEBUGGING_PORT);
139-
withFixedExposedPort(debuggingPortHost, DEBUGGING_PORT);
138+
addExposedPorts(DEBUGGING_PORT);
139+
addFixedExposedPort(debuggingPortHost, DEBUGGING_PORT);
140140
withEnv("JAVA_OPTS", "-agentlib:jdwp=transport=dt_socket,address=0.0.0.0:" + DEBUGGING_PORT + ",server=y,suspend=n");
141141
return self();
142142
}
@@ -610,8 +610,8 @@ private void putSubclassesIntoJar(
610610
* @return self
611611
*/
612612
public @NotNull SELF withControlCenter(final int controlCenterPort) {
613-
withExposedPorts(CONTROL_CENTER_PORT);
614-
withFixedExposedPort(controlCenterPort, CONTROL_CENTER_PORT);
613+
addExposedPorts(CONTROL_CENTER_PORT);
614+
addFixedExposedPort(controlCenterPort, CONTROL_CENTER_PORT);
615615
return self();
616616
}
617617

junit4/src/test/java/com/hivemq/testcontainer/junit4/DebuggingIT.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.hivemq.testcontainer.junit4;
1717

18+
import com.hivemq.client.mqtt.mqtt3.Mqtt3BlockingClient;
19+
import com.hivemq.client.mqtt.mqtt3.Mqtt3Client;
1820
import com.hivemq.testcontainer.core.HiveMQExtension;
1921
import com.hivemq.testcontainer.util.MyExtension;
2022
import org.junit.Test;
@@ -46,6 +48,10 @@ public void test() throws IOException {
4648
rule.start();
4749
final Socket localhost = new Socket("localhost", 9000);
4850
localhost.close();
51+
52+
final Mqtt3BlockingClient client = Mqtt3Client.builder().serverPort(rule.getMqttPort()).buildBlocking();
53+
client.connect();
54+
client.disconnect();
4955
rule.stop();
5056
}
5157

junit5/src/test/java/com/hivemq/testcontainer/junit5/DebuggingIT.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
*/
1616
package com.hivemq.testcontainer.junit5;
1717

18+
import com.hivemq.client.mqtt.mqtt3.Mqtt3BlockingClient;
19+
import com.hivemq.client.mqtt.mqtt3.Mqtt3Client;
1820
import com.hivemq.testcontainer.core.HiveMQExtension;
1921
import com.hivemq.testcontainer.util.MyExtension;
2022
import org.junit.jupiter.api.Test;
@@ -31,7 +33,7 @@
3133
*/
3234
public class DebuggingIT {
3335

34-
public static final int DEBUGGING_PORT_HOST = 9000;
36+
public static final int DEBUGGING_PORT_HOST = 5005;
3537

3638
@Test()
3739
@Timeout(value = 3, unit = TimeUnit.MINUTES)
@@ -47,8 +49,14 @@ void test() throws IOException {
4749
.withDebugging(DEBUGGING_PORT_HOST);
4850

4951
extension.beforeEach(null);
50-
final Socket localhost = new Socket("localhost", 9000);
52+
53+
final Socket localhost = new Socket("localhost", DEBUGGING_PORT_HOST);
5154
localhost.close();
55+
56+
final Mqtt3BlockingClient client = Mqtt3Client.builder().serverPort(extension.getMqttPort()).buildBlocking();
57+
client.connect();
58+
client.disconnect();
59+
5260
extension.afterEach(null);
5361
}
5462

0 commit comments

Comments
 (0)