Java Code Examples for org.apache.qpid.jms.JmsConnectionFactory#createConnection()
The following examples show how to use
org.apache.qpid.jms.JmsConnectionFactory#createConnection() .
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: SslIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testNonSslConnectionFailsToSslServer() throws Exception { TransportOptions serverOptions = new TransportOptions(); serverOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE); serverOptions.setKeyStorePassword(PASSWORD); serverOptions.setVerifyHost(false); try (NettySimpleAmqpServer server = new NettySimpleAmqpServer(serverOptions, true)) { server.start(); JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:" + server.getServerPort() + "?jms.connectTimeout=25"); try { factory.createConnection(); fail("should not have connected"); } catch (JMSException jmse) { String message = jmse.getMessage(); assertNotNull(message); assertTrue("Unexpected message: " + message, message.contains("Timed out while waiting to connect")); } } }
Example 2
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 3
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout=20000) public void testCreateConnectionGoodProviderString() 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(); JmsConnectionFactory factory = new JmsConnectionFactory("amqp://127.0.0.1:" + testPeer.getServerPort()); Connection connection = factory.createConnection(); assertNotNull(connection); testPeer.waitForAllHandlersToComplete(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example 4
Source File: JMSXUserIDPluginTest.java From activemq-artemis with Apache License 2.0 | 6 votes |
@Test public void testAddValidatedUserAMQP() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory("amqp://127.0.0.1:61616"); Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Queue queue = session.createQueue(ADDRESS.toString()); MessageProducer producer = session.createProducer(queue); producer.send(session.createMessage()); connection.close(); server.stop(); server.start(); connection = factory.createConnection(); session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); connection.start(); MessageConsumer consumer = session.createConsumer(queue); Message message = consumer.receive(5000); Assert.assertNotNull(message); Assert.assertEquals(message.getStringProperty("_AMQ_VALIDATED_USER"), "testuser"); connection.close(); }
Example 5
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 20_000) public void testConfigureFutureFactoryFromURITypeUnknown() throws Exception { 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() + "?provider.futureType=unknown"; JmsConnectionFactory factory = new JmsConnectionFactory(uri); try { factory.createConnection(); fail("Should not allow a connection to proceed with a bad future factory type"); } catch (JMSException ex) { String message = ex.getMessage(); assertTrue(message.contains("No ProviderFuture implementation")); } testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example 6
Source File: FailoverProviderTest.java From qpid-jms with Apache License 2.0 | 6 votes |
@Test(timeout = 30000) public void testMaxReconnectAttemptsWithBackOff() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory( "failover:(mock://localhost?mock.failOnConnect=true)" + "?failover.maxReconnectAttempts=5" + "&failover.maxReconnectDelay=60" + "&failover.reconnectDelay=10" + "&failover.useReconnectBackOff=true"); Connection connection = null; try { connection = factory.createConnection(); connection.start(); fail("Should have stopped after five retries."); } catch (JMSException ex) { } finally { if (connection != null) { connection.close(); } } assertEquals(5, mockPeer.getContextStats().getProvidersCreated()); assertEquals(5, mockPeer.getContextStats().getConnectionAttempts()); assertEquals(5, mockPeer.getContextStats().getCloseAttempts()); }
Example 7
Source File: JmsAmqpDiscoveryTest.java From qpid-jms with Apache License 2.0 | 5 votes |
protected Connection createFailingConnection() throws JMSException { String discoveryPrefix = DiscoveryProviderFactory.DISCOVERY_OPTION_PREFIX; JmsConnectionFactory factory = new JmsConnectionFactory( "discovery:(multicast://default?group=altGroup)?" + discoveryPrefix + "startupMaxReconnectAttempts=10" + "&" + discoveryPrefix +"maxReconnectDelay=100"); connection = factory.createConnection(); jmsConnection = (JmsConnection) connection; jmsConnection.addConnectionListener(this); jmsConnection.start(); return connection; }
Example 8
Source File: SslIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doCreateConnectionWithInvalidAliasTestImpl(String alias) throws Exception, IOException { TransportOptions sslOptions = new TransportOptions(); sslOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE); sslOptions.setTrustStoreLocation(BROKER_JKS_TRUSTSTORE); sslOptions.setKeyStorePassword(PASSWORD); sslOptions.setTrustStorePassword(PASSWORD); sslOptions.setVerifyHost(false); SSLContext context = TransportSupport.createJdkSslContext(sslOptions); try (TestAmqpPeer testPeer = new TestAmqpPeer(context, true);) { String connOptions = "?transport.keyStoreLocation=" + CLIENT_MULTI_KEYSTORE + "&" + "transport.keyStorePassword=" + PASSWORD + "&" + "transport.trustStoreLocation=" + CLIENT_JKS_TRUSTSTORE + "&" + "transport.trustStorePassword=" + PASSWORD + "&" + "transport.keyAlias=" + alias; // DONT use a test fixture, we will drive it directly (because creating the connection will fail). JmsConnectionFactory factory = new JmsConnectionFactory("amqps://127.0.0.1:" + testPeer.getServerPort() + connOptions); try { factory.createConnection(); fail("Expected exception to be thrown"); } catch (JMSException jmse) { // Expected } assertNull("Attempt should have failed locally, peer should not have accepted any TCP connection", testPeer.getClientSocket()); } }
Example 9
Source File: SimpleStreamingLargeMessageTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
private void jmsTest(boolean persistent, boolean tx) throws JMSException { int MESSAGE_SIZE = 100 * 1024; int MESSAGES = 10; String producerUri = "amqp://localhost:5672"; final JmsConnectionFactory producerFactory = new JmsConnectionFactory(producerUri); try (Connection producerConnection = producerFactory.createConnection(); Session producerSession = producerConnection.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE)) { producerConnection.start(); final Destination queue = producerSession.createQueue(getQueueName()); String consumerUri = "amqp://localhost:5672"; final JmsConnectionFactory consumerConnectionFactory = new JmsConnectionFactory(consumerUri); try (Connection consumerConnection = consumerConnectionFactory.createConnection(); Session consumerSession = consumerConnection.createSession(tx, tx ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE); MessageConsumer consumer = consumerSession.createConsumer(queue); MessageProducer producer = producerSession.createProducer(queue)) { if (persistent) { producer.setDeliveryMode(DeliveryMode.PERSISTENT); } else { producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); } consumerConnection.start(); final byte[] largeMessageContent = new byte[MESSAGE_SIZE]; final byte[] receivedContent = new byte[largeMessageContent.length]; ThreadLocalRandom.current().nextBytes(largeMessageContent); for (int i = 0; i < MESSAGES; i++) { final BytesMessage sentMessage = producerSession.createBytesMessage(); sentMessage.writeBytes(largeMessageContent); producer.send(sentMessage); if (tx) { producerSession.commit(); } final Message receivedMessage = consumer.receive(5000); Assert.assertNotNull("A message should be received in 5000 ms", receivedMessage); if (tx) { consumerSession.commit(); } Assert.assertThat(receivedMessage, IsInstanceOf.instanceOf(sentMessage.getClass())); Assert.assertEquals(largeMessageContent.length, ((BytesMessage) receivedMessage).readBytes(receivedContent)); Assert.assertArrayEquals(largeMessageContent, receivedContent); } } } }
Example 10
Source File: ConnectionFactoryIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout=20000) public void testSetCustomMessageIDBuilder() throws Exception { CustomJmsMessageIdBuilder custom = new CustomJmsMessageIdBuilder(); 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(); JmsConnectionFactory factory = new JmsConnectionFactory(uri); ((JmsDefaultMessageIDPolicy) factory.getMessageIDPolicy()).setMessageIDBuilder(custom); assertEquals(custom.toString(), ((JmsDefaultMessageIDPolicy) factory.getMessageIDPolicy()).getMessageIDType()); JmsConnection connection = (JmsConnection) factory.createConnection(); assertEquals(custom.toString(), ((JmsDefaultMessageIDPolicy) connection.getMessageIDPolicy()).getMessageIDBuilder().toString()); testPeer.waitForAllHandlersToComplete(1000); testPeer.expectOpen(); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToCompleteNoAssert(1000); } }
Example 11
Source File: JmsMessageProducerTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 10000) public void testInOrderSendFailuresCompletionsReturnInOrder() throws Exception { final int MESSAGE_COUNT = 3; final MockRemotePeer remotePoor = MockRemotePeer.INSTANCE; JmsConnectionFactory factory = new JmsConnectionFactory( "mock://localhost?mock.delayCompletionCalls=true"); Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final Destination destination = new JmsQueue("explicitDestination"); JmsMessageProducer producer = (JmsMessageProducer) session.createProducer(destination); final MyCompletionListener listener = new MyCompletionListener(); sendMessages(MESSAGE_COUNT, producer, listener); assertTrue("Not all messages sent", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return remotePoor.getPendingCompletions(destination).size() == MESSAGE_COUNT; } })); remotePoor.failAllPendingSends(destination, new ProviderException("Could not send message")); assertTrue("Not all completions triggered", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return listener.getFailedSends().size() == MESSAGE_COUNT; } })); assertMessageFailedInOrder(MESSAGE_COUNT, listener); connection.close(); }
Example 12
Source File: AMQPMessageRedistributionTest.java From activemq-artemis with Apache License 2.0 | 5 votes |
@Test public void testMessageRedistributionWithoutDupAMQP() throws Exception { setupCluster(MessageLoadBalancingType.ON_DEMAND); startServers(0, 1); setupSessionFactory(0, isNetty()); setupSessionFactory(1, isNetty()); createQueue(0, queue, queue, null, true, null, null, RoutingType.ANYCAST); createQueue(1, queue, queue, null, true, null, null, RoutingType.ANYCAST); waitForBindings(0, queue, 1, 0, true); waitForBindings(1, queue, 1, 0, true); waitForBindings(0, queue, 1, 0, false); waitForBindings(1, queue, 1, 0, false); final int NUMBER_OF_MESSAGES = 20; JmsConnectionFactory factory = new JmsConnectionFactory(broker0); Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = session.createProducer(session.createQueue(queue)); for (int i = 0; i < NUMBER_OF_MESSAGES; i++) { producer.send(session.createTextMessage("hello " + i)); } connection.close(); receiveOnBothNodes(NUMBER_OF_MESSAGES); }
Example 13
Source File: IdleTimeoutIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 20000) public void testConnectionSetFailedWhenPeerNeglectsToSendEmptyFrames() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { int configuredTimeout = 200; testPeer.expectSaslAnonymous(); testPeer.expectOpen(); // Each connection creates a session for managing temporary destinations etc testPeer.expectBegin(); 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"); testPeer.waitForAllHandlersToComplete(1000); // The peer is still connected, so it will get the close frame with error testPeer.expectClose(Matchers.notNullValue(), false); assertNull(testPeer.getThrowable()); testPeer.setSuppressReadExceptionOnClose(true); boolean failed = Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return connection.isFailed(); } }, 10000, 10); assertTrue("connection didnt fail in expected timeframe", failed); testPeer.waitForAllHandlersToComplete(1000); connection.close(); } }
Example 14
Source File: SaslIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doMechanismSelectedExternalTestImpl(boolean requireClientCert, Symbol clientSelectedMech, Symbol[] serverMechs) throws Exception { TransportOptions sslOptions = new TransportOptions(); sslOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE); sslOptions.setKeyStorePassword(PASSWORD); sslOptions.setVerifyHost(false); if (requireClientCert) { sslOptions.setTrustStoreLocation(BROKER_JKS_TRUSTSTORE); sslOptions.setTrustStorePassword(PASSWORD); } SSLContext context = TransportSupport.createJdkSslContext(sslOptions); try (TestAmqpPeer testPeer = new TestAmqpPeer(context, requireClientCert);) { String connOptions = "?transport.trustStoreLocation=" + CLIENT_JKS_TRUSTSTORE + "&" + "transport.trustStorePassword=" + PASSWORD + "&" + "jms.clientID=myclientid"; if (requireClientCert) { connOptions += "&transport.keyStoreLocation=" + CLIENT_JKS_KEYSTORE + "&" + "transport.keyStorePassword=" + PASSWORD; } testPeer.expectSaslFailingAuthentication(serverMechs, clientSelectedMech); JmsConnectionFactory factory = new JmsConnectionFactory("amqps://localhost:" + testPeer.getServerPort() + connOptions); try { factory.createConnection(); fail("Expected exception to be thrown"); } catch (JMSException jmse) { // Expected } testPeer.waitForAllHandlersToComplete(1000); } }
Example 15
Source File: FailoverProviderTest.java From qpid-jms with Apache License 2.0 | 5 votes |
@Test(timeout = 30000) public void testMaxReconnectAttemptsWithMultipleURIs() throws Exception { JmsConnectionFactory factory = new JmsConnectionFactory( "failover:(mock://192.168.2.1?mock.failOnConnect=true," + "mock://192.168.2.2?mock.failOnConnect=true," + "mock://192.168.2.3?mock.failOnConnect=true)" + "?failover.maxReconnectAttempts=5" + "&failover.reconnectDelay=1" + "&failover.useReconnectBackOff=false"); Connection connection = null; try { connection = factory.createConnection(); connection.start(); fail("Should have stopped after five retries."); } catch (JMSException ex) { } finally { if (connection != null) { connection.close(); } } // The number should scale by the number of URIs in the list assertEquals(15, mockPeer.getContextStats().getProvidersCreated()); assertEquals(15, mockPeer.getContextStats().getConnectionAttempts()); assertEquals(15, mockPeer.getContextStats().getCloseAttempts()); }
Example 16
Source File: SslIntegrationTest.java From qpid-jms with Apache License 2.0 | 5 votes |
private void doTestCreateSslConnectionWithServerSendingPreemptiveData(boolean openSSL) throws Exception { TransportOptions serverSslOptions = new TransportOptions(); serverSslOptions.setKeyStoreLocation(BROKER_JKS_KEYSTORE); serverSslOptions.setKeyStorePassword(PASSWORD); serverSslOptions.setVerifyHost(false); SSLContext serverSslContext = TransportSupport.createJdkSslContext(serverSslOptions); boolean sendServerSaslHeaderPreEmptively = true; try (TestAmqpPeer testPeer = new TestAmqpPeer(serverSslContext, false, sendServerSaslHeaderPreEmptively);) { // Don't use test fixture, handle the connection directly to control sasl behaviour testPeer.expectSaslAnonymousWithPreEmptiveServerHeader(); testPeer.expectOpen(); testPeer.expectBegin(); String connOptions = "?transport.trustStoreLocation=" + CLIENT_JKS_TRUSTSTORE + "&" + "transport.trustStorePassword=" + PASSWORD + "&" + "transport.useOpenSSL=" + openSSL; JmsConnectionFactory factory = new JmsConnectionFactory("amqps://localhost:" + testPeer.getServerPort() + connOptions); Connection connection = factory.createConnection(); connection.start(); Socket socket = testPeer.getClientSocket(); assertTrue(socket instanceof SSLSocket); testPeer.expectClose(); connection.close(); } }
Example 17
Source File: DivertTopicToQueueTest.java From activemq-artemis with Apache License 2.0 | 4 votes |
@Test public void divertTopicToQueueWithSelectorTest() throws Exception { final String address1 = "bss.order.workorderchanges.v1.topic"; final String address2 = "bss.order.Consumer.cbma.workorderchanges.v1.queue"; final String address3 = "bss.order.Consumer.pinpoint.workorderchanges.v1.queue"; DivertConfiguration dc1 = new DivertConfiguration().setName("WorkOrderChangesCBMA-Divert").setRoutingName("WorkOrderChangesCBMA-Divert").setAddress(address1).setForwardingAddress(address2).setExclusive(false).setRoutingType(ComponentConfigurationRoutingType.ANYCAST); DivertConfiguration dc2 = new DivertConfiguration().setName("WorkOrderChangesPinpoint-Divert").setRoutingName("WorkOrderChangesPinpoint-Divert").setAddress(address1).setForwardingAddress(address3).setExclusive(false).setRoutingType(ComponentConfigurationRoutingType.ANYCAST); server.deployDivert(dc1); server.deployDivert(dc2); JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI()); Connection connection = factory.createConnection(null, null); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); javax.jms.Topic topicSource = session.createTopic(address1); javax.jms.Queue queueTarget = session.createQueue(address2); javax.jms.Queue queueTarget2 = session.createQueue(address3); final MessageProducer producer = session.createProducer(topicSource); final TextMessage message = session.createTextMessage("Hello"); message.setStringProperty("filename", "BILHANDLE"); connection.start(); String selector = "filename='BILHANDLE'"; final MessageConsumer consumer = session.createConsumer(queueTarget, selector); final MessageConsumer consumer2 = session.createConsumer(queueTarget2, selector); producer.send(message); TextMessage receivedMessage = (TextMessage) consumer.receive(1000); TextMessage receivedMessage2 = (TextMessage) consumer2.receive(1000); Assert.assertNotNull(receivedMessage); Assert.assertNotNull(receivedMessage2); connection.close(); }
Example 18
Source File: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout=20000) public void testSendingMessageWithUUIDStringMessageIdFormat() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // DONT create a test fixture, we will drive everything directly. String uri = "amqp://127.0.0.1:" + testPeer.getServerPort() + "?jms.messageIDPolicy.messageIDType=UUID_STRING"; JmsConnectionFactory factory = new JmsConnectionFactory(uri); testPeer.expectSaslAnonymous(); testPeer.expectOpen(); testPeer.expectBegin(); testPeer.expectBegin(); testPeer.expectSenderAttach(); Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); String queueName = "myQueue"; Queue queue = session.createQueue(queueName); MessageProducer producer = session.createProducer(queue); String text = "myMessage"; MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true).withDurable(equalTo(true)); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); MessagePropertiesSectionMatcher propsMatcher = new MessagePropertiesSectionMatcher(true).withMessageId(isA(String.class)); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); messageMatcher.setPropertiesMatcher(propsMatcher); messageMatcher.setMessageContentMatcher(new EncodedAmqpValueMatcher(text)); testPeer.expectTransfer(messageMatcher); testPeer.expectClose(); Message message = session.createTextMessage(text); assertNull("JMSMessageID should not yet be set", message.getJMSMessageID()); producer.send(message); String jmsMessageID = message.getJMSMessageID(); assertNotNull("JMSMessageID should be set", jmsMessageID); assertTrue("JMS 'ID:' prefix not found", jmsMessageID.startsWith("ID:")); String noIdPrefix = AmqpMessageIdHelper.JMS_ID_PREFIX + AmqpMessageIdHelper.AMQP_NO_PREFIX; assertTrue("The 'No ID prefix' encoding hint was not found", jmsMessageID.startsWith(noIdPrefix)); connection.close(); testPeer.waitForAllHandlersToComplete(1000); // Get the value that was actually transmitted/received, verify it is a String, // verify it is only the UUID toString and has no "ID", check the encoded // JMSMessageID value that we have locally. Object receivedMessageId = propsMatcher.getReceivedMessageId(); String expected = jmsMessageID.substring(noIdPrefix.length()); UUID.fromString(expected); assertTrue("Expected String message id to be sent", receivedMessageId instanceof String); assertEquals("Expected UUID toString value to be present in AMQP message", expected, receivedMessageId); } }
Example 19
Source File: ProducerIntegrationTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 20000) public void testUserIdNotSetWhenNotConfiguredForInclusion() throws Exception { try (TestAmqpPeer testPeer = new TestAmqpPeer();) { // Expect a PLAIN connection String user = "user"; String pass = "qwerty123456"; testPeer.expectSaslPlain(user, pass); testPeer.expectOpen(); testPeer.expectBegin(); testPeer.expectBegin(); testPeer.expectSenderAttach(); JmsConnectionFactory factory = new JmsConnectionFactory( "amqp://localhost:" + testPeer.getServerPort()); factory.setPopulateJMSXUserID(false); Connection connection = factory.createConnection(user, pass); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); Queue queue = session.createQueue("TestQueue"); MessageProducer producer = session.createProducer(queue); MessagePropertiesSectionMatcher propertiesMatcher = new MessagePropertiesSectionMatcher(true); propertiesMatcher.withUserId(nullValue()); MessageHeaderSectionMatcher headersMatcher = new MessageHeaderSectionMatcher(true); MessageAnnotationsSectionMatcher msgAnnotationsMatcher = new MessageAnnotationsSectionMatcher(true); TransferPayloadCompositeMatcher messageMatcher = new TransferPayloadCompositeMatcher(); messageMatcher.setPropertiesMatcher(propertiesMatcher); messageMatcher.setHeadersMatcher(headersMatcher); messageMatcher.setMessageAnnotationsMatcher(msgAnnotationsMatcher); testPeer.expectTransfer(messageMatcher); producer.send(session.createMessage()); testPeer.expectClose(); connection.close(); testPeer.waitForAllHandlersToComplete(1000); } }
Example 20
Source File: JmsMessageProducerTest.java From qpid-jms with Apache License 2.0 | 4 votes |
@Test(timeout = 10000) public void testInterleavedCompletionsReturnedInOrder() throws Exception { final int MESSAGE_COUNT = 3; final MockRemotePeer remotePoor = MockRemotePeer.INSTANCE; JmsConnectionFactory factory = new JmsConnectionFactory( "mock://localhost?mock.delayCompletionCalls=true"); Connection connection = factory.createConnection(); Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); final Destination destination = new JmsQueue("explicitDestination"); JmsMessageProducer producer = (JmsMessageProducer) session.createProducer(destination); final MyCompletionListener listener = new MyCompletionListener(); sendMessages(MESSAGE_COUNT, producer, listener); assertTrue("Not all sends made it to the remote", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return remotePoor.getPendingCompletions(destination).size() == MESSAGE_COUNT; } })); List<JmsOutboundMessageDispatch> pending = remotePoor.getPendingCompletions(destination); assertEquals(MESSAGE_COUNT, pending.size()); Collections.reverse(pending); for (JmsOutboundMessageDispatch envelope : pending) { int sequence = envelope.getMessage().getIntProperty("sequence"); if (sequence % 2 == 0) { LOG.info("Trigger completion of message: {}", envelope.getMessage().getJMSMessageID()); remotePoor.completePendingSend(envelope); } else { LOG.info("Trigger failure of message: {}", envelope.getMessage().getJMSMessageID()); remotePoor.failPendingSend(envelope, new ProviderException("Failed to send message")); } } assertTrue("Not all completions triggered", Wait.waitFor(new Wait.Condition() { @Override public boolean isSatisfied() throws Exception { return listener.getCombinedSends().size() == MESSAGE_COUNT; } })); assertTotalCompletionOrder(MESSAGE_COUNT, listener); connection.close(); }