use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class PagingStoreImplTest method testRestartPage.
@Test
public void testRestartPage() 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 storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true);
storeImpl.start();
Assert.assertEquals(0, storeImpl.getNumberOfPages());
// Marked the store to be paged
storeImpl.startPaging();
storeImpl.depage();
Assert.assertNull(storeImpl.getCurrentPage());
storeImpl.startPaging();
Assert.assertNotNull(storeImpl.getCurrentPage());
storeImpl.stop();
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class PagingStoreImplTest method testConcurrentPaging.
protected void testConcurrentPaging(final SequentialFileFactory factory, final int numberOfThreads) throws Exception {
PagingStoreFactory storeFactory = new FakeStoreFactory(factory);
final int MAX_SIZE = 1024 * 10;
final AtomicLong messageIdGenerator = new AtomicLong(0);
final AtomicInteger aliveProducers = new AtomicInteger(numberOfThreads);
final CountDownLatch latchStart = new CountDownLatch(numberOfThreads);
final ConcurrentHashMap<Long, Message> buffers = new ConcurrentHashMap<>();
final ArrayList<Page> readPages = new ArrayList<>();
AddressSettings settings = new AddressSettings().setPageSizeBytes(MAX_SIZE).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE);
final PagingStore storeImpl = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true);
storeImpl.start();
Assert.assertEquals(0, storeImpl.getNumberOfPages());
// Marked the store to be paged
storeImpl.startPaging();
Assert.assertEquals(1, storeImpl.getNumberOfPages());
final SimpleString destination = new SimpleString("test");
class WriterThread extends Thread {
Exception e;
@Override
public void run() {
try {
boolean firstTime = true;
while (true) {
long id = messageIdGenerator.incrementAndGet();
// 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(id, storeImpl, destination, createRandomBuffer(id, 5));
final RoutingContextImpl ctx2 = new RoutingContextImpl(null);
if (storeImpl.page(msg, ctx2.getTransaction(), ctx2.getContextListing(storeImpl.getStoreName()), lock)) {
buffers.put(id, msg);
} else {
break;
}
if (firstTime) {
// We have at least one data paged. So, we can start depaging now
latchStart.countDown();
firstTime = false;
}
}
} catch (Exception e1) {
e1.printStackTrace();
this.e = e1;
} finally {
aliveProducers.decrementAndGet();
}
}
}
final class ReaderThread extends Thread {
Exception e;
@Override
public void run() {
try {
// Wait every producer to produce at least one message
ActiveMQTestBase.waitForLatch(latchStart);
while (aliveProducers.get() > 0) {
Page page = storeImpl.depage();
if (page != null) {
readPages.add(page);
}
}
} catch (Exception e1) {
e1.printStackTrace();
this.e = e1;
}
}
}
WriterThread[] producerThread = new WriterThread[numberOfThreads];
for (int i = 0; i < numberOfThreads; i++) {
producerThread[i] = new WriterThread();
producerThread[i].start();
}
ReaderThread consumer = new ReaderThread();
consumer.start();
for (int i = 0; i < numberOfThreads; i++) {
producerThread[i].join();
if (producerThread[i].e != null) {
throw producerThread[i].e;
}
}
consumer.join();
if (consumer.e != null) {
throw consumer.e;
}
final ConcurrentMap<Long, Message> buffers2 = new ConcurrentHashMap<>();
for (Page page : readPages) {
page.open();
List<PagedMessage> msgs = page.read(new NullStorageManager());
page.close();
for (PagedMessage msg : msgs) {
long id = msg.getMessage().toCore().getBodyBuffer().readLong();
msg.getMessage().toCore().getBodyBuffer().resetReaderIndex();
Message msgWritten = buffers.remove(id);
buffers2.put(id, msg.getMessage());
Assert.assertNotNull(msgWritten);
Assert.assertEquals(msg.getMessage().getAddress(), msgWritten.getAddress());
ActiveMQTestBase.assertEqualsBuffers(10, msgWritten.toCore().getBodyBuffer(), msg.getMessage().toCore().getBodyBuffer());
}
}
Assert.assertEquals(0, buffers.size());
List<String> files = factory.listFiles("page");
Assert.assertTrue(files.size() != 0);
for (String file : files) {
SequentialFile fileTmp = factory.createSequentialFile(file);
fileTmp.open();
Assert.assertTrue("The page file size (" + fileTmp.size() + ") shouldn't be > " + MAX_SIZE, fileTmp.size() <= MAX_SIZE);
fileTmp.close();
}
PagingStore storeImpl2 = new PagingStoreImpl(PagingStoreImplTest.destinationTestName, null, 100, createMockManager(), createStorageManagerMock(), factory, storeFactory, new SimpleString("test"), settings, getExecutorFactory().getExecutor(), true);
storeImpl2.start();
int numberOfPages = storeImpl2.getNumberOfPages();
Assert.assertTrue(numberOfPages != 0);
storeImpl2.startPaging();
storeImpl2.startPaging();
Assert.assertEquals(numberOfPages, storeImpl2.getNumberOfPages());
long lastMessageId = messageIdGenerator.incrementAndGet();
Message lastMsg = createMessage(lastMessageId, storeImpl, destination, createRandomBuffer(lastMessageId, 5));
storeImpl2.forceAnotherPage();
final RoutingContextImpl ctx = new RoutingContextImpl(null);
storeImpl2.page(lastMsg, ctx.getTransaction(), ctx.getContextListing(storeImpl2.getStoreName()), lock);
buffers2.put(lastMessageId, lastMsg);
Page lastPage = null;
while (true) {
Page page = storeImpl2.depage();
if (page == null) {
break;
}
lastPage = page;
page.open();
List<PagedMessage> msgs = page.read(new NullStorageManager());
page.close();
for (PagedMessage msg : msgs) {
long id = msg.getMessage().toCore().getBodyBuffer().readLong();
Message msgWritten = buffers2.remove(id);
Assert.assertNotNull(msgWritten);
Assert.assertEquals(msg.getMessage().getAddress(), msgWritten.getAddress());
ActiveMQTestBase.assertEqualsByteArrays(msgWritten.toCore().getBodyBuffer().writerIndex(), msgWritten.toCore().getBodyBuffer().toByteBuffer().array(), msg.getMessage().toCore().getBodyBuffer().toByteBuffer().array());
}
}
lastPage.open();
List<PagedMessage> lastMessages = lastPage.read(new NullStorageManager());
lastPage.close();
Assert.assertEquals(1, lastMessages.size());
lastMessages.get(0).getMessage().toCore().getBodyBuffer().resetReaderIndex();
Assert.assertEquals(lastMessages.get(0).getMessage().toCore().getBodyBuffer().readLong(), lastMessageId);
Assert.assertEquals(0, buffers2.size());
Assert.assertEquals(0, storeImpl.getAddressSize());
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class PageStressTest method testStopDuringDepage.
@Test
public void testStopDuringDepage() throws Exception {
Configuration config = createDefaultInVMConfig().setJournalSyncNonTransactional(false).setJournalSyncTransactional(false);
HashMap<String, AddressSettings> settings = new HashMap<>();
AddressSettings setting = new AddressSettings().setMaxSizeBytes(20 * 1024 * 1024);
settings.put("page-adr", setting);
server = addServer(createServer(true, config, 10 * 1024 * 1024, 20 * 1024 * 1024, settings));
server.start();
final int NUMBER_OF_MESSAGES = 60000;
ClientSessionFactory factory = createSessionFactory(locator);
ClientSession session = addClientSession(factory.createSession(null, null, false, false, true, false, 1024 * NUMBER_OF_MESSAGES));
SimpleString address = new SimpleString("page-adr");
session.createQueue(address, address, null, true);
ClientProducer prod = session.createProducer(address);
ClientMessage message = createBytesMessage(session, ActiveMQBytesMessage.TYPE, new byte[700], true);
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
if (i % 10000 == 0) {
System.out.println("Sent " + i);
}
prod.send(message);
}
session.commit();
session.start();
ClientConsumer consumer = session.createConsumer(address);
int msgs = 0;
ClientMessage msg;
do {
msg = consumer.receive(10000);
if (msg != null) {
msg.acknowledge();
if (++msgs % 1000 == 0) {
System.out.println("Received " + msgs);
}
}
} while (msg != null);
session.commit();
session.close();
server.stop();
System.out.println("server stopped, nr msgs: " + msgs);
server = addServer(createServer(true, config, 10 * 1024 * 1024, 20 * 1024 * 1024, settings));
server.start();
factory = createSessionFactory(locator);
session = addClientSession(factory.createSession(false, false, false));
consumer = session.createConsumer(address);
session.start();
do {
msg = consumer.receive(10000);
if (msg != null) {
msg.acknowledge();
session.commit();
if (++msgs % 1000 == 0) {
System.out.println("Received " + msgs);
}
}
} while (msg != null);
System.out.println("msgs second time: " + msgs);
Assert.assertEquals(NUMBER_OF_MESSAGES, msgs);
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class PageStressTest method testPageOnMultipleDestinations.
@Test
public void testPageOnMultipleDestinations() throws Exception {
HashMap<String, AddressSettings> settings = new HashMap<>();
AddressSettings setting = new AddressSettings().setMaxSizeBytes(20 * 1024 * 1024);
settings.put("page-adr", setting);
server = addServer(createServer(true, createDefaultInVMConfig(), 10 * 1024 * 1024, 20 * 1024 * 1024, settings));
server.start();
ClientSessionFactory factory = createSessionFactory(locator);
ClientSession session = null;
session = factory.createSession(false, false, false);
SimpleString address = new SimpleString("page-adr");
SimpleString[] queue = new SimpleString[] { new SimpleString("queue1"), new SimpleString("queue2") };
session.createQueue(address, queue[0], null, true);
session.createQueue(address, queue[1], null, true);
ClientProducer prod = session.createProducer(address);
ClientMessage message = createBytesMessage(session, ActiveMQBytesMessage.TYPE, new byte[700], false);
int NUMBER_OF_MESSAGES = 60000;
for (int i = 0; i < NUMBER_OF_MESSAGES; i++) {
if (i % 10000 == 0) {
System.out.println(i);
}
prod.send(message);
}
session.commit();
session.start();
int[] counters = new int[2];
ClientConsumer[] consumers = new ClientConsumer[] { session.createConsumer(queue[0]), session.createConsumer(queue[1]) };
while (true) {
int msgs1 = readMessages(session, consumers[0], queue[0]);
int msgs2 = readMessages(session, consumers[1], queue[1]);
counters[0] += msgs1;
counters[1] += msgs2;
System.out.println("msgs1 = " + msgs1 + " msgs2 = " + msgs2);
if (msgs1 + msgs2 == 0) {
break;
}
}
consumers[0].close();
consumers[1].close();
Assert.assertEquals(NUMBER_OF_MESSAGES, counters[0]);
Assert.assertEquals(NUMBER_OF_MESSAGES, counters[1]);
}
use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.
the class QueueManagerImpl method doIt.
private void doIt() {
Queue queue = server.locateQueue(queueName);
// the queue may already have been deleted and this is a result of that
if (queue == null) {
if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
ActiveMQServerLogger.LOGGER.debug("pno queue to delete \"" + queueName + ".\"");
}
return;
}
SimpleString address = queue.getAddress();
AddressSettings settings = server.getAddressSettingsRepository().getMatch(address.toString());
long consumerCount = queue.getConsumerCount();
long messageCount = queue.getMessageCount();
if (queue.isAutoCreated() && settings.isAutoDeleteQueues() && queue.getMessageCount() == 0 && queue.getConsumerCount() == 0) {
if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
ActiveMQServerLogger.LOGGER.debug("deleting " + (queue.isAutoCreated() ? "auto-created " : "") + "queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount + "; isAutoDeleteQueues = " + settings.isAutoDeleteQueues());
}
try {
server.destroyQueue(queueName, null, true, false);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.errorRemovingAutoCreatedQueue(e, queueName);
}
} else if (queue.isPurgeOnNoConsumers()) {
if (ActiveMQServerLogger.LOGGER.isDebugEnabled()) {
ActiveMQServerLogger.LOGGER.debug("purging queue \"" + queueName + ".\" consumerCount = " + consumerCount + "; messageCount = " + messageCount);
}
try {
queue.deleteMatchingReferences(QueueImpl.DEFAULT_FLUSH_LIMIT, null, AckReason.KILLED);
} catch (Exception e) {
ActiveMQServerLogger.LOGGER.failedToPurgeQueue(e, queueName);
}
}
}
Aggregations