Search in sources :

Example 71 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class SlowConsumerTest method testFastThenSlowConsumerSpared.

@Test
public void testFastThenSlowConsumerSpared() throws Exception {
    locator.setAckBatchSize(0);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(true, true));
    final ClientSession producerSession = addClientSession(sf.createSession(true, true));
    final ClientProducer producer = addClientProducer(producerSession.createProducer(QUEUE));
    final AtomicLong messagesProduced = new AtomicLong(0);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            ClientMessage m = createTextMessage(producerSession, "m", true);
            // send messages as fast as possible for 3 seconds
            while (System.currentTimeMillis() < (start + 3000)) {
                try {
                    producer.send(m);
                    messagesProduced.incrementAndGet();
                } catch (ActiveMQException e) {
                    e.printStackTrace();
                    return;
                }
            }
            start = System.currentTimeMillis();
            // send 1 msg/second for 10 seconds
            while (System.currentTimeMillis() < (start + 10000)) {
                try {
                    producer.send(m);
                    messagesProduced.incrementAndGet();
                    Thread.sleep(1000);
                } catch (Exception e) {
                    e.printStackTrace();
                    return;
                }
            }
        }
    });
    t.start();
    assertPaging();
    ClientConsumer consumer = addClientConsumer(session.createConsumer(QUEUE));
    session.start();
    ClientMessage m = null;
    long messagesConsumed = 0;
    do {
        m = consumer.receive(1500);
        if (m != null) {
            m.acknowledge();
            messagesConsumed++;
        }
    } while (m != null);
    assertEquals(messagesProduced.longValue(), messagesConsumed);
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) 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) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) Test(org.junit.Test)

Example 72 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class RedeliveryConsumerTest method setUp.

// Package protected ---------------------------------------------
// Protected -----------------------------------------------------
/**
 * @param persistDeliveryCountBeforeDelivery
 * @throws Exception
 */
private void setUp(final boolean persistDeliveryCountBeforeDelivery) throws Exception {
    Configuration config = createDefaultInVMConfig().setPersistDeliveryCountBeforeDelivery(persistDeliveryCountBeforeDelivery);
    server = createServer(true, config);
    server.start();
    locator = createInVMNonHALocator();
    factory = createSessionFactory(locator);
    ClientSession session = addClientSession(factory.createSession(false, false, false));
    try {
        session.createQueue(ADDRESS, ADDRESS, true);
    } catch (ActiveMQException expected) {
    // in case of restart
    }
    session.close();
}
Also used : Configuration(org.apache.activemq.artemis.core.config.Configuration) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession)

Example 73 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class SessionCloseTest method testCanNotUseAClosedSession.

// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testCanNotUseAClosedSession() throws Exception {
    final ClientSession session = sf.createSession(false, true, true);
    session.close();
    Assert.assertTrue(session.isClosed());
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createProducer();
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createConsumer(RandomUtil.randomSimpleString());
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString(), RandomUtil.randomBoolean());
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createTemporaryQueue(RandomUtil.randomSimpleString(), RandomUtil.randomSimpleString());
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.start();
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.stop();
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.commit();
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.rollback();
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.queueQuery(RandomUtil.randomSimpleString());
        }
    });
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.OBJECT_CLOSED, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.addressQuery(RandomUtil.randomSimpleString());
        }
    });
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) Test(org.junit.Test)

Example 74 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class SessionCreateAndDeleteQueueTest method testDeleteQueueNotExist.

@Test
public void testDeleteQueueNotExist() throws Exception {
    ClientSession session = createSessionFactory(locator).createSession(false, true, true);
    try {
        session.deleteQueue(queueName);
        Assert.fail("should throw exception");
    } catch (ActiveMQNonExistentQueueException neqe) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) Test(org.junit.Test)

Example 75 with ActiveMQException

use of org.apache.activemq.artemis.api.core.ActiveMQException in project activemq-artemis by apache.

the class ReceiveTest method testReceiveOnClosedException.

@Test
public void testReceiveOnClosedException() throws Exception {
    ClientSessionFactory cf = createSessionFactory(locator);
    ClientSession session = cf.createSession(false, true, true);
    session.createQueue(addressA, queueA, false);
    ClientConsumer cc = session.createConsumer(queueA);
    session.start();
    session.close();
    try {
        cc.receive();
        Assert.fail("should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    // ok
    } catch (ActiveMQException e) {
        Assert.fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) ClientSessionFactory(org.apache.activemq.artemis.api.core.client.ClientSessionFactory) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) Test(org.junit.Test)

Aggregations

ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)254 Test (org.junit.Test)140 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)121 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)84 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)79 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)78 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)59 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)54 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)45 CountDownLatch (java.util.concurrent.CountDownLatch)40 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)36 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)31 HashSet (java.util.HashSet)29 ActiveMQJAASSecurityManager (org.apache.activemq.artemis.spi.core.security.ActiveMQJAASSecurityManager)27 TransportConfiguration (org.apache.activemq.artemis.api.core.TransportConfiguration)23 Role (org.apache.activemq.artemis.core.security.Role)22 ActiveMQSecurityException (org.apache.activemq.artemis.api.core.ActiveMQSecurityException)20 Set (java.util.Set)16 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)16 Packet (org.apache.activemq.artemis.core.protocol.core.Packet)15