javax.jms.QueueConnection Java Examples

The following examples show how to use javax.jms.QueueConnection. 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: JmsQueueSenderTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateQueueSender() throws Exception {
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
    QueueConnection connection = factory.createQueueConnection();
    assertNotNull(connection);

    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);
    Queue queue = session.createQueue(name.getMethodName());
    QueueSender sender = session.createSender(queue);
    assertNotNull(sender);

    QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
    assertEquals(0, proxy.getQueueSize());
    connection.close();
}
 
Example #2
Source File: CloseCmdTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a AMQP connection with the number of channels specified, registered on top of it.
 *
 * @param numberOfChannels number of channels to be created using the connection
 * @param userName         admin user
 * @param password         admin password
 * @param hostName         localhost
 * @param port             the AMQP port for which the broker listens to
 * @return the created JMS connection
 * @throws NamingException if an error occurs while creating the context/connection factory using given properties.
 * @throws JMSException    if an error occurs while creating/starting the connection/session
 */
private Connection createConnection(int numberOfChannels, String userName, String password, String hostName,
                                    String port) throws NamingException, JMSException {

    InitialContext initialContext
            = ClientHelper.getInitialContextBuilder(userName, password, hostName, port).build();

    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    QueueConnection connection = connectionFactory.createQueueConnection();
    connection.start();
    for (int i = 0; i < numberOfChannels; i++) {
        QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

        /*
          For each channel, create a number of consumers that is equal to the channel number.
          e.g. if the channel count is 3, channel1 has 1 consumer, channel2 has 2 consumers and channel3 has 3
          consumers
        */
        for (int j = 0; j < i; j++) {
            Queue queue = session.createQueue("queue");
            session.createReceiver(queue);
        }
    }
    return connection;
}
 
Example #3
Source File: OutgoingConnectionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectionCredentialsFail() throws Exception {
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection();
   queueConnection.close();
   mc.destroy();

   try {
      queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
      queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
      fail("should throw esxception");
   } catch (JMSException e) {
      //pass
   }
}
 
Example #4
Source File: QueueReceiverTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void createReceiver() throws Exception
{
    Queue queue = createQueue(getTestName());
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        queueConnection.start();
        Utils.sendMessages(queueConnection, queue, 3);

        QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueReceiver receiver = session.createReceiver(queue, String.format("%s=2", INDEX));
        assertEquals("Queue names should match from QueueReceiver", queue.getQueueName(), receiver.getQueue().getQueueName());

        Message received = receiver.receive(getReceiveTimeout());
        assertNotNull("Message is not received", received);
        assertEquals("Unexpected message is received", 2, received.getIntProperty(INDEX));
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #5
Source File: QueueSessionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueSessionCannotCreateTemporaryTopics() throws Exception
{
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        try
        {
            queueSession.createTemporaryTopic();
            fail("expected exception did not occur");
        }
        catch (javax.jms.IllegalStateException s)
        {
            // PASS
        }
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #6
Source File: QueueSessionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueSessionCannotCreateTopics() throws Exception
{
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        try
        {
            queueSession.createTopic("abc");
            fail("expected exception did not occur");
        }
        catch (javax.jms.IllegalStateException s)
        {
            // PASS
        }
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #7
Source File: QueueSessionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueSessionCannotCreateDurableSubscriber() throws Exception
{
    Topic topic = createTopic(getTestName());
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        try
        {
            queueSession.createDurableSubscriber(topic, "abc");
            fail("expected exception did not occur");
        }
        catch (javax.jms.IllegalStateException s)
        {
            // PASS
        }
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #8
Source File: QueueSessionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueSessionCannotUnsubscribe() throws Exception
{
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        try
        {
            queueSession.unsubscribe("abc");
            fail("expected exception did not occur");
        }
        catch (javax.jms.IllegalStateException s)
        {
            // PASS
        }
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #9
Source File: OutgoingConnectionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultipleSessionsThrowsException() throws Exception {
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   try {
      Session s2 = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      fail("should throw javax,jms.IllegalStateException: Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
   } catch (JMSException e) {
   }
}
 
Example #10
Source File: XAConnectionPoolTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
    JmsPoolXAConnectionFactory pcf = createXAPooledConnectionFactory();

    QueueConnection connection = pcf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueSender sender = session.createSender(session.createQueue("AA"));
    assertNotNull(sender.getQueue().getQueueName());

    connection.close();

    TopicConnection topicConnection = pcf.createTopicConnection();
    TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
    assertNotNull(topicPublisher.getTopic().getTopicName());

    topicConnection.close();
    pcf.stop();
}
 
Example #11
Source File: JmsTypeHeaderInboundEndpointTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * Send a message to testInboundQueue queue
 *
 * @throws Exception
 */
private void sendMessage() throws Exception {
    InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext();
    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY);
    QueueConnection queueConnection = connectionFactory.createQueueConnection();
    QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME));

    String message = "<?xml version='1.0' encoding='UTF-8'?>" +
            "    <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " +
            "      <ser:request>" +
            "        <xsd:symbol>IBM</xsd:symbol>" +
            "      </ser:request>" +
            "    </ser:getQuote>";
    try {
        TextMessage jmsMessage = queueSession.createTextMessage(message);
        jmsMessage.setJMSType("incorrecttype");
        sender.send(jmsMessage);
    } finally {
        queueConnection.close();
    }
}
 
Example #12
Source File: SmtpJmsTransportTest.java    From javamail with Apache License 2.0 6 votes vote down vote up
@Before
public void setUp() throws Exception {
    System.setProperty(Context.INITIAL_CONTEXT_FACTORY, TestContextFactory.class.getName());
    QueueConnectionFactory queueConnectionFactory = Mockito.mock(QueueConnectionFactory.class);
    Queue queue = Mockito.mock(Queue.class);
    Context context = Mockito.mock(Context.class);
    TestContextFactory.context = context;
    when(context.lookup(eq("jms/queueConnectionFactory"))).thenReturn(queueConnectionFactory);
    when(context.lookup(eq("jms/mailQueue"))).thenReturn(queue);
    queueSender = Mockito.mock(QueueSender.class);
    QueueConnection queueConnection = Mockito.mock(QueueConnection.class);
    when(queueConnectionFactory.createQueueConnection()).thenReturn(queueConnection);
    when(queueConnectionFactory.createQueueConnection(anyString(), anyString())).thenReturn(queueConnection);
    QueueSession queueSession = Mockito.mock(QueueSession.class);
    bytesMessage = Mockito.mock(BytesMessage.class);
    when(queueSession.createBytesMessage()).thenReturn(bytesMessage);
    when(queueConnection.createQueueSession(anyBoolean(), anyInt())).thenReturn(queueSession);
    when(queueSession.createSender(eq(queue))).thenReturn(queueSender);
    transport = new SmtpJmsTransport(Session.getDefaultInstance(new Properties()), new URLName("jms"));
    transportListener = Mockito.mock(TransportListener.class);
    transport.addTransportListener(transportListener);
}
 
Example #13
Source File: SingleConnectionFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@Test
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);

	given(cf.createQueueConnection()).willReturn(con);

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	Connection con1 = scf.createQueueConnection();
	Connection con2 = scf.createQueueConnection();
	con1.start();
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(con).start();
	verify(con).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
Example #14
Source File: JMSConnectionFactoryTestCase.java    From micro-integrator with Apache License 2.0 6 votes vote down vote up
/**
 * Test create queue connection
 *
 * @throws Exception
 */
@Test
public void testCreateQueueConnections() throws Exception {
    String queueName = "testCreateConQ";
    Properties jmsProperties = JMSTestsUtils.getJMSPropertiesForDestination(queueName, PROVIDER_URL, true);
    JMSConnectionFactory connectionFactory = new JMSConnectionFactory(jmsProperties);
    JMSBrokerController brokerController = new JMSBrokerController(PROVIDER_URL, jmsProperties);
    try {
        brokerController.startProcess();
        QueueConnection queueConnection = connectionFactory.createQueueConnection();
        Assert.assertTrue("The queue connection is created", ((ActiveMQConnection) queueConnection).
                getTransport().getRemoteAddress().contains("61616"));
        QueueConnection queueConnectionWithCred = connectionFactory.createQueueConnection("admin", "admin");
        Assert.assertTrue("The queue connection is created", ((ActiveMQConnection) queueConnectionWithCred).
                getTransport().getRemoteAddress().contains("61616"));
    } finally {
        brokerController.disconnect();
        brokerController.stopProcess();
    }
}
 
Example #15
Source File: AbstractJMSProvider.java    From perf-harness with MIT License 6 votes vote down vote up
public QueueConnection getQueueConnection(QueueConnectionFactory qcf)
		throws JMSException {

	final QueueConnection qc;
	final String username = Config.parms.getString("us");
	if (username != null && username.length() != 0) {
		Log.logger.log(Level.INFO, "getQueueConnection(): authenticating as \"" + username + "\"");
		final String password = Config.parms.getString("pw");
		qc = qcf.createQueueConnection(username, password);
	} else {
		qc = qcf.createQueueConnection();
	}

	return qc;

}
 
Example #16
Source File: JmsConnectionFactory.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Override
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
    JmsQueueConnection connection = null;

    try {
        JmsConnectionInfo connectionInfo = configureConnectionInfo(username, password);
        Provider provider = createProvider(remoteURI);

        connection = new JmsQueueConnection(connectionInfo, provider);
        connection.setExceptionListener(exceptionListener);
        connection.connect();
    } catch (Exception e) {
        if (connection != null) {
            try {
                connection.close();
            } catch (Throwable ignored) {}
        }
        throw JmsExceptionSupport.create(e);
    }

    return connection;
}
 
Example #17
Source File: SingleConnectionFactory.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public QueueConnection createQueueConnection() throws JMSException {
	Connection con;
	synchronized (this.connectionMonitor) {
		this.pubSubMode = Boolean.FALSE;
		con = createConnection();
	}
	if (!(con instanceof QueueConnection)) {
		throw new javax.jms.IllegalStateException(
				"This SingleConnectionFactory does not hold a QueueConnection but rather: " + con);
	}
	return ((QueueConnection) con);
}
 
Example #18
Source File: OutgoingConnectionTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testConnectionCredentialsOKRecovery() throws Exception {
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   assertNotNull(mcf.getResourceRecovery());
}
 
Example #19
Source File: TransactionAwareConnectionFactoryProxy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Wrap the given Connection with a proxy that delegates every method call to it
 * but handles Session lookup in a transaction-aware fashion.
 * @param target the original Connection to wrap
 * @return the wrapped Connection
 */
protected Connection getTransactionAwareConnectionProxy(Connection target) {
	List<Class<?>> classes = new ArrayList<Class<?>>(3);
	classes.add(Connection.class);
	if (target instanceof QueueConnection) {
		classes.add(QueueConnection.class);
	}
	if (target instanceof TopicConnection) {
		classes.add(TopicConnection.class);
	}
	return (Connection) Proxy.newProxyInstance(
			Connection.class.getClassLoader(),
			classes.toArray(new Class<?>[classes.size()]),
			new TransactionAwareConnectionInvocationHandler(target));
}
 
Example #20
Source File: TransactionAwareConnectionFactoryProxy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public QueueConnection createQueueConnection(String username, String password) throws JMSException {
	if (!(this.targetConnectionFactory instanceof QueueConnectionFactory)) {
		throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
	}
	QueueConnection targetConnection =
			((QueueConnectionFactory) this.targetConnectionFactory).createQueueConnection(username, password);
	return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
 
Example #21
Source File: JmsTracing.java    From brave with Apache License 2.0 5 votes vote down vote up
public QueueConnection queueConnection(QueueConnection connection) {
  // It is common to implement both interfaces
  if (connection instanceof XAQueueConnection) {
    return xaQueueConnection((XAQueueConnection) connection);
  }
  return TracingConnection.create(connection, this);
}
 
Example #22
Source File: ManagedQueueTopicConnection.java    From ats-framework with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectionConsumer createConnectionConsumer(
                                                    Queue queue,
                                                    String messageSelector,
                                                    ServerSessionPool sessionPool,
                                                    int maxMessages ) throws JMSException {

    return addConnectionConsumer( ((QueueConnection) connection).createConnectionConsumer(queue,
                                                                                          messageSelector,
                                                                                          sessionPool,
                                                                                          maxMessages));
}
 
Example #23
Source File: AndesJMSConsumer.java    From product-ei with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a queue connection, session and receiver.
 *
 * @throws NamingException
 * @throws JMSException
 */
private void createQueueConnection() throws NamingException, JMSException {
    // Creates a queue connection, sessions and receiver
    QueueConnectionFactory connFactory = (QueueConnectionFactory) super.getInitialContext()
            .lookup(AndesClientConstants.CF_NAME);
    QueueConnection queueConnection = connFactory.createQueueConnection();
    queueConnection.start();
    QueueSession queueSession;

    // Sets acknowledgement mode
    if (QueueSession.SESSION_TRANSACTED == this.consumerConfig.getAcknowledgeMode().getType()) {
        queueSession = queueConnection
                .createQueueSession(true, this.consumerConfig.getAcknowledgeMode().getType());
    } else {
        queueSession = queueConnection
                .createQueueSession(false, this.consumerConfig.getAcknowledgeMode().getType());
    }

    Queue queue =
            (Queue) super.getInitialContext().lookup(this.consumerConfig.getDestinationName());
    connection = queueConnection;
    session = queueSession;

    // If selectors exists
    if (null != this.consumerConfig.getSelectors()) {
        receiver = queueSession.createReceiver(queue, this.consumerConfig.getSelectors());
    } else {
        receiver = queueSession.createReceiver(queue);
    }
}
 
Example #24
Source File: QueueReceiverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
 */
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
   QueueConnection qc = null;

   try {
      qc = createQueueConnection();
      QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");

      qc.start();

      TextMessage m = qs.createTextMessage();
      m.setText("one");
      m.setBooleanProperty("targetMessage", false);

      QueueSender qsender = qs.createSender(queue1);

      qsender.send(m);

      m.setText("two");
      m.setBooleanProperty("targetMessage", true);

      qsender.send(m);

      TextMessage rm = (TextMessage) qreceiver.receive(1000);

      ProxyAssertSupport.assertEquals("two", rm.getText());
   } finally {
      if (qc != null) {
         qc.close();
      }
      Thread.sleep(2000);
      removeAllMessages(queue1.getQueueName(), true);
      checkEmpty(queue1);
   }
}
 
Example #25
Source File: TransactionAwareConnectionFactoryProxy.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Override
public QueueConnection createQueueConnection() throws JMSException {
	if (!(this.targetConnectionFactory instanceof QueueConnectionFactory)) {
		throw new javax.jms.IllegalStateException("'targetConnectionFactory' is no QueueConnectionFactory");
	}
	QueueConnection targetConnection =
			((QueueConnectionFactory) this.targetConnectionFactory).createQueueConnection();
	return (QueueConnection) getTransactionAwareConnectionProxy(targetConnection);
}
 
Example #26
Source File: JmsPoolConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testQueueCreateConnection() throws Exception {
    QueueConnection connection = cf.createQueueConnection();

    assertNotNull(connection);
    assertEquals(1, cf.getNumConnections());

    connection.close();

    assertEquals(1, cf.getNumConnections());
}
 
Example #27
Source File: InitConfServer.java    From blog with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * 创建jms连接
 * 
 * @return
 * @throws JMSException
 */
private QueueConnection createSharedConnection() throws JMSException {
	ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(MQADDRESS);
	QueueConnection connection = null;
	try {
		connection = factory.createQueueConnection();
	} catch (JMSException e) {
		closeConnection(connection);
		throw e;
	}
	return connection;
}
 
Example #28
Source File: SingleConnectionFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
Example #29
Source File: JmsInvokerTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Before
public void setUpMocks() throws Exception {
	mockConnectionFactory = mock(QueueConnectionFactory.class);
	mockConnection = mock(QueueConnection.class);
	mockSession = mock(QueueSession.class);
	mockQueue = mock(Queue.class);

	given(mockConnectionFactory.createConnection()).willReturn(mockConnection);
	given(mockConnection.createSession(false, Session.AUTO_ACKNOWLEDGE)).willReturn(mockSession);
}
 
Example #30
Source File: SingleConnectionFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}