ARTEMIS-6189 Adding describe for MQTT Correlation - #6652
Merged
Conversation
clebertsuconic
force-pushed
the
ARTEMIS-6189
branch
4 times, most recently
from
August 28, 2026 17:11
566aa29 to
ebb0122
Compare
Contributor
|
The test you added obviously works, but it's more complicated that it needs to be. There are already tests that validate functionality with actual MQTT clients so you could simplify the test significantly by doing something like this instead: package org.apache.activemq.artemis.tests.integration.mqtt;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.apache.activemq.artemis.api.core.SimpleString;
import org.apache.activemq.artemis.cli.commands.tools.PrintData;
import org.apache.activemq.artemis.core.config.FileDeploymentManager;
import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration;
import org.apache.activemq.artemis.core.protocol.mqtt.MQTTStateManager;
import org.apache.activemq.artemis.core.protocol.mqtt.PacketIdCorrelationKey;
import org.apache.activemq.artemis.core.server.ActiveMQServer;
import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
import org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager;
import org.apache.activemq.artemis.spi.core.security.jaas.InVMLoginModule;
import org.apache.activemq.artemis.tests.util.ActiveMQTestBase;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class MQTTPrintDataTest extends ActiveMQTestBase {
@Test
@Timeout(30)
public void testPrintDataWithMQTTQoS2Correlation() throws Exception {
ActiveMQServer server = addServer(getActiveMQServer("dataprint/etc/broker.xml"));
try {
server.getConfiguration().setPersistenceEnabled(true);
server.start();
MQTTStateManager.getInstance(server).putPacketIdCorrelation("print-data-sub", PacketIdCorrelationKey.of(123L, SimpleString.of("mqtt/qos2/test")), 1);
server.stop();
String previousInstance = System.getProperty("artemis.instance");
try {
System.setProperty("artemis.instance", this.getClass().getClassLoader().getResource("dataprint").getFile());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
PrintStream printStream = new PrintStream(byteArrayOutputStream, true, StandardCharsets.UTF_8.name());
PrintData.printData(server.getConfiguration().getBindingsLocation().getAbsoluteFile(),
server.getConfiguration().getJournalLocation().getAbsoluteFile(),
server.getConfiguration().getPagingLocation().getAbsoluteFile(),
printStream, false, false, false, false, -1, true);
String output = byteArrayOutputStream.toString();
System.out.println(output);
assertTrue(output.contains("PacketIdCorrelation"), "Print data output should contain the MQTT PacketIdCorrelation record.\nOutput:\n" + output);
} finally {
if (previousInstance != null) {
System.setProperty("artemis.instance", previousInstance);
} else {
System.clearProperty("artemis.instance");
}
}
} finally {
try {
server.stop();
} catch (Exception e) {
}
}
}
protected ActiveMQServer getActiveMQServer(String brokerConfig) throws Exception {
FileConfiguration fc = new FileConfiguration();
FileJMSConfiguration fileConfiguration = new FileJMSConfiguration();
FileDeploymentManager deploymentManager = new FileDeploymentManager(brokerConfig);
deploymentManager.addDeployable(fc);
deploymentManager.addDeployable(fileConfiguration);
deploymentManager.readConfiguration();
ActiveMQJAASSecurityManager sm = new ActiveMQJAASSecurityManager(InVMLoginModule.class.getName(), new SecurityConfiguration());
recreateDirectory(fc.getBindingsDirectory());
recreateDirectory(fc.getJournalDirectory());
recreateDirectory(fc.getPagingDirectory());
recreateDirectory(fc.getLargeMessagesDirectory());
return addServer(new ActiveMQServerImpl(fc, sm));
}
} |
clebertsuconic
force-pushed
the
ARTEMIS-6189
branch
from
August 28, 2026 20:28
ebb0122 to
3ce66bb
Compare
Contributor
Author
|
@jbertram I amended the test |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.