use of javax.jms.IllegalStateException in project qpid-broker-j by apache.
the class ExceptionListenerTest method testExceptionListenerStopsConnection_ThrowsIllegalStateException.
@Test
public void testExceptionListenerStopsConnection_ThrowsIllegalStateException() throws Exception {
assumeThat(getBrokerAdmin().supportsRestart(), is(equalTo(true)));
final Connection connection = getConnection();
try {
final CountDownLatch exceptionReceivedLatch = new CountDownLatch(1);
final AtomicReference<JMSException> exceptionHolder = new AtomicReference<>();
final AtomicReference<Throwable> unexpectedExceptionHolder = new AtomicReference<>();
final ExceptionListener listener = exception -> {
exceptionHolder.set(exception);
try {
connection.stop();
fail("Exception not thrown");
} catch (IllegalStateException ise) {
// PASS
} catch (Throwable t) {
unexpectedExceptionHolder.set(t);
} finally {
exceptionReceivedLatch.countDown();
}
};
connection.setExceptionListener(listener);
getBrokerAdmin().restart();
assertTrue("Exception was not propagated into exception listener in timely manner", exceptionReceivedLatch.await(getReceiveTimeout(), TimeUnit.MILLISECONDS));
assertNotNull("Unexpected exception", exceptionHolder.get());
assertNull("Connection#stop() should not have thrown exception", unexpectedExceptionHolder.get());
} finally {
connection.close();
}
}
use of javax.jms.IllegalStateException in project qpid-broker-j by apache.
the class CommitRollbackTest method testCommitOnClosedSession.
@Test
public void testCommitOnClosedSession() throws Exception {
Connection connection = getConnection();
try {
Session transactedSession = connection.createSession(true, Session.SESSION_TRANSACTED);
transactedSession.close();
try {
transactedSession.commit();
fail("Commit on closed session should throw IllegalStateException!");
} catch (IllegalStateException e) {
// passed
}
} finally {
connection.close();
}
}
use of javax.jms.IllegalStateException in project qpid-broker-j by apache.
the class CommitRollbackTest method testGetTransactedOnClosedSession.
@Test
public void testGetTransactedOnClosedSession() throws Exception {
Connection connection = getConnection();
try {
Session transactedSession = connection.createSession(true, Session.SESSION_TRANSACTED);
transactedSession.close();
try {
transactedSession.getTransacted();
fail("According to Sun TCK invocation of Session#getTransacted on closed session should throw IllegalStateException!");
} catch (IllegalStateException e) {
// passed
}
} finally {
connection.close();
}
}
use of javax.jms.IllegalStateException in project rabbitmq-jms-client by rabbitmq.
the class RMQSession method rollback.
/**
* {@inheritDoc}
*/
@Override
public void rollback() throws JMSException {
logger.trace("rollback transaction on session {}", this);
illegalStateExceptionIfClosed();
if (!this.transacted)
throw new IllegalStateException("Session is not transacted");
if (this.enterCommittingBlock()) {
try {
// rollback the RabbitMQ transaction which may cause some messages to become unacknowledged
this.channel.txRollback();
// requeue all unacknowledged messages (not automatically done by RabbitMQ)
// requeue
this.channel.basicRecover(true);
} catch (IOException x) {
this.logger.error("RabbitMQ exception on channel.txRollback() or channel.basicRecover(true) in session {}", this, x);
throw new RMQJMSException(x);
} finally {
this.leaveCommittingBlock();
}
}
}
use of javax.jms.IllegalStateException in project rabbitmq-jms-client by rabbitmq.
the class RMQSession method commit.
/**
* {@inheritDoc}
*/
@Override
public void commit() throws JMSException {
logger.trace("commit transaction on session {}", this);
illegalStateExceptionIfClosed();
if (!this.transacted)
throw new IllegalStateException("Session is not transacted");
if (this.enterCommittingBlock()) {
try {
// Call commit on the channel.
// All messages ought already to have been acked.
this.channel.txCommit();
} catch (Exception x) {
this.logger.error("RabbitMQ exception on channel.txCommit() in session {}", this, x);
throw new RMQJMSException(x);
} finally {
this.leaveCommittingBlock();
}
}
}
Aggregations