use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubSelectorDelayTest method testProcess.
@Test
public void testProcess() throws Exception {
MsgProducer msgProducer = new MsgProducer();
msgProducer.start();
DurableSubscriber[] subscribers = new DurableSubscriber[10];
for (int i = 0; i < subscribers.length; i++) {
subscribers[i] = new DurableSubscriber(i);
subscribers[i].process();
}
// wait for server to finish
msgProducer.join();
for (int j = 0; j < subscribers.length; j++) {
LOG.info("Unsubscribing subscriber " + subscribers[j]);
subscribers[j].unsubscribe();
}
// allow the clean up thread time to run
TimeUnit.MINUTES.sleep(2);
final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
assertTrue("less than two journal file should be left, was: " + pa.getStore().getJournal().getFileMap().size(), Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return pa.getStore().getJournal().getFileMap().size() <= 2;
}
}, TimeUnit.MINUTES.toMillis(2)));
LOG.info("DONE.");
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubsOfflineSelectorConcurrentConsumeIndexUseTest method testIndexPageUsage.
public void testIndexPageUsage() throws Exception {
Connection con = createConnection();
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
session.close();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
session.close();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "all", null, true);
session.close();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "all2", null, true);
session.close();
con.close();
// send messages
final CountDownLatch goOn = new CountDownLatch(1);
Thread sendThread = new Thread() {
@Override
public void run() {
try {
final Connection sendCon = createConnection("send");
final Session sendSession = sendCon.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = sendSession.createProducer(null);
for (int i = 0; i < messageCount; i++) {
boolean filter = i % 2 == 1;
Message message = sendSession.createMessage();
message.setStringProperty("filter", filter ? "true" : "false");
producer.send(topic, message);
if (i > 0 && i % 10000 == 0) {
LOG.info("Sent:" + i);
}
if (i > messageCount / 2) {
goOn.countDown();
}
}
sendSession.close();
sendCon.close();
} catch (Exception e) {
exceptions.add(e);
}
}
};
sendThread.start();
goOn.await(5, TimeUnit.MINUTES);
LOG.info("Activating consumers");
// consume messages in parallel
con = createConnection();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumerTrue = session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
Listener listenerT = new Listener();
consumerTrue.setMessageListener(listenerT);
MessageConsumer consumerFalse = session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
Listener listenerF = new Listener();
consumerFalse.setMessageListener(listenerF);
MessageConsumer consumerAll = session.createDurableSubscriber(topic, "all", null, true);
Listener listenerA = new Listener();
consumerAll.setMessageListener(listenerA);
MessageConsumer consumerAll2 = session.createDurableSubscriber(topic, "all2", null, true);
Listener listenerA2 = new Listener();
consumerAll2.setMessageListener(listenerA2);
waitFor(listenerA, messageCount);
assertEquals(messageCount, listenerA.count);
waitFor(listenerA2, messageCount);
assertEquals(messageCount, listenerA2.count);
assertEquals(messageCount / 2, listenerT.count);
assertEquals(messageCount / 2, listenerF.count);
consumerTrue.close();
session.unsubscribe("true");
consumerFalse.close();
session.unsubscribe("false");
consumerAll.close();
session.unsubscribe("all");
session.close();
con.close();
PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
if (persistenceAdapter instanceof KahaDBPersistenceAdapter) {
final KahaDBStore store = ((KahaDBPersistenceAdapter) persistenceAdapter).getStore();
LOG.info("Store page count: " + store.getPageFile().getPageCount());
LOG.info("Store free page count: " + store.getPageFile().getFreePageCount());
LOG.info("Store page in-use: " + (store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount()));
assertTrue("no leak of pages, always use just 11", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 11 == store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount();
}
}, TimeUnit.SECONDS.toMillis(10)));
}
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubscriptionOfflineTest method testRemovedDurableSubDeletesFromIndex.
@Test(timeout = 60 * 1000)
public void testRemovedDurableSubDeletesFromIndex() throws Exception {
if (!(broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter)) {
return;
}
final int numMessages = 2750;
KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
PageFile pageFile = kahaDBPersistenceAdapter.getStore().getPageFile();
LOG.info("PageCount " + pageFile.getPageCount() + " f:" + pageFile.getFreePageCount() + ", fileSize:" + pageFile.getFile().length());
long lastDiff = 0;
for (int repeats = 0; repeats < 2; repeats++) {
LOG.info("Iteration: " + repeats + " Count:" + pageFile.getPageCount() + " f:" + pageFile.getFreePageCount());
Connection con = createConnection("cliId1" + "-" + repeats);
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "SubsId", "filter = 'true'", true);
session.close();
con.close();
// send messages
con = createConnection();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageProducer producer = session.createProducer(null);
for (int i = 0; i < numMessages; i++) {
Message message = session.createMessage();
message.setStringProperty("filter", "true");
producer.send(topic, message);
}
con.close();
Connection con2 = createConnection("cliId1" + "-" + repeats);
Session session2 = con2.createSession(false, Session.AUTO_ACKNOWLEDGE);
session2.unsubscribe("SubsId");
session2.close();
con2.close();
LOG.info("PageCount " + pageFile.getPageCount() + " f:" + pageFile.getFreePageCount() + " diff: " + (pageFile.getPageCount() - pageFile.getFreePageCount()) + " fileSize:" + pageFile.getFile().length());
if (lastDiff != 0) {
assertEquals("Only use X pages per iteration: " + repeats, lastDiff, pageFile.getPageCount() - pageFile.getFreePageCount());
}
lastDiff = pageFile.getPageCount() - pageFile.getFreePageCount();
}
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubSelectorDelayWithRestartTest method testProcess.
@Test
public void testProcess() throws Exception {
MsgProducer msgProducer = new MsgProducer();
msgProducer.start();
DurableSubscriber[] subscribers = new DurableSubscriber[NUMBER_SUBSCRIBERS];
for (int i = 0; i < subscribers.length - 1; i++) {
subscribers[i] = new DurableSubscriber(i);
subscribers[i].process();
}
// wait for server to finish
msgProducer.join();
// for the last subscriber pop one message into the topic.
subscribers[(subscribers.length - 1)] = new DurableSubscriber((subscribers.length - 1));
subscribers[(subscribers.length - 1)].subscribe();
MsgProducer msgProducer2 = new MsgProducer();
msgProducer2.send();
subscribers[(subscribers.length - 1)].process();
// unsubscribe all, but the last subscriber.
for (int j = 0; j < (subscribers.length - 1); j++) {
LOG.info("Unsubscribing subscriber " + subscribers[j]);
subscribers[j].unsubscribe();
}
final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
assertTrue("small number of journal files should be left ", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
LOG.info("journal data file count - expected {} actual {}", 4, pa.getStore().getJournal().getFileMap().size());
return pa.getStore().getJournal().getFileMap().size() < 4;
}
}, TimeUnit.MINUTES.toMillis(3)));
LOG.info("DONE.");
}
use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.
the class DurableSubsOfflineSelectorIndexUseTest method testIndexPageUsage.
public void testIndexPageUsage() throws Exception {
Connection con = createConnection();
Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
session.close();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
session.close();
con.close();
// send messages
final Connection sendCon = createConnection("send");
final Session sendSession = sendCon.createSession(false, Session.AUTO_ACKNOWLEDGE);
final MessageProducer producer = sendSession.createProducer(null);
Thread sendThread = new Thread() {
@Override
public void run() {
try {
for (int i = 0; i < messageCount; i++) {
boolean filter = i % 2 == 1;
Message message = sendSession.createMessage();
message.setStringProperty("filter", filter ? "true" : "false");
producer.send(topic, message);
if (i > 0 && i % 1000 == 0) {
LOG.info("Sent:" + i);
}
}
sendSession.close();
sendCon.close();
} catch (Exception e) {
exceptions.add(e);
}
}
};
sendThread.start();
sendThread.join();
// settle with sent messages
TimeUnit.SECONDS.sleep(4);
// consume messages
con = createConnection();
session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
MessageConsumer consumerTrue = session.createDurableSubscriber(topic, "true", "filter = 'true'", true);
Listener listenerT = new Listener();
consumerTrue.setMessageListener(listenerT);
waitFor(listenerT, messageCount / 2);
MessageConsumer consumerFalse = session.createDurableSubscriber(topic, "false", "filter = 'false'", true);
Listener listenerF = new Listener();
consumerFalse.setMessageListener(listenerF);
waitFor(listenerF, messageCount / 2);
assertEquals(messageCount / 2, listenerT.count);
assertEquals(messageCount / 2, listenerF.count);
consumerTrue.close();
session.unsubscribe("true");
consumerFalse.close();
session.unsubscribe("false");
session.close();
con.close();
PersistenceAdapter persistenceAdapter = broker.getPersistenceAdapter();
if (persistenceAdapter instanceof KahaDBPersistenceAdapter) {
final KahaDBStore store = ((KahaDBPersistenceAdapter) persistenceAdapter).getStore();
LOG.info("Store page count: " + store.getPageFile().getPageCount());
LOG.info("Store free page count: " + store.getPageFile().getFreePageCount());
LOG.info("Store page in-use: " + (store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount()));
assertTrue("no leak of pages, always use just 10", Wait.waitFor(new Wait.Condition() {
@Override
public boolean isSatisified() throws Exception {
return 10 == store.getPageFile().getPageCount() - store.getPageFile().getFreePageCount();
}
}, TimeUnit.SECONDS.toMillis(10)));
}
}
Aggregations