org.apache.qpid.jms.JmsConnection Java Examples
The following examples show how to use
org.apache.qpid.jms.JmsConnection.
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 testSessionCloseWithOpenResourcesDoesNotBlock() throws Exception { connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(_testName.getMethodName()); session.createConsumer(queue); session.createProducer(queue); mockPeer.shutdown(); connectionInterrupted.await(9, TimeUnit.SECONDS); session.close(); connection.close(); }
Example #2
Source File: FailoverIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
private JmsConnection establishAnonymousConnecton(String connectionParams, String failoverParams, TestAmqpPeer... peers) throws JMSException { if (peers.length == 0) { throw new IllegalArgumentException("No test peers were given, at least 1 required"); } String remoteURI = "failover:("; boolean first = true; for (TestAmqpPeer peer : peers) { if (!first) { remoteURI += ","; } remoteURI += createPeerURI(peer, connectionParams); first = false; } if (failoverParams == null) { remoteURI += ")?failover.maxReconnectAttempts=10"; } else { remoteURI += ")?" + failoverParams; } ConnectionFactory factory = new JmsConnectionFactory(remoteURI); Connection connection = factory.createConnection(); return (JmsConnection) connection; }
Example #3
Source File: AmqpClientActor.java From ditto with Eclipse Public License 2.0 | 6 votes |
/** * Close the JMS connection known to this actor in an isolated dispatcher because it is blocking. * * @return future where the closing operation executes. */ @SuppressWarnings("UnusedReturnValue") private CompletableFuture<Void> ensureJmsConnectionClosed() { if (jmsConnection != null) { final JmsConnection jmsConnectionToClose = jmsConnection; final Runnable closeJmsConnectionRunnable = () -> { try { jmsConnectionToClose.close(); } catch (final Throwable error) { // 'log' is final. It is okay to use it in a future. log.error(error, "RESOURCE-LEAK: failed to close JMSConnection"); throw new RuntimeException(error); } }; return CompletableFuture.runAsync(closeJmsConnectionRunnable, JMSConnectionHandlingActor.getOwnDispatcher(getContext().system())); } else { return CompletableFuture.completedFuture(null); } }
Example #4
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 #5
Source File: JmsMessageConsumerFailedTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override protected MessageConsumer createConsumer() throws Exception { connection = createConnectionToMockProvider(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(_testName.getMethodName()); MessageConsumer consumer = session.createConsumer(destination); connection.setExceptionListener(new ExceptionListener() { @Override public void onException(JMSException exception) { } }); connection.start(); providerListener.onConnectionFailure(new ProviderException("Something went wrong")); final JmsConnection jmsConnection = connection; assertTrue(Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return !jmsConnection.isConnected(); } }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2))); return consumer; }
Example #6
Source File: FailoverProviderOfflineBehaviorTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout=20000) public void testConsumerCloseDoesNotBlock() throws Exception { connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(_testName.getMethodName()); MessageConsumer consumer = session.createConsumer(queue); mockPeer.shutdown(); connectionInterrupted.await(9, TimeUnit.SECONDS); consumer.close(); connection.close(); }
Example #7
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 #8
Source File: JmsSessionFailedTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Override protected void createTestResources() throws Exception { connection = createConnectionToMockProvider(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.setExceptionListener(new ExceptionListener() { @Override public void onException(JMSException exception) { } }); Queue destination = session.createQueue(_testName.getMethodName()); sender = session.createProducer(destination); receiver = session.createConsumer(destination); connection.start(); providerListener.onConnectionFailure(new ProviderException("Something went wrong")); final JmsConnection jmsConnection = connection; assertTrue(Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return !jmsConnection.isConnected(); } }, TimeUnit.SECONDS.toMillis(30), TimeUnit.MILLISECONDS.toMillis(2))); }
Example #9
Source File: JMSWebSocketConnectionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testSendReceiveOverWS() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI()); JmsConnection connection = (JmsConnection) factory.createConnection(); try { Session session = connection.createSession(); Queue queue = session.createQueue(getQueueName()); MessageProducer producer = session.createProducer(queue); producer.send(session.createMessage()); producer.close(); connection.start(); MessageConsumer consumer = session.createConsumer(queue); Message message = consumer.receive(1000); assertNotNull(message); } finally { connection.close(); } }
Example #10
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 #11
Source File: JmsProducerFlowControlFailIfNoSpaceTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test public void testHandleSendFailIfNoSpaceSync() throws Exception { connection = createAmqpConnection(); JmsConnection jmsConnection = (JmsConnection) connection; jmsConnection.setForceSyncSend(true); connection.setExceptionListener(new TestExceptionListener()); connection.start(); Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(getDestinationName()); MessageProducer producer = session.createProducer(queue); producer.send(session.createTextMessage("Message:1")); try { producer.send(session.createTextMessage("Message:2")); fail("Should have failed to send message two"); } catch (JMSException ex) { LOG.debug("Caught expected exception"); } connection.close(); }
Example #12
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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 #13
Source File: SessionIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@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 #14
Source File: FailoverProviderOfflineBehaviorTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout=20000) public void testProducerCloseDoesNotBlock() throws Exception { connection = (JmsConnection) factory.createConnection(); connection.addConnectionListener(new ConnectionInterruptionListener()); connection.start(); Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); Queue queue = session.createQueue(_testName.getMethodName()); MessageProducer producer = session.createProducer(queue); mockPeer.shutdown(); connectionInterrupted.await(9, TimeUnit.SECONDS); producer.close(); connection.close(); }
Example #15
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 #16
Source File: JMSWebSocketConnectionTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testSendLargeMessageToClientFromOpenWire() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI()); JmsConnection connection = (JmsConnection) factory.createConnection(); sendLargeMessageViaOpenWire(); 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 #17
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 #18
Source File: ConsumerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testNoReceivedNoWaitMessagesWhenConnectionNotStarted() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { final CountDownLatch incoming = new CountDownLatch(1); Connection connection = testFixture.establishConnecton(testPeer); // Allow wait for incoming message before we call receive. ((JmsConnection) connection).addConnectionListener(new JmsDefaultConnectionListener() { @Override public void onInboundMessage(JmsInboundMessageDispatch envelope) { incoming.countDown(); } }); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(getTestName()); testPeer.expectReceiverAttach(); testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, new AmqpValueDescribedType("content"), 3); MessageConsumer consumer = session.createConsumer(destination); // Wait for a message to arrive then try and receive it, which should not happen // since the connection is not started. assertTrue(incoming.await(10, TimeUnit.SECONDS)); assertNull(consumer.receiveNoWait()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(2000); } }
Example #19
Source File: FailoverRedirectTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private JmsConnection establishAnonymousConnecton(TestAmqpPeer testPeer) throws Exception { final String remoteURI = "failover:(" + createPeerURI(testPeer).toString() + ")"; ConnectionFactory factory = new JmsConnectionFactory(remoteURI); Connection connection = factory.createConnection(); return (JmsConnection) connection; }
Example #20
Source File: ConsumerIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testNoReceivedMessagesWhenConnectionNotStarted() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { final CountDownLatch incoming = new CountDownLatch(1); Connection connection = testFixture.establishConnecton(testPeer); // Allow wait for incoming message before we call receive. ((JmsConnection) connection).addConnectionListener(new JmsDefaultConnectionListener() { @Override public void onInboundMessage(JmsInboundMessageDispatch envelope) { incoming.countDown(); } }); testPeer.expectBegin(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue destination = session.createQueue(getTestName()); testPeer.expectReceiverAttach(); testPeer.expectLinkFlowRespondWithTransfer(null, null, null, null, new AmqpValueDescribedType("content"), 3); MessageConsumer consumer = session.createConsumer(destination); // Wait for a message to arrive then try and receive it, which should not happen // since the connection is not started. assertTrue(incoming.await(10, TimeUnit.SECONDS)); assertNull(consumer.receive(100)); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(2000); } }
Example #21
Source File: IdleTimeoutIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testConnectionNotMarkedFailedWhenPeerSendsEmptyFrames() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { int configuredTimeout = 2000; int period = 500; int cycles = 6; final CountDownLatch latch = new CountDownLatch(cycles); testPeer.expectSaslAnonymous(); testPeer.expectOpen(); // Each connection creates a session for managing temporary destinations etc testPeer.expectBegin(); // Start to emit idle frames when the connection is set up, this should stop it timing out testPeer.runAfterLastHandler(new EmptyFrameSender(latch, period, cycles, testPeer)); JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + testPeer.getServerPort() + "?amqp.idleTimeout=" + configuredTimeout); final JmsConnection connection = (JmsConnection) factory.createConnection(); // Set a clientID to provoke the actual AMQP connection process to occur. connection.setClientID("clientName"); boolean framesSent = latch.await(cycles * period * 2, TimeUnit.MILLISECONDS); assertTrue("idle frames were not sent as expected", framesSent); assertFalse("connection shouldnt fail", connection.isFailed()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); assertNull(testPeer.getThrowable()); } }
Example #22
Source File: JmsProducerFlowControlFailIfNoSpaceTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test public void testHandleSendFailIfNoSpaceAsync() throws Exception { connection = createAmqpConnection(); JmsConnection jmsConnection = (JmsConnection) connection; jmsConnection.setForceSyncSend(false); connection.setExceptionListener(new TestExceptionListener()); connection.start(); Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue(getDestinationName()); MessageProducer producer = session.createProducer(queue); producer.send(session.createTextMessage("Message:1")); producer.send(session.createTextMessage("Message:2")); assertTrue("Should have got an error from no space.", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return !exceptions.isEmpty(); } })); connection.close(); }
Example #23
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testSetCustomRedeliveryPolicy() throws Exception { CustomJmsRedeliveryPolicy custom = new CustomJmsRedeliveryPolicy(); try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Ignore errors from peer close due to not sending any Open / Close frames testPeer.setSuppressReadExceptionOnClose(true); String uri = "amqp://127.0.0.1:" + testPeer.getServerPort(); testPeer.expectSaslAnonymous(); JmsConnectionFactory factory = new JmsConnectionFactory(uri); factory.setRedeliveryPolicy(custom); assertEquals(custom, factory.getRedeliveryPolicy()); JmsConnection connection = (JmsConnection) factory.createConnection(); assertTrue(connection.getRedeliveryPolicy() instanceof CustomJmsRedeliveryPolicy); assertNotSame(custom, connection.getRedeliveryPolicy()); testPeer.waitForAllHandlersToComplete(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example #24
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testSetCustomPresettlePolicy() throws Exception { CustomJmsPresettlePolicy custom = new CustomJmsPresettlePolicy(); try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Ignore errors from peer close due to not sending any Open / Close frames testPeer.setSuppressReadExceptionOnClose(true); String uri = "amqp://127.0.0.1:" + testPeer.getServerPort(); testPeer.expectSaslAnonymous(); JmsConnectionFactory factory = new JmsConnectionFactory(uri); factory.setPresettlePolicy(custom); assertEquals(custom, factory.getPresettlePolicy()); JmsConnection connection = (JmsConnection) factory.createConnection(); assertTrue(connection.getPresettlePolicy() instanceof CustomJmsPresettlePolicy); assertNotSame(custom, connection.getPresettlePolicy()); testPeer.waitForAllHandlersToComplete(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example #25
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testSetCustomPrefetchPolicy() throws Exception { CustomJmsPrefetchPolicy custom = new CustomJmsPrefetchPolicy(); try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Ignore errors from peer close due to not sending any Open / Close frames testPeer.setSuppressReadExceptionOnClose(true); String uri = "amqp://127.0.0.1:" + testPeer.getServerPort(); testPeer.expectSaslAnonymous(); JmsConnectionFactory factory = new JmsConnectionFactory(uri); factory.setPrefetchPolicy(custom); assertEquals(custom, factory.getPrefetchPolicy()); JmsConnection connection = (JmsConnection) factory.createConnection(); assertTrue(connection.getPrefetchPolicy() instanceof CustomJmsPrefetchPolicy); assertNotSame(custom, connection.getPrefetchPolicy()); testPeer.waitForAllHandlersToCompleteNoAssert(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example #26
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 #27
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testMessageIDFormatOptionApplied() throws Exception { BUILTIN[] formatters = JmsMessageIDBuilder.BUILTIN.values(); for (BUILTIN formatter : formatters) { LOG.info("Testing application of Message ID Format: {}", formatter.name()); try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Ignore errors from peer close due to not sending any Open / Close frames testPeer.setSuppressReadExceptionOnClose(true); // DONT create a test fixture, we will drive everything directly. testPeer.expectSaslAnonymous(); String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?jms.messageIDPolicy.messageIDType=" + formatter.name(); JmsConnectionFactory factory = new JmsConnectionFactory(uri); assertEquals(formatter.name(), ((JmsDefaultMessageIDPolicy) factory.getMessageIDPolicy()).getMessageIDType()); JmsConnection connection = (JmsConnection) factory.createConnection(); assertEquals(formatter.name(), ((JmsDefaultMessageIDPolicy) connection.getMessageIDPolicy()).getMessageIDBuilder().toString()); testPeer.waitForAllHandlersToComplete(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } } }
Example #28
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testUriOptionsAppliedToConnection() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Ignore errors from peer close due to not sending any Open / Close frames testPeer.setSuppressReadExceptionOnClose(true); // DONT create a test fixture, we will drive everything directly. testPeer.expectSaslAnonymous(); String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?jms.localMessagePriority=true&jms.forceAsyncSend=true"; JmsConnectionFactory factory = new JmsConnectionFactory(uri); assertTrue(factory.isLocalMessagePriority()); assertTrue(factory.isForceAsyncSend()); JmsConnection connection = (JmsConnection) factory.createConnection(); assertNotNull(connection); assertTrue(connection.isLocalMessagePriority()); assertTrue(connection.isForceAsyncSend()); testPeer.waitForAllHandlersToComplete(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example #29
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@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 #30
Source File: TransactionsIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@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); } }