From 0ae7d32532dce9980bab5031d99314c7f66c56f0 Mon Sep 17 00:00:00 2001 From: Justin Bertram Date: Tue, 7 Aug 2018 10:51:56 -0500 Subject: [PATCH] ARTEMIS-2014 Treat inability to create directory for paging as critial --- .../io/AbstractSequentialFileFactory.java | 6 +- .../tests/integration/paging/PagingTest.java | 58 +++++++++++++++++++ 2 files changed, 62 insertions(+), 2 deletions(-) diff --git a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java index 5f191cfa4c..482aaa2a51 100644 --- a/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java +++ b/artemis-journal/src/main/java/org/apache/activemq/artemis/core/io/AbstractSequentialFileFactory.java @@ -224,8 +224,10 @@ public abstract class AbstractSequentialFileFactory implements SequentialFileFac @Override public void createDirs() throws Exception { boolean ok = journalDir.mkdirs(); - if (!ok) { - throw new IOException("Failed to create directory " + journalDir); + if (!ok && !journalDir.exists()) { + IOException e = new IOException("Unable to create directory: " + journalDir); + onIOError(e, e.getMessage(), null); + throw e; } } diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PagingTest.java b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PagingTest.java index 1436bea031..71be960df2 100644 --- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PagingTest.java +++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/paging/PagingTest.java @@ -35,6 +35,7 @@ import java.util.HashSet; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.UUID; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -96,6 +97,7 @@ import org.apache.activemq.artemis.utils.actors.ArtemisExecutor; import org.jboss.logging.Logger; import org.junit.After; import org.junit.Assert; +import org.junit.Assume; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -1400,6 +1402,62 @@ public class PagingTest extends ActiveMQTestBase { } + @Test + public void testInabilityToCreateDirectoryDuringPaging() throws Exception { + // this test only applies to file-based stores + Assume.assumeTrue(storeType == StoreConfiguration.StoreType.FILE); + + clearDataRecreateServerDirs(); + + Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false).setPagingDirectory(UUID.randomUUID().toString()); + + server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX); + + server.start(); + + final int numberOfMessages = 100; + + locator = createInVMNonHALocator().setBlockOnNonDurableSend(true).setBlockOnDurableSend(true).setBlockOnAcknowledge(true); + + sf = createSessionFactory(locator); + + ClientSession session = sf.createSession(false, true, true); + + session.createQueue(PagingTest.ADDRESS, RoutingType.MULTICAST, PagingTest.ADDRESS, null, true); + + ClientProducer producer = session.createProducer(PagingTest.ADDRESS); + + ClientMessage message = null; + + byte[] body = new byte[MESSAGE_SIZE]; + + ByteBuffer bb = ByteBuffer.wrap(body); + + for (int j = 1; j <= MESSAGE_SIZE; j++) { + bb.put(getSamplebyte(j)); + } + + for (int i = 0; i < numberOfMessages; i++) { + message = session.createMessage(true); + + ActiveMQBuffer bodyLocal = message.getBodyBuffer(); + + bodyLocal.writeBytes(body); + + message.putIntProperty(new SimpleString("id"), i); + + try { + producer.send(message); + } catch (Exception e) { + // ignore + } + } + assertTrue(Wait.waitFor(() -> server.getState() == ActiveMQServer.SERVER_STATE.STOPPED, 5000, 200)); + session.close(); + sf.close(); + locator.close(); + } + /** * This test will remove all the page directories during a restart, simulating a crash scenario. The server should still start after this */