Search in sources :

Example 1 with ActiveMQObjectClosedException

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

the class ProducerFlowControlTest method testClosingSessionUnblocksBlockedProducer.

@Test
public void testClosingSessionUnblocksBlockedProducer() throws Exception {
    final SimpleString address = new SimpleString("testaddress");
    server = createServer(false, isNetty());
    AddressSettings addressSettings = new AddressSettings().setMaxSizeBytes(1024).setAddressFullMessagePolicy(AddressFullMessagePolicy.BLOCK);
    HierarchicalRepository<AddressSettings> repos = server.getAddressSettingsRepository();
    repos.addMatch(address.toString(), addressSettings);
    server.start();
    waitForServerToStart(server);
    locator.setProducerWindowSize(1024).setConsumerWindowSize(1024).setAckBatchSize(1024);
    sf = createSessionFactory(locator);
    session = sf.createSession(false, true, true, true);
    final SimpleString queueName = new SimpleString("testqueue");
    session.createQueue(address, queueName, null, false);
    ClientProducer producer = session.createProducer(address);
    byte[] bytes = new byte[2000];
    ClientMessage message = session.createMessage(false);
    message.getBodyBuffer().writeBytes(bytes);
    final AtomicBoolean closed = new AtomicBoolean(false);
    Thread t = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(500);
                closed.set(true);
                session.close();
            } catch (Exception e) {
            }
        }
    });
    t.start();
    try {
        // This will block
        for (int i = 0; i < 10; i++) {
            producer.send(message);
        }
    } catch (ActiveMQObjectClosedException expected) {
    }
    Assert.assertTrue(closed.get());
    t.join();
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 2 with ActiveMQObjectClosedException

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

the class ReattachTest method testReattachAttemptsFailsToReconnect.

@Test
public void testReattachAttemptsFailsToReconnect() throws Exception {
    final long retryInterval = 50;
    final double retryMultiplier = 1d;
    final int reconnectAttempts = 3;
    locator.setRetryInterval(retryInterval).setRetryIntervalMultiplier(retryMultiplier).setReconnectAttempts(reconnectAttempts).setConfirmationWindowSize(1024 * 1024);
    ClientSessionFactoryInternal sf = (ClientSessionFactoryInternal) createSessionFactory(locator);
    ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ReattachTest.ADDRESS, ReattachTest.ADDRESS, null, false);
    ClientProducer producer = session.createProducer(ReattachTest.ADDRESS);
    final int numMessages = 1000;
    for (int i = 0; i < numMessages; i++) {
        ClientMessage message = session.createMessage(ActiveMQTextMessage.TYPE, false, 0, System.currentTimeMillis(), (byte) 1);
        message.putIntProperty(new SimpleString("count"), i);
        message.getBodyBuffer().writeString("aardvarks");
        producer.send(message);
    }
    session.createConsumer(ReattachTest.ADDRESS);
    InVMConnector.failOnCreateConnection = true;
    RemotingConnection conn = ((ClientSessionInternal) session).getConnection();
    // Sleep for longer than max retries so should fail to reconnect
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                Thread.sleep(retryInterval * (reconnectAttempts + 1));
            } catch (InterruptedException ignore) {
            }
            InVMConnector.failOnCreateConnection = false;
        }
    };
    t.start();
    conn.fail(new ActiveMQNotConnectedException());
    try {
        session.start();
        Assert.fail("Should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
    sf.close();
    t.join();
}
Also used : ClientSessionFactoryInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal) ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientMessage(org.apache.activemq.artemis.api.core.client.ClientMessage) 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) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 3 with ActiveMQObjectClosedException

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

the class SessionClosedOnRemotingConnectionFailureTest method testSessionClosedOnRemotingConnectionFailure.

@Test
public void testSessionClosedOnRemotingConnectionFailure() throws Exception {
    ClientSession session = addClientSession(sf.createSession());
    session.createQueue("fooaddress", RoutingType.ANYCAST, "fooqueue");
    ClientProducer prod = session.createProducer("fooaddress");
    ClientConsumer cons = session.createConsumer("fooqueue");
    session.start();
    prod.send(session.createMessage(false));
    Assert.assertNotNull(cons.receive());
    // Now fail the underlying connection
    RemotingConnection connection = ((ClientSessionInternal) session).getConnection();
    connection.fail(new ActiveMQNotConnectedException());
    Assert.assertTrue(session.isClosed());
    Assert.assertTrue(prod.isClosed());
    Assert.assertTrue(cons.isClosed());
    try {
        prod.send(session.createMessage(false));
        Assert.fail("Should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    try {
        cons.receive();
        Assert.fail("Should throw exception");
    } catch (ActiveMQObjectClosedException oce) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
    session.close();
}
Also used : ClientSessionInternal(org.apache.activemq.artemis.core.client.impl.ClientSessionInternal) 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) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) ActiveMQNotConnectedException(org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException) ClientConsumer(org.apache.activemq.artemis.api.core.client.ClientConsumer) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 4 with ActiveMQObjectClosedException

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

the class SlowConsumerTest method testSlowWildcardConsumer.

@Test
public void testSlowWildcardConsumer() throws Exception {
    SimpleString addressAB = new SimpleString("a.b");
    SimpleString addressAC = new SimpleString("a.c");
    SimpleString address = new SimpleString("a.*");
    SimpleString queueName1 = new SimpleString("Q1");
    SimpleString queueName2 = new SimpleString("Q2");
    SimpleString queueName = new SimpleString("Q");
    AddressSettings addressSettings = new AddressSettings();
    addressSettings.setSlowConsumerCheckPeriod(2);
    addressSettings.setSlowConsumerThreshold(10);
    addressSettings.setSlowConsumerPolicy(SlowConsumerPolicy.KILL);
    server.getAddressSettingsRepository().addMatch(address.toString(), addressSettings);
    ClientSessionFactory sf = createSessionFactory(locator);
    ClientSession session = addClientSession(sf.createSession(false, true, true, false));
    session.createQueue(addressAB, queueName1, null, false);
    session.createQueue(addressAC, queueName2, null, false);
    session.createQueue(address, queueName, null, false);
    ClientProducer producer = session.createProducer(addressAB);
    ClientProducer producer2 = session.createProducer(addressAC);
    final int numMessages = 20;
    for (int i = 0; i < numMessages; i++) {
        producer.send(createTextMessage(session, "m1" + i));
        producer2.send(createTextMessage(session, "m2" + i));
    }
    ClientConsumer consumer = addClientConsumer(session.createConsumer(queueName));
    session.start();
    Thread.sleep(3000);
    try {
        consumer.receiveImmediate();
        fail();
    } catch (ActiveMQObjectClosedException e) {
        assertEquals(e.getType(), ActiveMQExceptionType.OBJECT_CLOSED);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) ActiveMQObjectClosedException(org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) 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)

Example 5 with ActiveMQObjectClosedException

use of org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException 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

ActiveMQObjectClosedException (org.apache.activemq.artemis.api.core.ActiveMQObjectClosedException)8 Test (org.junit.Test)7 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)5 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)4 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)3 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)3 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)3 ActiveMQNotConnectedException (org.apache.activemq.artemis.api.core.ActiveMQNotConnectedException)2 ClientSessionFactoryInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionFactoryInternal)2 ClientSessionInternal (org.apache.activemq.artemis.core.client.impl.ClientSessionInternal)2 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)2 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)2 HashMap (java.util.HashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Connection (javax.jms.Connection)1 ConnectionFactory (javax.jms.ConnectionFactory)1 JMSException (javax.jms.JMSException)1