ARTEMIS-1959 Fixing JournalDataPrintTest

This commit is contained in:
Clebert Suconic 2018-07-10 22:07:36 -04:00
parent 048f46bd4f
commit 7c0f6633f1
2 changed files with 24 additions and 9 deletions

View File

@ -105,12 +105,12 @@ public final class DescribeJournal {
private final List<RecordInfo> records; private final List<RecordInfo> records;
private final List<PreparedTransactionInfo> preparedTransactions; private final List<PreparedTransactionInfo> preparedTransactions;
private static final Configuration CONFIGURATION;
static { private static Configuration getConfiguration() {
Configuration configuration;
String instanceFolder = System.getProperty("artemis.instance"); String instanceFolder = System.getProperty("artemis.instance");
if (instanceFolder != null) { if (instanceFolder != null) {
CONFIGURATION = new FileConfiguration(); configuration = new FileConfiguration();
File configFile = new File(instanceFolder + "/etc/broker.xml"); File configFile = new File(instanceFolder + "/etc/broker.xml");
URL url; URL url;
@ -121,19 +121,21 @@ public final class DescribeJournal {
xml = XMLUtil.replaceSystemProps(xml); xml = XMLUtil.replaceSystemProps(xml);
Element e = XMLUtil.stringToElement(xml); Element e = XMLUtil.stringToElement(xml);
String root = ((FileConfiguration) CONFIGURATION).getRootElement(); String root = ((FileConfiguration) configuration).getRootElement();
NodeList children = e.getElementsByTagName(root); NodeList children = e.getElementsByTagName(root);
if (root != null && children.getLength() > 0) { if (root != null && children.getLength() > 0) {
Node item = children.item(0); Node item = children.item(0);
XMLUtil.validate(item, ((FileConfiguration) CONFIGURATION).getSchema()); XMLUtil.validate(item, ((FileConfiguration) configuration).getSchema());
((FileConfiguration) CONFIGURATION).parse((Element) item, url); ((FileConfiguration) configuration).parse((Element) item, url);
} }
} catch (Exception e) { } catch (Exception e) {
logger.error("failed to load broker.xml", e); logger.error("failed to load broker.xml", e);
} }
} else { } else {
CONFIGURATION = new ConfigurationImpl(); configuration = new ConfigurationImpl();
} }
return configuration;
} }
public DescribeJournal(List<RecordInfo> records, List<PreparedTransactionInfo> preparedTransactions) { public DescribeJournal(List<RecordInfo> records, List<PreparedTransactionInfo> preparedTransactions) {
@ -166,10 +168,11 @@ public final class DescribeJournal {
} }
public static DescribeJournal describeMessagesJournal(final File messagesDir, PrintStream out, boolean safe) throws Exception { public static DescribeJournal describeMessagesJournal(final File messagesDir, PrintStream out, boolean safe) throws Exception {
Configuration configuration = getConfiguration();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null, 1); SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null, 1);
// Will use only default values. The load function should adapt to anything different // 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); return describeJournal(messagesFF, messagesJournal, messagesDir, out, safe);
} }

View File

@ -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.FileDeploymentManager;
import org.apache.activemq.artemis.core.config.impl.FileConfiguration; import org.apache.activemq.artemis.core.config.impl.FileConfiguration;
import org.apache.activemq.artemis.core.config.impl.SecurityConfiguration; 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.ActiveMQServer;
import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl;
import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration; import org.apache.activemq.artemis.jms.server.config.impl.FileJMSConfiguration;
@ -32,6 +33,9 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.io.File; import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
public class JournalDataPrintTest extends ActiveMQTestBase { public class JournalDataPrintTest extends ActiveMQTestBase {
@ -49,9 +53,17 @@ public class JournalDataPrintTest extends ActiveMQTestBase {
try { try {
server.start(); server.start();
server.stop(); 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", System.setProperty("artemis.instance",
this.getClass().getClassLoader().getResource("dataprint").getFile()); 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 // list journal file
File dirFile = server.getConfiguration().getJournalLocation().getAbsoluteFile(); File dirFile = server.getConfiguration().getJournalLocation().getAbsoluteFile();