@@ -486,4 +486,63 @@ public void testPartitionedTopicLevelReplicationRemoteConflictTopicExist() throw
486
486
admin1 .topics ().deletePartitionedTopic (topicName );
487
487
admin2 .topics ().deletePartitionedTopic (topicName );
488
488
}
489
+
490
+ @ Test
491
+ public void testNamespaceLevelReplicationRemoteConflictTopicExist () throws Exception {
492
+ final String topicName = BrokerTestUtil .newUniqueName ("persistent://" + replicatedNamespace + "/tp" );
493
+ // Verify: will get a not found error when calling "getPartitionedTopicMetadata" on a topic not exists.
494
+ try {
495
+ admin1 .topics ().getPartitionedTopicMetadata (topicName );
496
+ fail ("Expected a not found error" );
497
+ } catch (Exception ex ) {
498
+ Throwable unWrapEx = FutureUtil .unwrapCompletionException (ex );
499
+ assertTrue (unWrapEx .getMessage ().contains ("not found" ));
500
+ }
501
+ // Verify: will get a conflict error when there is a topic with different partitions on the remote side.
502
+ admin2 .topics ().createPartitionedTopic (topicName , 1 );
503
+ try {
504
+ admin1 .topics ().createPartitionedTopic (topicName , 2 );
505
+ fail ("Expected error due to a conflict partitioned topic already exists." );
506
+ } catch (Exception ex ) {
507
+ Throwable unWrapEx = FutureUtil .unwrapCompletionException (ex );
508
+ assertTrue (unWrapEx .getMessage ().contains ("with different partitions" ));
509
+ }
510
+ // Verify: nothing has been changed after the failed calling.
511
+ Optional <PartitionedTopicMetadata > partitions1 = pulsar1 .getPulsarResources ().getNamespaceResources ()
512
+ .getPartitionedTopicResources ()
513
+ .getPartitionedTopicMetadataAsync (TopicName .get (topicName ), true ).join ();
514
+ assertFalse (partitions1 .isPresent ());
515
+ Optional <PartitionedTopicMetadata > partitions2 = pulsar2 .getPulsarResources ().getNamespaceResources ()
516
+ .getPartitionedTopicResources ()
517
+ .getPartitionedTopicMetadataAsync (TopicName .get (topicName ), true ).join ();
518
+ assertTrue (partitions2 .isPresent ());
519
+ assertEquals (partitions2 .get ().partitions , 1 );
520
+ // cleanup.
521
+ admin2 .topics ().deletePartitionedTopic (topicName );
522
+ }
523
+
524
+ @ Test
525
+ public void testNamespaceLevelPartitionedMetadataReplication () throws Exception {
526
+ final String topicName = BrokerTestUtil .newUniqueName ("persistent://" + replicatedNamespace + "/tp" );
527
+ // Verify: will get a not found error when calling "getPartitionedTopicMetadata" on a topic not exists.
528
+ try {
529
+ admin1 .topics ().getPartitionedTopicMetadata (topicName );
530
+ fail ("Expected a not found error" );
531
+ } catch (Exception ex ) {
532
+ Throwable unWrapEx = FutureUtil .unwrapCompletionException (ex );
533
+ assertTrue (unWrapEx .getMessage ().contains ("not found" ));
534
+ }
535
+ // Verify: will get a conflict error when there is a topic with different partitions on the remote side.
536
+ admin1 .topics ().createPartitionedTopic (topicName , 2 );
537
+ // Verify: nothing has been changed after the failed calling.
538
+ PartitionedTopicMetadata topicMetadata1 = admin1 .topics ().getPartitionedTopicMetadata (topicName );
539
+ assertEquals (topicMetadata1 .partitions , 2 );
540
+ PartitionedTopicMetadata topicMetadata2 = admin2 .topics ().getPartitionedTopicMetadata (topicName );
541
+ assertEquals (topicMetadata2 .partitions , 2 );
542
+ // cleanup.
543
+ cleanupTopics (() -> {
544
+ admin1 .topics ().deletePartitionedTopic (topicName );
545
+ admin2 .topics ().deletePartitionedTopic (topicName );
546
+ });
547
+ }
489
548
}
0 commit comments