125125import  org .apache .pulsar .common .policies .data .OffloadPoliciesImpl ;
126126import  org .apache .pulsar .common .policies .data .OffloadedReadPriority ;
127127import  org .apache .pulsar .common .policies .data .SubscriptionStats ;
128+ import  org .apache .pulsar .common .policies .data .TopicPolicies ;
128129import  org .apache .pulsar .common .policies .data .TopicStats ;
129130import  org .apache .pulsar .common .protocol .Commands ;
130131import  org .apache .pulsar .common .util .netty .EventLoopUtil ;
@@ -148,7 +149,8 @@ public class BrokerServiceTest extends BrokerTestBase {
148149    @ Override 
149150    protected  void  setup () throws  Exception  {
150151        conf .setSystemTopicEnabled (false );
151-         conf .setTopicLevelPoliciesEnabled (false );
152+         conf .setTopicLevelPoliciesEnabled (true );
153+         conf .setTopicPoliciesServiceClassName (MockTopicPoliciesService .class .getName ());
152154        super .baseSetup ();
153155    }
154156
@@ -2036,5 +2038,28 @@ public void testPulsarMetadataEventSyncProducerCreation() throws Exception {
20362038        retryStrategically ((test ) -> sync .getProducer () != null , 1000 , 10 );
20372039        assertNotNull (sync .getProducer ());
20382040    }
2041+ 
2042+     @ Test 
2043+     public  void  testGetTopicWhenTopicPoliciesFail () throws  Exception  {
2044+         final  var  topicName  = TopicName .get ("prop/ns-abc/test-get-topic-when-topic-policies-fail" );
2045+         MockTopicPoliciesService .FAILED_TOPICS .add (topicName );
2046+         @ Cleanup  final  var  producer  = pulsarClient .newProducer ().topic (topicName .toString ()).create ();
2047+         assertFalse (MockTopicPoliciesService .FAILED_TOPICS .contains (topicName ));
2048+     }
2049+ 
2050+     static  class  MockTopicPoliciesService  extends  TopicPoliciesService .TopicPoliciesServiceDisabled  {
2051+ 
2052+         static  final  Set <TopicName > FAILED_TOPICS  = ConcurrentHashMap .newKeySet ();
2053+ 
2054+         @ Override 
2055+         public  CompletableFuture <Optional <TopicPolicies >> getTopicPoliciesAsync (TopicName  topicName , GetType  type ) {
2056+             if  (FAILED_TOPICS .contains (topicName )) {
2057+                 // Only fail once 
2058+                 FAILED_TOPICS .remove (topicName );
2059+                 return  CompletableFuture .failedFuture (new  RuntimeException ("injected failure for "  + topicName ));
2060+             }
2061+             return  CompletableFuture .completedFuture (Optional .empty ());
2062+         }
2063+     }
20392064}
20402065
0 commit comments