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();
}
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());
}
}
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);
}
});
}
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;
}
}
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();
}
}
Aggregations