Search in sources :

Example 36 with KahaDBPersistenceAdapter

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

the class DurableSubProcessMultiRestartTest method testProcess.

/**
 * The test creates a durable subscriber and producer with a broker that is
 * continually restarted.
 *
 * Producer creates a message every .5 seconds -creates a new connection for
 * each message
 *
 * durable subscriber - comes online for 10 seconds, - then goes offline for
 * a "moment" - repeats the cycle
 *
 * approx every 10 seconds the broker restarts. Subscriber and Producer
 * connections will be closed BEFORE the restart.
 *
 * The Durable subscriber is "unsubscribed" before the the end of the test.
 *
 * checks for number of kahaDB files left on filesystem.
 *
 * @throws Exception
 */
@Test
public void testProcess() throws Exception {
    DurableSubscriber durableSubscriber = new DurableSubscriber(SUBSCRIPTION_ID);
    MsgProducer msgProducer = new MsgProducer();
    try {
        // register the subscription & start messages
        durableSubscriber.start();
        msgProducer.start();
        long endTime = System.currentTimeMillis() + RUNTIME;
        while (endTime > System.currentTimeMillis()) {
            Thread.sleep(10000);
            restartBroker();
        }
    } catch (Throwable e) {
        exit("ProcessTest.testProcess failed.", e);
    }
    // wait for threads to finish
    try {
        msgProducer.join();
        durableSubscriber.join();
    } catch (InterruptedException e) {
        e.printStackTrace(System.out);
    }
    // restart broker one last time
    restartBroker();
    assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
    final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
    assertTrue("only less than two journal files should be left: " + 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(3)));
    LOG.info("DONE.");
}
Also used : KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) Test(org.junit.Test)

Example 37 with KahaDBPersistenceAdapter

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

the class DurableSubProcessMultiRestartTest 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);
    broker.setKeepDurableSubsActive(true);
    File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
    if (deleteAllMessages)
        delete(kahadbData);
    broker.setPersistent(true);
    KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
    kahadb.setDirectory(kahadbData);
    kahadb.setJournalMaxFileLength(20 * 1024);
    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);
    broker.start();
}
Also used : File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 38 with KahaDBPersistenceAdapter

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

the class DurableSubProcessWithRestartTest 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);
    switch(PERSISTENT_ADAPTER) {
        case MEMORY:
            broker.setPersistent(false);
            break;
        case LEVELDB:
            File datadir = new File("activemq-data/" + getName() + "-leveldb");
            if (deleteAllMessages)
                delete(datadir);
            broker.setPersistent(true);
            LevelDBStore amq = new LevelDBStore();
            amq.setDirectory(datadir);
            broker.setPersistenceAdapter(amq);
            break;
        case KAHADB:
            File kahadbData = new File("activemq-data/" + getName() + "-kahadb");
            if (deleteAllMessages)
                delete(kahadbData);
            broker.setPersistent(true);
            KahaDBPersistenceAdapter kahadb = new KahaDBPersistenceAdapter();
            kahadb.setDirectory(kahadbData);
            kahadb.setJournalMaxFileLength(5 * 1024 * 1024);
            broker.setPersistenceAdapter(kahadb);
            break;
    }
    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);
    broker.start();
}
Also used : File(java.io.File) LevelDBStore(org.apache.activemq.leveldb.LevelDBStore) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 39 with KahaDBPersistenceAdapter

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

the class QueuePurgeTest method setUp.

@Override
protected void setUp() throws Exception {
    // 10 mins
    setMaxTestTime(10 * 60 * 1000);
    setAutoFail(true);
    super.setUp();
    broker = new BrokerService();
    File testDataDir = new File("target/activemq-data/QueuePurgeTest");
    broker.setDataDirectoryFile(testDataDir);
    broker.setUseJmx(true);
    broker.setDeleteAllMessagesOnStartup(true);
    broker.getSystemUsage().getMemoryUsage().setLimit(1024L * 1024 * 64);
    KahaDBPersistenceAdapter persistenceAdapter = new KahaDBPersistenceAdapter();
    persistenceAdapter.setDirectory(new File(testDataDir, "kahadb"));
    broker.setPersistenceAdapter(persistenceAdapter);
    broker.addConnector("tcp://localhost:0");
    broker.start();
    factory = new ActiveMQConnectionFactory(broker.getTransportConnectors().get(0).getConnectUri().toString());
    connection = factory.createConnection();
    connection.start();
}
Also used : ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) BrokerService(org.apache.activemq.broker.BrokerService) File(java.io.File) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 40 with KahaDBPersistenceAdapter

use of org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter in project fabric8 by jboss-fuse.

the class ServiceFactoryTest method testStartRetryOnIOException.

/**
 * Test for ENTMQ-2146.
 * Broker does not get restarted after it shuts down due to IOException
 * from KahaDB.
 *
 * @throws Exception
 */
@Test
public void testStartRetryOnIOException() throws Exception {
    final String brokerName = "amq-kahadb";
    underTest = new ActiveMQServiceFactory();
    underTest.curator = curator;
    Properties props = new Properties();
    props.put("config", "amq-kahadb.xml");
    props.put("broker-name", brokerName);
    props.put("connectors", "openwire");
    underTest.updated("b", props);
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return underTest.getBrokerService(brokerName) != null;
        }
    });
    underTest.getBrokerService(brokerName).waitUntilStarted(2000);
    final BrokerService brokerService = underTest.getBrokerService(brokerName);
    KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) brokerService.getPersistenceAdapter();
    // have the broker stop with an IOException on next checkpoint so it
    // has a pending local transaction to recover
    kahaDBPersistenceAdapter.getStore().getJournal().close();
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return brokerService.isStopped();
        }
    });
    assertTrue("Broker running again", Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            // check if broker is running
            BrokerService broker = underTest.getBrokerService(brokerName);
            return broker != null && broker.isStarted();
        }
    }));
}
Also used : Properties(java.util.Properties) Wait(org.apache.activemq.util.Wait) BrokerService(org.apache.activemq.broker.BrokerService) JMSException(javax.jms.JMSException) IOException(java.io.IOException) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) Test(org.junit.Test)

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