Java Code Examples for org.apache.qpid.jms.JmsConnection#createSession()
The following examples show how to use
org.apache.qpid.jms.JmsConnection#createSession() .
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: ProducerAndConsumerBench.java From qpid-jms with Apache License 2.0 | 6 votes |
private void publishMessages(AtomicLong count) throws Exception { JmsConnection connection = (JmsConnection) factory.createConnection(); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(getDestinationName()); MessageProducer producer = session.createProducer(queue); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); while (count.getAndDecrement() > 0) { BytesMessage message = session.createBytesMessage(); message.writeBytes(payload); producer.send(message); if ((count.get() % 10000) == 0) { LOG.info("Sent message: {}", NUM_SENDS - count.get()); } } producer.close(); connection.close(); }
Example 2
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testSessionSnapshotsPolicyObjects() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.start(); testPeer.expectBegin(); JmsSession session = (JmsSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE); assertNotSame(session.getMessageIDPolicy(), connection.getMessageIDPolicy()); assertNotSame(session.getPrefetchPolicy(), connection.getPrefetchPolicy()); assertNotSame(session.getPresettlePolicy(), connection.getPresettlePolicy()); assertNotSame(session.getRedeliveryPolicy(), connection.getRedeliveryPolicy()); testPeer.expectClose(); connection.close(); } }
Example 3
Source File: FailoverProviderOfflineBehaviorTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout=20000) public void testSessionCloseWhenDestroyCallFailsDoesNotBlock() throws Exception { mockPeer.setResourceDestroyFilter(new ResourceLifecycleFilter() { @Override public void onLifecycleEvent(JmsResource resource) throws Exception { if (resource instanceof JmsSessionInfo) { mockPeer.shutdownQuietly(); throw new ProviderIOException("Failure closing session"); } } }); connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); session.close(); connection.close(); }
Example 4
Source File: JMSWebSocketConnectionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Ignore("Broker can't accept messages over 65535 right now") @Test(timeout = 30000) public void testSendLargeMessageToClientFromAMQP() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI()); JmsConnection connection = (JmsConnection) factory.createConnection(); sendLargeMessageViaAMQP(); try { Session session = connection.createSession(); Queue queue = session.createQueue(getQueueName()); connection.start(); MessageConsumer consumer = session.createConsumer(queue); Message message = consumer.receive(1000); assertNotNull(message); assertTrue(message instanceof BytesMessage); } finally { connection.close(); } }
Example 5
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20000) public void testCloseSessionTimesOut() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer); connection.setCloseTimeout(500); testPeer.expectBegin(); testPeer.expectEnd(false); testPeer.expectClose(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull("Session should not be null", session); try { session.close(); fail("Should have thrown an timed out exception"); } catch (JmsOperationTimedOutException jmsEx) { LOG.info("Caught exception: {}", jmsEx.getMessage()); } connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 6
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 7
Source File: JMSQueueBrowserTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test(timeout = 60000) public void testBrowseAllInQueueZeroPrefetch() throws Exception { final int MSG_COUNT = 5; JmsConnection connection = (JmsConnection) createConnection(); ((JmsDefaultPrefetchPolicy) connection.getPrefetchPolicy()).setAll(0); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); assertNotNull(session); javax.jms.Queue queue = session.createQueue(getQueueName()); sendMessages(name.getMethodName(), MSG_COUNT, false); Queue queueView = getProxyToQueue(getQueueName()); Wait.assertEquals(MSG_COUNT, queueView::getMessageCount); QueueBrowser browser = session.createBrowser(queue); assertNotNull(browser); Enumeration<?> enumeration = browser.getEnumeration(); int count = 0; while (count < MSG_COUNT && enumeration.hasMoreElements()) { Message msg = (Message) enumeration.nextElement(); assertNotNull(msg); LOG.debug("Recv: {}", msg); count++; } LOG.debug("Received all expected message, checking that hasMoreElements returns false"); assertFalse(enumeration.hasMoreElements()); assertEquals(5, count); }
Example 8
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doCreateTemporaryDestinationFailsWhenLinkRefusedTestImpl(boolean topic, boolean deferAttachResponseWrite) throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { testPeer.expectSaslAnonymous(); testPeer.expectOpen(); testPeer.expectBegin(); testPeer.expectBegin(); JmsConnection connection = establishAnonymousConnecton(testPeer); connection.start(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); try { if (topic) { testPeer.expectAndRefuseTempTopicCreationAttach(AmqpError.UNAUTHORIZED_ACCESS, "Not Authorized to create temp topics.", false); //Expect the detach response to the test peer after refusal. testPeer.expectDetach(true, false, false); session.createTemporaryTopic(); } else { testPeer.expectAndRefuseTempQueueCreationAttach(AmqpError.UNAUTHORIZED_ACCESS, "Not Authorized to create temp queues.", false); //Expect the detach response to the test peer after refusal. testPeer.expectDetach(true, false, false); session.createTemporaryQueue(); } fail("Should have thrown security exception"); } catch (JMSSecurityException jmsse) { } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 9
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@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 10
Source File: FailoverProviderOfflineBehaviorTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testSessionCloseDoesNotBlock() throws Exception { connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); mockPeer.shutdown(); connectionInterrupted.await(9, TimeUnit.SECONDS); session.close(); connection.close(); }
Example 11
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@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 12
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); } }
Example 13
Source File: AnonymousFallbackProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Repeat(repetitions = 1) @Test(timeout = 20000) public void testAsyncCompletionListenerSendFailureHandled() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer, "?amqp.anonymousFallbackCacheSize=0&amqp.anonymousFallbackCacheTimeout=60000"); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; Topic dest = session.createTopic(topicName); // Expect no AMQP traffic when we create the anonymous producer, as it will wait // for an actual send to occur on the producer before anything occurs on the wire //Create an anonymous producer MessageProducer producer = session.createProducer(null); assertNotNull("Producer object was null", producer); // Expect a new message sent by the above producer to cause creation of a new // sender link to the given destination, then closing the link after the message is sent. TargetMatcher targetMatcher = new TargetMatcher(); targetMatcher.withAddress(equalTo(topicName)); targetMatcher.withDynamic(equalTo(false)); targetMatcher.withDurable(equalTo(TerminusDurability.NONE)); String content = "testContent"; TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true)); messageMatcher.setMessageAnnotationsMatcher(new MessageAnnotationsSectionMatcher(true)); messageMatcher.setPropertiesMatcher(new MessagePropertiesSectionMatcher(true)); messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(content)); TestJmsCompletionListener completionListener = new TestJmsCompletionListener(); Message message = session.createTextMessage(content); final String BREAD_CRUMB = "SEND FAILURE EXPECTED"; org.apache.qpid.jms.test.testpeer.describedtypes.Error rejectError = new org.apache.qpid.jms.test.testpeer.describedtypes.Error(); rejectError.setCondition(AmqpError.RESOURCE_LIMIT_EXCEEDED); rejectError.setDescription(BREAD_CRUMB); testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher, nullValue(), new Rejected().setError(rejectError), true); testPeer.expectDetach(true, true, true); // The fallback producer acts as synchronous regardless of the completion listener, // so exceptions are thrown from send. Only onComplete uses the listener. try { producer.send(dest, message, completionListener); } catch (JMSException jmsEx) { LOG.debug("Caught unexpected error from failed send."); fail("Send should not fail for asychrnous completion sends"); } // Repeat the send (but accept this time) and observe another attach->transfer->detach. testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); testPeer.expectDetach(true, true, true); assertTrue("Send failure not reported to exception handler", completionListener.awaitCompletion(5, TimeUnit.SECONDS)); assertNotNull(completionListener.exception); assertTrue(completionListener.exception instanceof ResourceAllocationException); assertTrue(completionListener.exception.getMessage().contains(BREAD_CRUMB)); TestJmsCompletionListener completionListener2 = new TestJmsCompletionListener(); producer.send(dest, message, completionListener2); assertTrue("Did not get completion callback", completionListener2.awaitCompletion(5, TimeUnit.SECONDS)); assertNull(completionListener2.exception); Message receivedMessage2 = completionListener2.message; assertNotNull(receivedMessage2); assertTrue(receivedMessage2 instanceof TextMessage); assertEquals(content, ((TextMessage) receivedMessage2).getText()); // Asynchronous send requires a wait otherwise we can close before the detach which we are testing for. testPeer.waitForAllHandlersToComplete(1000); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 14
Source File: AnonymousFallbackProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Repeat(repetitions = 1) @Test(timeout = 20000) public void testAsyncCompletionListenerSendWhenNoCacheConfigured() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer, "?amqp.anonymousFallbackCacheSize=0&amqp.anonymousFallbackCacheTimeout=60000"); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; Topic dest = session.createTopic(topicName); // Expect no AMQP traffic when we create the anonymous producer, as it will wait // for an actual send to occur on the producer before anything occurs on the wire //Create an anonymous producer MessageProducer producer = session.createProducer(null); assertNotNull("Producer object was null", producer); // Expect a new message sent by the above producer to cause creation of a new // sender link to the given destination, then closing the link after the message is sent. TargetMatcher targetMatcher = new TargetMatcher(); targetMatcher.withAddress(equalTo(topicName)); targetMatcher.withDynamic(equalTo(false)); targetMatcher.withDurable(equalTo(TerminusDurability.NONE)); String content = "testContent"; TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(new MessageHeaderSectionMatcher(true)); messageMatcher.setMessageAnnotationsMatcher(new MessageAnnotationsSectionMatcher(true)); messageMatcher.setPropertiesMatcher(new MessagePropertiesSectionMatcher(true)); messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(content)); testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); testPeer.expectDetach(true, true, true); TestJmsCompletionListener completionListener = new TestJmsCompletionListener(); Message message = session.createTextMessage(content); producer.send(dest, message, completionListener); assertTrue("Did not get completion callback", completionListener.awaitCompletion(5, TimeUnit.SECONDS)); assertNull(completionListener.exception); Message receivedMessage = completionListener.message; assertNotNull(receivedMessage); assertTrue(receivedMessage instanceof TextMessage); assertEquals(content, ((TextMessage) receivedMessage).getText()); // Repeat the send and observe another attach->transfer->detach. testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); testPeer.expectDetach(true, true, true); TestJmsCompletionListener completionListener2 = new TestJmsCompletionListener(); producer.send(dest, message, completionListener2); assertTrue("Did not get completion callback", completionListener2.awaitCompletion(5, TimeUnit.SECONDS)); assertNull(completionListener2.exception); Message receivedMessage2 = completionListener2.message; assertNotNull(receivedMessage2); assertTrue(receivedMessage2 instanceof TextMessage); assertEquals(content, ((TextMessage) receivedMessage2).getText()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 15
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testPassthroughOfSendFailsWhenDelayedDeliveryIsNotSupported() 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(); // DO NOT add capability to indicate server support for DELAYED-DELIVERY so that // send fails and we can see if the error passes through the failover provider JmsConnection connection = establishAnonymousConnecton(testPeer); connection.start(); Matcher<Symbol[]> desiredCapabilitiesMatcher = arrayContaining(new Symbol[] { DELAYED_DELIVERY }); Symbol[] offeredCapabilities = null; testPeer.expectSenderAttach(notNullValue(), notNullValue(), false, false, false, false, 0, 1, null, null, desiredCapabilitiesMatcher, offeredCapabilities); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; Topic dest = session.createTopic(topicName); MessageProducer producer = session.createProducer(dest); producer.setDeliveryDelay(5000); // Producer should fail to send when message has delivery delay since remote // did not report that it supports that option. Message message = session.createMessage(); try { producer.send(message); fail("Send should fail"); } catch (JMSException jmsEx) { LOG.debug("Caught expected error from failed send."); } testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 16
Source File: AnonymousFallbackProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Repeat(repetitions = 1) @Test(timeout = 20000) public void testSyncSendFailureHandled() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer, "?amqp.anonymousFallbackCacheSize=0&amqp.anonymousFallbackCacheTimeout=60000"); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; Topic dest = session.createTopic(topicName); // Expect no AMQP traffic when we create the anonymous producer, as it will wait // for an actual send to occur on the producer before anything occurs on the wire // Create an anonymous producer MessageProducer producer = session.createProducer(null); assertNotNull("Producer object was null", producer); // Expect a new message sent by the above producer to cause creation of a new // sender link to the given destination, then closing the link after the message is sent. TargetMatcher targetMatcher = new TargetMatcher(); targetMatcher.withAddress(equalTo(topicName)); targetMatcher.withDynamic(equalTo(false)); targetMatcher.withDurable(equalTo(TerminusDurability.NONE)); MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher, nullValue(), new Rejected(), true); testPeer.expectDetach(true, true, true); Message message = session.createMessage(); try { producer.send(dest, message); fail("Send should fail"); } catch (JMSException jmsEx) { LOG.debug("Caught expected error from failed send."); } // Repeat the send and observe another attach->transfer->detach. testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); testPeer.expectDetach(true, true, true); producer.send(dest, message); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 17
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
private void doFailoverHandlesConnectErrorInvalidFieldOnReconnectTestImpl(boolean includeContainerIdHint) throws Exception { try (TestAmqpPeer originalPeer = new TestAmqpPeer(); TestAmqpPeer rejectingPeer = new TestAmqpPeer(); TestAmqpPeer finalPeer = new TestAmqpPeer();) { final CountDownLatch finalConnected = new CountDownLatch(1); final String finalURI = createPeerURI(finalPeer); final DescribedType amqpValueNullContent = new AmqpValueDescribedType(null); originalPeer.expectSaslAnonymous(); originalPeer.expectOpen(); originalPeer.expectBegin(); originalPeer.dropAfterLastHandler(10); Map<Symbol, Object> errorInfo = null; if (includeContainerIdHint) { errorInfo = new HashMap<Symbol, Object>(); errorInfo.put(AmqpSupport.INVALID_FIELD, AmqpSupport.CONTAINER_ID); } rejectingPeer.rejectConnect(AmqpError.INVALID_FIELD, "Client ID already in use", errorInfo); finalPeer.expectSaslAnonymous(); finalPeer.expectOpen(); finalPeer.expectBegin(); final JmsConnection connection = establishAnonymousConnecton(originalPeer, rejectingPeer, finalPeer); connection.addConnectionListener(new JmsDefaultConnectionListener() { @Override public void onConnectionRestored(URI remoteURI) { LOG.info("Connection Established: {}", remoteURI); if (finalURI.equals(remoteURI.toString())) { finalConnected.countDown(); } } }); try { connection.start(); } catch (Exception ex) { fail("Should not have thrown an Exception: " + ex); } assertTrue("Should connect to final peer", finalConnected.await(5, TimeUnit.SECONDS)); finalPeer.expectBegin(); finalPeer.expectReceiverAttach(); finalPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, amqpValueNullContent); finalPeer.expectDispositionThatIsAcceptedAndSettled(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("myQueue"); MessageConsumer consumer = session.createConsumer(queue); Message message = consumer.receive(2000); assertNotNull(message); // Shut it down finalPeer.expectClose(); connection.close(); finalPeer.waitForAllHandlersToComplete(1000); } }
Example 18
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Repeat(repetitions = 1) @Test(timeout = 20000) public void testFailoverHandlesAnonymousFallbackWaitingForClose() throws Exception { try (TestAmqpPeer originalPeer = new TestAmqpPeer(); TestAmqpPeer finalPeer = new TestAmqpPeer();) { // DO NOT add capability to indicate server support for ANONYMOUS-RELAY // Create a peer to connect to, then one to reconnect to final String originalURI = createPeerURI(originalPeer); final String finalURI = createPeerURI(finalPeer); LOG.info("Original peer is at: {}", originalURI); LOG.info("Final peer is at: {}", finalURI); originalPeer.expectSaslAnonymous(); originalPeer.expectOpen(); originalPeer.expectBegin(); originalPeer.expectBegin(); originalPeer.expectSenderAttach(); originalPeer.expectTransfer(new TransferPayloadCompositeMatcher()); // Ensure that sender detach is not answered so that next send must wait for close originalPeer.expectDetach(true, false, false); originalPeer.dropAfterLastHandler(20); // Wait for sender to get into wait state // --- Post Failover Expectations of sender --- // finalPeer.expectSaslAnonymous(); finalPeer.expectOpen(); finalPeer.expectBegin(); finalPeer.expectBegin(); finalPeer.expectSenderAttach(); finalPeer.expectTransfer(new TransferPayloadCompositeMatcher()); finalPeer.expectDetach(true, true, true); finalPeer.expectClose(); final JmsConnection connection = establishAnonymousConnecton( "failover.initialReconnectDelay=25" + "&failover.nested.amqp.anonymousFallbackCacheSize=0" + "&failover.nested.amqp.anonymousFallbackCacheTimeout=0", originalPeer, finalPeer); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("myQueue"); MessageProducer producer = session.createProducer(null); // Send 2 messages String text = "myMessage"; TextMessage message = session.createTextMessage(text); producer.send(queue, message); producer.send(queue, message); producer.close(); connection.close(); finalPeer.waitForAllHandlersToComplete(1000); } }
Example 19
Source File: AnonymousFallbackProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Repeat(repetitions = 1) @Test(timeout = 30000) public void testCachedFallbackProducersAreTimedOut() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { final int CACHE_SIZE = 5; JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer, "?amqp.anonymousFallbackCacheSize=" + CACHE_SIZE + "&amqp.anonymousFallbackCacheTimeout=300"); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; // Expect no AMQP traffic when we create the anonymous producer, as it will wait // for an actual send to occur on the producer before anything occurs on the wire // Create an anonymous producer MessageProducer producer = session.createProducer(null); assertNotNull("Producer object was null", producer); // First round of sends should open and cache sender links for (int i = 1; i <= CACHE_SIZE; ++i) { Topic dest = session.createTopic(topicName + i); // Expect a new message sent by the above producer to cause creation of a new // sender link to the given destination. TargetMatcher targetMatcher = new TargetMatcher(); targetMatcher.withAddress(equalTo(dest.getTopicName())); targetMatcher.withDynamic(equalTo(false)); targetMatcher.withDurable(equalTo(TerminusDurability.NONE)); MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); Message message = session.createMessage(); testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); producer.send(dest, message); } // Cached senders should all close when the cache timeout is reached and they are expired for (int i = 1; i <= CACHE_SIZE; ++i) { testPeer.expectDetach(true, true, true); } // On a slow CI machine we could fail here due to the timeouts not having run. testPeer.waitForAllHandlersToComplete(6000); producer.close(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 20
Source File: AnonymousFallbackProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Repeat(repetitions = 1) @Test(timeout = 20000) public void testCachedFallbackProducerEvictedBySendToUncachedAddressHandlesDelayedResponse() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { JmsConnection connection = (JmsConnection) testFixture.establishConnecton(testPeer, "?amqp.anonymousFallbackCacheSize=1&amqp.anonymousFallbackCacheTimeout=0"); connection.start(); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String topicName = "myTopic"; // Expect no AMQP traffic when we create the anonymous producer, as it will wait // for an actual send to occur on the producer before anything occurs on the wire // Create an anonymous producer MessageProducer producer = session.createProducer(null); assertNotNull("Producer object was null", producer); MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); Topic dest1 = session.createTopic(topicName + 1); Topic dest2 = session.createTopic(topicName + 2); // Expect a new message sent by the above producer to cause creation of a new // sender link to the given destination. TargetMatcher targetMatcher = new TargetMatcher(); targetMatcher.withAddress(equalTo(dest1.getTopicName())); targetMatcher.withDynamic(equalTo(false)); targetMatcher.withDurable(equalTo(TerminusDurability.NONE)); Message message = session.createMessage(); testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); producer.send(dest1, message); // Expect new send to a different destination to detach the previous cached link // and once the response arrives the send should complete normally. targetMatcher = new TargetMatcher(); targetMatcher.withAddress(equalTo(dest2.getTopicName())); targetMatcher.withDynamic(equalTo(false)); targetMatcher.withDurable(equalTo(TerminusDurability.NONE)); message = session.createMessage(); testPeer.expectDetach(true, false, false); // Workaround to allow a deferred detach at a later time. testPeer.remotelyDetachLastOpenedLinkOnLastOpenedSession(false, true, AmqpError.RESOURCE_DELETED, "error", 20); testPeer.expectSenderAttach(targetMatcher, false, false); testPeer.expectTransfer(messageMatcher); testPeer.expectDetach(true, true, true); producer.send(dest2, message); producer.close(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }