Merge pull request #10684 from zzzeebra/Junit4to5-netty-mqtt
JUnit5 migration in netty-mqtt.
This commit is contained in:
commit
985596b03f
@ -82,21 +82,11 @@
|
|||||||
<artifactId>spring-boot-starter-test</artifactId>
|
<artifactId>spring-boot-starter-test</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>org.junit.vintage</groupId>
|
|
||||||
<artifactId>junit-vintage-engine</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.awaitility</groupId>
|
<groupId>org.awaitility</groupId>
|
||||||
<artifactId>awaitility</artifactId>
|
<artifactId>awaitility</artifactId>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>io.takari.junit</groupId>
|
|
||||||
<artifactId>takari-cpsuite</artifactId>
|
|
||||||
<scope>test</scope>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@ -1,27 +0,0 @@
|
|||||||
/**
|
|
||||||
* Copyright © 2016-2024 The Thingsboard Authors
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
package org.thingsboard.mqtt.integration;
|
|
||||||
|
|
||||||
import org.junit.extensions.cpsuite.ClasspathSuite;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
|
|
||||||
@RunWith(ClasspathSuite.class)
|
|
||||||
@ClasspathSuite.ClassnameFilters({
|
|
||||||
"org.thingsboard.mqtt.integration.*Test",
|
|
||||||
})
|
|
||||||
public class IntegrationTestSuite {
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -23,10 +23,11 @@ import io.netty.handler.codec.mqtt.MqttQoS;
|
|||||||
import io.netty.util.concurrent.Future;
|
import io.netty.util.concurrent.Future;
|
||||||
import io.netty.util.concurrent.Promise;
|
import io.netty.util.concurrent.Promise;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.junit.After;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.Assert;
|
import org.junit.jupiter.api.Assertions;
|
||||||
import org.junit.Before;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.api.parallel.ResourceLock;
|
||||||
import org.thingsboard.common.util.AbstractListeningExecutor;
|
import org.thingsboard.common.util.AbstractListeningExecutor;
|
||||||
import org.thingsboard.mqtt.MqttClient;
|
import org.thingsboard.mqtt.MqttClient;
|
||||||
import org.thingsboard.mqtt.MqttClientConfig;
|
import org.thingsboard.mqtt.MqttClientConfig;
|
||||||
@ -39,6 +40,7 @@ import java.util.concurrent.CountDownLatch;
|
|||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.concurrent.TimeoutException;
|
import java.util.concurrent.TimeoutException;
|
||||||
|
|
||||||
|
@ResourceLock("port8885") // test MQTT server port
|
||||||
@Slf4j
|
@Slf4j
|
||||||
public class MqttIntegrationTest {
|
public class MqttIntegrationTest {
|
||||||
|
|
||||||
@ -53,7 +55,7 @@ public class MqttIntegrationTest {
|
|||||||
|
|
||||||
AbstractListeningExecutor handlerExecutor;
|
AbstractListeningExecutor handlerExecutor;
|
||||||
|
|
||||||
@Before
|
@BeforeEach
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
this.handlerExecutor = new AbstractListeningExecutor() {
|
this.handlerExecutor = new AbstractListeningExecutor() {
|
||||||
@Override
|
@Override
|
||||||
@ -69,7 +71,7 @@ public class MqttIntegrationTest {
|
|||||||
this.mqttServer.init();
|
this.mqttServer.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
@After
|
@AfterEach
|
||||||
public void destroy() throws InterruptedException {
|
public void destroy() throws InterruptedException {
|
||||||
if (this.mqttClient != null) {
|
if (this.mqttClient != null) {
|
||||||
this.mqttClient.disconnect();
|
this.mqttClient.disconnect();
|
||||||
@ -100,7 +102,7 @@ public class MqttIntegrationTest {
|
|||||||
|
|
||||||
log.warn("Waiting for messages acknowledgments...");
|
log.warn("Waiting for messages acknowledgments...");
|
||||||
boolean awaitResult = latch.await(10, TimeUnit.SECONDS);
|
boolean awaitResult = latch.await(10, TimeUnit.SECONDS);
|
||||||
Assert.assertTrue(awaitResult);
|
Assertions.assertTrue(awaitResult);
|
||||||
log.warn("Messages are delivered successfully...");
|
log.warn("Messages are delivered successfully...");
|
||||||
|
|
||||||
//when
|
//when
|
||||||
@ -111,7 +113,7 @@ public class MqttIntegrationTest {
|
|||||||
List<MqttMessageType> allReceivedEvents = this.mqttServer.getEventsFromClient();
|
List<MqttMessageType> allReceivedEvents = this.mqttServer.getEventsFromClient();
|
||||||
long disconnectCount = allReceivedEvents.stream().filter(type -> type == MqttMessageType.DISCONNECT).count();
|
long disconnectCount = allReceivedEvents.stream().filter(type -> type == MqttMessageType.DISCONNECT).count();
|
||||||
|
|
||||||
Assert.assertEquals(1, disconnectCount);
|
Assertions.assertEquals(1, disconnectCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Future<Void> publishMsg() {
|
private Future<Void> publishMsg() {
|
||||||
|
|||||||
@ -46,7 +46,7 @@ public class MqttServer {
|
|||||||
private EventLoopGroup workerGroup;
|
private EventLoopGroup workerGroup;
|
||||||
|
|
||||||
public void init() throws Exception {
|
public void init() throws Exception {
|
||||||
log.info("Starting MQTT server...");
|
log.info("Starting MQTT server on port {}...", mqttPort);
|
||||||
bossGroup = new NioEventLoopGroup();
|
bossGroup = new NioEventLoopGroup();
|
||||||
workerGroup = new NioEventLoopGroup();
|
workerGroup = new NioEventLoopGroup();
|
||||||
ServerBootstrap b = new ServerBootstrap();
|
ServerBootstrap b = new ServerBootstrap();
|
||||||
|
|||||||
3
netty-mqtt/src/test/resources/junit-platform.properties
Normal file
3
netty-mqtt/src/test/resources/junit-platform.properties
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
junit.jupiter.execution.parallel.enabled = true
|
||||||
|
junit.jupiter.execution.parallel.mode.default = concurrent
|
||||||
|
junit.jupiter.execution.parallel.mode.classes.default = concurrent
|
||||||
14
netty-mqtt/src/test/resources/logback-test.xml
Normal file
14
netty-mqtt/src/test/resources/logback-test.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
|
||||||
|
<configuration>
|
||||||
|
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
|
||||||
|
<encoder>
|
||||||
|
<pattern>%d{ISO8601} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||||
|
</encoder>
|
||||||
|
</appender>
|
||||||
|
|
||||||
|
<root level="INFO">
|
||||||
|
<appender-ref ref="console"/>
|
||||||
|
</root>
|
||||||
|
|
||||||
|
</configuration>
|
||||||
Loading…
x
Reference in New Issue
Block a user