diff --git a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ReadOnlyAsyncDataManager.java b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ReadOnlyAsyncDataManager.java index 3203527ef5..5b67b70cd3 100644 --- a/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ReadOnlyAsyncDataManager.java +++ b/activemq-core/src/main/java/org/apache/activemq/kaha/impl/async/ReadOnlyAsyncDataManager.java @@ -48,6 +48,8 @@ public class ReadOnlyAsyncDataManager extends AsyncDataManager { } started = true; + + accessorPool = new DataFileAccessorPool(this); ArrayList files = new ArrayList(); for (File directory : dirs) { diff --git a/activemq-core/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java b/activemq-core/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java index d6d545418a..d944a2e0a1 100644 --- a/activemq-core/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java +++ b/activemq-core/src/test/java/org/apache/activemq/kaha/impl/async/JournalImplTest.java @@ -18,6 +18,7 @@ package org.apache.activemq.kaha.impl.async; import java.io.File; import java.io.IOException; +import java.util.ArrayList; import junit.framework.TestCase; @@ -26,6 +27,8 @@ import org.apache.activeio.journal.RecordLocation; import org.apache.activeio.packet.ByteArrayPacket; import org.apache.activeio.packet.Packet; import org.apache.activemq.kaha.impl.async.JournalFacade.RecordLocationFacade; +import org.apache.activemq.kaha.impl.async.ReadOnlyAsyncDataManager; +import org.apache.activemq.util.ByteSequence; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -126,6 +129,37 @@ public class JournalImplTest extends TestCase { log.info(journal); } + public void testReadOnlyRead() throws InvalidRecordLocationException, InterruptedException, IOException { + + Packet data1 = createPacket("Hello World 1"); + RecordLocation location1 = journal.write(data1, false); + Packet data2 = createPacket("Hello World 2"); + RecordLocation location2 = journal.write(data2, false); + Packet data3 = createPacket("Hello World 3"); + RecordLocation location3 = journal.write(data3, false); + + Packet packet; + packet = journal.read(location2); + assertEquals(data2, packet); + packet = journal.read(location1); + assertEquals(data1, packet); + packet = journal.read(location3); + assertEquals(data3, packet); + + ArrayList data = new ArrayList(); + data.add(logDirectory); + ReadOnlyAsyncDataManager rodm = new ReadOnlyAsyncDataManager(data); + rodm.start(); + try { + for (Location curr = rodm.getFirstLocation(); curr != null; curr = rodm.getNextLocation(curr)) { + ByteSequence bs = rodm.read(curr); + assertNotNull(bs); + } + } finally { + rodm.close(); + } + } + public void testCanReadFromArchivedLogFile() throws InvalidRecordLocationException, InterruptedException, IOException { Packet data1 = createPacket("Hello World 1");