Search in sources :

Example 51 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class MessageProducerTest method testSendToQueueOnlyWhenTopicWithSameAddress.

@Test
public void testSendToQueueOnlyWhenTopicWithSameAddress() throws Exception {
    SimpleString addr = SimpleString.toSimpleString("testAddr");
    EnumSet<RoutingType> supportedRoutingTypes = EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST);
    servers.get(0).getActiveMQServer().addAddressInfo(new AddressInfo(addr, supportedRoutingTypes));
    servers.get(0).getActiveMQServer().createQueue(addr, RoutingType.ANYCAST, addr, null, false, false);
    Connection pconn = createConnection();
    pconn.start();
    Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = ps.createQueue(addr.toString());
    Topic topic = ps.createTopic(addr.toString());
    MessageConsumer queueConsumer = ps.createConsumer(queue);
    MessageConsumer topicConsumer = ps.createConsumer(topic);
    MessageProducer queueProducer = ps.createProducer(queue);
    queueProducer.send(ps.createMessage());
    assertNotNull(queueConsumer.receive(1000));
    assertNull(topicConsumer.receive(1000));
    MessageProducer topicProducer = ps.createProducer(topic);
    topicProducer.send(ps.createMessage());
    assertNull(queueConsumer.receive(1000));
    assertNotNull(topicConsumer.receive(1000));
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) Queue(javax.jms.Queue) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Session(javax.jms.Session) Test(org.junit.Test)

Example 52 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class PagingTest method testPurge.

@Test
public void testPurge() throws Exception {
    clearDataRecreateServerDirs();
    Configuration config = createDefaultNettyConfig().setJournalSyncNonTransactional(false);
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    String queue = "purgeQueue";
    SimpleString ssQueue = new SimpleString(queue);
    server.addAddressInfo(new AddressInfo(ssQueue, RoutingType.ANYCAST));
    QueueImpl purgeQueue = (QueueImpl) server.createQueue(ssQueue, RoutingType.ANYCAST, ssQueue, null, true, false, 1, true, false);
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
    Connection connection = cf.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    javax.jms.Queue jmsQueue = session.createQueue(queue);
    MessageProducer producer = session.createProducer(jmsQueue);
    for (int i = 0; i < 100; i++) {
        producer.send(session.createTextMessage("hello" + i));
    }
    session.commit();
    Wait.assertEquals(0, purgeQueue::getMessageCount);
    Assert.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore().getAddressSize());
    MessageConsumer consumer = session.createConsumer(jmsQueue);
    for (int i = 0; i < 100; i++) {
        producer.send(session.createTextMessage("hello" + i));
        if (i == 10) {
            purgeQueue.getPageSubscription().getPagingStore().startPaging();
        }
    }
    session.commit();
    consumer.close();
    Wait.assertEquals(0, purgeQueue::getMessageCount);
    Wait.assertFalse(purgeQueue.getPageSubscription()::isPaging);
    Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
    purgeQueue.getPageSubscription().getPagingStore().startPaging();
    Wait.assertTrue(purgeQueue.getPageSubscription()::isPaging);
    consumer = session.createConsumer(jmsQueue);
    for (int i = 0; i < 100; i++) {
        purgeQueue.getPageSubscription().getPagingStore().startPaging();
        Assert.assertTrue(purgeQueue.getPageSubscription().isPaging());
        producer.send(session.createTextMessage("hello" + i));
        if (i % 2 == 0) {
            session.commit();
        }
    }
    session.commit();
    connection.start();
    server.getStorageManager().getMessageJournal().scheduleCompactAndBlock(50000);
    Assert.assertNotNull(consumer.receive(5000));
    session.commit();
    consumer.close();
    Wait.assertEquals(0, purgeQueue::getMessageCount);
    Wait.assertEquals(0, purgeQueue.getPageSubscription().getPagingStore()::getAddressSize);
    Wait.assertFalse(purgeQueue.getPageSubscription()::isPaging);
    StorageManager sm = server.getStorageManager();
    for (int i = 0; i < 1000; i++) {
        long tx = sm.generateID();
        PageTransactionInfoImpl txinfo = new PageTransactionInfoImpl(tx);
        sm.storePageTransaction(tx, txinfo);
        sm.commit(tx);
        tx = sm.generateID();
        sm.updatePageTransaction(tx, txinfo, 1);
        sm.commit(tx);
    }
    server.stop();
    server.start();
    Assert.assertEquals(0, server.getPagingManager().getTransactions().size());
}
Also used : MessageConsumer(javax.jms.MessageConsumer) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) PageTransactionInfoImpl(org.apache.activemq.artemis.core.paging.impl.PageTransactionInfoImpl) Connection(javax.jms.Connection) StorageManager(org.apache.activemq.artemis.core.persistence.StorageManager) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueImpl(org.apache.activemq.artemis.core.server.impl.QueueImpl) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) ActiveMQConnectionFactory(org.apache.activemq.artemis.jms.client.ActiveMQConnectionFactory) MessageProducer(javax.jms.MessageProducer) Session(javax.jms.Session) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 53 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class PagingTest method testSyncPage.

@Test
public void testSyncPage() throws Exception {
    Configuration config = createDefaultInVMConfig();
    server = createServer(true, config, PagingTest.PAGE_SIZE, PagingTest.PAGE_MAX);
    server.start();
    try {
        server.addAddressInfo(new AddressInfo(PagingTest.ADDRESS, RoutingType.ANYCAST));
        server.createQueue(PagingTest.ADDRESS, RoutingType.ANYCAST, PagingTest.ADDRESS, null, true, false);
        final CountDownLatch pageUp = new CountDownLatch(0);
        final CountDownLatch pageDone = new CountDownLatch(1);
        OperationContext ctx = new DummyOperationContext(pageUp, pageDone);
        OperationContextImpl.setContext(ctx);
        PagingManager paging = server.getPagingManager();
        PagingStore store = paging.getPageStore(ADDRESS);
        store.sync();
        assertTrue(pageUp.await(10, TimeUnit.SECONDS));
        assertTrue(pageDone.await(10, TimeUnit.SECONDS));
        server.stop();
    } finally {
        try {
            server.stop();
        } catch (Throwable ignored) {
        }
        OperationContextImpl.clearContext();
    }
}
Also used : OperationContext(org.apache.activemq.artemis.core.persistence.OperationContext) DivertConfiguration(org.apache.activemq.artemis.core.config.DivertConfiguration) StoreConfiguration(org.apache.activemq.artemis.core.config.StoreConfiguration) Configuration(org.apache.activemq.artemis.core.config.Configuration) DatabaseStorageConfiguration(org.apache.activemq.artemis.core.config.storage.DatabaseStorageConfiguration) PagingManager(org.apache.activemq.artemis.core.paging.PagingManager) CountDownLatch(java.util.concurrent.CountDownLatch) PagingStore(org.apache.activemq.artemis.core.paging.PagingStore) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 54 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class CorePluginTest method testUpdateAddress.

@Test
public void testUpdateAddress() throws Exception {
    server.addOrUpdateAddressInfo(new AddressInfo(SimpleString.toSimpleString("test"), RoutingType.ANYCAST));
    server.addOrUpdateAddressInfo(new AddressInfo(SimpleString.toSimpleString("test"), RoutingType.MULTICAST));
    verifier.validatePluginMethodsEquals(1, BEFORE_UPDATE_ADDRESS, AFTER_UPDATE_ADDRESS);
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 55 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class PagingCounterTest method testCounter.

@Test
public void testCounter() 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);
        StorageManager storage = server.getStorageManager();
        Transaction tx = new TransactionImpl(server.getStorageManager());
        counter.increment(tx, 1, 1000);
        assertEquals(0, counter.getValue());
        assertEquals(0, counter.getPersistentSize());
        tx.commit();
        storage.waitOnOperations();
        assertEquals(1, counter.getValue());
        assertEquals(1000, 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) Test(org.junit.Test)

Aggregations

AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)116 Test (org.junit.Test)89 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)73 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)32 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)24 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)23 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)23 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)22 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)21 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)19 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)18 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)17 JsonObject (javax.json.JsonObject)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)16 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)16 JsonArray (javax.json.JsonArray)15 Queue (org.apache.activemq.artemis.core.server.Queue)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)13 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Session (javax.jms.Session)11