use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class PagingCounterTest method testPrepareCounter.
@Test
public void testPrepareCounter() throws Exception {
Xid xid = newXID();
Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
PageSubscriptionCounter counter = locateCounter(queue);
StorageManager storage = server.getStorageManager();
Transaction tx = new TransactionImpl(xid, server.getStorageManager(), 300);
for (int i = 0; i < 2000; i++) {
counter.increment(tx, 1, 1000);
}
assertEquals(0, counter.getValue());
tx.prepare();
storage.waitOnOperations();
assertEquals(0, counter.getValue());
server.stop();
server = newActiveMQServer();
server.start();
storage = server.getStorageManager();
queue = server.locateQueue(new SimpleString("A1"));
assertNotNull(queue);
counter = locateCounter(queue);
tx = server.getResourceManager().removeTransaction(xid);
assertNotNull(tx);
assertEquals(0, counter.getValue());
tx.commit(false);
storage.waitOnOperations();
assertEquals(2000, counter.getValue());
}
use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class PagingCounterTest method testCounter.
@Test
public void testCounter() throws Exception {
ClientSessionFactory sf = createSessionFactory(sl);
ClientSession session = sf.createSession();
try {
server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
PageSubscriptionCounter counter = locateCounter(queue);
StorageManager storage = server.getStorageManager();
Transaction tx = new TransactionImpl(server.getStorageManager());
counter.increment(tx, 1, 1000);
assertEquals(0, counter.getValue());
assertEquals(0, counter.getPersistentSize());
tx.commit();
storage.waitOnOperations();
assertEquals(1, counter.getValue());
assertEquals(1000, counter.getPersistentSize());
} finally {
sf.close();
session.close();
}
}
use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.
the class PrintData method printPages.
private static void printPages(File pageDirectory, DescribeJournal describeJournal, PrintStream out, boolean safe) {
try {
ScheduledExecutorService scheduled = Executors.newScheduledThreadPool(1, ActiveMQThreadFactory.defaultThreadFactory());
final ExecutorService executor = Executors.newFixedThreadPool(10, ActiveMQThreadFactory.defaultThreadFactory());
ExecutorFactory execfactory = new ExecutorFactory() {
@Override
public ArtemisExecutor getExecutor() {
return ArtemisExecutor.delegate(executor);
}
};
final StorageManager sm = new NullStorageManager();
PagingStoreFactory pageStoreFactory = new PagingStoreFactoryNIO(sm, pageDirectory, 1000L, scheduled, execfactory, false, null);
HierarchicalRepository<AddressSettings> addressSettingsRepository = new HierarchicalObjectRepository<>();
addressSettingsRepository.setDefault(new AddressSettings());
PagingManager manager = new PagingManagerImpl(pageStoreFactory, addressSettingsRepository);
printPages(describeJournal, sm, manager, out, safe);
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.apache.activemq.artemis.core.persistence.StorageManager 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.persistence.StorageManager in project activemq-artemis by apache.
the class StompSession method sendInternalLarge.
public void sendInternalLarge(CoreMessage message, boolean direct) throws Exception {
int headerSize = message.getHeadersAndPropertiesEncodeSize();
if (headerSize >= connection.getMinLargeMessageSize()) {
throw BUNDLE.headerTooBig();
}
StorageManager storageManager = ((ServerSessionImpl) session).getStorageManager();
long id = storageManager.generateID();
LargeServerMessage largeMessage = storageManager.createLargeMessage(id, message);
ActiveMQBuffer body = message.getReadOnlyBodyBuffer();
byte[] bytes = new byte[body.readableBytes()];
body.readBytes(bytes);
largeMessage.addBytes(bytes);
largeMessage.releaseResources();
largeMessage.putLongProperty(Message.HDR_LARGE_BODY_SIZE, bytes.length);
session.send(largeMessage, direct);
largeMessage = null;
}
Aggregations