@@ -111,4 +111,43 @@ private void sendMessagesAsyncAndWait(Producer<String> producer, int messages) t
111111 latch .await ();
112112 }
113113
114+ @ Test (timeOut = 30000 )
115+ public void testAckMessageInAnotherTopic () throws Exception {
116+ final String [] topics = {
117+ "persistent://my-property/my-ns/test-ack-message-in-other-topic1" + UUID .randomUUID (),
118+ "persistent://my-property/my-ns/test-ack-message-in-other-topic2" + UUID .randomUUID (),
119+ "persistent://my-property/my-ns/test-ack-message-in-other-topic3" + UUID .randomUUID ()
120+ };
121+ @ Cleanup final Consumer <String > allTopicsConsumer = pulsarClient .newConsumer (Schema .STRING )
122+ .topic (topics )
123+ .subscriptionName ("sub1" )
124+ .subscribe ();
125+ Consumer <String > partialTopicsConsumer = pulsarClient .newConsumer (Schema .STRING )
126+ .topic (topics [0 ], topics [1 ])
127+ .subscriptionName ("sub2" )
128+ .subscribe ();
129+ for (int i = 0 ; i < topics .length ; i ++) {
130+ final Producer <String > producer = pulsarClient .newProducer (Schema .STRING )
131+ .topic (topics [i ])
132+ .create ();
133+ producer .send ("msg-" + i );
134+ producer .close ();
135+ }
136+ final List <MessageId > messageIdList = new ArrayList <>();
137+ for (int i = 0 ; i < topics .length ; i ++) {
138+ messageIdList .add (allTopicsConsumer .receive ().getMessageId ());
139+ }
140+ try {
141+ partialTopicsConsumer .acknowledge (messageIdList );
142+ Assert .fail ();
143+ } catch (PulsarClientException .NotConnectedException ignored ) {
144+ }
145+ partialTopicsConsumer .close ();
146+ partialTopicsConsumer = pulsarClient .newConsumer (Schema .STRING ).topic (topics [0 ])
147+ .subscriptionName ("sub2" ).subscribe ();
148+ pulsarClient .newProducer (Schema .STRING ).topic (topics [0 ]).create ().send ("done" );
149+ final Message <String > msg = partialTopicsConsumer .receive ();
150+ Assert .assertEquals (msg .getValue (), "msg-0" );
151+ partialTopicsConsumer .close ();
152+ }
114153}
0 commit comments