Skip to content

Commit

Permalink
Merge branch '3.1.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
sdelamo committed Jan 10, 2024
2 parents 4db8e90 + 2ce8475 commit 243e334
Show file tree
Hide file tree
Showing 13 changed files with 203 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ dependencies {
testImplementation(mn.micronaut.management)
testImplementation(mn.reactor)
testImplementation(projects.testSuiteUtils)
testImplementation(mnSerde.micronaut.serde.jackson)
}
3 changes: 2 additions & 1 deletion mqtt-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ dependencies {
api(mn.micronaut.inject)
api(mn.micronaut.aop)
api(mn.micronaut.messaging)
api(mnSerde.micronaut.serde.api)
api(mn.jackson.annotations)
implementation(mn.micronaut.retry)
implementation(mnSerde.micronaut.serde.jackson)
implementation(mn.reactor)
compileOnly(libs.kotlin.stdlib.jdk8)
}
1 change: 1 addition & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ include 'mqtt-bom'

include 'test-suite-groovy'
include 'test-suite'
include 'test-suite-jackson'
include 'test-suite-kotlin'
include 'test-suite-mqttv3-graal'
include 'test-suite-mqttv5-graal'
Expand Down
1 change: 1 addition & 0 deletions test-suite-groovy/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ dependencies {
testCompileOnly(mnValidation.micronaut.validation)
testImplementation projects.testSuiteUtils
testImplementation projects.micronautMqttv5
testImplementation(mnSerde.micronaut.serde.jackson)
}

tasks.named('test') {
Expand Down
33 changes: 33 additions & 0 deletions test-suite-jackson/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
plugins {
id 'java-library'
id 'groovy'
id("io.micronaut.build.internal.mqtt-tests")
}

repositories {
mavenCentral()
}

dependencies {
annotationProcessor(mn.micronaut.inject.java)

implementation(projects.micronautMqttv5)
implementation(mn.micronaut.inject)
implementation(mn.micronaut.jackson.databind)

runtimeOnly(mnLogging.logback.classic)

testAnnotationProcessor(mn.micronaut.inject.java)

testImplementation(projects.testSuiteUtils)

testImplementation(libs.awaitility)
testImplementation(libs.junit.jupiter.api)
testImplementation(mnTest.micronaut.test.junit5)

testRuntimeOnly(libs.junit.jupiter.engine)
}

tasks.named('test') {
useJUnitPlatform()
}
32 changes: 32 additions & 0 deletions test-suite-jackson/src/main/java/example/micronaut/Odour.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright 2017-2024 original 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
*
* https://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 example.micronaut;

import io.micronaut.core.annotation.Introspected;

@Introspected
public class Odour {

private final String name;

public Odour(String name) {
this.name = name;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright 2017-2024 original 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
*
* https://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 example.micronaut;

import io.micronaut.core.annotation.NonNull;
import io.micronaut.mqtt.annotation.MqttSubscriber;
import io.micronaut.mqtt.annotation.Topic;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@MqttSubscriber
public class SmellListener {

private static final Logger LOG = LoggerFactory.getLogger(SmellListener.class);
private Odour smell;

@Topic("house/livingroom/smell")
public void receive(Odour data) {
LOG.info("smell: {}", smell);
smell = data;
}

@NonNull
public String getSmell() {
return smell == null ? "" : smell.getName();
}
}
14 changes: 14 additions & 0 deletions test-suite-jackson/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
5 changes: 5 additions & 0 deletions test-suite-jackson/src/test-resources/mosquitto.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
persistence false
allow_anonymous true
connection_messages true
log_type all
listener 1883
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package example.micronaut;

import io.micronaut.context.ApplicationContext;
import org.testcontainers.containers.BindMode;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

public abstract class AbstractMQTTTest {

protected static GenericContainer mqttContainer = new GenericContainer(DockerImageName.parse("eclipse-mosquitto:1.6.12"))
.withExposedPorts(1883)
.waitingFor(new LogMessageWaitStrategy().withRegEx("(?s).*mosquitto version 1.6.12 running.*"))
.withClasspathResourceMapping("mosquitto.conf",
"/mosquitto/config/mosquitto.conf",
BindMode.READ_ONLY);

static {
mqttContainer.start();
}

protected ApplicationContext startContext() {
return ApplicationContext.run(getConfiguration(), "test");
}

protected Map<String, Object> getConfiguration() {
Map<String, Object> config = new HashMap<>();
config.put("mqtt.client.server-uri", "tcp://localhost:" + mqttContainer.getMappedPort(1883));
config.put("mqtt.client.client-id", UUID.randomUUID().toString());
config.put("spec.name", this.getClass().getSimpleName());
return config;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package example.micronaut;

import io.micronaut.context.ApplicationContext;
import io.micronaut.mqtt.annotation.Topic;
import io.micronaut.mqtt.annotation.v5.MqttPublisher;
import org.junit.jupiter.api.Test;

import java.util.concurrent.TimeUnit;

import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.assertEquals;

class SubscriptionTest extends AbstractMQTTTest {

@Test
void checkSubscriptionsAreReceived() {
try(ApplicationContext applicationContext = startContext()) {
SmellClient client = applicationContext.getBean(SmellClient.class);
SmellListener listener = applicationContext.getBean(SmellListener.class);

client.publishLivingroomSmell(new Odour("cheesy"));

await()
.atMost(5, TimeUnit.SECONDS)
.untilAsserted(() -> assertEquals("cheesy", listener.getSmell()));
}
}

@MqttPublisher
interface SmellClient {

@Topic("house/livingroom/smell")
void publishLivingroomSmell(Odour data);
}
}
1 change: 1 addition & 0 deletions test-suite-kotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ dependencies {

testImplementation projects.testSuiteUtils
testImplementation projects.micronautMqttv5
testImplementation(mnSerde.micronaut.serde.jackson)
}

tasks.named('test') {
Expand Down
1 change: 1 addition & 0 deletions test-suite/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ dependencies {

testImplementation projects.testSuiteUtils
testImplementation projects.micronautMqttv5
testImplementation(mnSerde.micronaut.serde.jackson)
}

tasks.named('test') {
Expand Down

0 comments on commit 243e334

Please sign in to comment.