|
23 | 23 | import static org.junit.Assert.fail; |
24 | 24 |
|
25 | 25 | import java.util.Enumeration; |
| 26 | +import java.util.concurrent.atomic.AtomicReference; |
26 | 27 |
|
27 | 28 | import jakarta.jms.CompletionListener; |
28 | 29 | import jakarta.jms.Destination; |
@@ -316,6 +317,34 @@ public void testProducerSendDestinationMessageQosParamsCompletionListener() thro |
316 | 317 | messageProducer.send(session.createQueue(methodNameDestinationName), null, 1, 4, 0l, null); |
317 | 318 | } |
318 | 319 |
|
| 320 | + /** |
| 321 | + * Jakarta Messaging 3.1 spec section 7.3.8: calling recover() from within a CompletionListener |
| 322 | + * callback must throw IllegalStateException. |
| 323 | + */ |
| 324 | + @Test |
| 325 | + public void testRecoverThrowsIllegalStateFromCompletionListenerCallback() throws JMSException { |
| 326 | + final AtomicReference<Exception> callbackException = new AtomicReference<>(); |
| 327 | + |
| 328 | + messageProducer.send(session.createTextMessage("test"), new CompletionListener() { |
| 329 | + @Override |
| 330 | + public void onCompletion(final Message message) { |
| 331 | + try { |
| 332 | + session.recover(); |
| 333 | + } catch (final Exception e) { |
| 334 | + callbackException.set(e); |
| 335 | + } |
| 336 | + } |
| 337 | + |
| 338 | + @Override |
| 339 | + public void onException(final Message message, final Exception exception) { |
| 340 | + } |
| 341 | + }); |
| 342 | + |
| 343 | + assertNotNull("recover() must throw from within CompletionListener callback", callbackException.get()); |
| 344 | + assertTrue("recover() must throw IllegalStateException from within CompletionListener callback", |
| 345 | + callbackException.get() instanceof jakarta.jms.IllegalStateException); |
| 346 | + } |
| 347 | + |
319 | 348 | protected static void sendMessage(JMSContext jmsContext, Destination testDestination, String textBody) { |
320 | 349 | assertNotNull(jmsContext); |
321 | 350 | JMSProducer jmsProducer = jmsContext.createProducer(); |
|
0 commit comments