javax.jms.TransactionRolledBackException Java Examples
The following examples show how to use
javax.jms.TransactionRolledBackException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FailoverProviderOfflineBehaviorTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout=20000) public void testTransactionRollbackSucceeds() throws Exception { connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(_testName.getMethodName()); MessageProducer producer = session.createProducer(queue); producer.send(session.createMessage()); mockPeer.shutdown(); connectionInterrupted.await(9, TimeUnit.SECONDS); try { session.rollback(); } catch (TransactionRolledBackException ex) { fail("Should allow a rollback while offline."); } connection.close(); }
Example #2
Source File: FailoverProviderOfflineBehaviorTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout=20000) public void testTransactionCommitFails() throws Exception { connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(_testName.getMethodName()); MessageProducer producer = session.createProducer(queue); producer.send(session.createMessage()); mockPeer.shutdown(); connectionInterrupted.await(9, TimeUnit.SECONDS); try { session.commit(); fail("Should not allow a commit while offline."); } catch (TransactionRolledBackException ex) {} connection.close(); }
Example #3
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testRollbackErrorWhenCoordinatorRemotelyClosed() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); Binary txnId = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); testPeer.expectDeclare(txnId); testPeer.remotelyCloseLastCoordinatorLink(); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); testPeer.waitForAllHandlersToComplete(2000); testPeer.expectCoordinatorAttach(); testPeer.expectDeclare(txnId); testPeer.expectDischarge(txnId, true); try { session.commit(); fail("Transaction should have rolled back"); } catch (TransactionRolledBackException ex) { LOG.info("Caught expected TransactionRolledBackException"); } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #4
Source File: JMS2.java From tomee with Apache License 2.0 | 5 votes |
public static JMSRuntimeException toRuntimeException(final JMSException e) { if (e instanceof javax.jms.IllegalStateException) { return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof InvalidClientIDException) { return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof InvalidDestinationException) { return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof InvalidSelectorException) { return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof JMSSecurityException) { return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof MessageFormatException) { return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof MessageNotWriteableException) { return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof ResourceAllocationException) { return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof TransactionInProgressException) { return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof TransactionRolledBackException) { return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e); } return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e); }
Example #5
Source File: JmsTxProducerFailoverTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=60000) @Repeat(repetitions = 1) public void testTxProducerSendsThenFailoverCommitFails() throws Exception { URI brokerURI = new URI(getAmqpFailoverURI()); connection = createAmqpConnection(brokerURI); connection.start(); final int MSG_COUNT = 5; final Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(name.getMethodName()); final MessageProducer producer = session.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); for (int i = 0; i < MSG_COUNT; ++i) { LOG.debug("Producer sening message #{}", i + 1); producer.send(session.createTextMessage("Message: " + i)); } assertEquals(0, proxy.getQueueSize()); stopPrimaryBroker(); restartPrimaryBroker(); proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); try { session.commit(); fail("Session commit should have failed with TX rolled back."); } catch (TransactionRolledBackException rb) { LOG.info("Transacted commit failed after failover: {}", rb.getMessage()); } assertEquals(0, proxy.getQueueSize()); }
Example #6
Source File: JmsTxConsumerFailoverTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=60000) public void testTxConsumerReceiveThenFailoverCommitFails() throws Exception { URI brokerURI = new URI(getAmqpFailoverURI()); connection = createAmqpConnection(brokerURI); connection.start(); final int MSG_COUNT = 5; final Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(name.getMethodName()); final MessageConsumer consumer = session.createConsumer(queue); sendMessages(connection, queue, MSG_COUNT); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(MSG_COUNT, proxy.getQueueSize()); for (int i = 0; i < MSG_COUNT; ++i) { Message received = consumer.receive(3000); assertNotNull("Mesage was not expected but not received", received); } stopPrimaryBroker(); restartPrimaryBroker(); proxy = getProxyToQueue(name.getMethodName()); assertEquals(MSG_COUNT, proxy.getQueueSize()); try { LOG.info("Session commit firing after connection failed."); session.commit(); fail("Session commit should have failed with TX rolled back."); } catch (TransactionRolledBackException rb) { LOG.info("Transacted commit failed after failover: {}", rb.getMessage()); } assertEquals(MSG_COUNT, proxy.getQueueSize()); }
Example #7
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testPassthroughOfRollbackErrorCoordinatorClosedOnCommit() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { final String testPeerURI = createPeerURI(testPeer); LOG.info("Original peer is at: {}", testPeerURI); testPeer.expectSaslAnonymous(); testPeer.expectOpen(); testPeer.expectBegin(); testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); JmsConnection connection = establishAnonymousConnecton(testPeer); connection.start(); Binary txnId1 = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); Binary txnId2 = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4}); testPeer.expectDeclare(txnId1); testPeer.remotelyCloseLastCoordinatorLinkOnDischarge(txnId1, false, true, txnId2); testPeer.expectCoordinatorAttach(); testPeer.expectDeclare(txnId2); testPeer.expectDischarge(txnId2, true); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); try { session.commit(); fail("Transaction should have rolled back"); } catch (TransactionRolledBackException ex) { LOG.info("Caught expected TransactionRolledBackException"); } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #8
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testRollbackErrorCoordinatorClosedOnCommit() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); Binary txnId1 = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); Binary txnId2 = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4}); testPeer.expectDeclare(txnId1); testPeer.remotelyCloseLastCoordinatorLinkOnDischarge(txnId1, false, true, txnId2); testPeer.expectCoordinatorAttach(); testPeer.expectDeclare(txnId2); testPeer.expectDischarge(txnId2, true); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); try { session.commit(); fail("Transaction should have rolled back"); } catch (TransactionRolledBackException ex) { LOG.info("Caught expected TransactionRolledBackException"); } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #9
Source File: ProviderTransactionRolledBackException.java From qpid-jms with Apache License 2.0 | 5 votes |
@Override public TransactionRolledBackException toJMSException() { TransactionRolledBackException jmsEx = new TransactionRolledBackException(getMessage()); jmsEx.initCause(this); jmsEx.setLinkedException(this); return jmsEx; }
Example #10
Source File: JmsExceptionUtils.java From activemq-artemis with Apache License 2.0 | 5 votes |
/** * Converts instances of sub-classes of {@link JMSException} into the corresponding sub-class of * {@link JMSRuntimeException}. * * @param e * @return */ public static JMSRuntimeException convertToRuntimeException(JMSException e) { if (e instanceof javax.jms.IllegalStateException) { return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof InvalidClientIDException) { return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof InvalidDestinationException) { return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof InvalidSelectorException) { return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof JMSSecurityException) { return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof MessageFormatException) { return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof MessageNotWriteableException) { return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof ResourceAllocationException) { return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof TransactionInProgressException) { return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e); } if (e instanceof TransactionRolledBackException) { return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e); } return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e); }
Example #11
Source File: FailoverTransactionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testAutoRollbackWithMissingRedeliveries() throws Exception { LOG.info(this + " running test testAutoRollbackWithMissingRedeliveries"); broker = createBroker(); broker.start(); ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")"); configureConnectionFactory(cf); Connection connection = cf.createConnection(); try { connection.start(); final Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final Queue destination = producerSession.createQueue(QUEUE_NAME + "?consumer.prefetchSize=1"); final Session consumerSession = connection.createSession(true, Session.SESSION_TRANSACTED); MessageConsumer consumer = consumerSession.createConsumer(destination); produceMessage(producerSession, destination); Message msg = consumer.receive(20000); Assert.assertNotNull(msg); broker.stop(); broker = createBroker(); // use empty jdbc store so that default wait(0) for redeliveries will timeout after failover broker.start(); try { consumerSession.commit(); Assert.fail("expected transaction rolledback ex"); } catch (TransactionRolledBackException expected) { } broker.stop(); broker = createBroker(); broker.start(); Assert.assertNotNull("should get rolledback message from original restarted broker", consumer.receive(20000)); } finally { connection.close(); } }
Example #12
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout=20000) public void testTransactionCommitFailWithEmptyRejectedDisposition() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); // First expect an unsettled 'declare' transfer to the txn coordinator, and // reply with a Declared disposition state containing the txnId. Binary txnId1 = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); testPeer.expectDeclare(txnId1); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue("myQueue"); // Create a producer to use in provoking creation of the AMQP transaction testPeer.expectSenderAttach(); MessageProducer producer = session.createProducer(queue); // Expect the message which was sent under the current transaction. Check it carries // TransactionalState with the above txnId but has no outcome. Respond with a // TransactionalState with Accepted outcome. TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true)); messageMatcher.setMessageAnnotationsMatcher(new MessageAnnotationsSectionMatcher(true)); TransactionalStateMatcher stateMatcher = new TransactionalStateMatcher(); stateMatcher.withTxnId(equalTo(txnId1)); stateMatcher.withOutcome(nullValue()); TransactionalState txState = new TransactionalState(); txState.setTxnId(txnId1); txState.setOutcome(new Accepted()); testPeer.expectTransfer(messageMatcher, stateMatcher, txState, true); producer.send(session.createMessage()); // Expect an unsettled 'discharge' transfer to the txn coordinator containing the txnId, // and reply with rejected and settled disposition to indicate the commit failed testPeer.expectDischarge(txnId1, false, new Rejected()); // Then expect an unsettled 'declare' transfer to the txn coordinator, and // reply with a declared disposition state containing the txnId. Binary txnId2 = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4}); testPeer.expectDeclare(txnId2); try { session.commit(); fail("Commit operation should have failed."); } catch (TransactionRolledBackException jmsTxRb) { } // session should roll back on close testPeer.expectDischarge(txnId2, true); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #13
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout=20000) public void testProducedMessagesAfterCommitOfSentMessagesFails() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { Connection connection = testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); testPeer.expectCoordinatorAttach(); // First expect an unsettled 'declare' transfer to the txn coordinator, and // reply with a Declared disposition state containing the txnId. Binary txnId1 = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8}); testPeer.expectDeclare(txnId1); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue("myQueue"); // Create a producer to use in provoking creation of the AMQP transaction testPeer.expectSenderAttach(); MessageProducer producer = session.createProducer(queue); // Expect the message which was sent under the current transaction. Check it carries // TransactionalState with the above txnId but has no outcome. Respond with a // TransactionalState with Accepted outcome. TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true)); messageMatcher.setMessageAnnotationsMatcher(new MessageAnnotationsSectionMatcher(true)); TransactionalStateMatcher stateMatcher = new TransactionalStateMatcher(); stateMatcher.withTxnId(equalTo(txnId1)); stateMatcher.withOutcome(nullValue()); TransactionalState txState = new TransactionalState(); txState.setTxnId(txnId1); txState.setOutcome(new Accepted()); testPeer.expectTransfer(messageMatcher, stateMatcher, txState, true); producer.send(session.createMessage()); // Expect an unsettled 'discharge' transfer to the txn coordinator containing the txnId, // and reply with rejected and settled disposition to indicate the commit failed Rejected commitFailure = new Rejected(new Error(Symbol.valueOf("failed"), "Unknown error")); testPeer.expectDischarge(txnId1, false, commitFailure); // Then expect an unsettled 'declare' transfer to the txn coordinator, and // reply with a declared disposition state containing the txnId. Binary txnId2 = new Binary(new byte[]{ (byte) 1, (byte) 2, (byte) 3, (byte) 4}); testPeer.expectDeclare(txnId2); try { session.commit(); fail("Commit operation should have failed."); } catch (TransactionRolledBackException jmsTxRb) { } // Expect the message which was sent under the current transaction. Check it carries // TransactionalState with the above txnId but has no outcome. Respond with a // TransactionalState with Accepted outcome. stateMatcher = new TransactionalStateMatcher(); stateMatcher.withTxnId(equalTo(txnId2)); stateMatcher.withOutcome(nullValue()); txState = new TransactionalState(); txState.setTxnId(txnId2); txState.setOutcome(new Accepted()); testPeer.expectTransfer(messageMatcher, stateMatcher, txState, true); testPeer.expectDischarge(txnId2, true); producer.send(session.createMessage()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example #14
Source File: JMSExceptionSupportTest.java From pooled-jms with Apache License 2.0 | 4 votes |
@Test(expected = TransactionRolledBackRuntimeException.class) public void testConvertsTransactionRolledBackExceptionToTransactionRolledBackRuntimeException() { throw JMSExceptionSupport.createRuntimeException(new TransactionRolledBackException("error")); }
Example #15
Source File: JmsExceptionSupportTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(expected = TransactionRolledBackRuntimeException.class) public void testConvertsTransactionRolledBackExceptionToTransactionRolledBackRuntimeException() { throw JmsExceptionSupport.createRuntimeException(new TransactionRolledBackException("error")); }
Example #16
Source File: AMQ1925Test.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testAMQ1925_TXBegin() throws Exception { Connection connection = cf.createConnection(); connection.start(); connection.setExceptionListener(this); Session session = connection.createSession(true, Session.SESSION_TRANSACTED); MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE_NAME)); boolean restartDone = false; try { for (int i = 0; i < MESSAGE_COUNT; i++) { Message message = consumer.receive(5000); Assert.assertNotNull(message); if (i == 222 && !restartDone) { // Simulate broker failure & restart bs.stop(); bs = createNewServer(); bs.start(); restartDone = true; } Assert.assertEquals(i, message.getIntProperty(PROPERTY_MSG_NUMBER)); try { session.commit(); } catch (TransactionRolledBackException expectedOnOccasion) { log.info("got rollback: " + expectedOnOccasion); i--; } } Assert.assertNull(consumer.receive(500)); } catch (Exception eee) { log.error("got exception", eee); throw eee; } finally { consumer.close(); session.close(); connection.close(); } assertQueueEmpty(); Assert.assertNull("no exception on connection listener: " + exception, exception); }
Example #17
Source File: JmsTxConsumerFailoverTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout=60000) public void testTxConsumerReceiveAfterFailoverCommits() throws Exception { URI brokerURI = new URI(getAmqpFailoverURI()); connection = createAmqpConnection(brokerURI); connection.start(); final int MSG_COUNT = 5; final Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(name.getMethodName()); final MessageConsumer consumer = session.createConsumer(queue); sendMessages(connection, queue, MSG_COUNT); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(MSG_COUNT, proxy.getQueueSize()); stopPrimaryBroker(); restartPrimaryBroker(); assertTrue("Should have a new connection.", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return brokerService.getAdminView().getCurrentConnectionsCount() == 1; } }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(100))); assertTrue("Should have a recovered consumer.", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return brokerService.getAdminView().getQueueSubscribers().length == 1; } }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(50))); for (int i = 0; i < MSG_COUNT; ++i) { Message received = consumer.receive(3000); assertNotNull("Mesage was not expected but not received", received); } try { session.commit(); LOG.info("Transacted commit ok after failover."); } catch (TransactionRolledBackException rb) { fail("Session commit should not have failed with TX rolled back."); } assertEquals(0, proxy.getQueueSize()); }
Example #18
Source File: DbRestartJDBCQueueMasterSlaveTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Override protected void consumeMessage(Message message, List<Message> messageList) { try { receiveSession.commit(); super.consumeMessage(message, messageList); } catch (JMSException e) { LOG.info("Failed to commit message receipt: " + message, e); try { receiveSession.rollback(); } catch (JMSException ignored) { } if (e instanceof TransactionRolledBackException) { TransactionRolledBackException transactionRolledBackException = (TransactionRolledBackException) e; if (transactionRolledBackException.getMessage().indexOf("in doubt") != -1) { // failover chucked bc there is a missing reply to a commit. // failover is involved b/c the store exception is handled broker side and the client just // sees a disconnect (socket.close()). // If the client needs to be aware of the failure then it should not use IOExceptionHandler // so that the exception will propagate back // for this test case: // the commit may have got there and the reply is lost "or" the commit may be lost. // so we may or may not get a resend. // // At the application level we need to determine if the message is there or not which is not trivial // for this test we assert received == sent // so we need to know whether the message will be replayed. // we can ask the store b/c we know it is jdbc - guess we could go through a destination // message store interface also or use jmx java.sql.Connection dbConnection = null; try { ActiveMQMessage mqMessage = (ActiveMQMessage) message; MessageId id = mqMessage.getMessageId(); dbConnection = sharedDs.getConnection(); PreparedStatement s = dbConnection.prepareStatement(((JDBCPersistenceAdapter) connectedToBroker().getPersistenceAdapter()).getStatements().getFindMessageStatement()); s.setString(1, id.getProducerId().toString()); s.setLong(2, id.getProducerSequenceId()); ResultSet rs = s.executeQuery(); if (!rs.next()) { // message is gone, so lets count it as consumed LOG.info("On TransactionRolledBackException we know that the ack/commit got there b/c message is gone so we count it: " + mqMessage); super.consumeMessage(message, messageList); } else { LOG.info("On TransactionRolledBackException we know that the ack/commit was lost so we expect a replay of: " + mqMessage); } } catch (Exception dbe) { dbe.printStackTrace(); } finally { try { dbConnection.close(); } catch (SQLException e1) { e1.printStackTrace(); } } } } } }
Example #19
Source File: JmsTxProducerFailoverTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout=60000) @Repeat(repetitions = 1) public void testTxProducerSendAfterFailoverCommits() throws Exception { URI brokerURI = new URI(getAmqpFailoverURI()); connection = createAmqpConnection(brokerURI); connection.start(); final int MSG_COUNT = 5; final Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(name.getMethodName()); final MessageProducer producer = session.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); stopPrimaryBroker(); restartPrimaryBroker(); assertTrue("Should have a new connection.", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return brokerService.getAdminView().getCurrentConnectionsCount() == 1; } }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(100))); assertTrue("Should have a recovered producer.", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return brokerService.getAdminView().getQueueProducers().length == 1; } }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(50))); for (int i = 0; i < MSG_COUNT; ++i) { LOG.debug("Producer sening message #{}", i + 1); producer.send(session.createTextMessage("Message: " + i)); } proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); try { session.commit(); LOG.info("Transacted commit ok after failover."); } catch (TransactionRolledBackException rb) { fail("Session commit should not have failed with TX rolled back."); } assertEquals(MSG_COUNT, proxy.getQueueSize()); }
Example #20
Source File: TransactionContextTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSyncBeforeEndCalledOnceOnRollback() throws Exception { final AtomicInteger beforeEndCountA = new AtomicInteger(0); final AtomicInteger beforeEndCountB = new AtomicInteger(0); final AtomicInteger rollbackCountA = new AtomicInteger(0); final AtomicInteger rollbackCountB = new AtomicInteger(0); underTest.addSynchronization(new Synchronization() { @Override public void beforeEnd() throws Exception { if (beforeEndCountA.getAndIncrement() == 0) { throw new TransactionRolledBackException("force rollback"); } } @Override public void afterCommit() throws Exception { fail("expected rollback exception"); } @Override public void afterRollback() throws Exception { rollbackCountA.incrementAndGet(); } }); underTest.addSynchronization(new Synchronization() { @Override public void beforeEnd() throws Exception { beforeEndCountB.getAndIncrement(); } @Override public void afterCommit() throws Exception { fail("expected rollback exception"); } @Override public void afterRollback() throws Exception { rollbackCountB.incrementAndGet(); } }); try { underTest.commit(); fail("expected rollback exception"); } catch (TransactionRolledBackException expected) { } assertEquals("beforeEnd A called once", 1, beforeEndCountA.get()); assertEquals("beforeEnd B called once", 1, beforeEndCountA.get()); assertEquals("rollbackCount B 0", 1, rollbackCountB.get()); assertEquals("rollbackCount A B", rollbackCountA.get(), rollbackCountB.get()); }
Example #21
Source File: JmsTxProducerFailoverTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout=60000) @Repeat(repetitions = 1) public void testTxProducerSendWorksButCommitFails() throws Exception { URI brokerURI = new URI(getAmqpFailoverURI()); connection = createAmqpConnection(brokerURI); connection.start(); final int MSG_COUNT = 10; final Session session = connection.createSession(true, Session.SESSION_TRANSACTED); Queue queue = session.createQueue(name.getMethodName()); final MessageProducer producer = session.createProducer(queue); producer.setDeliveryMode(DeliveryMode.PERSISTENT); QueueViewMBean proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); for (int i = 0; i < MSG_COUNT / 2; ++i) { LOG.debug("Producer sening message #{}", i + 1); producer.send(session.createTextMessage("Message: " + i)); } assertEquals(0, proxy.getQueueSize()); stopPrimaryBroker(); restartPrimaryBroker(); proxy = getProxyToQueue(name.getMethodName()); assertEquals(0, proxy.getQueueSize()); for (int i = MSG_COUNT / 2; i < MSG_COUNT; ++i) { LOG.debug("Producer sening message #{}", i + 1); producer.send(session.createTextMessage("Message: " + i)); } try { session.commit(); fail("Session commit should have failed with TX rolled back."); } catch (TransactionRolledBackException rb) { LOG.info("Transacted commit failed after failover: {}", rb.getMessage()); } assertEquals(0, proxy.getQueueSize()); }
Example #22
Source File: TransactionContextTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void testSyncBeforeEndCalledOnceOnRollback() throws Exception { final AtomicInteger beforeEndCountA = new AtomicInteger(0); final AtomicInteger beforeEndCountB = new AtomicInteger(0); final AtomicInteger rollbackCountA = new AtomicInteger(0); final AtomicInteger rollbackCountB = new AtomicInteger(0); underTest.addSynchronization(new Synchronization() { @Override public void beforeEnd() throws Exception { if (beforeEndCountA.getAndIncrement() == 0) { throw new TransactionRolledBackException("force rollback"); } } @Override public void afterCommit() throws Exception { fail("expected rollback exception"); } @Override public void afterRollback() throws Exception { rollbackCountA.incrementAndGet(); } }); underTest.addSynchronization(new Synchronization() { @Override public void beforeEnd() throws Exception { beforeEndCountB.getAndIncrement(); } @Override public void afterCommit() throws Exception { fail("expected rollback exception"); } @Override public void afterRollback() throws Exception { rollbackCountB.incrementAndGet(); } }); try { underTest.commit(); fail("expected rollback exception"); } catch (TransactionRolledBackException expected) { } assertEquals("beforeEnd A called once", 1, beforeEndCountA.get()); assertEquals("beforeEnd B called once", 1, beforeEndCountA.get()); assertEquals("rollbackCount B 0", 1, rollbackCountB.get()); assertEquals("rollbackCount A B", rollbackCountA.get(), rollbackCountB.get()); }