Search in sources :

Example 21 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class PagingCounterTest method testCleanupCounterNonPersistent.

@Test
public void testCleanupCounterNonPersistent() throws Exception {
    ClientSessionFactory sf = createSessionFactory(sl);
    ClientSession session = sf.createSession();
    try {
        server.addAddressInfo(new AddressInfo(new SimpleString("A1"), RoutingType.ANYCAST));
        Queue queue = server.createQueue(new SimpleString("A1"), RoutingType.ANYCAST, new SimpleString("A1"), null, true, false);
        PageSubscriptionCounter counter = locateCounter(queue);
        ((PageSubscriptionCounterImpl) counter).setPersistent(false);
        StorageManager storage = server.getStorageManager();
        Transaction tx = new TransactionImpl(server.getStorageManager());
        for (int i = 0; i < 2100; i++) {
            counter.increment(tx, 1, 1000);
            if (i % 200 == 0) {
                tx.commit();
                storage.waitOnOperations();
                assertEquals(i + 1, counter.getValue());
                assertEquals((i + 1) * 1000, counter.getPersistentSize());
                tx = new TransactionImpl(server.getStorageManager());
            }
        }
        tx.commit();
        storage.waitOnOperations();
        assertEquals(2100, counter.getValue());
        assertEquals(2100 * 1000, counter.getPersistentSize());
        server.stop();
        server = newActiveMQServer();
        server.start();
        queue = server.locateQueue(new SimpleString("A1"));
        assertNotNull(queue);
        counter = locateCounter(queue);
        assertEquals(0, counter.getValue());
        assertEquals(0, counter.getPersistentSize());
    } finally {
        sf.close();
        session.close();
    }
}
Also used : Transaction(org.apache.activemq.artemis.core.transaction.Transaction) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) PageSubscriptionCounter(org.apache.activemq.artemis.core.paging.cursor.PageSubscriptionCounter) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) PageSubscriptionCounterImpl(org.apache.activemq.artemis.core.paging.cursor.impl.PageSubscriptionCounterImpl) Test(org.junit.Test)

Example 22 with StorageManager

use of org.apache.activemq.artemis.core.persistence.StorageManager in project activemq-artemis by apache.

the class TopicCleanupTest method testSendTopic.

@Test
public void testSendTopic() throws Exception {
    Topic topic = createTopic("topic");
    Connection conn = cf.createConnection();
    try {
        conn.setClientID("someID");
        Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        MessageConsumer cons = sess.createDurableSubscriber(topic, "someSub");
        conn.start();
        MessageProducer prod = sess.createProducer(topic);
        TextMessage msg1 = sess.createTextMessage("text");
        prod.send(msg1);
        assertNotNull(cons.receive(5000));
        conn.close();
        StorageManager storage = server.getStorageManager();
        for (int i = 0; i < 100; i++) {
            long txid = storage.generateID();
            final Queue queue = new QueueImpl(storage.generateID(), SimpleString.toSimpleString("topic"), SimpleString.toSimpleString("topic"), FilterImpl.createFilter(Filter.GENERIC_IGNORED_FILTER), null, true, false, false, server.getScheduledPool(), server.getPostOffice(), storage, server.getAddressSettingsRepository(), server.getExecutorFactory().getExecutor(), server, null);
            LocalQueueBinding binding = new LocalQueueBinding(queue.getAddress(), queue, server.getNodeID());
            storage.addQueueBinding(txid, binding);
            storage.commitBindings(txid);
        }
        jmsServer.stop();
        jmsServer.start();
    } finally {
        try {
            conn.close();
        } catch (Throwable igonred) {
        }
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) LocalQueueBinding(org.apache.activemq.artemis.core.postoffice.impl.LocalQueueBinding) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) ActiveMQTopic(org.apache.activemq.artemis.jms.client.ActiveMQTopic) Queue(org.apache.activemq.artemis.core.server.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Aggregations

StorageManager (org.apache.activemq.artemis.core.persistence.StorageManager)22 Test (org.junit.Test)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)15 Queue (org.apache.activemq.artemis.core.server.Queue)9 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)7 Transaction (org.apache.activemq.artemis.core.transaction.Transaction)7 PageSubscription (org.apache.activemq.artemis.core.paging.cursor.PageSubscription)6 PagingStoreFactoryNIO (org.apache.activemq.artemis.core.paging.impl.PagingStoreFactoryNIO)6 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)6 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)6 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)5 Configuration (org.apache.activemq.artemis.core.config.Configuration)5 PagingManagerImpl (org.apache.activemq.artemis.core.paging.impl.PagingManagerImpl)5 NullStorageManager (org.apache.activemq.artemis.core.persistence.impl.nullpm.NullStorageManager)5 HierarchicalObjectRepository (org.apache.activemq.artemis.core.settings.impl.HierarchicalObjectRepository)5 ExecutorService (java.util.concurrent.ExecutorService)4 DivertConfiguration (org.apache.activemq.artemis.core.config.DivertConfiguration)4 StoreConfiguration (org.apache.activemq.artemis.core.config.StoreConfiguration)4