use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class HangConsumerTest method testDuplicateDestinationsOnTopic.
/**
* This will simulate what would happen with topic creationg where a single record is supposed to be created on the journal
*
* @throws Exception
*/
@Test
public void testDuplicateDestinationsOnTopic() throws Exception {
try {
for (int i = 0; i < 5; i++) {
if (server.locateQueue(SimpleString.toSimpleString("tt")) == null) {
server.createQueue(SimpleString.toSimpleString("tt"), RoutingType.ANYCAST, SimpleString.toSimpleString("tt"), SimpleString.toSimpleString(Filter.GENERIC_IGNORED_FILTER), true, false);
}
server.stop();
SequentialFileFactory messagesFF = new NIOSequentialFileFactory(server.getConfiguration().getBindingsLocation(), null, 1);
JournalImpl messagesJournal = new JournalImpl(1024 * 1024, 2, 2, 0, 0, messagesFF, "activemq-bindings", "bindings", 1);
messagesJournal.start();
LinkedList<RecordInfo> infos = new LinkedList<>();
messagesJournal.load(infos, null, null);
int bindings = 0;
for (RecordInfo info : infos) {
System.out.println("info: " + info);
if (info.getUserRecordType() == JournalRecordIds.QUEUE_BINDING_RECORD) {
bindings++;
}
}
assertEquals(1, bindings);
System.out.println("Bindings: " + bindings);
messagesJournal.stop();
if (i < 4)
server.start();
}
} finally {
try {
server.stop();
} catch (Throwable ignored) {
}
}
}
use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreImplTest method testOrderOnPaging.
@Test
public void testOrderOnPaging() throws Throwable {
clearDataRecreateServerDirs();
SequentialFileFactory factory = new NIOSequentialFileFactory(new File(getPageDir()), 1);
PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
final int MAX_SIZE = 1024 * 10;
AddressSettings settings = new AddressSettings().setPageSizeBytes(MAX_SIZE).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
final PagingStore store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), false);
store.start();
Assert.assertEquals(0, store.getNumberOfPages());
// Marked the store to be paged
store.startPaging();
final CountDownLatch producedLatch = new CountDownLatch(1);
Assert.assertEquals(1, store.getNumberOfPages());
final SimpleString destination = new SimpleString("test");
final long NUMBER_OF_MESSAGES = 100000;
final List<Throwable> errors = new ArrayList<>();
class WriterThread extends Thread {
WriterThread() {
super("PageWriter");
}
@Override
public void run() {
try {
for (long i = 0; i < NUMBER_OF_MESSAGES; i++) {
// Each thread will Keep paging until all the messages are depaged.
// This is possible because the depage thread is not actually reading the pages.
// Just using the internal API to remove it from the page file system
Message msg = createMessage(i, store, destination, createRandomBuffer(i, 1024));
msg.putLongProperty("count", i);
final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
while (!store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock)) {
store.startPaging();
}
if (i == 0) {
producedLatch.countDown();
}
}
} catch (Throwable e) {
e.printStackTrace();
errors.add(e);
}
}
}
class ReaderThread extends Thread {
ReaderThread() {
super("PageReader");
}
@Override
public void run() {
try {
long msgsRead = 0;
while (msgsRead < NUMBER_OF_MESSAGES) {
Page page = store.depage();
if (page != null) {
page.open();
List<PagedMessage> messages = page.read(new NullStorageManager());
for (PagedMessage pgmsg : messages) {
Message msg = pgmsg.getMessage();
Assert.assertEquals(msgsRead++, msg.getMessageID());
Assert.assertEquals(msg.getMessageID(), msg.getLongProperty("count").longValue());
}
page.close();
page.delete(null);
} else {
System.out.println("Depaged!!!! numerOfMessages = " + msgsRead + " of " + NUMBER_OF_MESSAGES);
Thread.sleep(500);
}
}
} catch (Throwable e) {
e.printStackTrace();
errors.add(e);
}
}
}
WriterThread producerThread = new WriterThread();
producerThread.start();
ReaderThread consumer = new ReaderThread();
consumer.start();
producerThread.join();
consumer.join();
store.stop();
for (Throwable e : errors) {
throw e;
}
}
use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class PageTest method testDamagedDataWithNIO.
@Test
public void testDamagedDataWithNIO() throws Exception {
recreateDirectory(getTestDir());
testDamagedPage(new NIOSequentialFileFactory(getTestDirfile(), 1), 1000);
}
use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class PageTest method testPageWithNIO.
@Test
public void testPageWithNIO() throws Exception {
recreateDirectory(getTestDir());
testAdd(new NIOSequentialFileFactory(getTestDirfile(), 1), 1000);
}
use of org.apache.activemq.artemis.core.io.nio.NIOSequentialFileFactory in project activemq-artemis by apache.
the class CompactJournal method compactJournal.
private void compactJournal(final File directory, final String journalPrefix, final String journalSuffix, final int minFiles, final int fileSize, final IOCriticalErrorListener listener) throws Exception {
NIOSequentialFileFactory nio = new NIOSequentialFileFactory(directory, listener, 1);
JournalImpl journal = new JournalImpl(fileSize, minFiles, minFiles, 0, 0, nio, journalPrefix, journalSuffix, 1);
journal.start();
journal.loadInternalOnly();
journal.compact();
journal.stop();
}
Aggregations