@@ -338,6 +338,39 @@ public void testBatchedMessagesWithOrderingKeyByDuration() throws Exception {
338338 publisher .shutdown ();
339339 }
340340
341+ @ Test
342+ public void testLargeMessagesDoNotReorderBatches () throws Exception {
343+ // Set the maximum batching size to 20 bytes.
344+ Publisher publisher =
345+ getTestPublisherBuilder ()
346+ .setBatchingSettings (
347+ Publisher .Builder .DEFAULT_BATCHING_SETTINGS
348+ .toBuilder ()
349+ .setElementCountThreshold (10L )
350+ .setRequestByteThreshold (20L )
351+ .setDelayThreshold (Duration .ofSeconds (100 ))
352+ .build ())
353+ .setEnableMessageOrdering (true )
354+ .build ();
355+ testPublisherServiceImpl .setAutoPublishResponse (true );
356+ ApiFuture <String > publishFuture1 = sendTestMessageWithOrderingKey (publisher , "m1" , "OrderA" );
357+ ApiFuture <String > publishFuture2 = sendTestMessageWithOrderingKey (publisher , "m2" , "OrderB" );
358+
359+ assertFalse (publishFuture1 .isDone ());
360+ assertFalse (publishFuture2 .isDone ());
361+
362+ ApiFuture <String > publishFuture3 =
363+ sendTestMessageWithOrderingKey (publisher , "VeryLargeMessage" , "OrderB" );
364+ // Verify that messages with "OrderB" were delivered in order.
365+ assertTrue (Integer .parseInt (publishFuture2 .get ()) < Integer .parseInt (publishFuture3 .get ()));
366+
367+ assertTrue (publishFuture1 .isDone ());
368+ assertTrue (publishFuture2 .isDone ());
369+ assertTrue (publishFuture3 .isDone ());
370+
371+ publisher .shutdown ();
372+ }
373+
341374 @ Test
342375 public void testOrderingKeyWhenDisabled_throwsException () throws Exception {
343376 // Message ordering is disabled by default.
0 commit comments