Skip to content

Commit

Permalink
Fix OutOfMemoryErrors:
Browse files Browse the repository at this point in the history
- Add test instance per class
- Remove static hivemq extension
- Fix MqttCliShell
Enable formatter tag exception
Rename and unify HIVEMQ in system tests
  • Loading branch information
LukasBrand committed Jan 5, 2023
1 parent 0e1ec52 commit 62d0ca8
Show file tree
Hide file tree
Showing 26 changed files with 348 additions and 313 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ tab_width = 4
ij_continuation_indent_size = 8
ij_formatter_off_tag = @formatter:off
ij_formatter_on_tag = @formatter:on
ij_formatter_tags_enabled = false
ij_formatter_tags_enabled = true
ij_smart_tabs = false
ij_visual_guides = none
ij_wrap_on_typing = false
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -295,12 +295,12 @@ val systemTest by tasks.registering(Test::class) {
useJUnitPlatform()
testClassesDirs = sourceSets["systemTest"].output.classesDirs
classpath = sourceSets["systemTest"].runtimeClasspath
maxHeapSize = "2g"
shouldRunAfter(tasks.test)
javaLauncher.set(javaToolchains.launcherFor {
languageVersion.set(JavaLanguageVersion.of(11))
})
dependsOn(tasks.shadowJar)
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
systemProperties["cliExec"] = javaLauncher.get().executablePath.asFile.absolutePath + " -jar " +
tasks.shadowJar.map { it.outputs.files.singleFile }.get()
systemProperties["java"] = javaLauncher.get().executablePath.asFile.absolutePath
Expand All @@ -317,6 +317,7 @@ val systemTestNative by tasks.registering(Test::class) {
languageVersion.set(JavaLanguageVersion.of(11))
})
dependsOn(tasks.nativeCompile)
systemProperties["junit.jupiter.testinstance.lifecycle.default"] = "per_class"
systemProperties["cliExec"] =
tasks.nativeCompile.map { it.outputs.files.singleFile }.get().resolve(project.name).absolutePath
systemProperties["java"] = javaLauncher.get().executablePath.asFile.absolutePath
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
class PublishConnectST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@
class PublishConnectTlsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
class PublishConnectWebsocketsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withWebsocketEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withWebsocketEnabled(true).build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
class PublishST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
class SubscribeConnectST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@
class SubscribeConnectTlsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVE_MQ = HiveMQ.builder().withTlsEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand All @@ -56,9 +57,9 @@ void test_mutualTls(final char mqttVersion) throws Exception {
final List<String> subscribeCommand = List.of(
"sub",
"-h",
HIVE_MQ.getHost(),
HIVEMQ.getHost(),
"-p",
String.valueOf(HIVE_MQ.getMqttTlsPort()),
String.valueOf(HIVEMQ.getMqttTlsPort()),
"-V",
String.valueOf(mqttVersion),
"-i",
Expand All @@ -80,11 +81,11 @@ void test_mutualTls(final char mqttVersion) throws Exception {
executionResult.awaitStdOut("received SUBACK");

assertConnectPacket(
HIVE_MQ.getConnectPackets().get(0),
HIVEMQ.getConnectPackets().get(0),
connectAssertion -> connectAssertion.setMqttVersion(MqttVersionConverter.toExtensionSdkVersion(
mqttVersion)));

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions =
List.of(new SubscriptionImpl("topic", Qos.EXACTLY_ONCE, RetainHandling.SEND, false, false));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
public class SubscribeConnectWebsocketsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVE_MQ = HiveMQ.builder().withWebsocketEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withWebsocketEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand All @@ -51,9 +52,9 @@ void test_websockets(final char mqttVersion) throws Exception {
final List<String> subscribeCommand = List.of(
"sub",
"-h",
HIVE_MQ.getHost(),
HIVEMQ.getHost(),
"-p",
String.valueOf(HIVE_MQ.getWebsocketsPort()),
String.valueOf(HIVEMQ.getWebsocketsPort()),
"-V",
String.valueOf(mqttVersion),
"-i",
Expand All @@ -62,19 +63,19 @@ void test_websockets(final char mqttVersion) throws Exception {
"topic",
"-ws",
"-ws:path",
HIVE_MQ.getWebsocketsPath(),
HIVEMQ.getWebsocketsPath(),
"-d");

final ExecutionResultAsync executionResult = mqttCli.executeAsync(subscribeCommand);
executionResult.awaitStdOut("received CONNACK");
executionResult.awaitStdOut("received SUBACK");

assertConnectPacket(
HIVE_MQ.getConnectPackets().get(0),
HIVEMQ.getConnectPackets().get(0),
connectAssertion -> connectAssertion.setMqttVersion(MqttVersionConverter.toExtensionSdkVersion(
mqttVersion)));

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions =
List.of(new SubscriptionImpl("topic", Qos.EXACTLY_ONCE, RetainHandling.SEND, false, false));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@
class SubscribeST {

@RegisterExtension
private static final @NotNull HiveMQ HIVE_MQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand All @@ -74,11 +75,11 @@ void test_successfulConnectAndSubscribe(final char mqttVersion) throws Exception

executionResult.awaitStdOut("message");

assertConnectPacket(HIVE_MQ.getConnectPackets().get(0),
assertConnectPacket(HIVEMQ.getConnectPackets().get(0),
connectAssertion -> connectAssertion.setMqttVersion(MqttVersionConverter.toExtensionSdkVersion(
mqttVersion)));

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand All @@ -95,7 +96,7 @@ void test_qos(final char mqttVersion) throws Exception {
final ExecutionResultAsync executionResult = mqttCli.executeAsync(subscribeCommand);
assertSubscribe(executionResult);

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.AT_LEAST_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand Down Expand Up @@ -130,17 +131,17 @@ void test_multipleTopics(final char mqttVersion) throws Exception {
executionResult.awaitStdOut("message3");


assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic1", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(1), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(1), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic2", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(2), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(2), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic3", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand Down Expand Up @@ -181,17 +182,17 @@ void test_multipleTopicsMultipleQoS(final char mqttVersion) throws Exception {
executionResult.awaitStdOut("message3");


assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic1", Qos.AT_MOST_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(1), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(1), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic2", Qos.AT_LEAST_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(2), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(2), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic3", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand Down Expand Up @@ -219,7 +220,7 @@ void test_outputFile(final char mqttVersion) throws Exception {
assertEquals(1, readLines.size());
assertEquals("message", readLines.get(0));

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand All @@ -246,7 +247,7 @@ void test_userProperties(final char mqttVersion) throws Exception {

executionResult.awaitStdOut("message");

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.EXACTLY_ONCE));

subscribeAssertion.setSubscriptions(expectedSubscriptions);
Expand Down Expand Up @@ -274,7 +275,7 @@ void test_base64(final char mqttVersion) throws Exception {
final String encodedPayload = Base64.getEncoder().encodeToString("message".getBytes(StandardCharsets.UTF_8));
executionResult.awaitStdOut(encodedPayload);

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand All @@ -294,7 +295,7 @@ void test_showTopic(final char mqttVersion) throws Exception {

executionResult.awaitStdOut("topic: message");

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand Down Expand Up @@ -324,7 +325,7 @@ void test_showJson(final char mqttVersion) throws Exception {
executionResult.awaitStdOut("\"retain\": false");
executionResult.awaitStdOut("}");

assertSubscribePacket(HIVE_MQ.getSubscribePackets().get(0), subscribeAssertion -> {
assertSubscribePacket(HIVEMQ.getSubscribePackets().get(0), subscribeAssertion -> {
final List<Subscription> expectedSubscriptions = List.of(createSubscription("topic", Qos.EXACTLY_ONCE));
subscribeAssertion.setSubscriptions(expectedSubscriptions);
});
Expand All @@ -334,7 +335,7 @@ void test_showJson(final char mqttVersion) throws Exception {
@Timeout(value = 3, unit = TimeUnit.MINUTES)
void test_subscribeMissingTopic() throws Exception {
final List<String> subscribeCommand =
List.of("sub", "-h", HIVE_MQ.getHost(), "-p", String.valueOf(HIVE_MQ.getMqttPort()));
List.of("sub", "-h", HIVEMQ.getHost(), "-p", String.valueOf(HIVEMQ.getMqttPort()));

final ExecutionResult executionResult = MqttCli.execute(subscribeCommand);

Expand All @@ -346,9 +347,9 @@ void test_subscribeMissingTopic() throws Exception {
final ArrayList<String> subscribeCommand = new ArrayList<>();
subscribeCommand.add("sub");
subscribeCommand.add("-h");
subscribeCommand.add(HIVE_MQ.getHost());
subscribeCommand.add(HIVEMQ.getHost());
subscribeCommand.add("-p");
subscribeCommand.add(String.valueOf(HIVE_MQ.getMqttPort()));
subscribeCommand.add(String.valueOf(HIVEMQ.getMqttPort()));
subscribeCommand.add("-V");
subscribeCommand.add(String.valueOf(mqttVersion));
subscribeCommand.add("-i");
Expand All @@ -369,8 +370,8 @@ private void assertSubscribe(final @NotNull ExecutionResultAsync executionResult
private void publishMessage(final @NotNull String topic, final @NotNull String message) {
final Mqtt5BlockingClient publisher = Mqtt5Client.builder()
.identifier("publisher")
.serverHost(HIVE_MQ.getHost())
.serverPort(HIVE_MQ.getMqttPort())
.serverHost(HIVEMQ.getHost())
.serverPort(HIVEMQ.getMqttPort())
.buildBlocking();
publisher.connect();
publisher.publishWith()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
class TestBrokerConnectST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
class TestBrokerConnectTlsST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().withTlsEnabled(true).build();

@RegisterExtension
private final @NotNull MqttCliAsync mqttCli = new MqttCliAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
class TestBrokerST {

@RegisterExtension
private static final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();
@SuppressWarnings("JUnitMalformedDeclaration")
private final @NotNull HiveMQ HIVEMQ = HiveMQ.builder().build();

@ParameterizedTest
@Timeout(value = 3, unit = TimeUnit.MINUTES)
Expand Down
Loading

0 comments on commit 62d0ca8

Please sign in to comment.