@@ -275,6 +275,66 @@ queueName, actorConfig, connection, objectMapper, new RetryStrategyFactory(), ne
275275 Assertions .assertEquals (1 , normalDeliveryCount .get ());
276276 }
277277
278+ /**
279+ * This test does the following:
280+ * - Publisher publishes the message with an expiry of -1ms with 1 consumer
281+ * - Consumer would consume the message normally and delay in consumption is 1000ms
282+ */
283+ @ Test
284+ public void testWhenMessagesAreNotExpiredCase4 () throws Exception {
285+ val queueName = "queue-6" ;
286+ val objectMapper = new ObjectMapper ();
287+ val actorConfig = new ActorConfig ();
288+ actorConfig .setExchange ("test-exchange-1" );
289+ val publisher = new UnmanagedPublisher <>(
290+ queueName , actorConfig , connection , objectMapper );
291+ publisher .start ();
292+
293+ val message = ImmutableMap .of (
294+ "key" , "value"
295+ );
296+
297+ publisher .publishWithExpiry (message , -1 );
298+ Thread .sleep (1000 );
299+ val normalDeliveryCount = new AtomicInteger ();
300+ val consumer = new UnmanagedConsumer <>(
301+ queueName , actorConfig , connection , objectMapper , new RetryStrategyFactory (), new ExceptionHandlingFactory (),
302+ Map .class , handleExpectedMessageWithDelay (1000 , normalDeliveryCount ), this ::handleForNoExpectedMsg , (x ) -> true );
303+ consumer .start ();
304+
305+
306+ Assertions .assertEquals (1 , normalDeliveryCount .get ());
307+ }
308+
309+ /**
310+ * This test does the following:
311+ * - Publisher publishes the message with 1 consumer
312+ * - Consumer would consume the message normally and delay in consumption is 1000ms
313+ */
314+ @ Test
315+ public void testRegressionForPublish () throws Exception {
316+ val queueName = "queue-7" ;
317+ val objectMapper = new ObjectMapper ();
318+ val actorConfig = new ActorConfig ();
319+ actorConfig .setExchange ("test-exchange-1" );
320+ val publisher = new UnmanagedPublisher <>(
321+ queueName , actorConfig , connection , objectMapper );
322+ publisher .start ();
323+
324+ val message = ImmutableMap .of (
325+ "key" , "value"
326+ );
327+
328+ publisher .publish (message );
329+ val normalDeliveryCount = new AtomicInteger ();
330+ val consumer = new UnmanagedConsumer <>(
331+ queueName , actorConfig , connection , objectMapper , new RetryStrategyFactory (), new ExceptionHandlingFactory (),
332+ Map .class , handleExpectedMessageWithDelay (0 , normalDeliveryCount ), this ::handleForNoExpectedMsg , (x ) -> true );
333+ consumer .start ();
334+ Thread .sleep (500 );
335+
336+ Assertions .assertEquals (1 , normalDeliveryCount .get ());
337+ }
278338 @ NotNull
279339 private MessageHandlingFunction <Map , Boolean > handleExpectedMessage (int maxDelay , AtomicInteger normalDeliveryCount ) {
280340 return (msg , meta ) -> {
@@ -284,6 +344,15 @@ private MessageHandlingFunction<Map, Boolean> handleExpectedMessage(int maxDelay
284344 };
285345 }
286346
347+ @ NotNull
348+ private MessageHandlingFunction <Map , Boolean > handleExpectedMessageWithDelay (int minDelay , AtomicInteger normalDeliveryCount ) {
349+ return (msg , meta ) -> {
350+ Assertions .assertTrue (meta .getDelayInMs () > minDelay );
351+ normalDeliveryCount .getAndIncrement ();
352+ return true ;
353+ };
354+ }
355+
287356 @ NotNull
288357 private MessageHandlingFunction <Map , Boolean > handleExpectedMessageForReDelivery (AtomicInteger expiredDeliveryCount ) {
289358 return (msg , meta ) -> {
0 commit comments