Search in sources :

Example 31 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class AutoDeleteJmsDestinationTest method testAutoDeleteNegative.

@Test
public void testAutoDeleteNegative() throws Exception {
    server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoDeleteQueues(false));
    Connection connection = cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    javax.jms.Queue queue = ActiveMQJMSClient.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    final int numMessages = 100;
    for (int i = 0; i < numMessages; i++) {
        TextMessage mess = session.createTextMessage("msg" + i);
        producer.send(mess);
    }
    producer.close();
    MessageConsumer messageConsumer = session.createConsumer(queue);
    connection.start();
    for (int i = 0; i < numMessages - 1; i++) {
        Message m = messageConsumer.receive(5000);
        Assert.assertNotNull(m);
    }
    session.close();
    // ensure the queue is still there
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString("test")).getBindable();
    Assert.assertEquals(1, q.getMessageCount());
    Assert.assertEquals(numMessages, q.getMessagesAdded());
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    messageConsumer = session.createConsumer(queue);
    Message m = messageConsumer.receive(5000);
    Assert.assertNotNull(m);
    connection.close();
    // ensure the queue was not removed
    Assert.assertNotNull(server.getPostOffice().getBinding(new SimpleString("test")));
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) MessageConsumer(javax.jms.MessageConsumer) TextMessage(javax.jms.TextMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Queue(org.apache.activemq.artemis.core.server.Queue) TextMessage(javax.jms.TextMessage) Session(javax.jms.Session) Test(org.junit.Test)

Example 32 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class CreateQueueTest method testUnsupportedRoutingType.

@Test
public void testUnsupportedRoutingType() throws Exception {
    ClientSession sendSession = cf.createSession(false, true, true);
    server.getAddressSettingsRepository().addMatch(addressA.toString(), new AddressSettings().setAutoCreateAddresses(false));
    server.getAddressSettingsRepository().addMatch(addressB.toString(), new AddressSettings().setAutoCreateAddresses(false));
    EnumSet<RoutingType> routingTypes = EnumSet.of(RoutingType.ANYCAST);
    sendSession.createAddress(addressA, routingTypes, false);
    try {
        sendSession.createQueue(addressA, RoutingType.MULTICAST, queueA);
        fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        ActiveMQException ae = (ActiveMQException) e;
        assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
    }
    routingTypes = EnumSet.of(RoutingType.MULTICAST);
    sendSession.createAddress(addressB, routingTypes, false);
    try {
        sendSession.createQueue(addressB, RoutingType.ANYCAST, queueB);
        fail("Creating a queue here should fail since the queue routing type differs from what is supported on the address.");
    } catch (Exception e) {
        assertTrue(e instanceof ActiveMQException);
        ActiveMQException ae = (ActiveMQException) e;
        assertEquals(ActiveMQExceptionType.INTERNAL_ERROR, ae.getType());
    }
    sendSession.close();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) Test(org.junit.Test)

Example 33 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ExpireTestOnRestartTest method setUp.

@Override
@Before
public void setUp() throws Exception {
    super.setUp();
    server = createServer(true);
    AddressSettings setting = new AddressSettings().setExpiryAddress(SimpleString.toSimpleString("exp")).setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE).setPageSizeBytes(100 * 1024).setMaxSizeBytes(200 * 1024);
    server.getConfiguration().setJournalSyncNonTransactional(false);
    server.getConfiguration().setMessageExpiryScanPeriod(-1);
    server.getConfiguration().setJournalSyncTransactional(false);
    server.getAddressSettingsRepository().addMatch("#", setting);
    server.start();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Before(org.junit.Before)

Example 34 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class ExpiryLargeMessageTest method testExpiryMessagesThenDLQ.

// Attributes ----------------------------------------------------
// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testExpiryMessagesThenDLQ() throws Exception {
    ActiveMQServer server = createServer(true);
    server.getConfiguration().setMessageExpiryScanPeriod(600000);
    AddressSettings setting = new AddressSettings().setAddressFullMessagePolicy(AddressFullMessagePolicy.PAGE).setMaxDeliveryAttempts(5).setMaxSizeBytes(50 * 1024).setPageSizeBytes(10 * 1024).setExpiryAddress(EXPIRY).setDeadLetterAddress(DLQ);
    server.getAddressSettingsRepository().addMatch(MY_QUEUE.toString(), setting);
    server.getAddressSettingsRepository().addMatch(EXPIRY.toString(), setting);
    server.start();
    server.createQueue(EXPIRY, RoutingType.ANYCAST, EXPIRY, null, true, false);
    server.createQueue(DLQ, RoutingType.ANYCAST, DLQ, null, true, false);
    server.createQueue(MY_QUEUE, RoutingType.ANYCAST, MY_QUEUE, null, true, false);
    ServerLocator locator = createInVMNonHALocator();
    ClientSessionFactory sf = addSessionFactory(createSessionFactory(locator));
    ClientSession session = sf.createSession(true, true, 0);
    byte[] bufferSample = new byte[messageSize];
    for (int i = 0; i < bufferSample.length; i++) {
        bufferSample[i] = getSamplebyte(i);
    }
    ClientProducer producer = session.createProducer(MY_QUEUE);
    long timeToExpiry = System.currentTimeMillis() + 1000;
    for (int i = 0; i < numberOfMessages; i++) {
        ClientMessage message = session.createMessage(true);
        message.putIntProperty("count", i);
        // Send a few regular messages first, then all is just large messages
        if (i % 2 == 0) {
            message.putBooleanProperty("tst-large", false);
            message.getBodyBuffer().writeBytes(bufferSample);
        } else {
            message.putBooleanProperty("tst-large", true);
            message.setBodyInputStream(createFakeLargeStream(messageSize));
        }
        message.setExpiration(timeToExpiry);
        producer.send(message);
    }
    session.close();
    server.stop();
    server.start();
    Queue queueExpiry = server.locateQueue(EXPIRY);
    Queue myQueue = server.locateQueue(MY_QUEUE);
    sf = createSessionFactory(locator);
    Thread.sleep(1500);
    long timeout = System.currentTimeMillis() + 5000;
    while (timeout > System.currentTimeMillis() && getMessageCount(queueExpiry) != numberOfMessages) {
        // What the Expiry Scan would be doing
        myQueue.expireReferences();
        Thread.sleep(50);
    }
    assertEquals(50, getMessageCount(queueExpiry));
    session = sf.createSession(false, false);
    ClientConsumer cons = session.createConsumer(EXPIRY);
    session.start();
    // Consume half of the messages to make sure all the messages are paging (on the second try)
    for (int i = 0; i < numberOfMessages / 2; i++) {
        ClientMessage msg = cons.receive(5000);
        assertNotNull(msg);
        msg.acknowledge();
    }
    session.commit();
    cons.close();
    for (int rep = 0; rep < 6; rep++) {
        cons = session.createConsumer(EXPIRY);
        session.start();
        log.info("Trying " + rep);
        for (int i = 0; i < numberOfMessages / 2; i++) {
            ClientMessage message = cons.receive(5000);
            assertNotNull(message);
            if (i % 10 == 0) {
                System.out.println("Received " + i);
            }
            for (int location = 0; location < messageSize; location++) {
                assertEquals(getSamplebyte(location), message.getBodyBuffer().readByte());
            }
            message.acknowledge();
        }
        session.rollback();
        cons.close();
        session.close();
        sf.close();
        if (rep == 0) {
            // restart the server at the first try
            server.stop();
            server.start();
        }
        sf = createSessionFactory(locator);
        session = sf.createSession(false, false);
        session.start();
    }
    cons = session.createConsumer(EXPIRY);
    session.start();
    assertNull(cons.receiveImmediate());
    cons.close();
    session.close();
    sf.close();
    for (int rep = 0; rep < 2; rep++) {
        sf = createSessionFactory(locator);
        session = sf.createSession(false, false);
        cons = session.createConsumer(DLQ);
        session.start();
        for (int i = 0; i < numberOfMessages / 2; i++) {
            ClientMessage message = cons.receive(5000);
            assertNotNull(message);
            if (i % 10 == 0) {
                System.out.println("Received " + i);
            }
            for (int location = 0; location < messageSize; location++) {
                assertEquals(getSamplebyte(location), message.getBodyBuffer().readByte());
            }
            message.acknowledge();
        }
        if (rep == 0) {
            session.rollback();
            session.close();
            sf.close();
            server.stop();
            server.start();
        }
    }
    session.commit();
    assertNull(cons.receiveImmediate());
    session.close();
    sf.close();
    locator.close();
    validateNoFilesOnLargeDir();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Queue(org.apache.activemq.artemis.core.server.Queue) ServerLocator(org.apache.activemq.artemis.api.core.client.ServerLocator) Test(org.junit.Test)

Example 35 with AddressSettings

use of org.apache.activemq.artemis.core.settings.impl.AddressSettings in project activemq-artemis by apache.

the class InterruptedLargeMessageTest method testSendPreparedXA.

@Test
public void testSendPreparedXA() throws Exception {
    ClientSession session = null;
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    ActiveMQServer server = createServer(true, createDefaultConfig(isNetty()), 10000, 20000, new HashMap<String, AddressSettings>());
    server.getConfiguration().getIncomingInterceptorClassNames().add(LargeMessageTestInterceptorIgnoreLastPacket.class.getName());
    server.start();
    locator.setBlockOnNonDurableSend(true).setBlockOnDurableSend(true);
    ClientSessionFactory sf = createSessionFactory(locator);
    session = sf.createSession(true, false, false);
    Xid xid1 = newXID();
    Xid xid2 = newXID();
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    session.start(xid1, XAResource.TMNOFLAGS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        clientFile.putIntProperty("txid", 1);
        producer.send(clientFile);
    }
    session.end(xid1, XAResource.TMSUCCESS);
    session.prepare(xid1);
    session.start(xid2, XAResource.TMNOFLAGS);
    for (int i = 0; i < 10; i++) {
        Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
        clientFile.putIntProperty("txid", 2);
        clientFile.putIntProperty("i", i);
        producer.send(clientFile);
    }
    session.end(xid2, XAResource.TMSUCCESS);
    session.prepare(xid2);
    session.close();
    sf.close();
    server.fail(false);
    server.start();
    for (int start = 0; start < 2; start++) {
        System.out.println("Start " + start);
        sf = createSessionFactory(locator);
        if (start == 0) {
            session = sf.createSession(true, false, false);
            session.commit(xid1, false);
            session.close();
        }
        session = sf.createSession(false, false, false);
        ClientConsumer cons1 = session.createConsumer(ADDRESS);
        session.start();
        for (int i = 0; i < 10; i++) {
            log.info("I = " + i);
            ClientMessage msg = cons1.receive(5000);
            Assert.assertNotNull(msg);
            Assert.assertEquals(1, msg.getIntProperty("txid").intValue());
            msg.acknowledge();
        }
        if (start == 1) {
            session.commit();
        } else {
            session.rollback();
        }
        session.close();
        sf.close();
        server.stop();
        server.start();
    }
    server.stop();
    validateNoFilesOnLargeDir(server.getConfiguration().getLargeMessagesDirectory(), 10);
    server.start();
    sf = createSessionFactory(locator);
    session = sf.createSession(true, false, false);
    session.rollback(xid2);
    sf.close();
    server.stop();
    server.start();
    server.stop();
    validateNoFilesOnLargeDir();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SessionContinuationMessage(org.apache.activemq.artemis.core.protocol.core.impl.wireformat.SessionContinuationMessage) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) Message(org.apache.activemq.artemis.api.core.Message) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) Xid(javax.transaction.xa.Xid) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Aggregations

AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)273 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)162 Test (org.junit.Test)161 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)103 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)103 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)88 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)81 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)65 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)54 Configuration (org.apache.activemq.artemis.core.config.Configuration)52 HashMap (java.util.HashMap)31 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)30 Queue (org.apache.activemq.artemis.core.server.Queue)24 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)21 Before (org.junit.Before)19 Session (javax.jms.Session)18 Message (org.apache.activemq.artemis.api.core.Message)18 ArrayList (java.util.ArrayList)15 PagingStore (org.apache.activemq.artemis.core.paging.PagingStore)15 ActiveMQBuffer (org.apache.activemq.artemis.api.core.ActiveMQBuffer)14