@@ -492,6 +492,43 @@ public void testDisableNamespacePolicyTakeSnapshot() throws Exception {
492492
493493 }
494494
495+ @ Test (timeOut = 30000 )
496+ public void testDisableNamespacePolicyTakeSnapshotShouldNotThrowException () throws Exception {
497+ cleanup ();
498+ conf .setBrokerDeduplicationEnabled (true );
499+ conf .setBrokerDeduplicationSnapshotFrequencyInSeconds (1 );
500+ conf .setBrokerDeduplicationSnapshotIntervalSeconds (1 );
501+ conf .setBrokerDeduplicationEntriesInterval (20000 );
502+ setup ();
503+
504+ final String topicName = testTopic + UUID .randomUUID ().toString ();
505+ final String producerName = "my-producer" ;
506+ @ Cleanup
507+ Producer <String > producer = pulsarClient
508+ .newProducer (Schema .STRING ).topic (topicName ).enableBatching (false ).producerName (producerName ).create ();
509+
510+ // disable deduplication
511+ admin .namespaces ().setDeduplicationStatus (myNamespace , false );
512+
513+ int msgNum = 50 ;
514+ CountDownLatch countDownLatch = new CountDownLatch (msgNum );
515+ for (int i = 0 ; i < msgNum ; i ++) {
516+ producer .newMessage ().value ("msg" + i ).sendAsync ().whenComplete ((res , e ) -> countDownLatch .countDown ());
517+ }
518+ countDownLatch .await ();
519+ PersistentTopic persistentTopic = (PersistentTopic ) pulsar .getBrokerService ()
520+ .getTopicIfExists (topicName ).get ().get ();
521+ ManagedCursor managedCursor = persistentTopic .getMessageDeduplication ().getManagedCursor ();
522+
523+ // when disable topic deduplication the cursor should be deleted.
524+ assertNull (managedCursor );
525+
526+ // this method will be called at brokerService forEachTopic.
527+ // if topic level disable deduplication.
528+ // this method should be skipped without throw exception.
529+ persistentTopic .checkDeduplicationSnapshot ();
530+ }
531+
495532 private void waitCacheInit (String topicName ) throws Exception {
496533 pulsarClient .newConsumer ().topic (topicName ).subscriptionName ("my-sub" ).subscribe ().close ();
497534 TopicName topic = TopicName .get (topicName );
0 commit comments