Java Code Examples for org.apache.qpid.jms.JmsConnection#setSendTimeout()
The following examples show how to use
org.apache.qpid.jms.JmsConnection#setSendTimeout() .
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: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testSendWhenLinkCreditIsZeroAndTimeout() throws Exception { try(TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.setSendTimeout(500); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); Message message = session.createTextMessage("text"); // Expect the producer to attach. Don't send any credit so that the client will // block on a send and we can test our timeouts. testPeer.expectSenderAttachWithoutGrantingCredit(); testPeer.expectClose(); MessageProducer producer = session.createProducer(queue); try { producer.send(message); fail("Send should time out."); } catch (JmsSendTimedOutException jmsEx) { LOG.info("Caught expected error: {}", jmsEx.getMessage()); } catch (Throwable error) { fail("Send should time out, but got: " + error.getMessage()); } connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 2
Source File: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testSendTimesOutWhenNoDispostionArrives() throws Exception { try(TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.setSendTimeout(500); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); Message message = session.createTextMessage("text"); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); // Expect the producer to attach and grant it some credit, it should send // a transfer which we will not send any response for which should cause the // send operation to time out. testPeer.expectSenderAttach(); testPeer.expectTransferButDoNotRespond(messageMatcher); testPeer.expectClose(); MessageProducer producer = session.createProducer(queue); try { producer.send(message); fail("Send should time out."); } catch (JmsSendTimedOutException jmsEx) { LOG.info("Caught expected error: {}", jmsEx.getMessage()); } catch (Throwable error) { fail("Send should time out, but got: " + error.getMessage()); } connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 3
Source File: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testAsyncCompletionGetsNotifiedWhenProducerClosed() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); // Use a send timeout to trigger the completion event connection.setSendTimeout(500); testPeer.expectBegin(); testPeer.expectSenderAttach(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("myQueue"); MessageProducer producer = session.createProducer(queue); // Create and transfer a new message String text = "myMessage"; testPeer.expectTransferButDoNotRespond(new TransferPayloadCompositeMatcher()); testPeer.expectDetach(true, true, true); testPeer.expectClose(); TextMessage message = session.createTextMessage(text); TestJmsCompletionListener listener = new TestJmsCompletionListener(); producer.send(message, listener); producer.close(); assertTrue("Did not get async callback", listener.awaitCompletion(5, TimeUnit.SECONDS)); assertNotNull(listener.exception); assertNotNull(listener.message); assertTrue(listener.message instanceof TextMessage); connection.close(); testPeer.waitForAllHandlersToComplete(2000); } }
Example 4
Source File: AnonymousFallbackProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doTestSendWhenLinkCreditIsZeroAndTimeout(int cacheSize) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Use a long timeout to ensure no early evictions in this test. JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer, "?amqp.anonymousFallbackCacheSize=" + cacheSize + "&amqp.anonymousFallbackCacheTimeout=60000"); connection.setSendTimeout(500); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); Message message = session.createTextMessage("text"); // Expect the producer to attach. Don't send any credit so that the client will // block on a send and we can test our timeouts. testPeer.expectSenderAttachWithoutGrantingCredit(); if (cacheSize == 0) { testPeer.expectDetach(true, true, true); } testPeer.expectClose(); MessageProducer producer = session.createProducer(null); try { producer.send(queue, message); fail("Send should time out."); } catch (JmsSendTimedOutException jmsEx) { LOG.info("Caught expected error: {}", jmsEx.getMessage()); } catch (Throwable error) { fail("Send should time out, but got: " + error.getMessage()); } connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 5
Source File: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testAsyncCompletionGetsTimedOutErrorWhenNoDispostionArrives() throws Exception { try(TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.setSendTimeout(500); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); Message message = session.createTextMessage("text"); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); // Expect the producer to attach and grant it some credit, it should send // a transfer which we will not send any response for which should cause the // send operation to time out. testPeer.expectSenderAttach(); testPeer.expectTransferButDoNotRespond(messageMatcher); testPeer.expectClose(); MessageProducer producer = session.createProducer(queue); TestJmsCompletionListener listener = new TestJmsCompletionListener(); try { producer.send(message, listener); } catch (Throwable error) { LOG.info("Caught unexpected error: {}", error.getMessage()); fail("Send should not fail for async."); } assertTrue("Did not get async callback", listener.awaitCompletion(5, TimeUnit.SECONDS)); assertNotNull(listener.exception); assertTrue(listener.exception instanceof JmsSendTimedOutException); assertNotNull(listener.message); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 6
Source File: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testCreditDrainedAfterSend() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.setSendTimeout(500); testPeer.expectBegin(); testPeer.expectSenderAttach(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(getTestName()); MessageProducer producer = session.createProducer(destination); MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); // After the first send lets drain off the remaining credit from the sender testPeer.expectTransferRespondWithDrain(messageMatcher, 1); testPeer.expectLinkFlow(true, false, Matchers.equalTo(UnsignedInteger.ZERO)); testPeer.expectDetach(true, true, true); testPeer.expectClose(); producer.send(session.createMessage()); // We don't have any credit now since we were drained, so the send should // block until more credit is issued. try { producer.send(session.createMessage()); fail("Should have timed out waiting for credit to send."); } catch (JmsSendTimedOutException jmsEx) { LOG.info("Caught expected send timeout."); } producer.close(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 7
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testPassthroughOfSendTimesOutWhenNoDispostionArrives() 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(); JmsConnection connection = establishAnonymousConnecton(testPeer); connection.setSendTimeout(500); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); Message message = session.createTextMessage("text"); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); // Expect the producer to attach and grant it some credit, it should send // a transfer which we will not send any response for which should cause the // send operation to time out. testPeer.expectSenderAttach(); testPeer.expectTransferButDoNotRespond(messageMatcher); testPeer.expectClose(); MessageProducer producer = session.createProducer(queue); try { producer.send(message); fail("Send should time out."); } catch (JmsSendTimedOutException jmsEx) { LOG.info("Caught expected error: {}", jmsEx.getMessage()); } catch (Throwable error) { fail("Send should time out, but got: " + error.getMessage()); } connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }