Search in sources :

Example 11 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class DurableSubscriptionOffline4Test method testCleanupDeletedSubAfterRestart.

@Test(timeout = 60 * 1000)
public // https://issues.apache.org/jira/browse/AMQ-3206
void testCleanupDeletedSubAfterRestart() throws Exception {
    Connection con = createConnection("cli1");
    Session session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId", null, true);
    session.close();
    con.close();
    con = createConnection("cli2");
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId", null, true);
    session.close();
    con.close();
    con = createConnection();
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(null);
    final int toSend = 500;
    final String payload = Arrays.toString(new byte[40 * 1024]);
    int sent = 0;
    for (int i = sent; i < toSend; i++) {
        Message message = session.createTextMessage(payload);
        message.setStringProperty("filter", "false");
        message.setIntProperty("ID", i);
        producer.send(topic, message);
        sent++;
    }
    con.close();
    LOG.info("sent: " + sent);
    // kill off cli1
    con = createConnection("cli1");
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.unsubscribe("SubsId");
    destroyBroker();
    createBroker(false);
    con = createConnection("cli2");
    session = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createDurableSubscriber(topic, "SubsId", null, true);
    final DurableSubscriptionOfflineTestListener listener = new DurableSubscriptionOfflineTestListener();
    consumer.setMessageListener(listener);
    assertTrue("got all sent", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            LOG.info("Want: " + toSend + ", current: " + listener.count);
            return listener.count == toSend;
        }
    }));
    session.close();
    con.close();
    destroyBroker();
    createBroker(false);
    final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
    assertTrue("Should have less than three journal files left but was: " + pa.getStore().getJournal().getFileMap().size(), Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return pa.getStore().getJournal().getFileMap().size() <= 3;
        }
    }));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Message(javax.jms.Message) Connection(javax.jms.Connection) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) Test(org.junit.Test)

Example 12 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class DurableSubscriptionOfflineTestListener method createBroker.

protected void createBroker(boolean deleteAllMessages) throws Exception {
    String currentTestName = getName(true);
    broker = BrokerFactory.createBroker("broker:(vm://" + currentTestName + ")");
    broker.setBrokerName(currentTestName);
    broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
    broker.getManagementContext().setCreateConnector(false);
    broker.setAdvisorySupport(false);
    broker.setKeepDurableSubsActive(keepDurableSubsActive);
    broker.addConnector("tcp://0.0.0.0:0");
    if (usePrioritySupport) {
        PolicyEntry policy = new PolicyEntry();
        policy.setPrioritizedMessages(true);
        PolicyMap policyMap = new PolicyMap();
        policyMap.setDefaultEntry(policy);
        broker.setDestinationPolicy(policyMap);
    }
    setDefaultPersistenceAdapter(broker);
    if (broker.getPersistenceAdapter() instanceof JDBCPersistenceAdapter) {
        // ensure it kicks in during tests
        ((JDBCPersistenceAdapter) broker.getPersistenceAdapter()).setCleanupPeriod(2 * 1000);
    } else if (broker.getPersistenceAdapter() instanceof KahaDBPersistenceAdapter) {
        // have lots of journal files
        ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).setJournalMaxFileLength(journalMaxFileLength);
    }
    broker.start();
    broker.waitUntilStarted();
}
Also used : JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) PolicyMap(org.apache.activemq.broker.region.policy.PolicyMap) PolicyEntry(org.apache.activemq.broker.region.policy.PolicyEntry) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 13 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class DurableSubscriptionOfflineTestListener method setPersistenceAdapter.

public PersistenceAdapter setPersistenceAdapter(BrokerService broker, PersistenceAdapterChoice choice) throws IOException {
    PersistenceAdapter adapter = null;
    switch(choice) {
        case JDBC:
            LOG.debug(">>>> setPersistenceAdapter to JDBC ");
            adapter = new JDBCPersistenceAdapter();
            break;
        case KahaDB:
            LOG.debug(">>>> setPersistenceAdapter to KahaDB ");
            adapter = new KahaDBPersistenceAdapter();
            break;
        case LevelDB:
            LOG.debug(">>>> setPersistenceAdapter to LevelDB ");
            adapter = new LevelDBPersistenceAdapter();
            break;
        case MEM:
            LOG.debug(">>>> setPersistenceAdapter to MEM ");
            adapter = new MemoryPersistenceAdapter();
            break;
    }
    broker.setPersistenceAdapter(adapter);
    return adapter;
}
Also used : JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) MemoryPersistenceAdapter(org.apache.activemq.store.memory.MemoryPersistenceAdapter) LevelDBPersistenceAdapter(org.apache.activemq.store.leveldb.LevelDBPersistenceAdapter) JDBCPersistenceAdapter(org.apache.activemq.store.jdbc.JDBCPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) PersistenceAdapter(org.apache.activemq.store.PersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 14 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class DurableSubSelectorDelayWithRestartTest method startBroker.

private void startBroker(boolean deleteAllMessages) throws Exception {
    if (broker != null)
        return;
    broker = BrokerFactory.createBroker("broker:(vm://" + getName() + ")");
    broker.setBrokerName(getName());
    broker.setAdvisorySupport(false);
    broker.setDeleteAllMessagesOnStartup(deleteAllMessages);
    File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
    if (deleteAllMessages)
        delete(kahadbData);
    broker.setPersistent(true);
    KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
    kahadb.setDirectory(kahadbData);
    kahadb.setJournalMaxFileLength(10 * 1024);
    kahadb.setCleanupInterval(5000);
    broker.setPersistenceAdapter(kahadb);
    broker.addConnector("tcp://localhost:61656");
    broker.getSystemUsage().getMemoryUsage().setLimit(256 * 1024 * 1024);
    broker.getSystemUsage().getTempUsage().setLimit(256 * 1024 * 1024);
    broker.getSystemUsage().getStoreUsage().setLimit(256 * 1024 * 1024);
    LOG.info(toString() + "Starting Broker...");
    broker.start();
    broker.waitUntilStarted();
    LOG.info(toString() + " Broker started!!");
}
Also used : File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 15 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project activemq-artemis by apache.

the class DurableSubscriptionActivationTest method createBroker.

private void createBroker(boolean delete) throws Exception {
    broker = BrokerFactory.createBroker("broker:(vm://localhost)");
    broker.setKeepDurableSubsActive(true);
    broker.setPersistent(true);
    broker.setDeleteAllMessagesOnStartup(delete);
    KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
    kahadb.setDirectory(new File("activemq-data/" + getName() + "-kahadb"));
    kahadb.setJournalMaxFileLength(500 * 1024);
    broker.setPersistenceAdapter(kahadb);
    broker.setBrokerName(getName());
    // only if we pre-create the destinations
    broker.setDestinations(new ActiveMQDestination[] { topic });
    broker.start();
    broker.waitUntilStarted();
    connection = createConnection();
}
Also used : File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Aggregations

KahaDBPersistenceAdapter (org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)40 File (java.io.File)18 BrokerService (org.apache.activemq.broker.BrokerService)12 Test (org.junit.Test)8 PersistenceAdapter (org.apache.activemq.store.PersistenceAdapter)5 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageProducer (javax.jms.MessageProducer)4 Session (javax.jms.Session)4 Wait (org.apache.activemq.util.Wait)4 IOException (java.io.IOException)3 URI (java.net.URI)3 LinkedList (java.util.LinkedList)3 JMSException (javax.jms.JMSException)3 MessageConsumer (javax.jms.MessageConsumer)3 JDBCPersistenceAdapter (org.apache.activemq.store.jdbc.JDBCPersistenceAdapter)3 CountDownLatch (java.util.concurrent.CountDownLatch)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 MessageListener (javax.jms.MessageListener)2 ObjectName (javax.management.ObjectName)2