use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.
the class AlignedJournalImplTest method testInconsistentAlignment.
@Test
public void testInconsistentAlignment() throws Exception {
factory = new FakeSequentialFileFactory(512, true);
try {
journalImpl = new JournalImpl(2000, 2, 2, 0, 0, factory, "tt", "tt", 1000);
Assert.fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException ignored) {
// expected
}
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreImplTest method testDepageOnCurrentPage.
@Test
public void testDepageOnCurrentPage() throws Exception {
SequentialFileFactory factory = new FakeSequentialFileFactory();
SimpleString destination = new SimpleString("test");
PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
PagingStoreImpl storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
storeImpl.start();
Assert.assertEquals(0, storeImpl.getNumberOfPages());
storeImpl.startPaging();
List<ActiveMQBuffer> buffers = new ArrayList<>();
int numMessages = 10;
for (int i = 0; i < numMessages; i++) {
ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
buffers.add(buffer);
Message msg = createMessage(i, storeImpl, destination, buffer);
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
}
Assert.assertEquals(1, storeImpl.getNumberOfPages());
storeImpl.sync();
Page page = storeImpl.depage();
page.open();
List<PagedMessage> msg = page.read(new NullStorageManager());
Assert.assertEquals(numMessages, msg.size());
Assert.assertEquals(1, storeImpl.getNumberOfPages());
page = storeImpl.depage();
Assert.assertNull(page);
Assert.assertEquals(0, storeImpl.getNumberOfPages());
for (int i = 0; i < numMessages; i++) {
ActiveMQBuffer horn1 = buffers.get(i);
ActiveMQBuffer horn2 = msg.get(i).getMessage().toCore().getBodyBuffer();
horn1.resetReaderIndex();
horn2.resetReaderIndex();
for (int j = 0; j < horn1.writerIndex(); j++) {
Assert.assertEquals(horn1.readByte(), horn2.readByte());
}
}
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreImplTest method testDoubleStart.
@Test
public void testDoubleStart() throws Exception {
SequentialFileFactory factory = new FakeSequentialFileFactory();
PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, new FakeStoreFactory(factory), PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
storeImpl.start();
// this is not supposed to throw an exception.
// As you could have start being called twice as Stores are dynamically
// created, on a multi-thread environment
storeImpl.start();
storeImpl.stop();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreImplTest method testDepageMultiplePages.
@Test
public void testDepageMultiplePages() throws Exception {
SequentialFileFactory factory = new FakeSequentialFileFactory();
SimpleString destination = new SimpleString("test");
PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
PagingStoreImpl store = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE), getExecutorFactory().getExecutor(), true);
store.start();
Assert.assertEquals(0, store.getNumberOfPages());
store.startPaging();
Assert.assertEquals(1, store.getNumberOfPages());
List<ActiveMQBuffer> buffers = new ArrayList<>();
for (int i = 0; i < 10; i++) {
ActiveMQBuffer buffer = createRandomBuffer(i + 1L, 10);
buffers.add(buffer);
if (i == 5) {
store.forceAnotherPage();
}
Message msg = createMessage(i, store, destination, buffer);
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
}
Assert.assertEquals(2, store.getNumberOfPages());
store.sync();
int sequence = 0;
for (int pageNr = 0; pageNr < 2; pageNr++) {
Page page = store.depage();
System.out.println("numberOfPages = " + store.getNumberOfPages());
page.open();
List<PagedMessage> msg = page.read(new NullStorageManager());
page.close();
Assert.assertEquals(5, msg.size());
for (int i = 0; i < 5; i++) {
Assert.assertEquals(sequence++, msg.get(i).getMessage().getMessageID());
ActiveMQTestBase.assertEqualsBuffers(18, buffers.get(pageNr * 5 + i), msg.get(i).getMessage().toCore().getBodyBuffer());
}
}
Assert.assertEquals(1, store.getNumberOfPages());
Assert.assertTrue(store.isPaging());
Message msg = createMessage(1, store, destination, buffers.get(0));
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
Page newPage = store.depage();
newPage.open();
Assert.assertEquals(1, newPage.read(new NullStorageManager()).size());
newPage.delete(null);
Assert.assertEquals(1, store.getNumberOfPages());
Assert.assertTrue(store.isPaging());
Assert.assertNull(store.depage());
Assert.assertFalse(store.isPaging());
{
final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
store.startPaging();
{
final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
Assert.assertTrue(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
Page page = store.depage();
page.open();
List<PagedMessage> msgs = page.read(new NullStorageManager());
Assert.assertEquals(1, msgs.size());
Assert.assertEquals(1L, msgs.get(0).getMessage().getMessageID());
ActiveMQTestBase.assertEqualsBuffers(18, buffers.get(0), msgs.get(0).getMessage().toCore().getBodyBuffer());
Assert.assertEquals(1, store.getNumberOfPages());
Assert.assertTrue(store.isPaging());
Assert.assertNull(store.depage());
Assert.assertEquals(0, store.getNumberOfPages());
page.open();
}
use of org.apache.activemq.artemis.tests.unit.core.journal.impl.fakes.FakeSequentialFileFactory in project activemq-artemis by apache.
the class PagingStoreImplTest method testStore.
@Test
public void testStore() throws Exception {
SequentialFileFactory factory = new FakeSequentialFileFactory();
PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
AddressSettings addressSettings = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true);
storeImpl.start();
Assert.assertEquals(0, storeImpl.getNumberOfPages());
storeImpl.startPaging();
Assert.assertEquals(1, storeImpl.getNumberOfPages());
List<ActiveMQBuffer> buffers = new ArrayList<>();
ActiveMQBuffer buffer = createRandomBuffer(0, 10);
buffers.add(buffer);
SimpleString destination = new SimpleString("test");
Message msg = createMessage(1, storeImpl, destination, buffer);
Assert.assertTrue(storeImpl.isPaging());
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertTrue(storeImpl.page(msg, ctx.getTransaction(), ctx.getContextListing(storeImpl.getStoreName()), lock));
Assert.assertEquals(1, storeImpl.getNumberOfPages());
storeImpl.sync();
storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, PagingStoreImplTest.destinationTestName, addressSettings, getExecutorFactory().getExecutor(), true);
storeImpl.start();
Assert.assertEquals(1, storeImpl.getNumberOfPages());
}
Aggregations