Search in sources :

Example 1 with PageFile

use of org.apache.activemq.store.kahadb.disk.page.PageFile 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();
    }
}
Also used : Message(javax.jms.Message) PageFile(org.apache.activemq.store.kahadb.disk.page.PageFile) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

Connection (javax.jms.Connection)1 Message (javax.jms.Message)1 MessageProducer (javax.jms.MessageProducer)1 Session (javax.jms.Session)1 KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)1 PageFile (org.apache.activemq.store.kahadb.disk.page.PageFile)1 Test (org.junit.Test)1