Search in sources :

Example 1 with TopicSession

use of jakarta.jms.TopicSession in project spring-framework by spring-projects.

the class SingleConnectionFactoryTests method testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage.

@Test
public void testCachingConnectionFactoryWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
    TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
    TopicConnection con = mock(TopicConnection.class);
    TopicSession txSession = mock(TopicSession.class);
    TopicSession nonTxSession = mock(TopicSession.class);
    given(cf.createTopicConnection()).willReturn(con);
    given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
    given(txSession.getTransacted()).willReturn(true);
    given(con.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);
    CachingConnectionFactory scf = new CachingConnectionFactory(cf);
    scf.setReconnectOnException(false);
    Connection con1 = scf.createTopicConnection();
    Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session1.getTransacted();
    // should lead to rollback
    session1.close();
    session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    session1.close();
    con1.start();
    TopicConnection con2 = scf.createTopicConnection();
    Session session2 = con2.createTopicSession(false, Session.CLIENT_ACKNOWLEDGE);
    session2.close();
    session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
    session2.getTransacted();
    session2.close();
    con2.start();
    con1.close();
    con2.close();
    // should trigger actual close
    scf.destroy();
    verify(txSession).close();
    verify(nonTxSession).close();
    verify(con).start();
    verify(con).stop();
    verify(con).close();
}
Also used : TopicConnectionFactory(jakarta.jms.TopicConnectionFactory) TopicSession(jakarta.jms.TopicSession) QueueConnection(jakarta.jms.QueueConnection) TopicConnection(jakarta.jms.TopicConnection) Connection(jakarta.jms.Connection) TopicConnection(jakarta.jms.TopicConnection) QueueSession(jakarta.jms.QueueSession) Session(jakarta.jms.Session) TopicSession(jakarta.jms.TopicSession) Test(org.junit.jupiter.api.Test)

Example 2 with TopicSession

use of jakarta.jms.TopicSession in project spring-framework by spring-projects.

the class DynamicDestinationResolverTests method resolveWithPubSubTopicSession.

@Test
public void resolveWithPubSubTopicSession() throws Exception {
    Topic expectedDestination = new StubTopic();
    TopicSession session = mock(TopicSession.class);
    given(session.createTopic(DESTINATION_NAME)).willReturn(expectedDestination);
    testResolveDestination(session, expectedDestination, true);
}
Also used : StubTopic(org.springframework.jms.StubTopic) TopicSession(jakarta.jms.TopicSession) Topic(jakarta.jms.Topic) StubTopic(org.springframework.jms.StubTopic) Test(org.junit.jupiter.api.Test)

Aggregations

TopicSession (jakarta.jms.TopicSession)2 Test (org.junit.jupiter.api.Test)2 Connection (jakarta.jms.Connection)1 QueueConnection (jakarta.jms.QueueConnection)1 QueueSession (jakarta.jms.QueueSession)1 Session (jakarta.jms.Session)1 Topic (jakarta.jms.Topic)1 TopicConnection (jakarta.jms.TopicConnection)1 TopicConnectionFactory (jakarta.jms.TopicConnectionFactory)1 StubTopic (org.springframework.jms.StubTopic)1