diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java index 640243f184..651620f38d 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Configurable.java @@ -124,7 +124,7 @@ public abstract class Configurable extends ActionAbstract { if (getBrokerInstance() == null) { - final String defaultLocation = "../data"; + final String defaultLocation = "./data"; fileConfiguration = new FileConfiguration(); // These will be the default places in case the file can't be loaded fileConfiguration.setBindingsDirectory(defaultLocation + "/bindings"); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java index 4450657b72..8d5f87e6ff 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Create.java @@ -98,8 +98,8 @@ public class Create extends InputAbstract @Option(name = "--home", description = "Directory where ActiveMQ Artemis is installed") File home; - @Option(name = "--data", description = "Directory where ActiveMQ Data is used. Path are relative to artemis.instance/bin") - String data = "../data"; + @Option(name = "--data", description = "Directory where ActiveMQ Data is used. Path are relative to artemis.instance") + String data = "./data"; @Option(name = "--clustered", description = "Enable clustering") boolean clustered = false; @@ -131,7 +131,7 @@ public class Create extends InputAbstract @Option(name = "--allow-anonymous", description = "Enables anonymous configuration on security (Default: input)") Boolean allowAnonymous = null; - @Option(name = "--require-login", description = "This will configure security to require user / password. Compliment --allow-anonymous") + @Option(name = "--require-login", description = "This will configure security to require user / password. Compliments --allow-anonymous") Boolean requireLogin = null; @Option(name = "--user", description = "The username (Default: input)") diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java index 34a3007e02..86796007b9 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/Run.java @@ -84,10 +84,10 @@ public class Run extends Configurable private void createDirectories(FileConfiguration fileConfiguration) { - new File(fileConfiguration.getBindingsDirectory()).mkdirs(); - new File(fileConfiguration.getJournalDirectory()).mkdirs(); - new File(fileConfiguration.getPagingDirectory()).mkdirs(); - new File(fileConfiguration.getLargeMessagesDirectory()).mkdirs(); + fileConfiguration.getPagingLocation().mkdirs(); + fileConfiguration.getJournalLocation().mkdirs(); + fileConfiguration.getBindingsLocation().mkdirs(); + fileConfiguration.getLargeMessagesLocation().mkdirs(); } /** @@ -137,7 +137,6 @@ public class Run extends Configurable { try { - //TODO stop components server.stop(); } catch (Exception e) diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java index 687399a254..ecd2e377ef 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DataAbstract.java @@ -42,7 +42,7 @@ public abstract class DataAbstract extends Configurable { if (largeMessges == null) { - largeMessges = getFileConfiguration().getLargeMessagesDirectory(); + largeMessges = getFileConfiguration().getLargeMessagesLocation().getAbsolutePath(); } checkIfDirectoryExists(largeMessges); @@ -55,7 +55,7 @@ public abstract class DataAbstract extends Configurable { if (binding == null) { - binding = getFileConfiguration().getBindingsDirectory(); + binding = getFileConfiguration().getBindingsLocation().getAbsolutePath(); } checkIfDirectoryExists(binding); @@ -67,7 +67,7 @@ public abstract class DataAbstract extends Configurable { if (journal == null) { - journal = getFileConfiguration().getJournalDirectory(); + journal = getFileConfiguration().getJournalLocation().getAbsolutePath(); } checkIfDirectoryExists(journal); @@ -79,7 +79,7 @@ public abstract class DataAbstract extends Configurable { if (paging == null) { - paging = getFileConfiguration().getPagingDirectory(); + paging = getFileConfiguration().getPagingLocation().getAbsolutePath(); } checkIfDirectoryExists(paging); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java index 966fc5d450..5b28a18ca3 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/DecodeJournal.java @@ -117,7 +117,7 @@ public class DecodeJournal extends Configurable implements Action System.err.println("Could not create directory " + directory); } - NIOSequentialFileFactory nio = new NIOSequentialFileFactory(directory, null); + NIOSequentialFileFactory nio = new NIOSequentialFileFactory(new File(directory), null); JournalImpl journal = new JournalImpl(fileSize, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java index 093874cec0..8b0721b497 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/EncodeJournal.java @@ -17,6 +17,7 @@ package org.apache.activemq.artemis.cli.commands.tools; import java.io.BufferedOutputStream; +import java.io.File; import java.io.FileOutputStream; import java.io.PrintStream; import java.util.List; @@ -112,7 +113,7 @@ public class EncodeJournal extends Configurable implements Action final int fileSize, final PrintStream out) throws Exception { - NIOSequentialFileFactory nio = new NIOSequentialFileFactory(directory, null); + NIOSequentialFileFactory nio = new NIOSequentialFileFactory(new File(directory), null); JournalImpl journal = new JournalImpl(fileSize, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1); diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java index d2b2f996ae..c9d2e10828 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/PrintData.java @@ -65,7 +65,7 @@ public class PrintData extends DataAbstract implements Action super.execute(context); try { - printData(getBinding(), getJournal(), getPaging()); + printData(new File(getBinding()), new File(getJournal()), new File(getPaging())); } catch (Exception e) { @@ -74,7 +74,7 @@ public class PrintData extends DataAbstract implements Action return null; } - public static void printData(String bindingsDirectory, String messagesDirectory, String pagingDirectory) throws Exception + public static void printData(File bindingsDirectory, File messagesDirectory, File pagingDirectory) throws Exception { // Having the version on the data report is an information very useful to understand what happened // When debugging stuff @@ -148,7 +148,7 @@ public class PrintData extends DataAbstract implements Action } - private static void printPages(String pageDirectory, DescribeJournal describeJournal) + private static void printPages(File pageDirectory, DescribeJournal describeJournal) { try { @@ -181,7 +181,7 @@ public class PrintData extends DataAbstract implements Action for (SimpleString store : stores) { PagingStore pgStore = manager.getPageStore(store); - String folder = null; + File folder = null; if (pgStore != null) { diff --git a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java index b3615c0e74..e099a0ba0e 100644 --- a/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java +++ b/artemis-cli/src/main/java/org/apache/activemq/artemis/cli/commands/tools/XmlDataExporter.java @@ -19,6 +19,7 @@ package org.apache.activemq.artemis.cli.commands.tools; import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; +import java.io.File; import java.io.OutputStream; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Method; @@ -344,7 +345,7 @@ public final class XmlDataExporter extends DataAbstract implements Action private void getJmsBindings() throws Exception { - SequentialFileFactory bindingsJMS = new NIOSequentialFileFactory(config.getBindingsDirectory()); + SequentialFileFactory bindingsJMS = new NIOSequentialFileFactory(config.getBindingsLocation()); Journal jmsJournal = new JournalImpl(1024 * 1024, 2, @@ -764,7 +765,7 @@ public final class XmlDataExporter extends DataAbstract implements Action } }; PagingStoreFactory pageStoreFactory = - new PagingStoreFactoryNIO(storageManager, config.getPagingDirectory(), 1000L, scheduled, executorFactory, true, + new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), 1000L, scheduled, executorFactory, true, null); HierarchicalRepository addressSettingsRepository = new HierarchicalObjectRepository<>(); addressSettingsRepository.setDefault(new AddressSettings()); @@ -780,7 +781,7 @@ public final class XmlDataExporter extends DataAbstract implements Action if (pageStore != null) { - String folder = pageStore.getFolder(); + File folder = pageStore.getFolder(); ActiveMQServerLogger.LOGGER.debug("Reading page store " + store + " folder = " + folder); int pageId = (int) pageStore.getFirstPage(); diff --git a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java index ce686609e8..46c9bf251c 100644 --- a/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java +++ b/artemis-jms-server/src/main/java/org/apache/activemq/artemis/jms/persistence/impl/journal/JMSJournalStorageManagerImpl.java @@ -57,8 +57,6 @@ public final class JMSJournalStorageManagerImpl implements JMSStorageManager private final IDGenerator idGenerator; - private final String journalDir; - private final boolean createDir; private final Journal jmsJournal; @@ -71,6 +69,8 @@ public final class JMSJournalStorageManagerImpl implements JMSStorageManager private final Map, PersistedBindings> mapBindings = new ConcurrentHashMap, PersistedBindings>(); + private final Configuration config; + // Static -------------------------------------------------------- // Constructors -------------------------------------------------- @@ -83,17 +83,11 @@ public final class JMSJournalStorageManagerImpl implements JMSStorageManager throw new IllegalArgumentException("Only NIO and AsyncIO are supported journals"); } - // Will use the same place as the bindings directory from the core journal - journalDir = config.getBindingsDirectory(); - - if (journalDir == null) - { - throw new NullPointerException("bindings-dir is null"); - } + this.config = config; createDir = config.isCreateBindingsDir(); - SequentialFileFactory bindingsJMS = new NIOSequentialFileFactory(journalDir); + SequentialFileFactory bindingsJMS = new NIOSequentialFileFactory(config.getJournalLocation()); Journal localJMS = new JournalImpl(1024 * 1024, 2, @@ -265,7 +259,7 @@ public final class JMSJournalStorageManagerImpl implements JMSStorageManager public void start() throws Exception { - checkAndCreateDir(journalDir, createDir); + checkAndCreateDir(config.getJournalLocation(), createDir); jmsJournal.start(); @@ -335,15 +329,14 @@ public final class JMSJournalStorageManagerImpl implements JMSStorageManager // Private ------------------------------------------------------- - private void checkAndCreateDir(final String dir, final boolean create) + private void checkAndCreateDir(final File dir, final boolean create) { - File f = new File(dir); - if (!f.exists()) + if (!dir.exists()) { if (create) { - if (!f.mkdirs()) + if (!dir.mkdirs()) { throw new IllegalStateException("Failed to create directory " + dir); } diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/SequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/SequentialFileFactory.java index 867b3b5334..cb47bd9cd3 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/SequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/SequentialFileFactory.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.journal; +import java.io.File; import java.nio.ByteBuffer; import java.util.List; @@ -71,7 +72,7 @@ public interface SequentialFileFactory int calculateBlockSize(int bytes); - String getDirectory(); + File getDirectory(); void clearBuffer(ByteBuffer buffer); diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFile.java index 27c1835847..acef8a5db9 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFile.java @@ -46,14 +46,14 @@ public class AIOSequentialFile extends AbstractSequentialFile implements IOExcep public AIOSequentialFile(final SequentialFileFactory factory, final int bufferSize, final long bufferTimeoutMilliseconds, - final String directory, + final File directory, final String fileName, final int maxIO, final BufferCallback bufferCallback, final Executor writerExecutor, final Executor pollerExecutor) { - super(directory, new File(directory + "/" + fileName), factory, writerExecutor); + super(directory, fileName, factory, writerExecutor); this.maxIO = maxIO; this.bufferCallback = bufferCallback; this.pollerExecutor = pollerExecutor; @@ -85,8 +85,8 @@ public class AIOSequentialFile extends AbstractSequentialFile implements IOExcep return new AIOSequentialFile(factory, -1, -1, - getFile().getParent(), - getFileName(), + getFile().getParentFile(), + getFile().getName(), maxIO, bufferCallback, writerExecutor, diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFileFactory.java index db7d8ed357..65e6a6fbf4 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AIOSequentialFileFactory.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.journal.impl; +import java.io.File; import java.nio.ByteBuffer; import java.security.AccessController; import java.security.PrivilegedAction; @@ -49,7 +50,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor ActiveMQJournalLogger.LOGGER.trace(message); } - public AIOSequentialFileFactory(final String journalDir) + public AIOSequentialFileFactory(final File journalDir) { this(journalDir, JournalConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, @@ -58,7 +59,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor null); } - public AIOSequentialFileFactory(final String journalDir, final IOCriticalErrorListener listener) + public AIOSequentialFileFactory(final File journalDir, final IOCriticalErrorListener listener) { this(journalDir, JournalConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, @@ -67,7 +68,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor listener); } - public AIOSequentialFileFactory(final String journalDir, + public AIOSequentialFileFactory(final File journalDir, final int bufferSize, final int bufferTimeout, final boolean logRates) @@ -75,7 +76,7 @@ public final class AIOSequentialFileFactory extends AbstractSequentialFileFactor this(journalDir, bufferSize, bufferTimeout, logRates, null); } - public AIOSequentialFileFactory(final String journalDir, + public AIOSequentialFileFactory(final File journalDir, final int bufferSize, final int bufferTimeout, final boolean logRates, diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFile.java index 7e1b0f88a7..a4eed58038 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFile.java @@ -41,7 +41,7 @@ public abstract class AbstractSequentialFile implements SequentialFile private File file; - private final String directory; + protected final File directory; protected final SequentialFileFactory factory; @@ -66,13 +66,13 @@ public abstract class AbstractSequentialFile implements SequentialFile * @param file * @param directory */ - public AbstractSequentialFile(final String directory, - final File file, + public AbstractSequentialFile(final File directory, + final String file, final SequentialFileFactory factory, final Executor writerExecutor) { super(); - this.file = file; + this.file = new File(directory, file); this.directory = directory; this.factory = factory; this.writerExecutor = writerExecutor; diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFileFactory.java index f7360019cf..ec0ab4d5ee 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/AbstractSequentialFileFactory.java @@ -45,7 +45,7 @@ abstract class AbstractSequentialFileFactory implements SequentialFileFactory // Timeout used to wait executors to shutdown protected static final int EXECUTOR_TIMEOUT = 60; - protected final String journalDir; + protected final File journalDir; protected final TimedBuffer timedBuffer; @@ -62,7 +62,7 @@ abstract class AbstractSequentialFileFactory implements SequentialFileFactory * */ protected ExecutorService writeExecutor; - AbstractSequentialFileFactory(final String journalDir, + AbstractSequentialFileFactory(final File journalDir, final boolean buffered, final int bufferSize, final int bufferTimeout, @@ -109,7 +109,8 @@ abstract class AbstractSequentialFileFactory implements SequentialFileFactory } } - public String getDirectory() + @Override + public File getDirectory() { return journalDir; } @@ -175,8 +176,7 @@ abstract class AbstractSequentialFileFactory implements SequentialFileFactory */ public void createDirs() throws Exception { - File file = new File(journalDir); - boolean ok = file.mkdirs(); + boolean ok = journalDir.mkdirs(); if (!ok) { throw new IOException("Failed to create directory " + journalDir); @@ -185,8 +185,6 @@ abstract class AbstractSequentialFileFactory implements SequentialFileFactory public List listFiles(final String extension) throws Exception { - File dir = new File(journalDir); - FilenameFilter fnf = new FilenameFilter() { public boolean accept(final File file, final String name) @@ -195,7 +193,7 @@ abstract class AbstractSequentialFileFactory implements SequentialFileFactory } }; - String[] fileNames = dir.list(fnf); + String[] fileNames = journalDir.list(fnf); if (fileNames == null) { diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java index 7586990fd2..6f5b75c929 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/CompactJournal.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.core.journal.impl; +import java.io.File; + import org.apache.activemq.artemis.core.journal.IOCriticalErrorListener; /** @@ -38,7 +40,7 @@ public final class CompactJournal // NO_UCD try { - CompactJournal.compactJournal(arg[0], arg[1], arg[2], 2, Integer.parseInt(arg[3]), null); + CompactJournal.compactJournal(new File(arg[0]), arg[1], arg[2], 2, Integer.parseInt(arg[3]), null); } catch (Exception e) { @@ -47,7 +49,7 @@ public final class CompactJournal // NO_UCD } - static void compactJournal(final String directory, + static void compactJournal(final File directory, final String journalPrefix, final String journalSuffix, final int minFiles, diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFile.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFile.java index 65ec8afec8..0dac7f2ed4 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFile.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFile.java @@ -51,21 +51,12 @@ public final class NIOSequentialFile extends AbstractSequentialFile private int maxIO; public NIOSequentialFile(final SequentialFileFactory factory, - final String directory, - final String fileName, + final File directory, + final String file, final int maxIO, final Executor writerExecutor) { - super(directory, new File(directory + "/" + fileName), factory, writerExecutor); - defaultMaxIO = maxIO; - } - - public NIOSequentialFile(final SequentialFileFactory factory, - final File file, - final int maxIO, - final Executor writerExecutor) - { - super(file.getParent(), new File(file.getPath()), factory, writerExecutor); + super(directory, file, factory, writerExecutor); defaultMaxIO = maxIO; } @@ -284,7 +275,7 @@ public final class NIOSequentialFile extends AbstractSequentialFile public SequentialFile cloneFile() { - return new NIOSequentialFile(factory, getFile(), maxIO, writerExecutor); + return new NIOSequentialFile(factory, directory, getFileName(), maxIO, writerExecutor); } public void writeDirect(final ByteBuffer bytes, final boolean sync, final IOAsyncTask callback) diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFileFactory.java index ad9d2fa535..e4719280c4 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/NIOSequentialFileFactory.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.journal.impl; +import java.io.File; import java.lang.ref.WeakReference; import java.nio.ByteBuffer; @@ -24,12 +25,12 @@ import org.apache.activemq.artemis.core.journal.SequentialFile; public class NIOSequentialFileFactory extends AbstractSequentialFileFactory { - public NIOSequentialFileFactory(final String journalDir) + public NIOSequentialFileFactory(final File journalDir) { this(journalDir, null); } - public NIOSequentialFileFactory(final String journalDir, final IOCriticalErrorListener listener) + public NIOSequentialFileFactory(final File journalDir, final IOCriticalErrorListener listener) { this(journalDir, false, @@ -39,12 +40,12 @@ public class NIOSequentialFileFactory extends AbstractSequentialFileFactory listener); } - public NIOSequentialFileFactory(final String journalDir, final boolean buffered) + public NIOSequentialFileFactory(final File journalDir, final boolean buffered) { this(journalDir, buffered, null); } - public NIOSequentialFileFactory(final String journalDir, + public NIOSequentialFileFactory(final File journalDir, final boolean buffered, final IOCriticalErrorListener listener) { @@ -56,7 +57,7 @@ public class NIOSequentialFileFactory extends AbstractSequentialFileFactory listener); } - public NIOSequentialFileFactory(final String journalDir, + public NIOSequentialFileFactory(final File journalDir, final boolean buffered, final int bufferSize, final int bufferTimeout, @@ -65,7 +66,7 @@ public class NIOSequentialFileFactory extends AbstractSequentialFileFactory this(journalDir, buffered, bufferSize, bufferTimeout, logRates, null); } - public NIOSequentialFileFactory(final String journalDir, + public NIOSequentialFileFactory(final File journalDir, final boolean buffered, final int bufferSize, final int bufferTimeout, diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/SyncSpeedTest.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/SyncSpeedTest.java index f6d7758b00..0c982dc917 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/SyncSpeedTest.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/journal/impl/SyncSpeedTest.java @@ -59,11 +59,11 @@ public class SyncSpeedTest { if (AIO) { - fileFactory = new AIOSequentialFileFactory(".", 0, 0, false, null); + fileFactory = new AIOSequentialFileFactory(new File("."), 0, 0, false, null); } else { - fileFactory = new NIOSequentialFileFactory(".", false, 0, 0, false, null); + fileFactory = new NIOSequentialFileFactory(new File("."), false, 0, 0, false, null); } } @@ -74,7 +74,7 @@ public class SyncSpeedTest return new AIOSequentialFile(fileFactory, 0, 0, - ".", + new File("."), fileName, 100000, null, @@ -83,7 +83,7 @@ public class SyncSpeedTest } else { - return new NIOSequentialFile(fileFactory, new File(fileName), 1000, null); + return new NIOSequentialFile(fileFactory, new File("."), fileName, 1000, null); } } diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/InVMNodeManagerServer.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/InVMNodeManagerServer.java index 139088c6e8..b8b1a67e9f 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/InVMNodeManagerServer.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/maven/InVMNodeManagerServer.java @@ -18,6 +18,8 @@ package org.apache.activemq.artemis.maven; import javax.management.MBeanServer; +import java.io.File; + import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; @@ -65,7 +67,7 @@ public final class InVMNodeManagerServer extends ActiveMQServerImpl } @Override - protected NodeManager createNodeManager(final String directory, boolean replicatingBackup) + protected NodeManager createNodeManager(final File directory, boolean replicatingBackup) { return nodeManager; } diff --git a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/server/ActiveMQBootstrap.java b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/server/ActiveMQBootstrap.java index 0e29bb56d4..35f38da1d8 100644 --- a/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/server/ActiveMQBootstrap.java +++ b/artemis-maven-plugin/src/main/java/org/apache/activemq/artemis/server/ActiveMQBootstrap.java @@ -174,7 +174,7 @@ public class ActiveMQBootstrap if (nodeManager == null) { boolean replicatedBackup = configuration.getHAPolicyConfiguration().getType() == HAPolicyConfiguration.TYPE.REPLICA; - nodeManager = new InVMNodeManager(replicatedBackup, configuration.getJournalDirectory()); + nodeManager = new InVMNodeManager(replicatedBackup, configuration.getJournalLocation()); managerMap.put(nodeId, nodeManager); } server = new InVMNodeManagerServer(configuration, ManagementFactory.getPlatformMBeanServer(), diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java index a78c5b5421..0c1bc3caca 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/Configuration.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.config; +import java.io.File; import java.util.List; import java.util.Map; import java.util.Set; @@ -434,6 +435,11 @@ public interface Configuration */ String getBindingsDirectory(); + /** + * The binding location related to artemis.instance. + */ + File getBindingsLocation(); + /** * Sets the file system directory used to store bindings. */ @@ -459,6 +465,12 @@ public interface Configuration */ String getJournalDirectory(); + /** + * The location of the journal related to artemis.instance. + * @return + */ + File getJournalLocation(); + /** * Sets the file system directory used to store journal log. */ @@ -675,6 +687,12 @@ public interface Configuration */ Configuration setPagingDirectory(String dir); + + /** + * The paging location related to artemis.instance + */ + File getPagingLocation(); + // Large Messages Properties ------------------------------------------------------------ /** @@ -683,6 +701,9 @@ public interface Configuration */ String getLargeMessagesDirectory(); + /** The large message location related to artemis.instance */ + File getLargeMessagesLocation(); + /** * Sets the file system directory used to store large messages. */ @@ -864,4 +885,15 @@ public interface Configuration HAPolicyConfiguration getHAPolicyConfiguration(); Configuration setHAPolicyConfiguration(HAPolicyConfiguration haPolicyConfiguration); + + /** + * Set the Artemis instance relative folder for data and stuff. + */ + void setArtemisInstance(File directory); + + /** + * Set the Artemis instance relative folder for data and stuff. + */ + File getArtemisInstance(); + } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java index 7f77acc600..aa1443491f 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/config/impl/ConfigurationImpl.java @@ -18,9 +18,11 @@ package org.apache.activemq.artemis.core.config.impl; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; +import java.io.File; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.Serializable; +import java.net.URI; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -217,6 +219,11 @@ public class ConfigurationImpl implements Configuration, Serializable private HAPolicyConfiguration haPolicyConfiguration; + /** + * Parent folder for all data folders. + */ + private File artemisInstance; + // Public ------------------------------------------------------------------------- public boolean isClustered() @@ -524,6 +531,11 @@ public class ConfigurationImpl implements Configuration, Serializable return this; } + public File getBindingsLocation() + { + return subFolder(getBindingsDirectory()); + } + public String getBindingsDirectory() { return bindingsDirectory; @@ -549,6 +561,10 @@ public class ConfigurationImpl implements Configuration, Serializable return this; } + public File getJournalLocation() + { + return subFolder(getJournalDirectory()); + } public String getJournalDirectory() { @@ -572,6 +588,11 @@ public class ConfigurationImpl implements Configuration, Serializable return this; } + public File getPagingLocation() + { + return subFolder(getPagingDirectory()); + } + public String getPagingDirectory() { return pagingDirectory; @@ -797,6 +818,11 @@ public class ConfigurationImpl implements Configuration, Serializable return largeMessagesDirectory; } + public File getLargeMessagesLocation() + { + return subFolder(getLargeMessagesDirectory()); + } + public ConfigurationImpl setLargeMessagesDirectory(final String directory) { largeMessagesDirectory = directory; @@ -1077,6 +1103,30 @@ public class ConfigurationImpl implements Configuration, Serializable return this.connectorServiceConfigurations; } + public File getArtemisInstance() + { + if (artemisInstance != null) + { + return artemisInstance; + } + + String strartemisInstance = System.getProperty("artemis.instance"); + + if (strartemisInstance == null) + { + strartemisInstance = System.getProperty("user.dir"); + } + + artemisInstance = new File(strartemisInstance); + + return artemisInstance; + } + + public void setArtemisInstance(File directory) + { + this.artemisInstance = directory; + } + public boolean isCheckForLiveServer() { if (haPolicyConfiguration instanceof ReplicaPolicyConfiguration) @@ -1568,4 +1618,23 @@ public class ConfigurationImpl implements Configuration, Serializable this.haPolicyConfiguration = haPolicyConfiguration; return this; } + + /** + * It will find the right location of a subFolder, related to artemisInstance + */ + private File subFolder(String subFolder) + { + try + { + // Resolve wont work without "/" as the last character + URI artemisHome = new URI(getArtemisInstance().toURI() + "/"); + URI relative = artemisHome.resolve(subFolder); + return new File(relative.getPath()); + } + catch (Exception e) + { + throw new RuntimeException(e); + } + } + } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/PagingStore.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/PagingStore.java index 735c6dbcea..3b74e45aca 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/PagingStore.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/PagingStore.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.paging; +import java.io.File; import java.util.Collection; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; @@ -53,7 +54,7 @@ public interface PagingStore extends ActiveMQComponent SimpleString getStoreName(); - String getFolder(); + File getFolder(); AddressFullMessagePolicy getAddressFullMessagePolicy(); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryNIO.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryNIO.java index b6b9b72bef..3a12b96047 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryNIO.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreFactoryNIO.java @@ -55,7 +55,7 @@ public class PagingStoreFactoryNIO implements PagingStoreFactory // Attributes ---------------------------------------------------- - private final String directory; + private final File directory; private final ExecutorFactory executorFactory; @@ -71,7 +71,7 @@ public class PagingStoreFactoryNIO implements PagingStoreFactory private final IOCriticalErrorListener critialErrorListener; - public PagingStoreFactoryNIO(final StorageManager storageManager, final String directory, + public PagingStoreFactoryNIO(final StorageManager storageManager, final File directory, final long syncTimeout, final ScheduledExecutorService scheduledExecutor, final ExecutorFactory executorFactory, @@ -118,7 +118,7 @@ public class PagingStoreFactoryNIO implements PagingStoreFactory factory.createDirs(); - File fileWithID = new File(directory + File.separatorChar + + File fileWithID = new File(directory, guid + File.separatorChar + PagingStoreFactoryNIO.ADDRESS_FILE); @@ -145,9 +145,7 @@ public class PagingStoreFactoryNIO implements PagingStoreFactory public List reloadStores(final HierarchicalRepository addressSettingsRepository) throws Exception { - File pageDirectory = new File(directory); - - File[] files = pageDirectory.listFiles(); + File[] files = directory.listFiles(); if (files == null) { @@ -210,6 +208,6 @@ public class PagingStoreFactoryNIO implements PagingStoreFactory private SequentialFileFactory newFileFactory(final String directoryName) { - return new NIOSequentialFileFactory(directory + File.separatorChar + directoryName, false, critialErrorListener); + return new NIOSequentialFileFactory(new File(directory, directoryName), false, critialErrorListener); } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java index 53a7bc9bbe..78cbbc3728 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/paging/impl/PagingStoreImpl.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.paging.impl; +import java.io.File; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; @@ -264,7 +265,7 @@ public class PagingStoreImpl implements PagingStore return pageSize; } - public String getFolder() + public File getFolder() { SequentialFileFactory factoryUsed = this.fileFactory; if (factoryUsed != null) 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 b6972bad2d..3c251642e8 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 @@ -17,6 +17,7 @@ package org.apache.activemq.artemis.core.persistence.impl.journal; import javax.transaction.xa.Xid; +import java.io.File; import java.io.PrintStream; import java.util.HashMap; import java.util.LinkedList; @@ -105,7 +106,7 @@ public final class DescribeJournal return preparedTransactions; } - public static void describeBindingsJournal(final String bindingsDir) throws Exception + public static void describeBindingsJournal(final File bindingsDir) throws Exception { SequentialFileFactory bindingsFF = new NIOSequentialFileFactory(bindingsDir, null); @@ -114,7 +115,7 @@ public final class DescribeJournal describeJournal(bindingsFF, bindings, bindingsDir); } - public static DescribeJournal describeMessagesJournal(final String messagesDir) throws Exception + public static DescribeJournal describeMessagesJournal(final File messagesDir) throws Exception { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(messagesDir, null); @@ -139,7 +140,7 @@ public final class DescribeJournal * @param journal * @throws Exception */ - private static DescribeJournal describeJournal(SequentialFileFactory fileFactory, JournalImpl journal, final String path) throws Exception + private static DescribeJournal describeJournal(SequentialFileFactory fileFactory, JournalImpl journal, final File path) throws Exception { List files = journal.orderFiles(); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java index b3508f7cce..e74215dea9 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/persistence/impl/journal/JournalStorageManager.java @@ -201,18 +201,12 @@ public class JournalStorageManager implements StorageManager private final int perfBlastPages; - private final boolean createBindingsDir; - - private final String bindingsDir; - - private final boolean createJournalDir; - - private final String journalDir; - private final String largeMessagesDirectory; private boolean journalLoaded = false; + private final Configuration config; + // Persisted core configuration private final Map mapPersistedRoles = new ConcurrentHashMap(); @@ -232,6 +226,8 @@ public class JournalStorageManager implements StorageManager { this.executorFactory = executorFactory; + this.config = config; + executor = executorFactory.getExecutor(); if (config.getJournalType() != JournalType.NIO && config.getJournalType() != JournalType.ASYNCIO) @@ -239,17 +235,8 @@ public class JournalStorageManager implements StorageManager throw ActiveMQMessageBundle.BUNDLE.invalidJournal(); } - bindingsDir = config.getBindingsDirectory(); - if (bindingsDir == null) - { - throw new NullPointerException("bindings-dir is null"); - } - createBindingsDir = config.isCreateBindingsDir(); - - journalDir = config.getJournalDirectory(); - - SequentialFileFactory bindingsFF = new NIOSequentialFileFactory(bindingsDir, criticalErrorListener); + SequentialFileFactory bindingsFF = new NIOSequentialFileFactory(config.getBindingsLocation(), criticalErrorListener); Journal localBindings = new JournalImpl(1024 * 1024, 2, @@ -263,13 +250,6 @@ public class JournalStorageManager implements StorageManager bindingsJournal = localBindings; originalBindingsJournal = localBindings; - if (journalDir == null) - { - throw new NullPointerException("journal-dir is null"); - } - - createJournalDir = config.isCreateJournalDir(); - syncNonTransactional = config.isJournalSyncNonTransactional(); syncTransactional = config.isJournalSyncTransactional(); @@ -278,7 +258,7 @@ public class JournalStorageManager implements StorageManager { ActiveMQServerLogger.LOGGER.journalUseAIO(); - journalFF = new AIOSequentialFileFactory(journalDir, + journalFF = new AIOSequentialFileFactory(config.getJournalLocation(), config.getJournalBufferSize_AIO(), config.getJournalBufferTimeout_AIO(), config.isLogJournalWriteRate(), @@ -287,7 +267,7 @@ public class JournalStorageManager implements StorageManager else if (config.getJournalType() == JournalType.NIO) { ActiveMQServerLogger.LOGGER.journalUseNIO(); - journalFF = new NIOSequentialFileFactory(journalDir, + journalFF = new NIOSequentialFileFactory(config.getJournalLocation(), true, config.getJournalBufferSize_NIO(), config.getJournalBufferTimeout_NIO(), @@ -316,7 +296,7 @@ public class JournalStorageManager implements StorageManager largeMessagesDirectory = config.getLargeMessagesDirectory(); - largeMessagesFactory = new NIOSequentialFileFactory(largeMessagesDirectory, false, criticalErrorListener); + largeMessagesFactory = new NIOSequentialFileFactory(config.getLargeMessagesLocation(), false, criticalErrorListener); perfBlastPages = config.getJournalPerfBlastPages(); @@ -2242,11 +2222,11 @@ public class JournalStorageManager implements StorageManager return; } - checkAndCreateDir(bindingsDir, createBindingsDir); + checkAndCreateDir(config.getBindingsLocation(), config.isCreateBindingsDir()); - checkAndCreateDir(journalDir, createJournalDir); + checkAndCreateDir(config.getJournalLocation(), config.isCreateJournalDir()); - checkAndCreateDir(largeMessagesDirectory, createJournalDir); + checkAndCreateDir(config.getLargeMessagesLocation(), config.isCreateJournalDir()); cleanupIncompleteFiles(); @@ -2524,22 +2504,20 @@ public class JournalStorageManager implements StorageManager // Private ---------------------------------------------------------------------------------- - private void checkAndCreateDir(final String dir, final boolean create) + private void checkAndCreateDir(final File dir, final boolean create) { - File f = new File(dir); - - if (!f.exists()) + if (!dir.exists()) { if (create) { - if (!f.mkdirs()) + if (!dir.mkdirs()) { throw new IllegalStateException("Failed to create directory " + dir); } } else { - throw ActiveMQMessageBundle.BUNDLE.cannotCreateDir(dir); + throw ActiveMQMessageBundle.BUNDLE.cannotCreateDir(dir.getAbsolutePath()); } } } diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java index 63443a74ef..ec16825b86 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/replication/ReplicationEndpoint.java @@ -294,7 +294,7 @@ public final class ReplicationEndpoint implements ChannelHandler, ActiveMQCompon } pageManager = - new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, config.getPagingDirectory(), + new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, config.getPagingLocation(), config.getJournalBufferSize_NIO(), server.getScheduledPool(), server.getExecutorFactory(), diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java index 756be5ffc3..82b6398098 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/NodeManager.java @@ -34,7 +34,7 @@ public abstract class NodeManager implements ActiveMQComponent private static final String ACCESS_MODE = "rw"; protected final boolean replicatedBackup; - private final String directory; + private final File directory; private final Object nodeIDGuard = new Object(); private SimpleString nodeID; private UUID uuid; @@ -42,7 +42,7 @@ public abstract class NodeManager implements ActiveMQComponent protected FileChannel channel; - public NodeManager(final boolean replicatedBackup, final String directory) + public NodeManager(final boolean replicatedBackup, final File directory) { this.directory = directory; this.replicatedBackup = replicatedBackup; diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AIOFileLockNodeManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AIOFileLockNodeManager.java index e591547f19..7adee2e28b 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AIOFileLockNodeManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/AIOFileLockNodeManager.java @@ -39,12 +39,12 @@ public final class AIOFileLockNodeManager extends FileLockNodeManager * @param directory * @param replicatingBackup */ - public AIOFileLockNodeManager(final String directory, boolean replicatingBackup) + public AIOFileLockNodeManager(final File directory, boolean replicatingBackup) { super(directory, replicatingBackup); } - public AIOFileLockNodeManager(final String directory, boolean replicatingBackup, long lockAcquisitionTimeout) + public AIOFileLockNodeManager(final File directory, boolean replicatingBackup, long lockAcquisitionTimeout) { super(directory, replicatingBackup); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java index d3c1722ee0..f0db70f9fd 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java @@ -353,7 +353,7 @@ public class ActiveMQServerImpl implements ActiveMQServer /* * Can be overridden for tests */ - protected NodeManager createNodeManager(final String directory, boolean replicatingBackup) + protected NodeManager createNodeManager(final File directory, boolean replicatingBackup) { NodeManager manager; if (!configuration.isPersistenceEnabled()) @@ -396,7 +396,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { checkJournalDirectory(); - nodeManager = createNodeManager(configuration.getJournalDirectory(), false); + nodeManager = createNodeManager(configuration.getJournalLocation(), false); nodeManager.start(); @@ -500,7 +500,7 @@ public class ActiveMQServerImpl implements ActiveMQServer { nodeManager.stop(); nodeManager = - createNodeManager(configuration.getJournalDirectory(), true); + createNodeManager(configuration.getJournalLocation(), true); } public Activation getActivation() @@ -1603,7 +1603,7 @@ public class ActiveMQServerImpl implements ActiveMQServer private PagingManager createPagingManager() { - return new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, configuration.getPagingDirectory(), + return new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, configuration.getPagingLocation(), configuration.getJournalBufferTimeout_NIO(), scheduledPool, executorFactory, @@ -2240,7 +2240,7 @@ public class ActiveMQServerImpl implements ActiveMQServer */ void checkJournalDirectory() { - File journalDir = new File(configuration.getJournalDirectory()); + File journalDir = configuration.getJournalLocation(); if (!journalDir.exists() && configuration.isPersistenceEnabled()) { diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileLockNodeManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileLockNodeManager.java index 8a1151d239..62902c9157 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileLockNodeManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/FileLockNodeManager.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.core.server.impl; +import java.io.File; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.FileLock; @@ -50,12 +51,12 @@ public class FileLockNodeManager extends NodeManager protected boolean interrupted = false; - public FileLockNodeManager(final String directory, boolean replicatedBackup) + public FileLockNodeManager(final File directory, boolean replicatedBackup) { super(replicatedBackup, directory); } - public FileLockNodeManager(final String directory, boolean replicatedBackup, long lockAcquisitionTimeout) + public FileLockNodeManager(final File directory, boolean replicatedBackup, long lockAcquisitionTimeout) { super(replicatedBackup, directory); diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java index 2c1afe2f08..dfd74a4e55 100644 --- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java +++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/InVMNodeManager.java @@ -16,11 +16,7 @@ */ package org.apache.activemq.artemis.core.server.impl; -import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.LIVE; -import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.FAILING_BACK; -import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.NOT_STARTED; -import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.PAUSED; - +import java.io.File; import java.io.IOException; import java.util.concurrent.Semaphore; @@ -29,6 +25,11 @@ import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.utils.UUIDGenerator; +import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.FAILING_BACK; +import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.LIVE; +import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.NOT_STARTED; +import static org.apache.activemq.artemis.core.server.impl.InVMNodeManager.State.PAUSED; + /** * NodeManager used to run multiple servers in the same VM. *

@@ -59,7 +60,7 @@ public final class InVMNodeManager extends NodeManager throw new RuntimeException("if replicated-backup, we need its journal directory"); } - public InVMNodeManager(boolean replicatedBackup, String directory) + public InVMNodeManager(boolean replicatedBackup, File directory) { super(replicatedBackup, directory); liveLock = new Semaphore(1); diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java index c689cf207b..8a98be99cc 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ActiveMQTestBase.java @@ -897,6 +897,11 @@ public abstract class ActiveMQTestBase extends Assert return testDir; } + protected final File getTestDirfile() + { + return new File(testDir); + } + protected final void setTestDir(String testDir) { this.testDir = testDir; @@ -983,6 +988,12 @@ public abstract class ActiveMQTestBase extends Assert return getPageDir(getTestDir()); } + protected File getPageDirFile() + { + return new File(getPageDir()); + + } + /** * @return the pageDir */ @@ -1883,7 +1894,7 @@ public abstract class ActiveMQTestBase extends Assert JournalImpl messagesJournal = null; try { - SequentialFileFactory messagesFF = new NIOSequentialFileFactory(getJournalDir(), null); + SequentialFileFactory messagesFF = new NIOSequentialFileFactory(new File(getJournalDir()), null); messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), @@ -1929,7 +1940,7 @@ public abstract class ActiveMQTestBase extends Assert protected HashMap countJournal(Configuration config) throws Exception { final HashMap recordsType = new HashMap(); - SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getJournalDirectory(), null); + SequentialFileFactory messagesFF = new NIOSequentialFileFactory(config.getJournalLocation(), null); JournalImpl messagesJournal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), @@ -1977,7 +1988,7 @@ public abstract class ActiveMQTestBase extends Assert if (messageJournal) { - ff = new NIOSequentialFileFactory(config.getJournalDirectory(), null); + ff = new NIOSequentialFileFactory(config.getJournalLocation(), null); journal = new JournalImpl(config.getJournalFileSize(), config.getJournalMinFiles(), 0, @@ -1989,7 +2000,7 @@ public abstract class ActiveMQTestBase extends Assert } else { - ff = new NIOSequentialFileFactory(config.getBindingsDirectory(), null); + ff = new NIOSequentialFileFactory(config.getJournalLocation(), null); journal = new JournalImpl(1024 * 1024, 2, config.getJournalCompactMinFiles(), diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ColocatedActiveMQServer.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ColocatedActiveMQServer.java index 7ad1afece5..4f9dd48833 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ColocatedActiveMQServer.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/ColocatedActiveMQServer.java @@ -18,6 +18,8 @@ package org.apache.activemq.artemis.tests.util; import javax.management.MBeanServer; +import java.io.File; + import org.apache.activemq.artemis.core.asyncio.impl.AsynchronousFileImpl; import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.config.impl.FileConfiguration; @@ -62,7 +64,7 @@ public class ColocatedActiveMQServer extends ActiveMQServerImpl @Override protected NodeManager - createNodeManager(final String directory, boolean replicatingBackup) + createNodeManager(final File directory, boolean replicatingBackup) { if (replicatingBackup) { diff --git a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/InVMNodeManagerServer.java b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/InVMNodeManagerServer.java index c1409bc692..ea887e13dd 100644 --- a/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/InVMNodeManagerServer.java +++ b/artemis-server/src/test/java/org/apache/activemq/artemis/tests/util/InVMNodeManagerServer.java @@ -18,6 +18,8 @@ package org.apache.activemq.artemis.tests.util; import javax.management.MBeanServer; +import java.io.File; + import org.apache.activemq.artemis.core.config.Configuration; import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; @@ -65,7 +67,7 @@ public final class InVMNodeManagerServer extends ActiveMQServerImpl } @Override - protected NodeManager createNodeManager(final String directory, boolean replicatingBackup) + protected NodeManager createNodeManager(final File directory, boolean replicatingBackup) { return nodeManager; } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/HangConsumerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/HangConsumerTest.java index 61d061c581..a6bce80e46 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/HangConsumerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/HangConsumerTest.java @@ -16,6 +16,15 @@ */ package org.apache.activemq.artemis.tests.integration.client; +import javax.management.MBeanServer; +import java.lang.management.ManagementFactory; +import java.util.LinkedList; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executor; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; + import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.Interceptor; import org.apache.activemq.artemis.api.core.SimpleString; @@ -62,15 +71,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.management.MBeanServer; -import java.lang.management.ManagementFactory; -import java.util.LinkedList; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Executor; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; - /** * This test will simulate a consumer hanging on the delivery packet due to unbehaved clients * and it will make sure we can still perform certain operations on the queue such as produce @@ -480,7 +480,7 @@ public class HangConsumerTest extends ActiveMQTestBase server.stop(); - SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsDirectory(), null); + SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsLocation(), null); JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java index 22cdbfe52d..e71189fa99 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/JournalCrashTest.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.tests.integration.client; +import java.io.File; import java.util.ArrayList; import java.util.Arrays; @@ -220,7 +221,7 @@ public class JournalCrashTest extends ActiveMQTestBase */ private void printJournal() throws Exception { - NIOSequentialFileFactory factory = new NIOSequentialFileFactory(getJournalDir()); + NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir())); JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 0, diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/PagingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/PagingTest.java index 8599524b2a..9d0d4d7ad6 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/PagingTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/PagingTest.java @@ -16,6 +16,23 @@ */ package org.apache.activemq.artemis.tests.integration.client; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; +import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.ActiveMQExceptionType; @@ -62,23 +79,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.transaction.xa.XAResource; -import javax.transaction.xa.Xid; -import java.io.File; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.ByteBuffer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - public class PagingTest extends ActiveMQTestBase { private ServerLocator locator; @@ -1734,7 +1734,7 @@ public class PagingTest extends ActiveMQTestBase 2, 0, 0, - new NIOSequentialFileFactory(server.getConfiguration().getJournalDirectory()), + new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation()), "activemq-data", "amq", 1); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RedeliveryConsumerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RedeliveryConsumerTest.java index 550805e0c5..460c4df6cd 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RedeliveryConsumerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/client/RedeliveryConsumerTest.java @@ -297,7 +297,7 @@ public class RedeliveryConsumerTest extends ActiveMQTestBase 2, 0, 0, - new NIOSequentialFileFactory(server.getConfiguration().getJournalDirectory()), + new NIOSequentialFileFactory(server.getConfiguration().getJournalLocation()), "activemq-data", "amq", 1); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/NodeManagerAction.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/NodeManagerAction.java index ec551b8136..8afe1ce215 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/NodeManagerAction.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/NodeManagerAction.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.tests.integration.cluster; +import java.io.File; + import org.apache.activemq.artemis.core.server.NodeManager; import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager; @@ -128,7 +130,7 @@ public class NodeManagerAction } NodeManagerAction nodeManagerAction = new NodeManagerAction(work1); - FileLockNodeManager nodeManager = new FileLockNodeManager(".", false); + FileLockNodeManager nodeManager = new FileLockNodeManager(new File("."), false); nodeManager.start(); try { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java index c5507971e0..51acdcbcf0 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/RealNodeManagerTest.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.tests.integration.cluster; +import java.io.File; import java.util.ArrayList; import java.util.List; @@ -32,7 +33,7 @@ public class RealNodeManagerTest extends NodeManagerTest @Test public void testId() throws Exception { - NodeManager nodeManager = new FileLockNodeManager(getTemporaryDir(), false); + NodeManager nodeManager = new FileLockNodeManager(new File(getTemporaryDir()), false); nodeManager.start(); UUID id1 = nodeManager.getUUID(); nodeManager.stop(); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeTest.java index 5fea52d875..e88a4bfea8 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/bridge/BridgeTest.java @@ -16,6 +16,18 @@ */ package org.apache.activemq.artemis.tests.integration.cluster.bridge; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Semaphore; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.Interceptor; @@ -67,18 +79,6 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.HashMap; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.Semaphore; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - @RunWith(value = Parameterized.class) public class BridgeTest extends ActiveMQTestBase { @@ -1926,7 +1926,7 @@ public class BridgeTest extends ActiveMQTestBase protected Map loadQueues(ActiveMQServer serverToInvestigate) throws Exception { SequentialFileFactory messagesFF = new NIOSequentialFileFactory(serverToInvestigate.getConfiguration() - .getJournalDirectory()); + .getJournalLocation()); JournalImpl messagesJournal = new JournalImpl(serverToInvestigate.getConfiguration().getJournalFileSize(), serverToInvestigate.getConfiguration().getJournalMinFiles(), diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java index edf6bf9061..f1e3c06f4e 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/distribution/ClusterTestBase.java @@ -16,6 +16,22 @@ */ package org.apache.activemq.artemis.tests.integration.cluster.distribution; +import java.io.File; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.BroadcastGroupConfiguration; @@ -68,21 +84,6 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; -import java.io.PrintWriter; -import java.io.StringWriter; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.LinkedList; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; - public abstract class ClusterTestBase extends ActiveMQTestBase { private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER; @@ -152,7 +153,7 @@ public abstract class ClusterTestBase extends ActiveMQTestBase for (int i = 0, nodeManagersLength = nodeManagers.length; i < nodeManagersLength; i++) { - nodeManagers[i] = new InVMNodeManager(isSharedStore(), getJournalDir(i, true)); + nodeManagers[i] = new InVMNodeManager(isSharedStore(), new File(getJournalDir(i, true))); } locators = new ServerLocator[ClusterTestBase.MAX_SERVERS]; @@ -1717,7 +1718,7 @@ public abstract class ClusterTestBase extends ActiveMQTestBase * backup case. *
* Use - * {@link #setupClusterConnectionWithBackups(String, String, boolean, int, boolean, int, int[])} + * {@link #setupClusterConnectionWithBackups(String, String, org.apache.activemq.artemis.core.server.cluster.impl.MessageLoadBalancingType, int, boolean, int, int[])} * to add it. * * @param node @@ -2169,11 +2170,6 @@ public abstract class ClusterTestBase extends ActiveMQTestBase clusterConfs.add(clusterConf); } - /** - * XXX waitForPrevious actually masks what can be considered a bug: that even controlling for - * {@link org.apache.activemq.artemis.core.server.ActiveMQServer#waitForInitialization} we still need to wait between starting a shared - * store backup and its live. - */ protected void startServers(final int... nodes) throws Exception { for (int node : nodes) diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/BackupSyncJournalTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/BackupSyncJournalTest.java index 3b749bdd3d..a4c96991d0 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/BackupSyncJournalTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/BackupSyncJournalTest.java @@ -16,6 +16,14 @@ */ package org.apache.activemq.artemis.tests.integration.cluster.failover; +import java.io.File; +import java.io.RandomAccessFile; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.HashSet; +import java.util.Set; +import java.util.concurrent.TimeUnit; + import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.Pair; import org.apache.activemq.artemis.api.core.SimpleString; @@ -40,14 +48,6 @@ import org.apache.activemq.artemis.utils.UUID; import org.junit.Before; import org.junit.Test; -import java.io.File; -import java.io.RandomAccessFile; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.util.HashSet; -import java.util.Set; -import java.util.concurrent.TimeUnit; - public class BackupSyncJournalTest extends FailoverTestBase { protected static final int BACKUP_WAIT_TIME = 20; @@ -227,9 +227,9 @@ public class BackupSyncJournalTest extends FailoverTestBase { System.out.println("\n\n BINDINGS JOURNAL\n\n"); Configuration config = server.getServer().getConfiguration(); - DescribeJournal.describeBindingsJournal(config.getBindingsDirectory()); + DescribeJournal.describeBindingsJournal(config.getBindingsLocation()); System.out.println("\n\n MESSAGES JOURNAL\n\n"); - DescribeJournal.describeMessagesJournal(config.getJournalDirectory()); + DescribeJournal.describeMessagesJournal(config.getJournalLocation()); } catch (Exception ignored) { diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTestBase.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTestBase.java index 9a7159e25d..fa23f7ef40 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTestBase.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/cluster/failover/FailoverTestBase.java @@ -16,6 +16,13 @@ */ package org.apache.activemq.artemis.tests.integration.cluster.failover; +import java.io.IOException; +import java.net.ServerSocket; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; + import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.SimpleString; import org.apache.activemq.artemis.api.core.TransportConfiguration; @@ -40,19 +47,12 @@ import org.apache.activemq.artemis.core.server.impl.ActiveMQServerImpl; import org.apache.activemq.artemis.core.server.impl.InVMNodeManager; import org.apache.activemq.artemis.tests.integration.cluster.util.SameProcessActiveMQServer; import org.apache.activemq.artemis.tests.integration.cluster.util.TestableServer; -import org.apache.activemq.artemis.tests.util.ReplicatedBackupUtils; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.apache.activemq.artemis.tests.util.ReplicatedBackupUtils; import org.junit.After; import org.junit.Assert; import org.junit.Before; -import java.io.IOException; -import java.net.ServerSocket; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.TimeUnit; - public abstract class FailoverTestBase extends ActiveMQTestBase { // Constants ----------------------------------------------------- @@ -213,7 +213,7 @@ public abstract class FailoverTestBase extends ActiveMQTestBase .setSecurityEnabled(false); setupHAPolicyConfiguration(); - nodeManager = new InVMNodeManager(true, backupConfig.getJournalDirectory()); + nodeManager = new InVMNodeManager(true, backupConfig.getJournalLocation()); backupServer = createTestableServer(backupConfig); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOImportExportTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOImportExportTest.java index 2dddab9eac..3848dbf3a0 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOImportExportTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOImportExportTest.java @@ -40,6 +40,6 @@ public class AIOImportExportTest extends NIOImportExportTest file.mkdir(); - return new AIOSequentialFileFactory(getTestDir()); + return new AIOSequentialFileFactory(getTestDirfile()); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalCompactTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalCompactTest.java index 65739d01b8..39972e7088 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalCompactTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalCompactTest.java @@ -41,7 +41,7 @@ public class AIOJournalCompactTest extends NIOJournalCompactTest file.mkdir(); - return new AIOSequentialFileFactory(getTestDir(), + return new AIOSequentialFileFactory(getTestDirfile(), JournalConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, 100000, false); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalImplTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalImplTest.java index 6730c64840..acbaac4edb 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalImplTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOJournalImplTest.java @@ -66,7 +66,7 @@ public class AIOJournalImplTest extends JournalImplTestUnit file.mkdir(); - return new AIOSequentialFileFactory(getTestDir(), + return new AIOSequentialFileFactory(getTestDirfile(), JournalConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, 1000000, false); } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java index 5d2d29328f..072c820ccc 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/AIOSequentialFileFactoryTest.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.activemq.artemis.tests.integration.journal; +import java.io.File; import java.nio.ByteBuffer; import org.apache.activemq.artemis.tests.unit.core.journal.impl.SequentialFileFactoryTestBase; @@ -37,7 +38,7 @@ public class AIOSequentialFileFactoryTest extends SequentialFileFactoryTestBase @Override protected SequentialFileFactory createFactory(String folder) { - return new AIOSequentialFileFactory(folder); + return new AIOSequentialFileFactory(new File(folder)); } @Test diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalPerfTuneTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalPerfTuneTest.java deleted file mode 100644 index 70b0cde897..0000000000 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/JournalPerfTuneTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.activemq.artemis.tests.integration.journal; -import java.util.List; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.atomic.AtomicLong; - -import org.apache.activemq.artemis.api.core.ActiveMQBuffer; -import org.apache.activemq.artemis.tests.integration.IntegrationTestLogger; -import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; -import org.apache.activemq.artemis.core.journal.EncodingSupport; -import org.apache.activemq.artemis.core.journal.IOCompletion; -import org.apache.activemq.artemis.core.journal.Journal; -import org.apache.activemq.artemis.core.journal.LoaderCallback; -import org.apache.activemq.artemis.core.journal.PreparedTransactionInfo; -import org.apache.activemq.artemis.core.journal.RecordInfo; -import org.apache.activemq.artemis.core.journal.SequentialFileFactory; -import org.apache.activemq.artemis.core.journal.impl.AIOSequentialFileFactory; -import org.apache.activemq.artemis.core.journal.impl.JournalImpl; -import org.apache.activemq.artemis.utils.DataConstants; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -@Ignore -public class JournalPerfTuneTest extends ActiveMQTestBase -{ - private static final IntegrationTestLogger log = IntegrationTestLogger.LOGGER; - - private Journal journal; - - static final class LoaderCB implements LoaderCallback - { - - public void addPreparedTransaction(PreparedTransactionInfo preparedTransaction) - { - // no-op - } - - public void addRecord(RecordInfo info) - { - // no-op - } - - public void deleteRecord(long id) - { - // no-op - } - - public void updateRecord(RecordInfo info) - { - // no-op - } - - public void failedTransaction(long transactionID, List records, List recordsToDelete) - { - // no-op - } - - } - - @Override - @Before - public void setUp() throws Exception - { - super.setUp(); - - final int fileSize = 1024 * 1024 * 10; - final int minFiles = 10; - final int compactMinFiles = 20; - final int compactPercentage = 30; - final String filePrefix = "data"; - final String extension = "amq"; - final int maxIO = 500; - - final String journalDir = getTestDir(); - final int bufferSize = 490 * 1024; - final int bufferTimeout = (int)(1000000000d / 2000); - final boolean logRates = true; - - recreateDirectory(journalDir); - - SequentialFileFactory fileFactory = new AIOSequentialFileFactory(journalDir, bufferSize, bufferTimeout, logRates); - - journal = new JournalImpl(fileSize, - minFiles, - compactMinFiles, - compactPercentage, - fileFactory, - filePrefix, - extension, - maxIO); - addActiveMQComponent(journal); - journal.start(); - - journal.load(new LoaderCB()); - } - - static final class TestCallback implements IOCompletion - { - private final CountDownLatch latch; - - TestCallback(final int counts) - { - this.latch = new CountDownLatch(counts); - } - - public void await() throws Exception - { - waitForLatch(latch); - } - - public void storeLineUp() - { - } - - public void done() - { - latch.countDown(); - - log.info(latch.getCount()); - } - - public void onError(int errorCode, String errorMessage) - { - } - - } - - @Test - public void test1() throws Exception - { - final int itersPerThread = 10000000; - - final int numThreads = 1; - - this.callback = new TestCallback(2 * itersPerThread * numThreads); - - Worker[] workers = new Worker[numThreads]; - - for (int i = 0; i < numThreads; i++) - { - workers[i] = new Worker(itersPerThread); - - workers[i].start(); - } - - for (int i = 0; i < numThreads; i++) - { - workers[i].join(); - } - - callback.await(); - } - - private final AtomicLong idGen = new AtomicLong(0); - - private TestCallback callback; - - class Worker extends Thread - { - final int iters; - - Worker(final int iters) - { - this.iters = iters; - } - - @Override - public void run() - { - try - { - Record record = new Record(new byte[1024]); - - for (int i = 0; i < iters; i++) - { - long id = idGen.getAndIncrement(); - - journal.appendAddRecord(id, (byte)0, record, true, callback); - - journal.appendDeleteRecord(id, true, callback); - - // log.info("did " + i); - } - } - catch (Exception e) - { - log.error("Failed", e); - } - } - } - - static class Record implements EncodingSupport - { - private byte[] bytes; - - Record(byte[] bytes) - { - this.bytes = bytes; - } - - public void decode(ActiveMQBuffer buffer) - { - int length = buffer.readInt(); - - bytes = new byte[length]; - - buffer.readBytes(bytes); - } - - public void encode(ActiveMQBuffer buffer) - { - buffer.writeInt(bytes.length); - - buffer.writeBytes(bytes); - } - - public int getEncodeSize() - { - return DataConstants.SIZE_INT + bytes.length; - } - } -} diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOBufferedJournalCompactTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOBufferedJournalCompactTest.java index b3bf93bbbb..1a69dab929 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOBufferedJournalCompactTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOBufferedJournalCompactTest.java @@ -34,7 +34,7 @@ public class NIOBufferedJournalCompactTest extends NIOJournalCompactTest file.mkdir(); - return new NIOSequentialFileFactory(getTestDir(), true); + return new NIOSequentialFileFactory(getTestDirfile(), true); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java index 2359410355..daeb0a2fb9 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOImportExportTest.java @@ -16,6 +16,8 @@ */ package org.apache.activemq.artemis.tests.integration.journal; +import java.io.File; + import org.apache.activemq.artemis.core.journal.EncodingSupport; import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; @@ -24,8 +26,6 @@ import org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.SimpleEnco import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.junit.Test; -import java.io.File; - public class NIOImportExportTest extends JournalImplTestBase { @@ -41,7 +41,7 @@ public class NIOImportExportTest extends JournalImplTestBase file.mkdir(); - return new NIOSequentialFileFactory(getTestDir(), true); + return new NIOSequentialFileFactory(getTestDirfile(), true); } // Constants ----------------------------------------------------- diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java index 6478593d31..2166af8038 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalCompactTest.java @@ -1939,7 +1939,7 @@ public class NIOJournalCompactTest extends JournalImplTestBase @Override protected SequentialFileFactory getFileFactory() throws Exception { - return new NIOSequentialFileFactory(getTestDir()); + return new NIOSequentialFileFactory(getTestDirfile()); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalImplTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalImplTest.java index a8ba29ae15..ad7671f643 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalImplTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOJournalImplTest.java @@ -39,7 +39,7 @@ public class NIOJournalImplTest extends JournalImplTestUnit file.mkdir(); - return new NIOSequentialFileFactory(getTestDir(), true); + return new NIOSequentialFileFactory(getTestDirfile(), true); } @Override diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONoBufferJournalImplTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONoBufferJournalImplTest.java index a252a440be..059bf5919e 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONoBufferJournalImplTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONoBufferJournalImplTest.java @@ -38,7 +38,7 @@ public class NIONoBufferJournalImplTest extends JournalImplTestUnit file.mkdir(); - return new NIOSequentialFileFactory(getTestDir(), false); + return new NIOSequentialFileFactory(new File(getTestDir()), false); } @Override diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONonBufferedSequentialFileFactoryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONonBufferedSequentialFileFactoryTest.java index 376d24c19b..717d03ceaa 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONonBufferedSequentialFileFactoryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIONonBufferedSequentialFileFactoryTest.java @@ -15,6 +15,8 @@ * limitations under the License. */ package org.apache.activemq.artemis.tests.integration.journal; +import java.io.File; + import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; import org.apache.activemq.artemis.tests.unit.core.journal.impl.SequentialFileFactoryTestBase; @@ -25,7 +27,7 @@ public class NIONonBufferedSequentialFileFactoryTest extends SequentialFileFacto @Override protected SequentialFileFactory createFactory(String folder) { - return new NIOSequentialFileFactory(folder, false); + return new NIOSequentialFileFactory(new File(folder), false); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOSequentialFileFactoryTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOSequentialFileFactoryTest.java index 2f82220e81..1ca667b9d7 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOSequentialFileFactoryTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/NIOSequentialFileFactoryTest.java @@ -15,6 +15,8 @@ * limitations under the License. */ package org.apache.activemq.artemis.tests.integration.journal; +import java.io.File; + import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; import org.apache.activemq.artemis.tests.unit.core.journal.impl.SequentialFileFactoryTestBase; @@ -25,7 +27,7 @@ public class NIOSequentialFileFactoryTest extends SequentialFileFactoryTestBase @Override protected SequentialFileFactory createFactory(String folder) { - return new NIOSequentialFileFactory(folder, true); + return new NIOSequentialFileFactory(new File(folder), true); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/OldFormatTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/OldFormatTest.java deleted file mode 100644 index 8e23b905f8..0000000000 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/OldFormatTest.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.activemq.artemis.tests.integration.journal; - -import java.nio.ByteBuffer; - -import org.apache.activemq.artemis.core.journal.RecordInfo; -import org.apache.activemq.artemis.core.journal.SequentialFile; -import org.apache.activemq.artemis.core.journal.SequentialFileFactory; -import org.apache.activemq.artemis.core.journal.impl.JournalImpl; -import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; -import org.apache.activemq.artemis.tests.unit.core.journal.impl.JournalImplTestBase; -import org.apache.activemq.artemis.utils.DataConstants; -import org.junit.Test; - -public class OldFormatTest extends JournalImplTestBase -{ - - // Constants ----------------------------------------------------- - - // Attributes ---------------------------------------------------- - - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - - // Public -------------------------------------------------------- - - // This will generate records using the Version 1 format, and reading at the current version - @Test - public void testFormatOne() throws Exception - { - setup(2, 100 * 1024, true); - - SequentialFile file = fileFactory.createSequentialFile("amq-1.amq", 1); - - ByteBuffer buffer = ByteBuffer.allocateDirect(100 * 1024); - - initHeader(buffer, 1); - - byte[] record = new byte[1]; - - for (long i = 0; i < 10; i++) - { - add(buffer, 1, i, record); - - update(buffer, 1, i, record); - } - - file.open(1, false); - - buffer.rewind(); - - file.writeDirect(buffer, true); - - file.close(); - - createJournal(); - startJournal(); - loadAndCheck(); - - startCompact(); - finishCompact(); - - stopJournal(); - createJournal(); - startJournal(); - loadAndCheck(); - } - - private void add(ByteBuffer buffer, int fileID, long id, byte[] record) - { - int pos = buffer.position(); - - buffer.put(JournalImpl.ADD_RECORD); - - buffer.putInt(fileID); - - buffer.putLong(id); - - buffer.putInt(record.length); - - buffer.put((byte) 0); - - buffer.put(record); - - buffer.putInt(buffer.position() - pos + DataConstants.SIZE_INT); - - records.add(new RecordInfo(id, (byte) 0, record, false, (short) 0)); - } - - private void update(ByteBuffer buffer, int fileID, long id, byte[] record) - { - int pos = buffer.position(); - - buffer.put(JournalImpl.UPDATE_RECORD); - - buffer.putInt(fileID); - - buffer.putLong(id); - - buffer.putInt(record.length); - - buffer.put((byte) 0); - - buffer.put(record); - - buffer.putInt(buffer.position() - pos + DataConstants.SIZE_INT); - - records.add(new RecordInfo(id, (byte) 0, record, true, (short) 0)); - - } - - /** - * @param buffer - */ - private void initHeader(ByteBuffer buffer, int fileID) - { - buffer.putInt(1); - - buffer.putInt(0); - - buffer.putLong(fileID); - } - - /* (non-Javadoc) - * @see JournalImplTestBase#getFileFactory() - */ - @Override - protected SequentialFileFactory getFileFactory() throws Exception - { - return new NIOSequentialFileFactory(getTestDir()); - } -} diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/RelativePathTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/RelativePathTest.java new file mode 100644 index 0000000000..4bffdfd1ff --- /dev/null +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/RelativePathTest.java @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.apache.activemq.artemis.tests.integration.journal; + +import java.io.File; +import java.io.FileFilter; +import java.util.HashMap; + +import org.apache.activemq.artemis.core.config.Configuration; +import org.apache.activemq.artemis.core.server.ActiveMQServer; +import org.apache.activemq.artemis.core.settings.impl.AddressSettings; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.junit.Assert; +import org.junit.Test; + +public class RelativePathTest extends ActiveMQTestBase +{ + @Test + public void testRelativePathOnDefaultConfig() throws Exception + { + Configuration configuration = createDefaultConfig(false); + ActiveMQServer server = createServer(true, configuration, AddressSettings.DEFAULT_PAGE_SIZE, AddressSettings.DEFAULT_MAX_SIZE_BYTES, new HashMap()); + + server.start(); + server.stop(); + + checkData(new File(configuration.getJournalDirectory()), ".amq"); + checkData(new File(configuration.getBindingsDirectory()), ".bindings"); + } + + @Test + public void testDataOutsideHome() throws Exception + { + Configuration configuration = createDefaultConfig(false); + + File instanceHome = new File(getTemporaryDir(), "artemisHome"); + + configuration.setArtemisInstance(instanceHome); + + // the journal should be outside of the artemisInstance on this case + File journalOutside = new File(getTemporaryDir(), "./journalOut").getAbsoluteFile(); + configuration.setJournalDirectory(journalOutside.getAbsolutePath()); + + // Somewhere inside artemis.instance + configuration.setBindingsDirectory("./bind"); + + File bindingsInside = new File(instanceHome, "bind"); + +// configuration.setJournal + + System.out.println("Journal dir::" + configuration.getJournalDirectory()); + System.out.println("Journal loc::" + configuration.getJournalLocation()); + + ActiveMQServer server = createServer(true, configuration, AddressSettings.DEFAULT_PAGE_SIZE, AddressSettings.DEFAULT_MAX_SIZE_BYTES, new HashMap()); + + server.start(); + server.stop(); + + checkData(journalOutside, ".amq"); + // Checking if the journal created the lock as well + checkData(journalOutside, "server.lock"); + checkData(bindingsInside, ".bindings"); + } + + @Test + public void testRelativePath() throws Exception + { + Configuration configuration = createDefaultConfig(false); + + File instanceHome = new File(getTemporaryDir(), "artemisHome"); + File dataHome = new File(instanceHome, "data"); + // One folder up for testing + File bindingsHome = new File(instanceHome, "../binx"); + + System.out.println("InstanceHome->" + instanceHome); + instanceHome.mkdirs(); + configuration.setArtemisInstance(instanceHome); + + configuration.setJournalDirectory("./data"); + configuration.setPagingDirectory("./paging"); + configuration.setBindingsDirectory("../binx"); + // one folder up from instance home + configuration.setLargeMessagesDirectory("./large"); + + ActiveMQServer server = createServer(true, configuration, AddressSettings.DEFAULT_PAGE_SIZE, AddressSettings.DEFAULT_MAX_SIZE_BYTES, new HashMap()); + + server.start(); + server.stop(); + + checkData(dataHome, ".amq"); + checkData(bindingsHome, ".bindings"); + } + + public void checkData(File dataHome, final String extension) + { + Assert.assertTrue("Folder " + dataHome + " doesn't exist", dataHome.exists()); + + File[] files = dataHome.listFiles(new FileFilter() + { + @Override + public boolean accept(File pathname) + { + return (extension == null || pathname.toString().endsWith(extension)); + } + }); + + Assert.assertNotNull(files); + + Assert.assertTrue(files.length > 0); + } +} diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/ValidateTransactionHealthTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/ValidateTransactionHealthTest.java index 8d25a410d1..5e8587d70c 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/ValidateTransactionHealthTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/journal/ValidateTransactionHealthTest.java @@ -378,18 +378,18 @@ public class ValidateTransactionHealthTest extends ActiveMQTestBase { if (factoryType.equals("aio")) { - return new AIOSequentialFileFactory(directory, + return new AIOSequentialFileFactory(new File(directory), JournalConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, JournalConstants.DEFAULT_JOURNAL_BUFFER_TIMEOUT_AIO, false); } else if (factoryType.equals("nio2")) { - return new NIOSequentialFileFactory(directory, true); + return new NIOSequentialFileFactory(new File(directory), true); } else { - return new NIOSequentialFileFactory(directory, false); + return new NIOSequentialFileFactory(new File(directory), false); } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/ReplicationTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/ReplicationTest.java index a59b4b28a5..2990294663 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/ReplicationTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/replication/ReplicationTest.java @@ -16,6 +16,20 @@ */ package org.apache.activemq.artemis.tests.integration.replication; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledThreadPoolExecutor; +import java.util.concurrent.ThreadFactory; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.concurrent.atomic.AtomicInteger; + import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.ActiveMQBuffers; import org.apache.activemq.artemis.api.core.ActiveMQException; @@ -67,8 +81,8 @@ import org.apache.activemq.artemis.core.server.impl.ServerMessageImpl; import org.apache.activemq.artemis.core.settings.HierarchicalRepository; import org.apache.activemq.artemis.core.settings.impl.AddressSettings; import org.apache.activemq.artemis.spi.core.protocol.RemotingConnection; -import org.apache.activemq.artemis.tests.util.ReplicatedBackupUtils; import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.apache.activemq.artemis.tests.util.ReplicatedBackupUtils; import org.apache.activemq.artemis.tests.util.TransportConfigurationUtils; import org.apache.activemq.artemis.utils.ActiveMQThreadFactory; import org.apache.activemq.artemis.utils.ExecutorFactory; @@ -78,20 +92,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Map; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.ScheduledExecutorService; -import java.util.concurrent.ScheduledThreadPoolExecutor; -import java.util.concurrent.ThreadFactory; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.concurrent.atomic.AtomicInteger; - public final class ReplicationTest extends ActiveMQTestBase { @@ -653,7 +653,7 @@ public final class ReplicationTest extends ActiveMQTestBase final HierarchicalRepository addressSettingsRepository) throws Exception { - PagingManager paging = new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, configuration.getPagingDirectory(), + PagingManager paging = new PagingManagerImpl(new PagingStoreFactoryNIO(storageManager, configuration.getPagingLocation(), 1000, null, executorFactory, false, null), addressSettingsRepository); diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/JournalExample.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/JournalExample.java deleted file mode 100644 index e7eb876e46..0000000000 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/util/JournalExample.java +++ /dev/null @@ -1,158 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You 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.apache.activemq.artemis.tests.util; - -import java.util.ArrayList; - -import org.apache.activemq.artemis.core.journal.PreparedTransactionInfo; -import org.apache.activemq.artemis.core.journal.RecordInfo; -import org.apache.activemq.artemis.core.journal.SequentialFileFactory; -import org.apache.activemq.artemis.core.journal.impl.AIOSequentialFileFactory; -import org.apache.activemq.artemis.core.journal.impl.JournalImpl; -import org.apache.activemq.artemis.utils.TimeAndCounterIDGenerator; - -/** - * A JournalExample: Just an example on how to use the Journal Directly - *
- * TODO: find a better place to store this example - */ -public class JournalExample -{ - - // Constants ----------------------------------------------------- - - // Attributes ---------------------------------------------------- - - // Static -------------------------------------------------------- - - // Constructors -------------------------------------------------- - - // Public -------------------------------------------------------- - - // Package protected --------------------------------------------- - - // Protected ----------------------------------------------------- - - // Private ------------------------------------------------------- - - // Inner classes ------------------------------------------------- - - public static void main(final String[] arg) - { - TimeAndCounterIDGenerator idgenerator = new TimeAndCounterIDGenerator(); - try - { - SequentialFileFactory fileFactory = new AIOSequentialFileFactory("/tmp"); // any dir you want - // SequentialFileFactory fileFactory = new NIOSequentialFileFactory("/tmp"); // any dir you want - JournalImpl journalExample = new JournalImpl(10 * 1024 * 1024, // 10M.. we believe that's the usual cilinder - // bufferSize.. not an exact science here - 2, // number of files pre-allocated - 0, - 0, - fileFactory, // AIO or NIO - "exjournal", // file name - "dat", // extension - 10000); // it's like a semaphore for callback on the AIO layer - - ArrayList committedRecords = new ArrayList(); - ArrayList preparedTransactions = new ArrayList(); - journalExample.start(); - System.out.println("Loading records and creating data files"); - journalExample.load(committedRecords, preparedTransactions, null); - - System.out.println("Loaded Record List:"); - - for (RecordInfo record : committedRecords) - { - System.out.println("Record id = " + record.id + - " userType = " + - record.userRecordType + - " with " + - record.data.length + - " bytes is stored on the journal"); - } - - System.out.println("Adding Records:"); - - for (int i = 0; i < 10; i++) - { - journalExample.appendAddRecord(idgenerator.generateID(), (byte) 1, new byte[]{ - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2}, false); - } - - long tx = idgenerator.generateID(); // some id generation system - - for (int i = 0; i < 100; i++) - { - journalExample.appendAddRecordTransactional(tx, idgenerator.generateID(), (byte) 2, new byte[]{0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 0, - 1, - 2, - 5}); - } - - // After this is complete, you're sure the records are there - journalExample.appendCommitRecord(tx, true); - - System.out.println("Done!"); - - journalExample.stop(); - } - catch (Exception e) - { - e.printStackTrace(); - } - } - -} diff --git a/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplAIOTest.java b/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplAIOTest.java index 2439339bc5..7fa9e14993 100644 --- a/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplAIOTest.java +++ b/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplAIOTest.java @@ -51,7 +51,7 @@ public class RealJournalImplAIOTest extends JournalImplTestUnit file.mkdir(); - return new AIOSequentialFileFactory(getTestDir()); + return new AIOSequentialFileFactory(getTestDirfile()); } } diff --git a/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplNIOTest.java b/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplNIOTest.java index c95f853699..4d2fbcf604 100644 --- a/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplNIOTest.java +++ b/tests/performance-tests/src/test/java/org/apache/activemq/artemis/tests/performance/journal/RealJournalImplNIOTest.java @@ -37,7 +37,7 @@ public class RealJournalImplNIOTest extends JournalImplTestUnit file.mkdir(); - return new NIOSequentialFileFactory(getTestDir()); + return new NIOSequentialFileFactory(getTestDirfile()); } } diff --git a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AIOAllPossibilitiesCompactStressTest.java b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AIOAllPossibilitiesCompactStressTest.java index 949891f922..a3a9e1fe4f 100644 --- a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AIOAllPossibilitiesCompactStressTest.java +++ b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AIOAllPossibilitiesCompactStressTest.java @@ -51,7 +51,7 @@ public class AIOAllPossibilitiesCompactStressTest extends AllPossibilitiesCompac file.mkdir(); - return new AIOSequentialFileFactory(getTestDir(), + return new AIOSequentialFileFactory(getTestDirfile(), JournalConstants.DEFAULT_JOURNAL_BUFFER_SIZE_AIO, 1000000, false); diff --git a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AddAndRemoveStressTest.java b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AddAndRemoveStressTest.java index 5e21718e53..83ed360e60 100644 --- a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AddAndRemoveStressTest.java +++ b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/AddAndRemoveStressTest.java @@ -76,7 +76,7 @@ public class AddAndRemoveStressTest extends ActiveMQTestBase public void testInsertAndLoad() throws Exception { - SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDir()); + SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile()); JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, @@ -101,7 +101,7 @@ public class AddAndRemoveStressTest extends ActiveMQTestBase impl.stop(); - factory = new AIOSequentialFileFactory(getTestDir()); + factory = new AIOSequentialFileFactory(getTestDirfile()); impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, @@ -127,7 +127,7 @@ public class AddAndRemoveStressTest extends ActiveMQTestBase impl.stop(); - factory = new AIOSequentialFileFactory(getTestDir()); + factory = new AIOSequentialFileFactory(getTestDirfile()); impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, @@ -164,7 +164,7 @@ public class AddAndRemoveStressTest extends ActiveMQTestBase public void testInsertUpdateAndLoad() throws Exception { - SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDir()); + SequentialFileFactory factory = new AIOSequentialFileFactory(getTestDirfile()); JournalImpl impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, @@ -190,7 +190,7 @@ public class AddAndRemoveStressTest extends ActiveMQTestBase impl.stop(); - factory = new AIOSequentialFileFactory(getTestDir()); + factory = new AIOSequentialFileFactory(getTestDirfile()); impl = new JournalImpl(10 * 1024 * 1024, 10, 0, 0, factory, "amq", "amq", 1000); impl.start(); @@ -209,7 +209,7 @@ public class AddAndRemoveStressTest extends ActiveMQTestBase impl.stop(); - factory = new AIOSequentialFileFactory(getTestDir()); + factory = new AIOSequentialFileFactory(getTestDirfile()); impl = new JournalImpl(10 * 1024 * 1024, AddAndRemoveStressTest.NUMBER_OF_FILES_ON_JOURNAL, 0, diff --git a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/JournalCleanupCompactStressTest.java b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/JournalCleanupCompactStressTest.java index d8e659efc1..9516700f2a 100644 --- a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/JournalCleanupCompactStressTest.java +++ b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/JournalCleanupCompactStressTest.java @@ -114,12 +114,12 @@ public class JournalCleanupCompactStressTest extends ActiveMQTestBase int maxAIO; if (AsynchronousFileImpl.isLoaded()) { - factory = new AIOSequentialFileFactory(dir.getPath()); + factory = new AIOSequentialFileFactory(dir); maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoAio(); } else { - factory = new NIOSequentialFileFactory(dir.getPath(), true); + factory = new NIOSequentialFileFactory(dir, true); maxAIO = ActiveMQDefaultConfiguration.getDefaultJournalMaxIoNio(); } diff --git a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/MixupCompactorTestBase.java b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/MixupCompactorTestBase.java index 13aa3b306c..d351fe5efe 100644 --- a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/MixupCompactorTestBase.java +++ b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/MixupCompactorTestBase.java @@ -241,6 +241,6 @@ public abstract class MixupCompactorTestBase extends JournalImplTestBase @Override protected SequentialFileFactory getFileFactory() throws Exception { - return new NIOSequentialFileFactory(getTestDir()); + return new NIOSequentialFileFactory(getTestDirfile()); } } diff --git a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/NIOMultiThreadCompactorStressTest.java b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/NIOMultiThreadCompactorStressTest.java index f8a6475850..616c4a356e 100644 --- a/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/NIOMultiThreadCompactorStressTest.java +++ b/tests/stress-tests/src/test/java/org/apache/activemq/artemis/tests/stress/journal/NIOMultiThreadCompactorStressTest.java @@ -16,6 +16,13 @@ */ package org.apache.activemq.artemis.tests.stress.journal; +import javax.transaction.xa.XAResource; +import javax.transaction.xa.Xid; +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.CountDownLatch; + import org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration; import org.apache.activemq.artemis.api.core.ActiveMQException; import org.apache.activemq.artemis.api.core.SimpleString; @@ -38,12 +45,6 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import javax.transaction.xa.XAResource; -import javax.transaction.xa.Xid; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.CountDownLatch; - public class NIOMultiThreadCompactorStressTest extends ActiveMQTestBase { @@ -89,7 +90,7 @@ public class NIOMultiThreadCompactorStressTest extends ActiveMQTestBase internalTestProduceAndConsume(); stopServer(); - NIOSequentialFileFactory factory = new NIOSequentialFileFactory(getJournalDir()); + NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getJournalDir())); JournalImpl journal = new JournalImpl(ActiveMQDefaultConfiguration.getDefaultJournalFileSize(), 2, 0, diff --git a/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/AIOJournalImplTest.java b/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/AIOJournalImplTest.java index 1cc3872eb8..385d604d40 100644 --- a/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/AIOJournalImplTest.java +++ b/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/AIOJournalImplTest.java @@ -39,7 +39,7 @@ public class AIOJournalImplTest extends JournalImplTestUnit file.mkdir(); - return new AIOSequentialFileFactory(getTestDir()); + return new AIOSequentialFileFactory(getTestDirfile()); } } diff --git a/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/NIOJournalImplTest.java b/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/NIOJournalImplTest.java index 48e989f023..c607493591 100644 --- a/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/NIOJournalImplTest.java +++ b/tests/timing-tests/src/test/java/org/apache/activemq/artemis/tests/timing/core/journal/impl/NIOJournalImplTest.java @@ -18,7 +18,6 @@ package org.apache.activemq.artemis.tests.timing.core.journal.impl; import java.io.File; -import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; import org.apache.activemq.artemis.tests.unit.UnitTestLogger; @@ -27,20 +26,12 @@ public class NIOJournalImplTest extends JournalImplTestUnit { private static final UnitTestLogger log = UnitTestLogger.LOGGER; - protected String journalDir = System.getProperty("java.io.tmpdir", "/tmp") + "/journal-test"; - @Override protected SequentialFileFactory getFileFactory() throws Exception { - File file = new File(journalDir); + File file = new File(getTemporaryDir()); - NIOJournalImplTest.log.debug("deleting directory " + journalDir); - - ActiveMQTestBase.deleteDirectory(file); - - file.mkdir(); - - return new NIOSequentialFileFactory(journalDir); + return new NIOSequentialFileFactory(file); } } diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java index 78e0dd4fbf..e078043482 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/CleanBufferTest.java @@ -16,18 +16,17 @@ */ package org.apache.activemq.artemis.tests.unit.core.journal.impl; -import org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory; -import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; -import org.junit.Test; - +import java.io.File; import java.nio.ByteBuffer; -import org.junit.Assert; - import org.apache.activemq.artemis.core.asyncio.impl.AsynchronousFileImpl; import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.AIOSequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; +import org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.junit.Assert; +import org.junit.Test; public class CleanBufferTest extends ActiveMQTestBase { @@ -45,7 +44,7 @@ public class CleanBufferTest extends ActiveMQTestBase @Test public void testCleanOnNIO() { - SequentialFileFactory factory = new NIOSequentialFileFactory("Whatever"); + SequentialFileFactory factory = new NIOSequentialFileFactory(new File("Whatever")); testBuffer(factory); } @@ -55,7 +54,7 @@ public class CleanBufferTest extends ActiveMQTestBase { if (AsynchronousFileImpl.isLoaded()) { - SequentialFileFactory factory = new AIOSequentialFileFactory("Whatever"); + SequentialFileFactory factory = new AIOSequentialFileFactory(new File("Whatever")); testBuffer(factory); } diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java index 864d28efb2..59586fd656 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/journal/impl/fakes/FakeSequentialFileFactory.java @@ -728,7 +728,7 @@ public class FakeSequentialFileFactory implements SequentialFileFactory } @Override - public String getDirectory() + public File getDirectory() { // TODO Auto-generated method stub return null; diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java index 6368a22c7b..8c4ff47fcb 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PageTest.java @@ -22,8 +22,6 @@ import java.util.List; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; import org.apache.activemq.artemis.api.core.SimpleString; -import org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory; -import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.apache.activemq.artemis.core.journal.SequentialFile; import org.apache.activemq.artemis.core.journal.SequentialFileFactory; import org.apache.activemq.artemis.core.journal.impl.NIOSequentialFileFactory; @@ -33,6 +31,8 @@ import org.apache.activemq.artemis.core.paging.impl.PagedMessageImpl; import org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager; import org.apache.activemq.artemis.core.server.ServerMessage; import org.apache.activemq.artemis.core.server.impl.ServerMessageImpl; +import org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; import org.junit.Assert; import org.junit.Test; @@ -52,14 +52,14 @@ public class PageTest extends ActiveMQTestBase public void testPageWithNIO() throws Exception { recreateDirectory(getTestDir()); - testAdd(new NIOSequentialFileFactory(getTestDir()), 1000); + testAdd(new NIOSequentialFileFactory(getTestDirfile()), 1000); } @Test public void testDamagedDataWithNIO() throws Exception { recreateDirectory(getTestDir()); - testDamagedPage(new NIOSequentialFileFactory(getTestDir()), 1000); + testDamagedPage(new NIOSequentialFileFactory(getTestDirfile()), 1000); } @Test diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingManagerImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingManagerImplTest.java index fc92f531b3..96499665a0 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingManagerImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingManagerImplTest.java @@ -57,7 +57,7 @@ public class PagingManagerImplTest extends ActiveMQTestBase final StorageManager storageManager = new NullStorageManager(); PagingStoreFactoryNIO storeFactory = - new PagingStoreFactoryNIO(storageManager, getPageDir(), 100, null, getOrderedExecutor(), true, null); + new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null); PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java index 4276182efb..1a657c1583 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/paging/impl/PagingStoreImplTest.java @@ -16,6 +16,7 @@ */ package org.apache.activemq.artemis.tests.unit.core.paging.impl; +import java.io.File; import java.nio.ByteBuffer; import java.util.ArrayList; import java.util.List; @@ -128,7 +129,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase public void testPageWithNIO() throws Exception { ActiveMQTestBase.recreateDirectory(getTestDir()); - testConcurrentPaging(new NIOSequentialFileFactory(getTestDir()), 1); + testConcurrentPaging(new NIOSequentialFileFactory(new File(getTestDir())), 1); } @Test @@ -644,7 +645,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase public void testRestartPage() throws Throwable { clearDataRecreateServerDirs(); - SequentialFileFactory factory = new NIOSequentialFileFactory(getPageDir()); + SequentialFileFactory factory = new NIOSequentialFileFactory(new File(getPageDir())); PagingStoreFactory storeFactory = new FakeStoreFactory(factory); @@ -681,7 +682,7 @@ public class PagingStoreImplTest extends ActiveMQTestBase public void testOrderOnPaging() throws Throwable { clearDataRecreateServerDirs(); - SequentialFileFactory factory = new NIOSequentialFileFactory(getPageDir()); + SequentialFileFactory factory = new NIOSequentialFileFactory(new File(getPageDir())); PagingStoreFactory storeFactory = new FakeStoreFactory(factory); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java index 48a85b14e2..3c1fb882e2 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/persistence/impl/BatchIDGeneratorUnitTest.java @@ -15,6 +15,7 @@ * limitations under the License. */ package org.apache.activemq.artemis.tests.unit.core.persistence.impl; +import java.io.File; import java.util.ArrayList; import org.apache.activemq.artemis.api.core.ActiveMQBuffer; @@ -38,7 +39,7 @@ public class BatchIDGeneratorUnitTest extends ActiveMQTestBase @Test public void testSequence() throws Exception { - NIOSequentialFileFactory factory = new NIOSequentialFileFactory(getTestDir()); + NIOSequentialFileFactory factory = new NIOSequentialFileFactory(new File(getTestDir())); Journal journal = new JournalImpl(10 * 1024, 2, 0, 0, factory, "activemq-bindings", "bindings", 1); journal.start(); diff --git a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/FileLockTest.java b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/FileLockTest.java index 6eefcc4b43..643e6c2ce5 100644 --- a/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/FileLockTest.java +++ b/tests/unit-tests/src/test/java/org/apache/activemq/artemis/tests/unit/core/server/impl/FileLockTest.java @@ -15,16 +15,14 @@ * limitations under the License. */ package org.apache.activemq.artemis.tests.unit.core.server.impl; -import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; -import org.junit.Before; - -import org.junit.Test; - import java.io.File; import org.apache.activemq.artemis.core.asyncio.impl.AsynchronousFileImpl; import org.apache.activemq.artemis.core.server.impl.AIOFileLockNodeManager; import org.apache.activemq.artemis.core.server.impl.FileLockNodeManager; +import org.apache.activemq.artemis.tests.util.ActiveMQTestBase; +import org.junit.Before; +import org.junit.Test; public class FileLockTest extends ActiveMQTestBase { @@ -42,7 +40,7 @@ public class FileLockTest extends ActiveMQTestBase @Test public void testNIOLock() throws Exception { - doTestLock(new FileLockNodeManager(getTestDir(), false), new FileLockNodeManager(getTestDir(), false)); + doTestLock(new FileLockNodeManager(getTestDirfile(), false), new FileLockNodeManager(getTestDirfile(), false)); } @@ -51,7 +49,7 @@ public class FileLockTest extends ActiveMQTestBase { if (AsynchronousFileImpl.isLoaded()) { - doTestLock(new AIOFileLockNodeManager(getTestDir(), false), new AIOFileLockNodeManager(getTestDir(), false)); + doTestLock(new AIOFileLockNodeManager(getTestDirfile(), false), new AIOFileLockNodeManager(getTestDirfile(), false)); } }