27
27
import java .util .concurrent .Semaphore ;
28
28
import lombok .extern .slf4j .Slf4j ;
29
29
import org .apache .pulsar .broker .BrokerTestUtil ;
30
+ import org .apache .pulsar .broker .ServiceConfiguration ;
30
31
import org .apache .pulsar .client .api .ProducerConsumerBase ;
31
32
import org .apache .pulsar .client .api .PulsarClient ;
32
33
import org .apache .pulsar .client .api .PulsarClientException ;
38
39
import org .apache .pulsar .common .policies .data .TopicType ;
39
40
import org .apache .pulsar .common .util .FutureUtil ;
40
41
import org .awaitility .Awaitility ;
42
+ import org .testng .Assert ;
41
43
import org .testng .annotations .AfterMethod ;
42
44
import org .testng .annotations .DataProvider ;
43
45
import org .testng .annotations .Test ;
@@ -325,17 +327,20 @@ public Object[][] autoCreationParamsNotAllow(){
325
327
{true , false , false },
326
328
{false , false , true },
327
329
{false , false , false },
328
- // These test cases are for the following PR.
329
- // Which was described in the Motivation of https://github.com/apache/pulsar/pull/22206.
330
- //{false, true, true},
331
- //{false, true, false},
330
+ {false , true , true },
331
+ {false , true , false },
332
332
};
333
333
}
334
334
335
335
@ Test (dataProvider = "autoCreationParamsNotAllow" )
336
336
public void testGetMetadataIfNotAllowedCreate (boolean configAllowAutoTopicCreation ,
337
337
boolean paramMetadataAutoCreationEnabled ,
338
338
boolean isUsingHttpLookup ) throws Exception {
339
+ if (!configAllowAutoTopicCreation && paramMetadataAutoCreationEnabled ) {
340
+ // These test cases are for the following PR.
341
+ // Which was described in the Motivation of https://github.com/apache/pulsar/pull/22206.
342
+ return ;
343
+ }
339
344
conf .setAllowAutoTopicCreationType (TopicType .PARTITIONED );
340
345
conf .setDefaultNumPartitions (3 );
341
346
conf .setAllowAutoTopicCreation (configAllowAutoTopicCreation );
@@ -379,7 +384,34 @@ public void testGetMetadataIfNotAllowedCreate(boolean configAllowAutoTopicCreati
379
384
client .close ();
380
385
}
381
386
382
- @ Test (dataProvider = "autoCreationParamsNotAllow" )
387
+ @ DataProvider (name = "autoCreationParamsForNonPersistentTopic" )
388
+ public Object [][] autoCreationParamsForNonPersistentTopic (){
389
+ return new Object [][]{
390
+ // configAllowAutoTopicCreation, paramCreateIfAutoCreationEnabled, isUsingHttpLookup.
391
+ {true , true , true },
392
+ {true , true , false },
393
+ {false , true , true },
394
+ {false , true , false },
395
+ {false , false , true }
396
+ };
397
+ }
398
+
399
+ /**
400
+ * Regarding the API "get partitioned metadata" about non-persistent topic.
401
+ * The original behavior is:
402
+ * param-auto-create = true, broker-config-auto-create = true
403
+ * HTTP API: default configuration {@link ServiceConfiguration#getDefaultNumPartitions()}
404
+ * binary API: default configuration {@link ServiceConfiguration#getDefaultNumPartitions()}
405
+ * param-auto-create = true, broker-config-auto-create = false
406
+ * HTTP API: {partitions: 0}
407
+ * binary API: {partitions: 0}
408
+ * param-auto-create = false
409
+ * HTTP API: not found error
410
+ * binary API: not support
411
+ * This test only guarantees that the behavior is the same as before. The following separated PR will fix the
412
+ * incorrect behavior.
413
+ */
414
+ @ Test (dataProvider = "autoCreationParamsForNonPersistentTopic" )
383
415
public void testGetNonPersistentMetadataIfNotAllowedCreate (boolean configAllowAutoTopicCreation ,
384
416
boolean paramMetadataAutoCreationEnabled ,
385
417
boolean isUsingHttpLookup ) throws Exception {
@@ -399,17 +431,34 @@ public void testGetNonPersistentMetadataIfNotAllowedCreate(boolean configAllowAu
399
431
// Regarding non-persistent topic, we do not know whether it exists or not.
400
432
// Broker will return a non-partitioned metadata if partitioned metadata does not exist.
401
433
PulsarClient client = PulsarClient .builder ().serviceUrl (pulsar .getBrokerServiceUrl ()).build ();
434
+
435
+ if (!configAllowAutoTopicCreation && !paramMetadataAutoCreationEnabled && isUsingHttpLookup ) {
436
+ try {
437
+ lookup .getPartitionedTopicMetadata (TopicName .get (topicNameStr ), paramMetadataAutoCreationEnabled )
438
+ .join ();
439
+ Assert .fail ("Expected a not found ex" );
440
+ } catch (Exception ex ) {
441
+ // Cleanup.
442
+ client .close ();
443
+ return ;
444
+ }
445
+ }
446
+
402
447
PartitionedTopicMetadata metadata = lookup
403
448
.getPartitionedTopicMetadata (TopicName .get (topicNameStr ), paramMetadataAutoCreationEnabled ).join ();
404
- assertEquals (metadata .partitions , 0 );
449
+ if (configAllowAutoTopicCreation && paramMetadataAutoCreationEnabled ) {
450
+ assertEquals (metadata .partitions , 3 );
451
+ } else {
452
+ assertEquals (metadata .partitions , 0 );
453
+ }
405
454
406
455
List <String > partitionedTopics = admin .topics ().getPartitionedTopicList ("public/default" );
407
- pulsar .getPulsarResources ().getNamespaceResources ().getPartitionedTopicResources (). partitionedTopicExists ( topicName );
408
- assertFalse ( partitionedTopics . contains ( topicNameStr ) );
409
- List < String > topicList = admin . topics (). getList ( "public/default" );
410
- assertFalse ( topicList .contains (topicNameStr ));
411
- for ( int i = 0 ; i < 3 ; i ++) {
412
- assertFalse (topicList .contains (topicName . getPartition ( i ) ));
456
+ pulsar .getPulsarResources ().getNamespaceResources ().getPartitionedTopicResources ()
457
+ . partitionedTopicExists ( topicName );
458
+ if ( configAllowAutoTopicCreation && paramMetadataAutoCreationEnabled ) {
459
+ assertTrue ( partitionedTopics .contains (topicNameStr ));
460
+ } else {
461
+ assertFalse (partitionedTopics .contains (topicNameStr ));
413
462
}
414
463
415
464
// Verify: lookup semaphore has been releases.
0 commit comments