Java Code Examples for org.apache.qpid.jms.JmsConnection#setRequestTimeout()

The following examples show how to use org.apache.qpid.jms.JmsConnection#setRequestTimeout() . 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: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testCreateTemporaryQueueTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        connection.start();

        testPeer.expectBegin();
        testPeer.expectTempQueueCreationAttach(null, false);
        testPeer.expectDetach(true, false, true);

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        try {
            session.createTemporaryQueue();
            fail("Should have timed out on create.");
        } catch (JmsOperationTimedOutException jmsEx) {
            LOG.info("Caught expected exception: {}", jmsEx.getMessage());
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 2
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testCreateTemporaryTopicTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        connection.start();

        testPeer.expectBegin();
        testPeer.expectTempTopicCreationAttach(null, false);
        testPeer.expectDetach(true, false, true);

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        try {
            session.createTemporaryTopic();
            fail("Should have timed out on create.");
        } catch (JmsOperationTimedOutException jmsEx) {
            LOG.info("Caught expected exception: {}", jmsEx.getMessage());
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 3
Source File: TransactionsIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testSessionCreateFailsOnDeclareTimeout() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        connection.start();

        testPeer.expectBegin();
        testPeer.expectCoordinatorAttach();
        testPeer.expectDeclareButDoNotRespond();
        // Expect the AMQP session to be closed due to the JMS session creation failure.
        testPeer.expectEnd();

        try {
            connection.createSession(true, Session.SESSION_TRANSACTED);
            fail("Should have timed out waiting for declare.");
        } catch (JmsOperationTimedOutException jmsEx) {
        } catch (Throwable error) {
            fail("Should have caught an timed out exception:");
            LOG.error("Caught -> ", error);
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 4
Source File: TransactionsIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testTransactionRolledBackOnSessionCloseTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        connection.start();

        testPeer.expectBegin();
        testPeer.expectCoordinatorAttach();

        Binary txnId = new Binary(new byte[]{ (byte) 5, (byte) 6, (byte) 7, (byte) 8});
        testPeer.expectDeclare(txnId);

        // Closed session should roll-back the TX with a failed discharge
        testPeer.expectDischargeButDoNotRespond(txnId, true);

        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

        try {
            session.close();
            fail("Should have timed out waiting for declare.");
        } catch (JmsOperationTimedOutException jmsEx) {
        } catch (Throwable error) {
            fail("Should have caught an timed out exception:");
            LOG.error("Caught -> ", error);
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 5
Source File: TransactionsIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testTransactionRolledBackTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        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);

        // Expect discharge but don't respond so that the request timeout kicks in and fails
        // the discharge.  The pipelined declare should arrive as well and be discharged as the
        // client attempts to recover to a known good state.
        testPeer.expectDischargeButDoNotRespond(txnId1, true);

        // Session should throw from the rollback and then try and recover.
        testPeer.expectDeclare(txnId2);
        testPeer.expectDischarge(txnId2, true);

        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

        try {
            session.rollback();
            fail("Should have timed out waiting for declare.");
        } catch (JmsOperationTimedOutException jmsEx) {
        } catch (Throwable error) {
            fail("Should have caught an timed out exception:");
            LOG.error("Caught -> ", error);
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 6
Source File: TransactionsIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testTransactionCommitTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        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);

        // Expect discharge but don't respond so that the request timeout kicks in and fails
        // the discharge.  The pipelined declare should arrive as well and we respond with
        // successful declare.
        testPeer.expectDischargeButDoNotRespond(txnId1, false);
        testPeer.expectDeclare(txnId2);

        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

        try {
            session.commit();
            fail("Should have timed out waiting for declare.");
        } catch (JmsOperationTimedOutException jmsEx) {
        } catch (Throwable error) {
            fail("Should have caught an timed out exception:");
            LOG.error("Caught -> ", error);
        }

        // Session rolls back on close
        testPeer.expectDischarge(txnId2, true);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 7
Source File: FailoverIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testPassthroughOfSessionCreateFailsOnDeclareTimeout() 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();
        testPeer.expectDeclareButDoNotRespond();
        // Expect the AMQP session to be closed due to the JMS session creation failure.
        testPeer.expectEnd();

        JmsConnection connection = establishAnonymousConnecton(testPeer);
        connection.setRequestTimeout(500);
        connection.start();

        try {
            connection.createSession(true, Session.SESSION_TRANSACTED);
            fail("Should have timed out waiting for declare.");
        } catch (JmsOperationTimedOutException jmsEx) {
        } catch (Throwable error) {
            fail("Should have caught an timed out exception:");
            LOG.error("Caught -> ", error);
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example 8
Source File: TransactionsIntegrationTest.java    From qpid-jms with Apache License 2.0 4 votes vote down vote up
@Test(timeout=20000)
public void testTransactionCommitTimesOutAndNoNextBeginTimesOut() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer);
        connection.setRequestTimeout(500);
        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);

        // Expect discharge and don't respond so that the request timeout kicks in
        // Expect pipelined declare and don't response so that the request timeout kicks in.
        // The commit operation should throw a timed out exception at that point.
        testPeer.expectDischargeButDoNotRespond(txnId1, false);
        testPeer.expectDeclareButDoNotRespond();

        Session session = connection.createSession(true, Session.SESSION_TRANSACTED);

        // After the pipelined operations both time out, the session should attempt to
        // recover by creating a new TX, then on close the session should roll it back
        testPeer.expectDeclare(txnId2);
        testPeer.expectDischarge(txnId2, true);

        try {
            session.commit();
            fail("Should have timed out waiting for declare.");
        } catch (JmsOperationTimedOutException jmsEx) {
        } catch (Throwable error) {
            fail("Should have caught an timed out exception:");
            LOG.error("Caught -> ", error);
        }

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}