@@ -240,6 +240,35 @@ public void testProducerTasksCleanupWhenUsingExclusiveProducers(String type, boo
240240 Awaitility .await ().untilAsserted (() -> Assert .assertEquals (timer .pendingTimeouts (), 0 ));
241241 }
242242
243+ @ Test (dataProvider = "topics" )
244+ public void testSharedProducerCloseWithWaitForExclusiveProducer (String type , boolean partitioned ) throws Exception {
245+ String topic = newTopic (type , partitioned );
246+ Producer <String > p1 = pulsarClient .newProducer (Schema .STRING )
247+ .topic (topic )
248+ .accessMode (ProducerAccessMode .Shared )
249+ .create ();
250+ Producer <String > p2 = pulsarClient .newProducer (Schema .STRING )
251+ .topic (topic )
252+ .accessMode (ProducerAccessMode .Shared )
253+ .create ();
254+ CompletableFuture <Producer <String >> p3Future = pulsarClient .newProducer (Schema .STRING )
255+ .topic (topic )
256+ .accessMode (ProducerAccessMode .WaitForExclusive )
257+ .createAsync ();
258+ // sleep 1 second to make sure p1, p2, p3Future are added to broker producers and waitingExclusiveProducers
259+ Thread .sleep (1000L );
260+ // now p3Future is still pending because p1,p2 are active in shared mode.
261+ assertFalse (p3Future .isDone ());
262+ p1 .close ();
263+ p2 .close ();
264+ // close p1,p2 and p3Future should be done and return a producer.
265+ Awaitility .await ().atMost (3 , TimeUnit .SECONDS ).untilAsserted (() -> {
266+ assertTrue (p3Future .isDone ());
267+ assertTrue (p3Future .get ().isConnected ());
268+ });
269+ p3Future .get ().close ();
270+ }
271+
243272 @ Test (dataProvider = "topics" )
244273 public void existingSharedProducer (String type , boolean partitioned ) throws Exception {
245274 String topic = newTopic (type , partitioned );
0 commit comments