diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java index 1842a5848e..d05e23d4f4 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/DescribeJournal.java @@ -105,12 +105,12 @@ public final class DescribeJournal { private final List records; private final List preparedTransactions; - private static final Configuration CONFIGURATION; - static { + private static Configuration getConfiguration() { + Configuration configuration; String instanceFolder = System.getProperty("artemis.instance"); if (instanceFolder != null) { - CONFIGURATION = new FileConfiguration(); + configuration = new FileConfiguration(); File configFile = new File(instanceFolder + "/etc/broker.xml"); URL url; @@ -121,19 +121,21 @@ public final class DescribeJournal { xml = XMLUtil.replaceSystemProps(xml); Element e = XMLUtil.stringToElement(xml); - String root = ((FileConfiguration) CONFIGURATION).getRootElement(); + String root = ((FileConfiguration) configuration).getRootElement(); NodeList children = e.getElementsByTagName(root); if (root != null && children.getLength() > 0) { Node item = children.item(0); - XMLUtil.validate(item, ((FileConfiguration) CONFIGURATION).getSchema()); - ((FileConfiguration) CONFIGURATION).parse((Element) item, url); + XMLUtil.validate(item, ((FileConfiguration) configuration).getSchema()); + ((FileConfiguration) configuration).parse((Element) item, url); } } catch (Exception e) { logger.error("failed to load broker.xml", e); } } else { - CONFIGURATION = new ConfigurationImpl(); + configuration = new ConfigurationImpl(); } + + return configuration; } public DescribeJournal(List records, List preparedTransactions) { @@ -166,10 +168,11 @@ public final class DescribeJournal { } public static DescribeJournal describeMessagesJournal(final File messagesDir, PrintStream out, boolean safe) throws Exception { + Configuration configuration = getConfiguration(); SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null, 1); // Will use only default values. The load function should adapt to anything different - JournalImpl messagesJournal = new JournalImpl(CONFIGURATION.getJournalFileSize(), CONFIGURATION.getJournalMinFiles(), CONFIGURATION.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); + JournalImpl messagesJournal = new JournalImpl(configuration.getJournalFileSize(), configuration.getJournalMinFiles(), configuration.getJournalPoolFiles(), 0, 0, messagesFF, "activemq-data", "amq", 1); return describeJournal(messagesFF, messagesJournal, messagesDir, out, safe); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java index 8e8b0d3b06..dd8fe38ca5 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalDataPrintTest.java @@ -21,6 +21,7 @@ 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.persistence.impl.journal.DescribeJournal; 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; @@ -32,6 +33,9 @@ import org.junit.Before; import org.junit.Test; import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; public class JournalDataPrintTest extends ActiveMQTestBase { @@ -49,9 +53,17 @@ public class JournalDataPrintTest extends ActiveMQTestBase { try { server.start(); server.stop(); + // This will force some static load that used to be on the class, which would make this test to fail. + DescribeJournal journal = new DescribeJournal(null, null); System.setProperty("artemis.instance", this.getClass().getClassLoader().getResource("dataprint").getFile()); - PrintData.printData(server.getConfiguration().getBindingsLocation().getAbsoluteFile(), server.getConfiguration().getJournalLocation().getAbsoluteFile(), server.getConfiguration().getPagingLocation().getAbsoluteFile()); + PrintData.printData(server.getConfiguration().getBindingsLocation().getAbsoluteFile(), server.getConfiguration().getJournalLocation().getAbsoluteFile(), server.getConfiguration().getPagingLocation().getAbsoluteFile(), + new PrintStream(new OutputStream() { + @Override + public void write(int b) throws IOException { + // dev/null + } + }), false); // list journal file File dirFile = server.getConfiguration().getJournalLocation().getAbsoluteFile();