@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()); }
/** * test messages are acknowledged and recovered properly * * @throws Exception */ public void testClientAcknowledge() throws Exception { Destination destination = createDestination(getClass().getName()); Connection connection = createConnection(); connection.setClientID(idGen.generateId()); connection.start(); Session consumerSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE); MessageConsumer consumer = consumerSession.createConsumer(destination); Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); MessageProducer producer = producerSession.createProducer(destination); producer.setDeliveryMode(deliveryMode); // send some messages TextMessage sent1 = producerSession.createTextMessage(); sent1.setText("msg1"); sent1.setStringProperty("str", "1"); producer.send(sent1); TextMessage sent2 = producerSession.createTextMessage(); sent2.setText("msg2"); sent2.setStringProperty("str", "2"); producer.send(sent2); TextMessage sent3 = producerSession.createTextMessage(); sent2.setText("msg3"); sent2.setStringProperty("str", "3"); producer.send(sent3); TextMessage msgTest = (TextMessage) consumer.receive(RECEIVE_TIMEOUT); System.out.println("msgTest::" + msgTest + " // " + msgTest.getText()); TextMessage rec2 = (TextMessage) consumer.receive(RECEIVE_TIMEOUT); System.out.println("msgTest::" + rec2 + " // " + rec2.getText()); assertNull(consumer.receiveNoWait()); // ack rec2 rec2.acknowledge(); TextMessage sent4 = producerSession.createTextMessage(); sent4.setText("msg4"); producer.send(sent4); TextMessage rec4 = (TextMessage) consumer.receive(RECEIVE_TIMEOUT); assertTrue(rec4.equals(sent4)); consumerSession.recover(); rec4 = (TextMessage) consumer.receive(RECEIVE_TIMEOUT); assertTrue(rec4.equals(sent4)); assertTrue(rec4.getJMSRedelivered()); rec4.acknowledge(); connection.close(); }