Search in sources :

Example 51 with ActiveMQException

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

the class InterruptedLargeMessageTest method testCloseConsumerDuringTransmission.

@Test
public void testCloseConsumerDuringTransmission() throws Exception {
    ActiveMQServer server = createServer(true, isNetty());
    LargeMessageTestInterceptorIgnoreLastPacket.disableInterrupt();
    server.start();
    locator.setBlockOnNonDurableSend(false).setBlockOnDurableSend(false).addIncomingInterceptor(new LargeMessageTestInterceptorIgnoreLastPacket());
    ClientSessionFactory sf = createSessionFactory(locator);
    final ClientSession session = sf.createSession(false, true, true);
    session.createQueue(ADDRESS, ADDRESS, true);
    ClientProducer producer = session.createProducer(ADDRESS);
    Message clientFile = createLargeClientMessageStreaming(session, LARGE_MESSAGE_SIZE, true);
    producer.send(clientFile);
    session.commit();
    LargeMessageTestInterceptorIgnoreLastPacket.clearInterrupt();
    final AtomicInteger unexpectedErrors = new AtomicInteger(0);
    final AtomicInteger expectedErrors = new AtomicInteger(0);
    final ClientConsumer cons = session.createConsumer(ADDRESS);
    session.start();
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                System.out.println("Receiving message");
                ClientMessage msg = cons.receive(5000);
                if (msg == null) {
                    System.err.println("Message not received");
                    unexpectedErrors.incrementAndGet();
                    return;
                }
                msg.checkCompletion();
            } catch (ActiveMQException e) {
                e.printStackTrace();
                expectedErrors.incrementAndGet();
            }
        }
    };
    t.start();
    LargeMessageTestInterceptorIgnoreLastPacket.awaitInterrupt();
    cons.close();
    t.join();
    Assert.assertEquals(0, unexpectedErrors.get());
    Assert.assertEquals(1, expectedErrors.get());
    session.close();
    server.stop();
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) 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) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) 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) Test(org.junit.Test)

Example 52 with ActiveMQException

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

the class MessageDurabilityTest method testNonDurableMessageOnNonDurableQueue.

// Static --------------------------------------------------------
// Constructors --------------------------------------------------
// Public --------------------------------------------------------
@Test
public void testNonDurableMessageOnNonDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, !durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(!durable));
    restart();
    session.start();
    try {
        session.createConsumer(queue);
    } catch (ActiveMQNonExistentQueueException neqe) {
    // ok
    } catch (ActiveMQException e) {
        fail("Invalid Exception type:" + e.getType());
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQNonExistentQueueException(org.apache.activemq.artemis.api.core.ActiveMQNonExistentQueueException) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 53 with ActiveMQException

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

the class MessageDurabilityTest method testDurableMessageOnNonDurableQueue.

/**
 * we can send a durable msg to a non durable queue but the msg won't be persisted
 */
@Test
public void testDurableMessageOnNonDurableQueue() throws Exception {
    boolean durable = true;
    SimpleString address = RandomUtil.randomSimpleString();
    final SimpleString queue = RandomUtil.randomSimpleString();
    session.createQueue(address, queue, !durable);
    ClientProducer producer = session.createProducer(address);
    producer.send(session.createMessage(durable));
    restart();
    session.start();
    ActiveMQTestBase.expectActiveMQException(ActiveMQExceptionType.QUEUE_DOES_NOT_EXIST, new ActiveMQAction() {

        @Override
        public void run() throws ActiveMQException {
            session.createConsumer(queue);
        }
    });
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ClientProducer(org.apache.activemq.artemis.api.core.client.ClientProducer) Test(org.junit.Test)

Example 54 with ActiveMQException

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

the class ServerConsumerImpl method acknowledge.

@Override
public synchronized void acknowledge(Transaction tx, final long messageID) throws Exception {
    if (browseOnly) {
        return;
    }
    // Acknowledge acknowledges all refs delivered by the consumer up to and including the one explicitly
    // acknowledged
    // We use a transaction here as if the message is not found, we should rollback anything done
    // This could eventually happen on retries during transactions, and we need to make sure we don't ACK things we are not supposed to acknowledge
    boolean startedTransaction = false;
    if (tx == null) {
        startedTransaction = true;
        tx = new TransactionImpl(storageManager);
    }
    try {
        MessageReference ref;
        do {
            synchronized (lock) {
                ref = deliveringRefs.poll();
            }
            if (logger.isTraceEnabled()) {
                logger.trace("ACKing ref " + ref + " on tx= " + tx + ", consumer=" + this);
            }
            if (ref == null) {
                ActiveMQIllegalStateException ils = ActiveMQMessageBundle.BUNDLE.consumerNoReference(id, messageID, messageQueue.getName());
                tx.markAsRollbackOnly(ils);
                throw ils;
            }
            ref.acknowledge(tx);
            acks++;
        } while (ref.getMessageID() != messageID);
        if (startedTransaction) {
            tx.commit();
        }
    } catch (ActiveMQException e) {
        if (startedTransaction) {
            tx.rollback();
        } else {
            tx.markAsRollbackOnly(e);
        }
        throw e;
    } catch (Throwable e) {
        ActiveMQServerLogger.LOGGER.errorAckingMessage((Exception) e);
        ActiveMQException activeMQIllegalStateException = new ActiveMQIllegalStateException(e.getMessage());
        if (startedTransaction) {
            tx.rollback();
        } else {
            tx.markAsRollbackOnly(activeMQIllegalStateException);
        }
        throw activeMQIllegalStateException;
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) TransactionImpl(org.apache.activemq.artemis.core.transaction.impl.TransactionImpl) MessageReference(org.apache.activemq.artemis.core.server.MessageReference) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException)

Example 55 with ActiveMQException

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

the class SharedNothingLiveActivation method startReplication.

public void startReplication(CoreRemotingConnection rc, final ClusterConnection clusterConnection, final Pair<TransportConfiguration, TransportConfiguration> pair, final boolean isFailBackRequest) throws ActiveMQException {
    if (replicationManager != null) {
        throw new ActiveMQAlreadyReplicatingException();
    }
    if (!activeMQServer.isStarted()) {
        throw new ActiveMQIllegalStateException();
    }
    synchronized (replicationLock) {
        if (replicationManager != null) {
            throw new ActiveMQAlreadyReplicatingException();
        }
        ReplicationFailureListener listener = new ReplicationFailureListener();
        rc.addCloseListener(listener);
        rc.addFailureListener(listener);
        replicationManager = new ReplicationManager(rc, clusterConnection.getCallTimeout(), replicatedPolicy.getInitialReplicationSyncTimeout(), activeMQServer.getExecutorFactory());
        replicationManager.start();
        Thread t = new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    activeMQServer.getStorageManager().startReplication(replicationManager, activeMQServer.getPagingManager(), activeMQServer.getNodeID().toString(), isFailBackRequest && replicatedPolicy.isAllowAutoFailBack(), replicatedPolicy.getInitialReplicationSyncTimeout());
                    clusterConnection.nodeAnnounced(System.currentTimeMillis(), activeMQServer.getNodeID().toString(), replicatedPolicy.getGroupName(), replicatedPolicy.getScaleDownGroupName(), pair, true);
                    if (isFailBackRequest && replicatedPolicy.isAllowAutoFailBack()) {
                        BackupTopologyListener listener1 = new BackupTopologyListener(activeMQServer.getNodeID().toString(), clusterConnection.getConnector());
                        clusterConnection.addClusterTopologyListener(listener1);
                        if (listener1.waitForBackup()) {
                            // if we have to many backups kept or are not configured to restart just stop, otherwise restart as a backup
                            activeMQServer.fail(true);
                            ActiveMQServerLogger.LOGGER.restartingReplicatedBackupAfterFailback();
                            // activeMQServer.moveServerData(replicatedPolicy.getReplicaPolicy().getMaxSavedReplicatedJournalsSize());
                            activeMQServer.setHAPolicy(replicatedPolicy.getReplicaPolicy());
                            activeMQServer.start();
                        } else {
                            ActiveMQServerLogger.LOGGER.failbackMissedBackupAnnouncement();
                        }
                    }
                } catch (Exception e) {
                    if (activeMQServer.getState() == ActiveMQServerImpl.SERVER_STATE.STARTED) {
                        /*
                   * The reasoning here is that the exception was either caused by (1) the
                   * (interaction with) the backup, or (2) by an IO Error at the storage. If (1), we
                   * can swallow the exception and ignore the replication request. If (2) the live
                   * will crash shortly.
                   */
                        ActiveMQServerLogger.LOGGER.errorStartingReplication(e);
                    }
                    try {
                        ActiveMQServerImpl.stopComponent(replicationManager);
                    } catch (Exception amqe) {
                        ActiveMQServerLogger.LOGGER.errorStoppingReplication(amqe);
                    } finally {
                        synchronized (replicationLock) {
                            replicationManager = null;
                        }
                    }
                }
            }
        });
        t.start();
    }
}
Also used : ReplicationManager(org.apache.activemq.artemis.core.replication.ReplicationManager) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQDisconnectedException(org.apache.activemq.artemis.api.core.ActiveMQDisconnectedException) ActiveMQIllegalStateException(org.apache.activemq.artemis.api.core.ActiveMQIllegalStateException) ActiveMQAlreadyReplicatingException(org.apache.activemq.artemis.api.core.ActiveMQAlreadyReplicatingException)

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