use of org.apache.activemq.artemis.core.paging.impl.Page in project activemq-artemis by apache.
the class PageTest method testDamagedPage.
protected void testDamagedPage(final SequentialFileFactory factory, final int numberOfElements) throws Exception {
SequentialFile file = factory.createSequentialFile("00010.page");
Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
Assert.assertEquals(10, impl.getPageId());
impl.open();
Assert.assertEquals(1, factory.listFiles("page").size());
SimpleString simpleDestination = new SimpleString("Test");
addPageElements(simpleDestination, impl, numberOfElements);
impl.sync();
long positionA = file.position();
// Add one record that will be damaged
addPageElements(simpleDestination, impl, 1);
long positionB = file.position();
// Add more 10 as they will need to be ignored
addPageElements(simpleDestination, impl, 10);
// Damage data... position the file on the middle between points A and B
file.position(positionA + (positionB - positionA) / 2);
ByteBuffer buffer = ByteBuffer.allocate((int) (positionB - file.position()));
for (int i = 0; i < buffer.capacity(); i++) {
buffer.put((byte) 'Z');
}
buffer.rewind();
file.writeDirect(buffer, true);
impl.close();
file = factory.createSequentialFile("00010.page");
file.open();
impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
List<PagedMessage> msgs = impl.read(new NullStorageManager());
Assert.assertEquals(numberOfElements, msgs.size());
Assert.assertEquals(numberOfElements, impl.getNumberOfMessages());
for (int i = 0; i < msgs.size(); i++) {
Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString());
}
impl.delete(null);
Assert.assertEquals(0, factory.listFiles("page").size());
Assert.assertEquals(1, factory.listFiles("invalidPage").size());
}
use of org.apache.activemq.artemis.core.paging.impl.Page in project activemq-artemis by apache.
the class PageTest method testAdd.
/**
* Validate if everything we add is recovered
*/
protected void testAdd(final SequentialFileFactory factory, final int numberOfElements) throws Exception {
SequentialFile file = factory.createSequentialFile("00010.page");
Page impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
Assert.assertEquals(10, impl.getPageId());
impl.open();
Assert.assertEquals(1, factory.listFiles("page").size());
SimpleString simpleDestination = new SimpleString("Test");
addPageElements(simpleDestination, impl, numberOfElements);
impl.sync();
impl.close();
file = factory.createSequentialFile("00010.page");
file.open();
impl = new Page(new SimpleString("something"), new NullStorageManager(), factory, file, 10);
List<PagedMessage> msgs = impl.read(new NullStorageManager());
Assert.assertEquals(numberOfElements, msgs.size());
Assert.assertEquals(numberOfElements, impl.getNumberOfMessages());
for (int i = 0; i < msgs.size(); i++) {
Assert.assertEquals(simpleDestination, msgs.get(i).getMessage().getAddressSimpleString());
}
impl.delete(null);
Assert.assertEquals(0, factory.listFiles(".page").size());
}
use of org.apache.activemq.artemis.core.paging.impl.Page in project activemq-artemis by apache.
the class PagingManagerImplTest method testPagingManager.
@Test
public void testPagingManager() throws Exception {
HierarchicalRepository<AddressSettings> addressSettings = new HierarchicalObjectRepository<>();
addressSettings.setDefault(new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE));
final StorageManager storageManager = new NullStorageManager();
PagingStoreFactoryNIO storeFactory = new PagingStoreFactoryNIO(storageManager, getPageDirFile(), 100, null, getOrderedExecutor(), true, null);
PagingManagerImpl managerImpl = new PagingManagerImpl(storeFactory, addressSettings);
managerImpl.start();
PagingStore store = managerImpl.getPageStore(new SimpleString("simple-test"));
ICoreMessage msg = createMessage(1L, new SimpleString("simple-test"), createRandomBuffer(10));
final RoutingContextImpl ctx = new RoutingContextImpl(null);
Assert.assertFalse(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
store.startPaging();
Assert.assertTrue(store.page(msg, ctx.getTransaction(), ctx.getContextListing(store.getStoreName()), lock));
Page page = store.depage();
page.open();
List<PagedMessage> msgs = page.read(new NullStorageManager());
page.close();
Assert.assertEquals(1, msgs.size());
ActiveMQTestBase.assertEqualsByteArrays(msg.getBodyBuffer().writerIndex(), msg.getBodyBuffer().toByteBuffer().array(), (msgs.get(0).getMessage()).toCore().getBodyBuffer().toByteBuffer().array());
Assert.assertTrue(store.isPaging());
Assert.assertNull(store.depage());
final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
Assert.assertFalse(store.page(msg, ctx2.getTransaction(), ctx2.getContextListing(store.getStoreName()), lock));
}
use of org.apache.activemq.artemis.core.paging.impl.Page in project activemq-artemis by apache.
the class ReplicationEndpoint method getPage.
private Page getPage(final SimpleString storeName, final int pageId) throws Exception {
ConcurrentMap<Integer, Page> map = getPageMap(storeName);
Page page = map.get(pageId);
if (page == null) {
page = newPage(pageId, storeName, map);
}
return page;
}
use of org.apache.activemq.artemis.core.paging.impl.Page in project activemq-artemis by apache.
the class ReplicationEndpoint method newPage.
/**
* @param pageId
* @param map
* @return
*/
private synchronized Page newPage(final int pageId, final SimpleString storeName, final ConcurrentMap<Integer, Page> map) throws Exception {
Page page = map.get(pageId);
if (page == null) {
page = pageManager.getPageStore(storeName).createPage(pageId);
page.open();
map.put(pageId, page);
}
return page;
}
Aggregations