javax.jms.Session

Here are the examples of the java api class javax.jms.Session taken from open source projects.

1. DurableUnsubscribeTest#testUnsubscribe()

View license
public void testUnsubscribe() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId");
    session.close();
    Destination d = broker.getDestination(topic);
    assertEquals("Subscription is missing.", 1, d.getConsumers().size());
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(topic);
    for (int i = 0; i < 1000; i++) {
        producer.send(session.createTextMessage("text"));
    }
    Thread.sleep(1000);
    session.unsubscribe("SubsId");
    session.close();
    assertEquals("Subscription exists.", 0, d.getConsumers().size());
}

2. JmsRedeliveredTest#testNoReceiveConsumerDoesNotIncrementRedelivery()

View license
public void testNoReceiveConsumerDoesNotIncrementRedelivery() throws Exception {
    connection.setClientID(getName());
    connection.start();
    Session session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = session.createQueue("queue-" + getName());
    MessageConsumer consumer = session.createConsumer(queue);
    MessageProducer producer = createProducer(session, queue);
    producer.send(createTextMessage(session));
    session.commit();
    TimeUnit.SECONDS.sleep(1);
    consumer.close();
    consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    assertFalse("Message should not be redelivered.", msg.getJMSRedelivered());
    session.commit();
    session.close();
}

3. JmsRedeliveredTest#testNoReceiveDurableConsumerDoesNotIncrementRedelivery()

View license
public void testNoReceiveDurableConsumerDoesNotIncrementRedelivery() throws Exception {
    connection.setClientID(getName());
    connection.start();
    Session session = connection.createSession(true, Session.CLIENT_ACKNOWLEDGE);
    Topic topic = session.createTopic("topic-" + getName());
    MessageConsumer consumer = session.createDurableSubscriber(topic, "sub");
    MessageProducer producer = createProducer(session, topic);
    producer.send(createTextMessage(session));
    session.commit();
    TimeUnit.SECONDS.sleep(1);
    consumer.close();
    consumer = session.createDurableSubscriber(topic, "sub");
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    assertFalse("Message should not be redelivered.", msg.getJMSRedelivered());
    session.commit();
    session.close();
}

4. JmsRollbackRedeliveryTest#populateDestinationWithInterleavedProducer()

View license
private void populateDestinationWithInterleavedProducer(final int nbMessages, final String destinationName, Connection connection) throws JMSException {
    Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination1 = session1.createQueue(destinationName);
    MessageProducer producer1 = session1.createProducer(destination1);
    Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination2 = session2.createQueue(destinationName);
    MessageProducer producer2 = session2.createProducer(destination2);
    for (int i = 1; i <= nbMessages; i++) {
        if (i % 2 == 0) {
            producer1.send(session1.createTextMessage("<hello id='" + i + "'/>"));
        } else {
            producer2.send(session2.createTextMessage("<hello id='" + i + "'/>"));
        }
    }
    producer1.close();
    session1.close();
    producer2.close();
    session2.close();
}

5. QpidBrokerTestCase#assertProducingConsuming()

Project: qpid-java
Source File: QpidBrokerTestCase.java
View license
/**
     * Tests that a connection is functional by producing and consuming a single message.
     * Will fail if failover interrupts either transaction.
     */
public void assertProducingConsuming(final Connection connection) throws Exception {
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createQueue(getTestQueueName());
    MessageConsumer consumer = session.createConsumer(destination);
    sendMessage(session, destination, 1);
    session.commit();
    connection.start();
    Message m1 = consumer.receive(RECEIVE_TIMEOUT);
    assertNotNull("Message 1 is not received", m1);
    assertEquals("Unexpected first message received", 0, m1.getIntProperty(INDEX));
    session.commit();
    session.close();
}

6. QueueMessageDurabilityTest#testPersistentContentRetainedOnTransientQueue()

View license
public void testPersistentContentRetainedOnTransientQueue() throws Exception {
    setTestClientSystemProperty(ClientProperties.QPID_DECLARE_QUEUES_PROP_NAME, "false");
    Connection conn = getConnection();
    Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = session.createProducer(null);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    conn.start();
    producer.send(session.createTopic("N.N.Y.Y"), session.createTextMessage("test1"));
    session.commit();
    MessageConsumer consumer = session.createConsumer(session.createQueue(DURABLE_DEFAULT_PERSIST_NAME));
    Message msg = consumer.receive(1000l);
    assertNotNull(msg);
    assertTrue(msg instanceof TextMessage);
    assertEquals("test1", ((TextMessage) msg).getText());
    session.commit();
    System.gc();
    consumer = session.createConsumer(session.createQueue(NONDURABLE_ALWAYS_PERSIST_NAME));
    msg = consumer.receive(1000l);
    assertNotNull(msg);
    assertTrue(msg instanceof TextMessage);
    assertEquals("test1", ((TextMessage) msg).getText());
    session.commit();
}

7. AddressBasedDestinationTest#testTopicRereceiveAfterRollback()

View license
/**
    * Tests that a client using a session in [email protected] Session#SESSION_TRANSACTED} can correctly
    * rollback a session and re-receive the same message.
    */
public void testTopicRereceiveAfterRollback() throws Exception {
    final Session jmsSession = _connection.createSession(true, Session.SESSION_TRANSACTED);
    final Destination topic = jmsSession.createTopic("ADDR:amq.topic/topic1; {link:{name: queue1}}");
    final MessageProducer prod = jmsSession.createProducer(topic);
    final MessageConsumer consForTopic1 = jmsSession.createConsumer(topic);
    final Message sentMessage = jmsSession.createTextMessage("Hello");
    prod.send(sentMessage);
    jmsSession.commit();
    Message receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be received by consumer", receivedMessage);
    jmsSession.rollback();
    receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be re-received by consumer after rollback", receivedMessage);
    jmsSession.commit();
}

8. DynamicQueueExchangeCreateTest#testExchangeNotDeclaredDuringProducerCreation()

View license
/**
     * Checks that setting [email protected] ClientProperties#QPID_DECLARE_EXCHANGES_PROP_NAME} false results in
     * disabling implicit ExchangeDeclares during producer creation when using a [email protected] BindingURL}
     */
public void testExchangeNotDeclaredDuringProducerCreation() throws Exception {
    Connection connection = getConnection();
    Session session1 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String exchangeName1 = getTestQueueName() + "1";
    Queue queue = session1.createQueue("direct://" + exchangeName1 + "/queue/queue");
    session1.createProducer(queue);
    ((AMQSession<?, ?>) session1).sync();
    assertTrue("Exchange does not exist", exchangeExists(exchangeName1));
    //Now disable the implicit exchange declares and try again
    setSystemProperty(ClientProperties.QPID_DECLARE_EXCHANGES_PROP_NAME, "false");
    Session session2 = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String exchangeName2 = getTestQueueName() + "2";
    Queue queue2 = session2.createQueue("direct://" + exchangeName2 + "/queue/queue");
    session2.createProducer(queue2);
    ((AMQSession<?, ?>) session2).sync();
    assertFalse("Exchange exists", exchangeExists(exchangeName2));
}

9. FailoverProviderOfflineBehaviorTest#testSessionCloseWithOpenResourcesDoesNotBlock()

View license
@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();
}

10. JmsOfflineBehaviorTests#testSessionCloseWithOpenResourcesDoesNotBlock()

View license
@Test(timeout = 60000)
public void testSessionCloseWithOpenResourcesDoesNotBlock() throws Exception {
    URI brokerURI = new URI(getAmqpFailoverURI());
    Connection connection = createAmqpConnection(brokerURI);
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = session.createQueue(name.getMethodName());
    session.createConsumer(queue);
    session.createProducer(queue);
    stopPrimaryBroker();
    session.close();
    connection.close();
}

11. JmsAutoAckTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowleged messages are being consumed.
    *
    * @throws javax.jms.JMSException
    */
public void testAckedMessageAreConsumed() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    // Reset the session.
    session.close();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

12. JmsClientAckListenerTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowleged messages are being consumed.
    *
    * @throws javax.jms.JMSException
    */
public void testAckedMessageAreConsumed() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    consumer.setMessageListener(this);
    Thread.sleep(10000);
    // Reset the session.
    session.close();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

13. JmsClientAckTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowledged messages are being consumed.
    *
    * @throws JMSException
    */
public void testAckedMessageAreConsumed() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    // Reset the session.
    session.close();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

14. JmsClientAckTest#testUnAckedMessageAreNotConsumedOnSessionClose()

View license
/**
    * Tests if unacknowledged messages are being re-delivered when the consumer connects again.
    *
    * @throws JMSException
    */
public void testUnAckedMessageAreNotConsumedOnSessionClose() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    // Don't ack the message.
    // Reset the session.  This should cause the unacknowledged message to be re-delivered.
    session.close();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(2000);
    assertNotNull(msg);
    msg.acknowledge();
    session.close();
}

15. JMSIndividualAckTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowledged messages are being consumed.
    *
    * @throws JMSException
    */
public void testAckedMessageAreConsumed() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
    Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    // Reset the session.
    session.close();
    session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

16. JMSIndividualAckTest#testUnAckedMessageAreNotConsumedOnSessionClose()

View license
/**
    * Tests if unacknowledged messages are being re-delivered when the consumer connects again.
    *
    * @throws JMSException
    */
public void testUnAckedMessageAreNotConsumedOnSessionClose() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
    Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    // Don't ack the message.
    // Reset the session.  This should cause the unacknowledged message to be re-delivered.
    session.close();
    session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(2000);
    assertNotNull(msg);
    msg.acknowledge();
    session.close();
}

17. CloseRollbackRedeliveryQueueTest#testVerifySessionCloseRedeliveryWithFailoverTransport()

View license
public void testVerifySessionCloseRedeliveryWithFailoverTransport() throws Throwable {
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    Message message = consumer.receive(1000);
    String id = message.getJMSMessageID();
    assertNotNull(message);
    LOG.info("got message " + message);
    // close will rollback the current tx
    session.close();
    session = connection.createSession(true, Session.SESSION_TRANSACTED);
    consumer = session.createConsumer(destination);
    message = consumer.receive(1000);
    session.commit();
    assertNotNull(message);
    assertEquals("redelivered message", id, message.getJMSMessageID());
    assertEquals(2, message.getLongProperty("JMSXDeliveryCount"));
}

18. CloseRollbackRedeliveryQueueTest#testVerifyConsumerAndSessionCloseRedeliveryWithFailoverTransport()

View license
public void testVerifyConsumerAndSessionCloseRedeliveryWithFailoverTransport() throws Throwable {
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    Message message = consumer.receive(1000);
    String id = message.getJMSMessageID();
    assertNotNull(message);
    LOG.info("got message " + message);
    consumer.close();
    session.close();
    session = connection.createSession(true, Session.SESSION_TRANSACTED);
    consumer = session.createConsumer(destination);
    message = consumer.receive(1000);
    session.commit();
    assertNotNull(message);
    assertEquals("redelivered message", id, message.getJMSMessageID());
    assertEquals(2, message.getLongProperty("JMSXDeliveryCount"));
}

19. CloseRollbackRedeliveryQueueTest#testVerifyConsumerCloseSessionRollbackRedeliveryWithFailoverTransport()

View license
public void testVerifyConsumerCloseSessionRollbackRedeliveryWithFailoverTransport() throws Throwable {
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    Message message = consumer.receive(1000);
    String id = message.getJMSMessageID();
    assertNotNull(message);
    LOG.info("got message " + message);
    consumer.close();
    session.rollback();
    consumer = session.createConsumer(destination);
    message = consumer.receive(1000);
    session.commit();
    assertNotNull(message);
    assertEquals("redelivered message", id, message.getJMSMessageID());
    assertEquals(2, message.getLongProperty("JMSXDeliveryCount"));
}

20. AMQ1925Test#sendMessagesToQueue()

Project: activemq-artemis
Source File: AMQ1925Test.java
View license
private void sendMessagesToQueue() throws Exception {
    Connection connection = cf.createConnection();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer producer = session.createProducer(session.createQueue(QUEUE_NAME));
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);
    for (int i = 0; i < MESSAGE_COUNT; i++) {
        TextMessage message = session.createTextMessage("Test message " + i);
        message.setIntProperty(PROPERTY_MSG_NUMBER, i);
        producer.send(message);
    }
    session.commit();
    producer.close();
    session.close();
    connection.close();
    assertQueueLength(MESSAGE_COUNT);
}

21. FailoverTransactionTest#testFailoverProducerCloseBeforeTransaction()

View license
@Test
public void testFailoverProducerCloseBeforeTransaction() throws Exception {
    LOG.info(this + " running test testFailoverProducerCloseBeforeTransaction");
    startCleanBroker();
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")");
    configureConnectionFactory(cf);
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue(QUEUE_NAME);
    MessageConsumer consumer = session.createConsumer(destination);
    produceMessage(session, destination);
    // restart to force failover and connection state recovery before the commit
    broker.stop();
    startBroker();
    session.commit();
    Assert.assertNotNull("we got the message", consumer.receive(20000));
    session.commit();
    connection.close();
}

22. FailoverTransactionTest#testFailoverProducerCloseBeforeTransactionFailWhenDisabled()

View license
@Test
public void testFailoverProducerCloseBeforeTransactionFailWhenDisabled() throws Exception {
    LOG.info(this + " running test testFailoverProducerCloseBeforeTransactionFailWhenDisabled");
    startCleanBroker();
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("failover:(" + url + ")?trackTransactionProducers=false");
    configureConnectionFactory(cf);
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue(QUEUE_NAME);
    MessageConsumer consumer = session.createConsumer(destination);
    produceMessage(session, destination);
    // restart to force failover and connection state recovery before the commit
    broker.stop();
    startBroker();
    session.commit();
    // without tracking producers, message will not be replayed on recovery
    Assert.assertNull("we got the message", consumer.receive(5000));
    session.commit();
    connection.close();
}

23. DurableUnsubscribeTest#testDestroy()

View license
public void testDestroy() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createDurableSubscriber(topic, "SubsId2");
    session.close();
    connection.close();
    connection = null;
    Thread.sleep(1000);
    Destination d = broker.getDestination(topic);
    assertEquals("Subscription is missing.", 1, d.getConsumers().size());
    MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
    ObjectName[] subNames = broker.getAdminView().getInactiveDurableTopicSubscribers();
    mbs.invoke(subNames[0], "destroy", new Object[0], new String[0]);
    assertEquals("Subscription exists.", 0, d.getConsumers().size());
}

24. JMSReconnectTest#testNoReconnectCloseAfterFailToReconnectWithTempQueue()

View license
//If server is shutdown, and then connection is closed, after a temp queue has been created, the close should complete normally
@Test
public void testNoReconnectCloseAfterFailToReconnectWithTempQueue() throws Exception {
    ActiveMQConnectionFactory jbcf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
    jbcf.setReconnectAttempts(0);
    Connection conn = jbcf.createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    sess.createTemporaryQueue();
    Thread.sleep(2000);
    this.server.stop();
    this.server.start();
    sess.close();
    conn.close();
}

25. JmsAutoAckTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowleged messages are being consumed.
    *
    * @throws javax.jms.JMSException
    */
@Test
public void testAckedMessageAreConsumed() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(queueName);
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    // Reset the session.
    session.close();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

26. JmsClientAckTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowledged messages are being consumed.
    *
    * @throws JMSException
    */
@Test
public void testAckedMessageAreConsumed() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Queue queue = session.createQueue(getQueueName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    msg.acknowledge();
    // Reset the session.
    session.close();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

27. JMSIndividualAckTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowledged messages are being consumed.
    *
    * @throws JMSException
    */
@Test
public void testAckedMessageAreConsumed() throws JMSException {
    connection.start();
    Session session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
    Queue queue = (Queue) this.createDestination(session, ActiveMQDestination.QUEUE_TYPE);
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(5000);
    assertNotNull(msg);
    msg.acknowledge();
    // Reset the session.
    session.close();
    session = connection.createSession(false, ActiveMQSession.INDIVIDUAL_ACKNOWLEDGE);
    // Attempt to Consume the message...
    consumer = session.createConsumer(queue);
    msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

28. ProtonPubSubTest#testDurablePubSubUnsubscribe()

View license
@Test
public void testDurablePubSubUnsubscribe() throws Exception {
    int numMessages = 100;
    Topic topic = createTopic(pubAddress);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber sub = session.createDurableSubscriber(topic, "myPubId");
    Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sendSession.createProducer(topic);
    connection.start();
    for (int i = 0; i < numMessages; i++) {
        producer.send(sendSession.createTextMessage("message:" + i));
    }
    for (int i = 0; i < numMessages; i++) {
        TextMessage receive = (TextMessage) sub.receive(5000);
        Assert.assertNotNull(receive);
        Assert.assertEquals(receive.getText(), "message:" + i);
    }
    sub.close();
    session.unsubscribe("myPubId");
}

29. ExternalACLTest#testClientDeleteQueueSuccess()

Project: qpid-java
Source File: ExternalACLTest.java
View license
public void testClientDeleteQueueSuccess() throws Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
    conn.start();
    // create kipper
    Topic kipper = sess.createTopic("kipper");
    TopicSubscriber subscriber = sess.createDurableSubscriber(kipper, "kipper");
    subscriber.close();
    sess.unsubscribe("kipper");
    //Do something to show connection is active.
    sess.rollback();
    conn.close();
}

30. ExternalACLTest#testClientDeleteQueueSuccessWithOnlyAllPermissions()

Project: qpid-java
Source File: ExternalACLTest.java
View license
public void testClientDeleteQueueSuccessWithOnlyAllPermissions() throws Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
    conn.start();
    // create kipper
    String topicName = "kipper";
    Topic topic = sess.createTopic(topicName);
    TopicSubscriber subscriber = sess.createDurableSubscriber(topic, topicName);
    subscriber.close();
    sess.unsubscribe(topicName);
    //Do something to show connection is active.
    sess.rollback();
    conn.close();
}

31. StatisticsReportingTest#sendUsing()

View license
private void sendUsing(Connection con, int number, int size) throws Exception {
    Session session = con.createSession(true, Session.SESSION_TRANSACTED);
    createQueue(session);
    MessageProducer producer = session.createProducer(_queue);
    String content = new String(new byte[size]);
    TextMessage msg = session.createTextMessage(content);
    for (int i = 0; i < number; i++) {
        producer.send(msg);
    }
    session.commit();
    session.close();
}

32. QueueRestTest#setUp()

Project: qpid-java
Source File: QueueRestTest.java
View license
public void setUp() throws Exception {
    super.setUp();
    _connection = getConnection();
    Session session = _connection.createSession(true, Session.SESSION_TRANSACTED);
    String queueName = getTestQueueName();
    Destination queue = session.createQueue(queueName);
    MessageConsumer consumer = session.createConsumer(queue);
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < MESSAGE_NUMBER; i++) {
        producer.send(session.createTextMessage("Test-" + i));
    }
    session.commit();
    _connection.start();
    Message m = consumer.receive(1000l);
    assertNotNull("Message is not received", m);
    session.commit();
}

33. JMSXUserIDTest#testJMSXUserIDIsSetByDefault()

Project: qpid-java
Source File: JMSXUserIDTest.java
View license
public void testJMSXUserIDIsSetByDefault() throws Exception {
    Connection connection = getConnection();
    Destination destination = getTestQueue();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    TextMessage message = session.createTextMessage("test");
    producer.send(message);
    assertEquals("Unexpected user ID", GUEST_USERNAME, message.getStringProperty("JMSXUserID"));
    session.commit();
    connection.start();
    Message receivedMessage = consumer.receive(RECEIVE_TIMEOUT);
    session.commit();
    assertNotNull("Expected receivedMessage not received", receivedMessage);
    assertEquals("Unexpected user ID", GUEST_USERNAME, receivedMessage.getStringProperty("JMSXUserID"));
}

34. JMSXUserIDTest#testJMSXUserIDDisabled()

Project: qpid-java
Source File: JMSXUserIDTest.java
View license
public void testJMSXUserIDDisabled() throws Exception {
    String url = String.format("amqp://guest:[email protected]/?brokerlist='tcp://localhost:%s'&populateJMSXUserID='false'", getDefaultBroker().getAmqpPort());
    Connection connection = getConnection(new AMQConnectionURL(url));
    Destination destination = getTestQueue();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    TextMessage message = session.createTextMessage("test");
    producer.send(message);
    String userId = message.getStringProperty("JMSXUserID");
    assertEquals("Unexpected user ID =[" + userId + "]", null, userId);
    session.commit();
    connection.start();
    Message receivedMessage = consumer.receive(RECEIVE_TIMEOUT);
    session.commit();
    assertNotNull("Expected receivedMessage not received", receivedMessage);
    String receivedUserId = receivedMessage.getStringProperty("JMSXUserID");
    assertEquals("Unexpected user ID " + receivedUserId, null, receivedUserId);
}

35. PropertyValueTest#sendReceiveMessageWithHeader()

Project: qpid-java
Source File: PropertyValueTest.java
View license
private void sendReceiveMessageWithHeader(Connection connection, final String propName, final String propValue) throws Exception {
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = session.createQueue(getTestQueueName());
    Message message = session.createMessage();
    message.setStringProperty(propName, propValue);
    MessageConsumer consumer = session.createConsumer(destination);
    MessageProducer producer = session.createProducer(destination);
    producer.setDisableMessageID(true);
    producer.setDisableMessageTimestamp(true);
    producer.send(message);
    session.commit();
    Message receivedMessage = consumer.receive(1000);
    assertNotNull("Message not received", receivedMessage);
    assertEquals("Message has unexpected property value", propValue, receivedMessage.getStringProperty(propName));
    session.commit();
}

36. JmsTransactedConsumerTest#testRollbackRececeivedMessageAndClose()

View license
@Test(timeout = 30000)
public void testRollbackRececeivedMessageAndClose() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(getDestinationName());
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("TestMessage-0"));
    producer.close();
    session.commit();
    MessageConsumer consumer = session.createConsumer(queue);
    Message msg = consumer.receive(3000);
    assertNotNull(msg);
    session.rollback();
    connection.close();
}

37. JmsTransactedProducerTest#testTXProducerCommitsAreQueued()

View license
@Test(timeout = 60000)
public void testTXProducerCommitsAreQueued() throws Exception {
    final int MSG_COUNT = 10;
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Session nonTxSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(name.getMethodName());
    MessageConsumer consumer = nonTxSession.createConsumer(queue);
    MessageProducer producer = session.createProducer(queue);
    for (int i = 0; i < MSG_COUNT; ++i) {
        producer.send(session.createTextMessage());
    }
    Message msg = consumer.receive(2000);
    assertNull(msg);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    session.commit();
    assertEquals(MSG_COUNT, proxy.getQueueSize());
}

38. SecurityExample#checkUserSendAndReceive()

View license
// Check the user connection has both send and receive permissions on the topic
private static void checkUserSendAndReceive(final Topic topic, final Connection connection, final String user) throws JMSException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TextMessage msg = session.createTextMessage("hello-world-4");
    MessageProducer producer = session.createProducer(topic);
    MessageConsumer consumer = session.createConsumer(topic);
    producer.send(msg);
    TextMessage receivedMsg = (TextMessage) consumer.receive(5000);
    if (receivedMsg != null) {
        System.out.println("User " + user + " can send message: [" + msg.getText() + "] to topic: " + topic);
        System.out.println("User " + user + " can receive message: [" + msg.getText() + "] from topic: " + topic);
    } else {
        throw new IllegalStateException("Error! User " + user + " cannot receive the message! ");
    }
    session.close();
}

39. SecurityExample#checkUserSendAndReceive()

View license
// Check the user connection has both send and receive permissions on the topic
private static void checkUserSendAndReceive(final Topic topic, final Connection connection, final String user) throws JMSException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TextMessage msg = session.createTextMessage("hello-world-4");
    MessageProducer producer = session.createProducer(topic);
    MessageConsumer consumer = session.createConsumer(topic);
    producer.send(msg);
    TextMessage receivedMsg = (TextMessage) consumer.receive(5000);
    if (receivedMsg != null) {
        System.out.println("User " + user + " can send message: [" + msg.getText() + "] to topic: " + topic);
        System.out.println("User " + user + " can receive message: [" + msg.getText() + "] from topic: " + topic);
    } else {
        throw new IllegalStateException("Error! User " + user + " cannot receive the message! ");
    }
    session.close();
}

40. DestinationListenerTest#testConsumerForcesNotificationOfNewDestination()

View license
public void testConsumerForcesNotificationOfNewDestination() throws Exception {
    // now lets cause a destination to be created
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    ActiveMQQueue newQueue = new ActiveMQQueue("Test.Cheese");
    session.createConsumer(newQueue);
    Thread.sleep(3000);
    assertThat(newQueue, isIn(newDestinations));
    LOG.info("New destinations are: " + newDestinations);
}

41. AbortSlowConsumer1Test#testAbortAlreadyClosedConnection()

View license
@Test(timeout = 60 * 1000)
public void testAbortAlreadyClosedConnection() throws Exception {
    Connection conn = createConnectionFactory().createConnection();
    conn.setExceptionListener(this);
    Session sess = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    sess.createConsumer(destination);
    conn.start();
    startProducers(destination, 20);
    TimeUnit.SECONDS.sleep(1);
    LOG.info("closing connection: " + conn);
    conn.close();
    TimeUnit.SECONDS.sleep(5);
    assertTrue("no exceptions : " + exceptions, exceptions.isEmpty());
}

42. RedeliveryRestartWithExceptionTest#populateDestination()

View license
private void populateDestination(final int nbMessages, final Destination destination, javax.jms.Connection connection, boolean persistent) throws JMSException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
    for (int i = 1; i <= nbMessages; i++) {
        producer.send(session.createTextMessage("<hello id='" + i + "'/>"));
    }
    producer.close();
    session.close();
}

43. JmsAutoAckListenerTest#testAckedMessageAreConsumed()

View license
/**
    * Tests if acknowleged messages are being consumed.
    *
    * @throws javax.jms.JMSException
    */
public void testAckedMessageAreConsumed() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("test");
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    consumer.setMessageListener(this);
    Thread.sleep(10000);
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Attempt to Consume the message...check if message was acknowledge
    consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

44. JmsMultipleClientsTestSupport#sendMessages()

View license
protected void sendMessages(Connection connection, Destination destination, int count) throws Exception {
    connections.add(connection);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = session.createProducer(destination);
    producer.setDeliveryMode(persistent ? DeliveryMode.PERSISTENT : DeliveryMode.NON_PERSISTENT);
    for (int i = 0; i < count; i++) {
        TextMessage msg = createTextMessage(session, "" + i);
        producer.send(msg);
    }
    producer.close();
    session.close();
    connection.close();
}

45. JmsRollbackRedeliveryTest#populateDestination()

View license
private void populateDestination(final int nbMessages, final String destinationName, Connection connection) throws JMSException {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(destinationName);
    MessageProducer producer = session.createProducer(destination);
    for (int i = 1; i <= nbMessages; i++) {
        producer.send(session.createTextMessage("<hello id='" + i + "'/>"));
    }
    producer.close();
    session.close();
}

46. JmsTempDestinationTest#testDeleteDestinationWithSubscribersFails()

View license
/**
    * Test you can't delete a Destination with Active Subscribers
    *
    * @throws JMSException
    */
@Test
public void testDeleteDestinationWithSubscribersFails() throws JMSException {
    Connection connection = factory.createConnection();
    connections.add(connection);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue queue = session.createTemporaryQueue();
    connection.start();
    session.createConsumer(queue);
    // now closed.
    try {
        queue.delete();
        Assert.fail("Should fail as Subscribers are active");
    } catch (JMSException e) {
        Assert.assertTrue("failed to throw an exception", true);
    }
}

47. AMQ1925Test#tryToFetchMissingMessages()

Project: activemq-artemis
Source File: AMQ1925Test.java
View license
private int tryToFetchMissingMessages() throws JMSException {
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(true, 0);
    MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE_NAME));
    int count = 0;
    while (true) {
        Message message = consumer.receive(500);
        if (message == null)
            break;
        log.info("Found \"missing\" message: " + message);
        count++;
    }
    consumer.close();
    session.close();
    connection.close();
    return count;
}

48. AMQ1925Test#assertQueueEmpty()

Project: activemq-artemis
Source File: AMQ1925Test.java
View license
private void assertQueueEmpty() throws Exception {
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageConsumer consumer = session.createConsumer(session.createQueue(QUEUE_NAME));
    Message msg = consumer.receive(500);
    if (msg != null) {
        Assert.fail(msg.toString());
    }
    consumer.close();
    session.close();
    connection.close();
    assertQueueLength(0);
}

49. FanoutTest#assertMessagesReceived()

Project: activemq-artemis
Source File: FanoutTest.java
View license
protected void assertMessagesReceived(String brokerURL) throws Exception {
    ActiveMQConnectionFactory consumerFactory = new ActiveMQConnectionFactory(brokerURL);
    Connection consumerConnection = consumerFactory.createConnection();
    consumerConnection.start();
    Session consumerSession = consumerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(consumerSession.createQueue("TEST"));
    MessageIdList listener = new MessageIdList();
    consumer.setMessageListener(listener);
    listener.waitForMessagesToArrive(messageCount);
    listener.assertMessagesReceived(messageCount);
    consumer.close();
    consumerSession.close();
    consumerConnection.close();
}

50. ChangeSentMessageTest#testDoChangeSentMessage()

View license
/**
    * test Object messages can be changed after sending with no side-affects
    *
    * @throws Exception
    */
@SuppressWarnings("rawtypes")
public void testDoChangeSentMessage() throws Exception {
    Destination destination = createDestination("test-" + ChangeSentMessageTest.class.getName());
    Connection connection = createConnection();
    connection.start();
    Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = consumerSession.createConsumer(destination);
    Session publisherSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = publisherSession.createProducer(destination);
    HashMap<String, Integer> map = new HashMap<>();
    ObjectMessage message = publisherSession.createObjectMessage();
    for (int i = 0; i < COUNT; i++) {
        map.put(VALUE_NAME, Integer.valueOf(i));
        message.setObject(map);
        producer.send(message);
        assertTrue(message.getObject() == map);
    }
    for (int i = 0; i < COUNT; i++) {
        ObjectMessage msg = (ObjectMessage) consumer.receive();
        HashMap receivedMap = (HashMap) msg.getObject();
        Integer intValue = (Integer) receivedMap.get(VALUE_NAME);
        assertTrue(intValue.intValue() == i);
    }
}

51. DurableSubscriptionTestSupport#testDurableSubWorksInNewSession()

View license
public void testDurableSubWorksInNewSession() throws JMSException {
    // Create the consumer.
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Topic topic = session.createTopic("topic-" + getName());
    MessageConsumer consumer = session.createDurableSubscriber(topic, "sub1");
    // Drain any messages that may already be in the sub
    while (consumer.receive(1000) != null) {
    }
    // See if the durable sub works in a new session.
    session.close();
    session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    // Send a Message that should be added to the durable sub.
    MessageProducer producer = createProducer(session, topic);
    producer.send(session.createTextMessage("Message 1"));
    // Activate the durable sub now. And receive the message.
    consumer = session.createDurableSubscriber(topic, "sub1");
    Message msg = consumer.receive(1000);
    assertNotNull(msg);
    assertEquals("Message 1", ((TextMessage) msg).getText());
}

52. NewConsumerCreatesDestinationTest#testNewConsumerCausesNewDestinationToBeAutoCreated()

View license
public void testNewConsumerCausesNewDestinationToBeAutoCreated() throws Exception {
    // lets create a wildcard thats kinda like those used by Virtual Topics
    String wildcardText = "org.*" + getDestinationString().substring("org.apache".length());
    wildcard = new ActiveMQQueue(wildcardText);
    LOG.info("Using wildcard: " + wildcard);
    LOG.info("on destination: " + destination);
    assertDestinationCreated(destination, false);
    assertDestinationCreated(wildcard, false);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createConsumer(destination);
    assertDestinationCreated(destination, true);
    assertDestinationCreated(wildcard, true);
}

53. ConnectionTest#testTXTypeInvalid()

View license
@Test
public void testTXTypeInvalid() throws Exception {
    conn = cf.createConnection();
    Session sess = conn.createSession(false, Session.SESSION_TRANSACTED);
    assertEquals(Session.AUTO_ACKNOWLEDGE, sess.getAcknowledgeMode());
    sess.close();
    TopicSession tpSess = ((TopicConnection) conn).createTopicSession(false, Session.SESSION_TRANSACTED);
    assertEquals(Session.AUTO_ACKNOWLEDGE, tpSess.getAcknowledgeMode());
    tpSess.close();
    QueueSession qSess = ((QueueConnection) conn).createQueueSession(false, Session.SESSION_TRANSACTED);
    assertEquals(Session.AUTO_ACKNOWLEDGE, qSess.getAcknowledgeMode());
    qSess.close();
}

54. JMSQueueControlTest#testRetryMessage()

View license
/**
    * Test retrying a specific message on DLQ.
    * Expected to be sent back to original queue.
    * @throws Exception
    */
@Test
public void testRetryMessage() throws Exception {
    ActiveMQQueue dlq = createDLQ(RandomUtil.randomString());
    ActiveMQQueue testQueue = createTestQueueWithDLQ(RandomUtil.randomString(), dlq);
    String messageID = JMSUtil.sendMessages(testQueue, 1)[0];
    Connection connection = createConnection();
    connection.start();
    Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(testQueue);
    consumer.receive(500L);
    // All <numMessagesToTest> messages should now be on DLQ
    session.rollback();
    JMSQueueControl testQueueControl = createManagementControl(testQueue);
    JMSQueueControl dlqQueueControl = createManagementControl(dlq);
    Assert.assertEquals(0, getMessageCount(testQueueControl));
    Assert.assertEquals(1, getMessageCount(dlqQueueControl));
    dlqQueueControl.retryMessage(messageID);
    Assert.assertEquals(1, getMessageCount(testQueueControl));
    Assert.assertEquals(0, getMessageCount(dlqQueueControl));
}

55. JmsAutoAckListenerTest#testAckedMessageAreConsumed()

View license
@Test
public void testAckedMessageAreConsumed() throws Exception {
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(queueName);
    MessageProducer producer = session.createProducer(queue);
    producer.send(session.createTextMessage("Hello"));
    // Consume the message...
    MessageConsumer consumer = session.createConsumer(queue);
    consumer.setMessageListener(this);
    latch.await(10, TimeUnit.SECONDS);
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    // Attempt to Consume the message...check if message was acknowledge
    consumer = session.createConsumer(queue);
    Message msg = consumer.receive(1000);
    assertNull(msg);
    session.close();
}

56. SimpleOpenWireTest#testInvalidDestinationExceptionWhenNoQueueExistsOnCreateProducer()

View license
@Test
public void testInvalidDestinationExceptionWhenNoQueueExistsOnCreateProducer() throws Exception {
    AddressSettings addressSetting = new AddressSettings();
    addressSetting.setAutoCreateJmsQueues(false);
    server.getAddressSettingsRepository().addMatch("jms.queue.foo", addressSetting);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue("foo");
    try {
        session.createProducer(queue);
    } catch (JMSException expected) {
    }
    session.close();
}

57. ProtonPubSubTest#testDurablePubSub()

View license
@Test
public void testDurablePubSub() throws Exception {
    int numMessages = 100;
    Topic topic = createTopic(pubAddress);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber sub = session.createDurableSubscriber(topic, "myPubId");
    Session sendSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer producer = sendSession.createProducer(topic);
    connection.start();
    for (int i = 0; i < numMessages; i++) {
        producer.send(sendSession.createTextMessage("message:" + i));
    }
    for (int i = 0; i < numMessages; i++) {
        TextMessage receive = (TextMessage) sub.receive(5000);
        Assert.assertNotNull(receive);
        Assert.assertEquals(receive.getText(), "message:" + i);
    }
}

58. ProtonTest#testConnection()

Project: activemq-artemis
Source File: ProtonTest.java
View license
@Test
public void testConnection() throws Exception {
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer cons = session.createConsumer(createQueue(address));
    org.apache.activemq.artemis.core.server.Queue serverQueue = server.locateQueue(SimpleString.toSimpleString(coreAddress));
    assertEquals(1, serverQueue.getConsumerCount());
    cons.close();
    for (int i = 0; i < 100 && serverQueue.getConsumerCount() != 0; i++) {
        Thread.sleep(500);
    }
    assertEquals(0, serverQueue.getConsumerCount());
    session.close();
}

59. ProtonTest#testMessagesSentTransactional()

Project: activemq-artemis
Source File: ProtonTest.java
View license
@Test
public void testMessagesSentTransactional() throws Exception {
    int numMessages = 1000;
    javax.jms.Queue queue = createQueue(address);
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer p = session.createProducer(queue);
    byte[] bytes = new byte[2048];
    new Random().nextBytes(bytes);
    for (int i = 0; i < numMessages; i++) {
        TextMessage message = session.createTextMessage();
        message.setText("msg:" + i);
        p.send(message);
    }
    session.commit();
    connection.close();
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(coreAddress)).getBindable();
    for (long timeout = System.currentTimeMillis() + 5000; timeout > System.currentTimeMillis() && getMessageCount(q) != numMessages; ) {
        Thread.sleep(1);
    }
    Assert.assertEquals(numMessages, getMessageCount(q));
}

60. ProtonTest#testMessagesSentTransactionalRolledBack()

Project: activemq-artemis
Source File: ProtonTest.java
View license
@Test
public void testMessagesSentTransactionalRolledBack() throws Exception {
    int numMessages = 1;
    javax.jms.Queue queue = createQueue(address);
    Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    MessageProducer p = session.createProducer(queue);
    byte[] bytes = new byte[2048];
    new Random().nextBytes(bytes);
    for (int i = 0; i < numMessages; i++) {
        TextMessage message = session.createTextMessage();
        message.setText("msg:" + i);
        p.send(message);
    }
    session.close();
    connection.close();
    Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(coreAddress)).getBindable();
    Assert.assertEquals(getMessageCount(q), 0);
}

61. DurableSubscriptionTest#testUnsubscribeWithActiveConsumer()

View license
// See JMS 1.1. spec sec 6.11
@Test
public void testUnsubscribeWithActiveConsumer() throws Exception {
    Connection conn = createConnection();
    conn.setClientID("zeke");
    Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber dursub = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub0");
    try {
        s.unsubscribe("dursub0");
        ProxyAssertSupport.fail();
    } catch (IllegalStateException e) {
    }
    dursub.close();
    s.unsubscribe("dursub0");
}

62. DurableSubscriptionTest#testSubscribeWithActiveSubscription()

View license
@Test
public void testSubscribeWithActiveSubscription() throws Exception {
    Connection conn = createConnection();
    conn.setClientID("zeke");
    Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber dursub1 = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub1");
    try {
        s.createDurableSubscriber(ActiveMQServerTestCase.topic1, "dursub1");
        ProxyAssertSupport.fail();
    } catch (IllegalStateException e) {
    }
    dursub1.close();
    s.unsubscribe("dursub1");
}

63. DurableSubscriptionTest#testDurableSubscriptionWithPeriodsInName()

View license
@Test
public void testDurableSubscriptionWithPeriodsInName() throws Exception {
    Connection conn = createConnection();
    conn.setClientID(".client.id.with.periods.");
    Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber subscriber = s.createDurableSubscriber(ActiveMQServerTestCase.topic1, ".subscription.name.with.periods.");
    s.createProducer(ActiveMQServerTestCase.topic1).send(s.createTextMessage("Subscription test"));
    conn.start();
    Message m = subscriber.receive(1000L);
    ProxyAssertSupport.assertNotNull(m);
    ProxyAssertSupport.assertTrue(m instanceof TextMessage);
    subscriber.close();
    s.unsubscribe(".subscription.name.with.periods.");
}

64. SessionTest#testCreateTwoSessions()

Project: activemq-artemis
Source File: SessionTest.java
View license
//
// Test session state
//
@Test
public void testCreateTwoSessions() throws Exception {
    Connection conn = getConnectionFactory().createConnection();
    Session sessionOne = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    ProxyAssertSupport.assertFalse(sessionOne.getTransacted());
    Session sessionTwo = conn.createSession(true, -1);
    ProxyAssertSupport.assertTrue(sessionTwo.getTransacted());
    // this test whether session's transacted state is correctly scoped per instance (by an
    // interceptor or othewise)
    ProxyAssertSupport.assertFalse(sessionOne.getTransacted());
    conn.close();
}

65. SessionTest#testCloseAndCreateSession()

Project: activemq-artemis
Source File: SessionTest.java
View license
@Test
public void testCloseAndCreateSession() throws Exception {
    Connection c = getConnectionFactory().createConnection();
    Session s = c.createSession(false, Session.AUTO_ACKNOWLEDGE);
    s.close();
    // this test whether session's closed state is correctly scoped per instance (by an
    // interceptor or othewise)
    s = c.createSession(true, -1);
    c.close();
}

66. TemporaryDestinationTest#testCanNotCreateConsumerFromAnotherConnectionForTemporaryQueue()

View license
/**
    * https://jira.jboss.org/jira/browse/JBMESSAGING-1566
    */
@Test
public void testCanNotCreateConsumerFromAnotherConnectionForTemporaryQueue() throws Exception {
    Connection conn = createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = sess.createTemporaryQueue();
    Connection anotherConn = createConnection();
    Session sessFromAnotherConn = anotherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        sessFromAnotherConn.createConsumer(tempQueue);
        ProxyAssertSupport.fail("Only temporary destination's own connection is allowed to create MessageConsumers for them.");
    } catch (JMSException e) {
    }
    conn.close();
    anotherConn.close();
}

67. TemporaryDestinationTest#testCanNotCreateConsumerFromAnotherCnnectionForTemporaryTopic()

View license
/**
    * https://jira.jboss.org/jira/browse/JBMESSAGING-1566
    */
@Test
public void testCanNotCreateConsumerFromAnotherCnnectionForTemporaryTopic() throws Exception {
    Connection conn = createConnection();
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic tempTopic = sess.createTemporaryTopic();
    Connection anotherConn = createConnection();
    Session sessFromAnotherConn = anotherConn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    try {
        sessFromAnotherConn.createConsumer(tempTopic);
        ProxyAssertSupport.fail("Only temporary destination's own connection is allowed to create MessageConsumers for them.");
    } catch (JMSException e) {
    }
}

68. OrderClient#sendOrder()

Project: camelinaction
Source File: OrderClient.java
View license
public void sendOrder(int customerId, Date date, String... itemIds) throws Exception {
    // format the JMS message from the input parameters
    String d = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").format(date);
    String body = customerId + "," + d;
    for (String id : itemIds) {
        body += "," + id;
    }
    // use JMS code to send the message (a bit ugly code but it works)
    Connection con = fac.createConnection();
    con.start();
    Session ses = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = ses.createQueue("order");
    MessageProducer prod = ses.createProducer(dest);
    prod.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    Message msg = ses.createTextMessage(body);
    prod.send(msg);
    prod.close();
    ses.close();
    con.close();
}

69. BDBUpgradeTest#testBindingAndMessageDurabability()

Project: qpid-java
Source File: BDBUpgradeTest.java
View license
/**
     * Test that the upgraded queue continues to function properly when used
     * for persistent messaging and restarting the broker.
     *
     * Sends the new messages to the queue BEFORE consuming those which were
     * sent before the upgrade. In doing so, this also serves to test that
     * the queue bindings were successfully transitioned during the upgrade.
     */
public void testBindingAndMessageDurabability() throws Exception {
    // Create a connection and start it
    TopicConnection connection = (TopicConnection) getConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(QUEUE_NAME);
    MessageProducer messageProducer = session.createProducer(queue);
    // Send a new message
    sendMessages(session, messageProducer, queue, DeliveryMode.PERSISTENT, 256 * 1024, 1);
    session.close();
    // Restart the broker
    restartDefaultBroker();
    // Drain the queue of all messages
    connection = (TopicConnection) getConnection();
    connection.start();
    consumeQueueMessages(connection, true);
}

70. ChannelLoggingTest#testChannelCloseViaChannelClose()

Project: qpid-java
Source File: ChannelLoggingTest.java
View license
/**
     * Description:
     * When the client gracefully closes the Connection then a CHN-1003 Close
     * message will be issued. This must be the last message logged for this
     * Channel.
     * Input:
     * 1. Running Broker
     * 2. Connected Client
     * 3. Client then requests that the Channel is closed
     * Output:
     *
     * <date> CHN-1003 : Close
     *
     * Validation Steps:
     * 4. The MST ID is correct
     * 5. This must be the last message logged for this Channel.
     *
     * @throws Exception - if an error occurs
     */
public void testChannelCloseViaChannelClose() throws Exception {
    assertLoggingNotYetOccured(CHANNEL_PREFIX);
    Connection connection = getConnection();
    // Create a session and then close it
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    waitForMessage("CHN-1001");
    // Wait to ensure that the CHN-1003 message is logged
    session.close();
    waitForMessage("CHN-1003");
    List<String> results = findMatches(CHANNEL_PREFIX);
    assertTrue("No CHN messages logged", results.size() > 0);
    // Verify
    validateChannelClose(results);
}

71. ExternalACLTest#testClientCreateVirtualHostQueue()

Project: qpid-java
Source File: ExternalACLTest.java
View license
public void testClientCreateVirtualHostQueue() throws NamingException, JMSException, QpidException, Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination dest = sess.createQueue(getTestQueueName());
    sess.createConsumer(dest);
    conn.close();
    try {
        conn = getConnection("test", "guest", "guest");
        sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
        sess.createConsumer(dest);
        fail("Queue creation for user 'guest' is denied");
    } catch (JMSException e) {
        check403Exception(e.getLinkedException());
    }
}

72. ExternalACLTest#testClientPublishUsingTransactionSuccess()

Project: qpid-java
Source File: ExternalACLTest.java
View license
public void testClientPublishUsingTransactionSuccess() throws Exception {
    Connection conn = getConnection("test", "client", "guest");
    Session sess = conn.createSession(true, Session.SESSION_TRANSACTED);
    conn.start();
    Queue queue = sess.createQueue("example.RequestQueue");
    ((AMQSession<?, ?>) sess).declareAndBind((AMQDestination) queue);
    MessageProducer sender = sess.createProducer(queue);
    sender.send(sess.createTextMessage("test"));
    //Send the message using a transaction as this will allow us to retrieve any errors that occur on the broker.
    sess.commit();
    conn.close();
}

73. CloseOnNoRouteForMandatoryMessageTest#testNoRouteForNonMandatoryMessage_brokerKeepsConnectionOpenAndCallsExceptionListener()

View license
public void testNoRouteForNonMandatoryMessage_brokerKeepsConnectionOpenAndCallsExceptionListener() throws Exception {
    createConnectionWithCloseWhenNoRoute(true);
    Session transactedSession = _connection.createSession(true, Session.SESSION_TRANSACTED);
    String testQueueName = getTestQueueName();
    MessageProducer nonMandatoryProducer = ((AMQSession<?, ?>) transactedSession).createProducer(transactedSession.createQueue(testQueueName), // mandatory
    false, // immediate
    false);
    Message message = transactedSession.createMessage();
    nonMandatoryProducer.send(message);
    // should succeed - the message is simply discarded
    transactedSession.commit();
    _testExceptionListener.assertNoException();
}

74. CloseOnNoRouteForMandatoryMessageTest#testClientDisablesCloseOnNoRoute_brokerKeepsConnectionOpenAndCallsExceptionListener()

View license
public void testClientDisablesCloseOnNoRoute_brokerKeepsConnectionOpenAndCallsExceptionListener() throws Exception {
    createConnectionWithCloseWhenNoRoute(false);
    Session transactedSession = _connection.createSession(true, Session.SESSION_TRANSACTED);
    String testQueueName = getTestQueueName();
    MessageProducer mandatoryProducer = ((AMQSession<?, ?>) transactedSession).createProducer(transactedSession.createQueue(testQueueName), // mandatory
    true, // immediate
    false);
    Message message = transactedSession.createMessage();
    mandatoryProducer.send(message);
    transactedSession.commit();
    _testExceptionListener.assertReceivedNoRouteWithReturnedMessage(message, getTestQueueName());
}

75. AddressBasedDestinationTest#testTopicRereceiveAfterRecover()

View license
/**
     * Tests that a client using a session in [email protected] Session#CLIENT_ACKNOWLEDGE} can correctly
     * recover a session and re-receive the same message.
     */
public void testTopicRereceiveAfterRecover() throws Exception {
    final Session jmsSession = _connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    final Destination topic = jmsSession.createTopic("ADDR:amq.topic/topic1; {link:{name: queue1}}");
    final MessageProducer prod = jmsSession.createProducer(topic);
    final MessageConsumer consForTopic1 = jmsSession.createConsumer(topic);
    final Message sentMessage = jmsSession.createTextMessage("Hello");
    prod.send(sentMessage);
    Message receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be received by consumer", receivedMessage);
    jmsSession.recover();
    receivedMessage = consForTopic1.receive(1000);
    assertNotNull("message should be re-received by consumer after recover", receivedMessage);
    receivedMessage.acknowledge();
}

76. ImmediateAndMandatoryPublishingTest#produceMessage()

View license
private Message produceMessage(int acknowledgeMode, boolean pubSub, boolean mandatory, boolean immediate) throws JMSException {
    Session session = _connection.createSession(acknowledgeMode == Session.SESSION_TRANSACTED, acknowledgeMode);
    Destination destination = null;
    if (pubSub) {
        destination = session.createTopic(getTestQueueName());
    } else {
        destination = session.createQueue(getTestQueueName());
    }
    MessageProducer producer = ((AMQSession<?, ?>) session).createProducer(destination, mandatory, immediate);
    Message message = session.createMessage();
    producer.send(message);
    if (session.getTransacted()) {
        session.commit();
    }
    return message;
}

77. QueueBrowserAutoAckTest#sendMessages()

View license
protected void sendMessages(Connection producerConnection, int messageSendCount) throws JMSException {
    producerConnection.start();
    Session producerSession = producerConnection.createSession(true, Session.AUTO_ACKNOWLEDGE);
    //Ensure _queue is created
    producerSession.createConsumer(_queue).close();
    MessageProducer producer = producerSession.createProducer(_queue);
    for (int messsageID = 0; messsageID < messageSendCount; messsageID++) {
        TextMessage textMsg = producerSession.createTextMessage("Message " + messsageID);
        textMsg.setIntProperty(MESSAGE_ID_PROPERTY, messsageID);
        producer.send(textMsg);
    }
    producerSession.commit();
    producerConnection.close();
}

78. PubSubTwoConnectionTest#testTwoConnections()

View license
/**
     * This tests that a consumer is set up synchronously
     * @throws Exception
     */
public void testTwoConnections() throws Exception {
    AMQConnection con1 = (AMQConnection) getConnection("guest", "guest");
    Topic topic = new AMQTopic(con1, "MyTopic");
    Session session1 = con1.createSession(false, AMQSession.NO_ACKNOWLEDGE);
    MessageProducer producer = session1.createProducer(topic);
    Connection con2 = (AMQConnection) getConnection("guest", "guest");
    Session session2 = con2.createSession(false, AMQSession.NO_ACKNOWLEDGE);
    MessageConsumer consumer = session2.createConsumer(topic);
    con2.start();
    producer.send(session1.createTextMessage("Hello"));
    TextMessage tm1 = (TextMessage) consumer.receive(2000);
    assertNotNull(tm1);
    assertEquals("Hello", tm1.getText());
    con1.close();
    con2.close();
}

79. DynamicQueueExchangeCreateTest#testQueueNotBoundDuringConsumerCreation()

View license
public void testQueueNotBoundDuringConsumerCreation() throws Exception {
    setSystemProperty(ClientProperties.QPID_BIND_QUEUES_PROP_NAME, "false");
    setSystemProperty(ClientProperties.VERIFY_QUEUE_ON_SEND, "true");
    Connection connection = getConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(getTestQueueName());
    session.createConsumer(queue);
    try {
        session.createProducer(queue).send(session.createMessage());
        fail("JMSException should be thrown as the queue does not exist");
    } catch (InvalidDestinationException ide) {
    }
}

80. DynamicQueueExchangeCreateTest#createExchange()

View license
private String createExchange(final boolean createProducer, final String optionName) throws Exception {
    Connection connection = getConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    String queueName = getTestQueueName() + "1";
    String exchangeName = getTestQueueName() + "1";
    Queue queue = session.createQueue("direct://" + exchangeName + "/" + queueName + "/" + queueName + "?" + optionName + "='true'");
    if (createProducer) {
        session.createProducer(queue);
    } else {
        session.createConsumer(queue);
    }
    session.close();
    return exchangeName;
}

81. TemporaryQueueTest#testConsumeFromAnotherConnectionProhibited()

Project: qpid-java
Source File: TemporaryQueueTest.java
View license
/**
     * Tests that a temporary queue cannot be used by a MessageConsumer on another Connection.
     */
public void testConsumeFromAnotherConnectionProhibited() throws Exception {
    final Connection conn = getConnection();
    final Connection conn2 = getConnection();
    final Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final TemporaryQueue queue = session1.createTemporaryQueue();
    assertNotNull(queue);
    try {
        session2.createConsumer(queue);
        fail("Expected a JMSException when subscribing to a temporary queue created on a different session");
    } catch (JMSException je) {
        assertEquals("Cannot consume from a temporary destination created on another connection", je.getMessage());
    }
}

82. TemporaryQueueTest#testPublishFromAnotherConnectionAllowed()

Project: qpid-java
Source File: TemporaryQueueTest.java
View license
/**
     * Tests that a temporary queue can be used by a MessageProducer on another Connection.
     */
public void testPublishFromAnotherConnectionAllowed() throws Exception {
    final Connection conn = getConnection();
    final Connection conn2 = getConnection();
    final Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final TemporaryQueue queue = session1.createTemporaryQueue();
    assertNotNull(queue);
    MessageProducer producer = session2.createProducer(queue);
    producer.send(session2.createMessage());
    conn.start();
    MessageConsumer consumer = session1.createConsumer(queue);
    Message message = consumer.receive(RECEIVE_TIMEOUT);
    assertNotNull("Message not received", message);
}

83. MessageConsumerCloseTest#testConsumerCloseAndSessionCommit()

View license
/**
     * JMS Session says "The content of a transaction's input and output units is simply those messages that have
     * been produced and consumed within the session's current transaction.".  Closing a consumer must not therefore
     * prevent previously received messages from being committed.
     */
public void testConsumerCloseAndSessionCommit() throws Exception {
    Connection connection = getConnection();
    connection.start();
    final Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
    Destination destination = getTestQueue();
    MessageConsumer consumer1 = session.createConsumer(destination);
    sendMessage(session, destination, 2);
    Message message = consumer1.receive(RECEIVE_TIMEOUT);
    assertNotNull("First message is not received", message);
    assertEquals("First message unexpected has unexpected property", 0, message.getIntProperty(INDEX));
    consumer1.close();
    session.commit();
    MessageConsumer consumer2 = session.createConsumer(destination);
    message = consumer2.receive(RECEIVE_TIMEOUT);
    assertNotNull("Second message is not received", message);
    assertEquals("Second message unexpected has unexpected property", 1, message.getIntProperty(INDEX));
    message = consumer2.receive(100l);
    assertNull("Unexpected third message", message);
}

84. DurableSubscriptionTest#testDurSubNoSelectorResubscribeNoClose()

View license
/**
     * <ul>
     * <li>create and register a durable subscriber with no message selector
     * <li>try to create another durable with the same name, should fail
     * </ul>
     * <p>
     * QPID-2418
     */
public void testDurSubNoSelectorResubscribeNoClose() throws Exception {
    Connection conn = getConnection();
    conn.start();
    Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    AMQTopic topic = new AMQTopic((AMQConnection) conn, "subscriptionName");
    // create and register a durable subscriber with no message selector
    session.createDurableSubscriber(topic, "subscriptionName", null, false);
    // try to recreate the durable subscriber
    try {
        session.createDurableSubscriber(topic, "subscriptionName", null, false);
        fail("Subscription should not have been created");
    } catch (Exception e) {
        _logger.error("Error creating durable subscriber", e);
    }
}

85. DurableSubscriptionTest#testNoLocalOnSameConnection()

View license
/**
     * Tests that a subscriber created on a same <i>connection</i> but separate
     * <i>sessionM</i> as producer with no local true does not receive messages.
     */
public void testNoLocalOnSameConnection() throws Exception {
    Connection connection = getConnection();
    Session consumerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic topic = consumerSession.createTopic(getTestQueueName());
    MessageProducer producer = producerSession.createProducer(topic);
    TopicSubscriber subscriber = null;
    try {
        subscriber = consumerSession.createDurableSubscriber(topic, getTestName(), null, true);
        connection.start();
        producer.send(createNextMessage(producerSession, 1));
        Message m = subscriber.receive(NEGATIVE_RECEIVE_TIMEOUT);
        assertNull("Unexpected message received", m);
    } finally {
        consumerSession.unsubscribe(getTestName());
    }
}

86. TemporaryTopicTest#testUseFromAnotherConnectionProhibited()

Project: qpid-java
Source File: TemporaryTopicTest.java
View license
/**
     * Tests that a temporary topic cannot be used by another [email protected] Connection}.
     */
public void testUseFromAnotherConnectionProhibited() throws Exception {
    final Connection conn = getConnection();
    final Connection conn2 = getConnection();
    final Session session1 = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    final TemporaryTopic topic = session1.createTemporaryTopic();
    try {
        session2.createConsumer(topic);
        fail("Expected a JMSException when subscribing to a temporary topic created on a different connection");
    } catch (JMSException je) {
        assertEquals("Cannot consume from a temporary destination created on another connection", je.getMessage());
    }
}

87. FailoverProviderOfflineBehaviorTest#testSessionCloseWhenDestroyCallFailsDoesNotBlock()

View license
@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 IOException();
            }
        }
    });
    connection = (JmsConnection) factory.createConnection();
    connection.addConnectionListener(new ConnectionInterruptionListener());
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session.close();
    connection.close();
}

88. FailoverProviderOfflineBehaviorTest#testSessionCloseWhenProviderSuddenlyClosesDoesNotBlock()

View license
@Test(timeout = 20000)
public void testSessionCloseWhenProviderSuddenlyClosesDoesNotBlock() throws Exception {
    connection = (JmsConnection) factory.createConnection();
    connection.addConnectionListener(new ConnectionInterruptionListener());
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    mockPeer.silentlyCloseConnectedProviders();
    session.close();
}

89. FailoverProviderOfflineBehaviorTest#testSessionRecoverDoesNotBlock()

View license
@Test(timeout = 20000)
public void testSessionRecoverDoesNotBlock() 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.recover();
    connection.close();
}

90. FailoverProviderTest#testSessionRecoverPassthrough()

Project: qpid-jms
Source File: FailoverProviderTest.java
View license
@Test(timeout = 30000)
public void testSessionRecoverPassthrough() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory("failover:(mock://localhost)");
    Connection connection = factory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session.recover();
    connection.close();
    assertEquals(1, mockPeer.getContextStats().getRecoverCalls());
}

91. FailoverProviderTest#testSessionUnsubscribePassthrough()

Project: qpid-jms
Source File: FailoverProviderTest.java
View license
@Test(timeout = 30000)
public void testSessionUnsubscribePassthrough() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory("failover:(mock://localhost)");
    Connection connection = factory.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session.unsubscribe("some-subscription");
    connection.close();
    assertEquals(1, mockPeer.getContextStats().getUnsubscribeCalls());
}

92. JmsDurableSubscriberTest#testDurableSubscriptionUnsubscribe()

View license
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribe() throws Exception {
    connection = createAmqpConnection();
    connection.setClientID("DURABLE-AMQP");
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Topic topic = session.createTopic(name.getMethodName());
    session.createDurableSubscriber(topic, getSubscriptionName()).close();
    BrokerViewMBean broker = getProxyToBroker();
    assertEquals(1, broker.getInactiveDurableTopicSubscribers().length);
    session.unsubscribe(getSubscriptionName());
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);
    assertEquals(0, broker.getDurableTopicSubscribers().length);
}

93. JmsMessageConsumerTest#testCreateMessageConsumer()

View license
@Test(timeout = 60000)
public void testCreateMessageConsumer() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    session.createConsumer(queue);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(0, proxy.getQueueSize());
}

94. JmsTemporaryQueueTest#testCreateTemporaryQueue()

Project: qpid-jms
Source File: JmsTemporaryQueueTest.java
View license
@Test(timeout = 60000)
public void testCreateTemporaryQueue() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    TemporaryQueue queue = session.createTemporaryQueue();
    session.createConsumer(queue);
    assertEquals(1, brokerService.getAdminView().getTemporaryQueues().length);
}

95. JmsTemporaryQueueTest#testCantConsumeFromTemporaryQueueCreatedOnAnotherConnection()

Project: qpid-jms
Source File: JmsTemporaryQueueTest.java
View license
@Test(timeout = 60000)
public void testCantConsumeFromTemporaryQueueCreatedOnAnotherConnection() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = session.createTemporaryQueue();
    session.createConsumer(tempQueue);
    Connection connection2 = createAmqpConnection();
    try {
        Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            session2.createConsumer(tempQueue);
            fail("should not be able to consumer from temporary queue from another connection");
        } catch (InvalidDestinationException ide) {
        }
    } finally {
        connection2.close();
    }
}

96. JmsTemporaryTopicTest#testCreateTemporaryTopic()

Project: qpid-jms
Source File: JmsTemporaryTopicTest.java
View license
@Test(timeout = 60000)
public void testCreateTemporaryTopic() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    TemporaryTopic topic = session.createTemporaryTopic();
    session.createConsumer(topic);
    assertEquals(1, brokerService.getAdminView().getTemporaryTopics().length);
}

97. JmsTemporaryTopicTest#testCantConsumeFromTemporaryTopicCreatedOnAnotherConnection()

Project: qpid-jms
Source File: JmsTemporaryTopicTest.java
View license
@Test(timeout = 60000)
public void testCantConsumeFromTemporaryTopicCreatedOnAnotherConnection() throws Exception {
    connection = createAmqpConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic tempTopic = session.createTemporaryTopic();
    session.createConsumer(tempTopic);
    Connection connection2 = createAmqpConnection();
    try {
        Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            session2.createConsumer(tempTopic);
            fail("should not be able to consumer from temporary topic from another connection");
        } catch (InvalidDestinationException ide) {
        }
    } finally {
        connection2.close();
    }
}

98. JmsAnonymousProducerTest#testCreateProducer()

View license
@Test(timeout = 60000)
public void testCreateProducer() throws Exception {
    connection = createAmqpConnection();
    assertNotNull(connection);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    session.createProducer(null);
    assertTrue(brokerService.getAdminView().getTotalProducerCount() == 0);
}

99. JmsMessageProducerTest#testCreateMessageProducer()

View license
@Test(timeout = 60000)
public void testCreateMessageProducer() throws Exception {
    connection = createAmqpConnection();
    assertNotNull(connection);
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    session.createProducer(queue);
    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(0, proxy.getQueueSize());
}

100. JmsSessionTest#testSessionCreateProducer()

Project: qpid-jms
Source File: JmsSessionTest.java
View license
@Test(timeout = 30000)
public void testSessionCreateProducer() throws Exception {
    connection = createAmqpConnection();
    assertNotNull(connection);
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue("test.queue");
    MessageProducer producer = session.createProducer(queue);
    producer.close();
    session.close();
}