Search in sources :

Example 26 with KahaDBPersistenceAdapter

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

the class DurablePersistentFalseRestartTest method configureBroker.

@Override
protected void configureBroker(BrokerService broker) throws Exception {
    super.configureBroker(broker);
    broker.setPersistent(false);
    broker.setPersistenceAdapter(new KahaDBPersistenceAdapter());
    broker.addConnector("tcp://0.0.0.0:0");
}
Also used : KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 27 with KahaDBPersistenceAdapter

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

the class kahaDbJdbcLeaseQueueMasterSlaveTest method createSlave.

@Override
protected void createSlave() throws Exception {
    // use a separate thread as the slave will block waiting for
    // the exclusive db lock
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                BrokerService broker = new BrokerService();
                broker.setBrokerName("slave");
                TransportConnector connector = new TransportConnector();
                connector.setUri(new URI(SLAVE_URL));
                broker.addConnector(connector);
                broker.setUseJmx(false);
                broker.setPersistent(true);
                KahaDBPersistenceAdapter kahaDBPersistenceAdapter = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
                LeaseDatabaseLocker leaseDatabaseLocker = new LeaseDatabaseLocker();
                leaseDatabaseLocker.setDataSource(getExistingDataSource());
                leaseDatabaseLocker.setStatements(new Statements());
                kahaDBPersistenceAdapter.setLocker(leaseDatabaseLocker);
                configureLocker(kahaDBPersistenceAdapter);
                configureBroker(broker);
                broker.start();
                slave.set(broker);
                slaveStarted.countDown();
            } catch (IllegalStateException expectedOnShutdown) {
            } catch (Exception e) {
                fail("failed to start slave broker, reason:" + e);
            }
        }
    };
    t.start();
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) Statements(org.apache.activemq.store.jdbc.Statements) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) LeaseDatabaseLocker(org.apache.activemq.store.jdbc.LeaseDatabaseLocker) IOException(java.io.IOException) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 28 with KahaDBPersistenceAdapter

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

the class mKahaDbQueueMasterSlaveTest method createSlave.

@Override
protected void createSlave() throws Exception {
    // use a separate thread as the slave will block waiting for
    // the exclusive db lock
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                BrokerService broker = new BrokerService();
                broker.setBrokerName("slave");
                TransportConnector connector = new TransportConnector();
                connector.setUri(new URI(SLAVE_URL));
                broker.addConnector(connector);
                // no need for broker.setMasterConnectorURI(masterConnectorURI)
                // as the db lock provides the slave/master initialisation
                broker.setUseJmx(false);
                broker.setPersistent(true);
                MultiKahaDBPersistenceAdapter mKahaDB = new MultiKahaDBPersistenceAdapter();
                List<FilteredKahaDBPersistenceAdapter> adapters = new LinkedList<>();
                FilteredKahaDBPersistenceAdapter defaultEntry = new FilteredKahaDBPersistenceAdapter();
                defaultEntry.setPersistenceAdapter(new KahaDBPersistenceAdapter());
                defaultEntry.setPerDestination(true);
                adapters.add(defaultEntry);
                mKahaDB.setFilteredPersistenceAdapters(adapters);
                broker.setPersistenceAdapter(mKahaDB);
                broker.start();
                slave.set(broker);
                slaveStarted.countDown();
            } catch (IllegalStateException expectedOnShutdown) {
            } catch (Exception e) {
                fail("failed to start slave broker, reason:" + e);
            }
        }
    };
    t.start();
}
Also used : TransportConnector(org.apache.activemq.broker.TransportConnector) FilteredKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.FilteredKahaDBPersistenceAdapter) MultiKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter) BrokerService(org.apache.activemq.broker.BrokerService) URI(java.net.URI) LinkedList(java.util.LinkedList) MultiKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter) FilteredKahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.FilteredKahaDBPersistenceAdapter) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter)

Example 29 with KahaDBPersistenceAdapter

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

the class DurableSubDelayedUnsubscribeTest method testProcess.

@Test
public void testProcess() throws Exception {
    server.start();
    clientManager.start();
    houseKeeper.start();
    // Sleep to
    Thread.sleep(RUNTIME);
    // inform message producer to stop
    server.stopped = true;
    // add one Subscriber to the topic that will not be unsubscribed.
    // should not have any pending messages in the kahadb store
    Client lastClient = new Client(32000, ClientType.A);
    lastClient.process(1000);
    // stop client manager from creating any more clients
    clientManager.stopped = true;
    final BrokerService brokerService = this.broker;
    // Wait for all client subscription to be unsubscribed or swept away.
    // Ensure we sleep longer than the housekeeper's sweep delay otherwise we can
    // miss the fact that all durables that were abandoned do finally get cleaned up.
    // Wait for all clients to stop
    Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return clientManager.getClientCount() == 0;
        }
    }, Client.lifetime + TimeUnit.SECONDS.toMillis(10));
    assertTrue("should have only one inactiveSubscriber subscribed but was: " + brokerService.getAdminView().getInactiveDurableTopicSubscribers().length, Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return brokerService.getAdminView().getInactiveDurableTopicSubscribers().length == 1;
        }
    }, houseKeeper.SWEEP_DELAY * 2));
    assertTrue("should be no subscribers subscribed but was: " + brokerService.getAdminView().getDurableTopicSubscribers().length, Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return brokerService.getAdminView().getDurableTopicSubscribers().length == 0;
        }
    }, TimeUnit.MINUTES.toMillis(3)));
    processLock.writeLock().lock();
    // check outcome.
    ObjectName[] subscribers = broker.getAdminView().getDurableTopicSubscribers();
    ObjectName[] inactiveSubscribers = broker.getAdminView().getInactiveDurableTopicSubscribers();
    final KahaDBPersistenceAdapter persistenceAdapter = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
    printDebugClientInfo(subscribers, inactiveSubscribers, persistenceAdapter);
    assertEquals("should have only one inactiveSubscriber subscribed", 1, broker.getAdminView().getInactiveDurableTopicSubscribers().length);
    assertEquals("should be no subscribers subscribed", 0, broker.getAdminView().getDurableTopicSubscribers().length);
    final KahaDBPersistenceAdapter pa = (KahaDBPersistenceAdapter) broker.getPersistenceAdapter();
    assertTrue("should be less than 3 journal file left but was: " + persistenceAdapter.getStore().getJournal().getFileMap().size(), Wait.waitFor(new Wait.Condition() {

        @Override
        public boolean isSatisified() throws Exception {
            return pa.getStore().getJournal().getFileMap().size() <= 3;
        }
    }, TimeUnit.MINUTES.toMillis(3)));
    // Be good and cleanup our mess a bit.
    this.houseKeeper.shutdown();
    assertTrue("no exceptions: " + exceptions, exceptions.isEmpty());
    LOG.info("DONE.");
}
Also used : Wait(org.apache.activemq.util.Wait) BrokerService(org.apache.activemq.broker.BrokerService) IOException(java.io.IOException) JMSException(javax.jms.JMSException) ObjectName(javax.management.ObjectName) KahaDBPersistenceAdapter(org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter) Test(org.junit.Test)

Example 30 with KahaDBPersistenceAdapter

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

the class DurableSubProcessConcurrentCommitActivateNoDuplicateTest 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 amqData = new File("activemq-data/" + getName() + "-leveldb");
            if (deleteAllMessages)
                delete(amqData);
            broker.setPersistent(true);
            LevelDBStore amq = new LevelDBStore();
            amq.setDirectory(amqData);
            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(1024 * 1024 * 1024);
    PolicyMap policyMap = new PolicyMap();
    PolicyEntry defaultEntry = new PolicyEntry();
    defaultEntry.setMaxAuditDepth(20000);
    policyMap.setDefaultEntry(defaultEntry);
    broker.setDestinationPolicy(policyMap);
    broker.start();
}
Also used : PolicyMap(org.apache.activemq.broker.region.policy.PolicyMap) File(java.io.File) PolicyEntry(org.apache.activemq.broker.region.policy.PolicyEntry) LevelDBStore(org.apache.activemq.leveldb.LevelDBStore) 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