@Test public void testWithQueueConnectionFactoryAndJms11Usage() throws JMSException { QueueConnectionFactory cf = mock(QueueConnectionFactory.class); QueueConnection con = mock(QueueConnection.class); given(cf.createConnection()).willReturn(con); SingleConnectionFactory scf = new SingleConnectionFactory(cf); Connection con1 = scf.createConnection(); Connection con2 = scf.createConnection(); 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); }
@Test public void testWithQueueConnection() throws JMSException { Connection con = mock(QueueConnection.class); SingleConnectionFactory scf = new SingleConnectionFactory(con); QueueConnection con1 = scf.createQueueConnection(); con1.start(); con1.stop(); con1.close(); QueueConnection con2 = scf.createQueueConnection(); con2.start(); con2.stop(); con2.close(); scf.destroy(); // should trigger actual close verify(con, times(2)).start(); verify(con, times(2)).stop(); verify(con).close(); verifyNoMoreInteractions(con); }
@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); }
verify(nonTxSession).close(); verify(con).start(); verify(con).stop(); verify(con).close();
public void stop() throws JMSException { conn.stop(); session.close(); conn.close(); }
public void stop() throws Exception { if (conn != null) { conn.stop(); } if (session != null) { session.close(); } if (conn != null) { conn.close(); } }
public void destroy() throws JMSException { sender.close(); conn.stop(); session.close(); conn.close(); } }
@Override public void destroy() { //Drop our table Connection sqlConn = null; CallableStatement stmt = null; try { sqlConn = ds.getConnection(); log.info("Dropping table"); stmt = sqlConn.prepareCall("DROP TABLE WebAppTestTable"); stmt.execute(); } catch (SQLException e) { // AutoGenerated e.printStackTrace(); } finally { safeClose(stmt); safeClose(sqlConn); } try { conn.stop(); conn.close(); } catch (JMSException ignore) { } }
@Destroy public void destroy() throws JMSException { try { queueConnection.stop(); } catch (javax.jms.IllegalStateException e) { // as for JEE v5 specs, section EE 6.6 // At least WebSphere v7 enforce this log.warn("queueSession.stop() called during @Destroy in an invalid context for this container. Msg={0}", e.getMessage()); } queueConnection.close(); }
/** * Test that a <code>MessageProducer</code> can send messages while a * <code>Connection</code> is stopped. */ public void testMessageSentWhenConnectionClosed() { try { senderConnection.stop(); Message message = senderSession.createTextMessage(); sender.send(message); receiver.receive(TestConfig.TIMEOUT); } catch (JMSException e) { fail(e); } }
/** * Providers may be doing all sorts of exotic things and need to be able to clean up on * dispose. * <p/> * Cache operations are illegal when this method is called. The cache itself is partly * disposed when this method is called. * * @throws net.sf.ehcache.CacheException */ public void dispose() throws net.sf.ehcache.CacheException { try { getQueueConnection.stop(); getQueueSession.close(); getQueueSender.close(); getQueueConnection.close(); } catch (JMSException e) { throw new net.sf.ehcache.CacheException("Problem stopping queue connection: " + e.getMessage(), e); } status = Status.STATUS_SHUTDOWN; }
/** * Providers may be doing all sorts of exotic things and need to be able to clean up on * dispose. * <p/> * Cache operations are illegal when this method is called. The cache itself is partly * disposed when this method is called. * * @throws net.sf.ehcache.CacheException */ public void dispose() throws net.sf.ehcache.CacheException { try { getQueueConnection.stop(); getQueueSession.close(); getQueueSender.close(); getQueueConnection.close(); } catch (JMSException e) { throw new net.sf.ehcache.CacheException("Problem stopping queue connection: " + e.getMessage(), e); } status = Status.STATUS_SHUTDOWN; }
/** * Test that an empty string as a message selector indicates that there * is no message selector for the message consumer. */ public void testEmptyStringAsSelector() { try { receiverConnection.stop(); if (receiver!=null) { receiver.close(); } receiver = receiverSession.createReceiver(receiverQueue, ""); receiverConnection.start(); TextMessage message = senderSession.createTextMessage(); message.setText("testEmptyStringAsSelector"); sender.send(message); TextMessage msg = (TextMessage) receiver.receive(TestConfig.TIMEOUT); assertTrue("No message was received", msg != null); assertEquals("testEmptyStringAsSelector", msg.getText()); } catch (JMSException e) { fail(e); } }
/** * Test that a <code>MessageProducer</code> can send messages while a * <code>Connection</code> is stopped. */ @Test public void testMessageSentWhenConnectionClosed() { try { senderConnection.stop(); Message message = senderSession.createTextMessage(); sender.send(message); receiver.receive(TestConfig.TIMEOUT); } catch (JMSException e) { fail(e); } }
receiverConnection.stop(); if (receiver!=null)
receiverConnection.stop(); if (receiver!=null)
/** * Test that invoking the <code>acknowledge()</code> method of a received message * from a closed connection's session must throw an <code>IllegalStateException</code>. */ @Test public void testAcknowledge() { try { receiverConnection.stop(); receiverSession = receiverConnection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); receiver.close(); // Before assigning a new receiver, we need to close the old one... // Not closing it could cause load balancing between receivers. // Not having this close might be valid for JORAM or JBossMQ, but it's not valid for ActiveMQ Artemis (and still legal) receiver = receiverSession.createReceiver(receiverQueue); receiverConnection.start(); Message message = senderSession.createMessage(); sender.send(message); Message m = receiver.receive(TestConfig.TIMEOUT); receiverConnection.close(); m.acknowledge(); Assert.fail("sec. 4.3.5 Invoking the acknowledge method of a received message from a closed " + "connection's session must throw a [javax.jms.]IllegalStateException.\n"); } catch (javax.jms.IllegalStateException e) { } catch (JMSException e) { Assert.fail("sec. 4.3.5 Invoking the acknowledge method of a received message from a closed " + "connection's session must throw a [javax.jms.]IllegalStateException, not a " + e); } catch (java.lang.IllegalStateException e) { Assert.fail("sec. 4.3.5 Invoking the acknowledge method of a received message from a closed " + "connection's session must throw an [javax.jms.]IllegalStateException " + "[not a java.lang.IllegalStateException]"); } }