@@ -4,12 +4,14 @@ open System
4
4
open System.Text .Json
5
5
open System.Threading
6
6
open System.Diagnostics
7
+ open System.Net .Http
7
8
8
9
open Expecto
9
10
open Expecto.Flip
10
11
11
12
open System.Text
12
13
open System.Threading .Tasks
14
+ open Microsoft.Extensions .Logging
13
15
open Pulsar.Client .Api
14
16
open Pulsar.Client .Common
15
17
open Serilog
@@ -373,6 +375,71 @@ let tests =
373
375
Expect.isTrue " " isReplicated
374
376
Log.Debug( " Finished 'Create the replicated subscription should be successful'" )
375
377
}
378
+
379
+ testTask " Delete topic subscribed by the pattern consumer should not throw error or recreate topic" {
380
+ Log.Debug( " Started 'Delete topic subscribed by the pattern consumer should not throw error or recreate topic'" )
381
+ let topicName = " public/default/topic-" + Guid.NewGuid() .ToString( " N" )
382
+ let client = getClient()
383
+
384
+ let pattern = topicName + " -.*"
385
+ let! ( producer1 : IProducer < byte []>) =
386
+ client.NewProducer()
387
+ .Topic( topicName + " -1" )
388
+ .CreateAsync()
389
+ let! ( producer2 : IProducer < byte []>) =
390
+ client.NewProducer()
391
+ .Topic( topicName + " -2" )
392
+ .CreateAsync()
393
+
394
+ do ! producer1.SendAsync([| 0 uy |])
395
+ do ! producer2.SendAsync([| 0 uy |])
396
+
397
+ let! ( consumer : IConsumer < byte []>) =
398
+ client.NewConsumer()
399
+ .TopicsPattern( pattern)
400
+ .ConsumerName( " test" )
401
+ .SubscriptionName( " test" )
402
+ .SubscriptionType( SubscriptionType.Exclusive)
403
+ .SubscriptionInitialPosition( SubscriptionInitialPosition.Latest)
404
+ .ReplicateSubscriptionState( true )
405
+ .SubscribeAsync()
406
+
407
+ do ! producer1.DisposeAsync() .AsTask()
408
+ do ! producer2.DisposeAsync() .AsTask()
409
+
410
+ let task = consumer.ReceiveAsync()
411
+
412
+ // Check that the task doesn't fail immediately
413
+ Expect.isFalse " " task.IsFaulted
414
+ Expect.isFalse " " task.IsCanceled
415
+
416
+ // Delete topic using HTTP request
417
+ let deleteUrl = $" {pulsarHttpAddress}/admin/v2/persistent/{topicName}-1?force=true"
418
+ let! ( response : HttpResponseMessage ) = commonHttpClient.DeleteAsync( deleteUrl)
419
+ response.EnsureSuccessStatusCode() |> ignore
420
+
421
+ do ! Task.Delay( 1000 ) // This make sure that the topic won't be recreated
422
+
423
+ // Verify topic is deleted by trying to get stats (should return NotFound)
424
+ let statsUrl = $" {pulsarHttpAddress}/admin/v2/persistent/{topicName}-1/stats"
425
+ let! ( statsResponse : HttpResponseMessage ) = commonHttpClient.GetAsync( statsUrl)
426
+ Expect.equal " " System.Net.HttpStatusCode.NotFound statsResponse.StatusCode
427
+
428
+ // Check that the task is running
429
+ Expect.isFalse " " task.IsCompleted
430
+
431
+ let! ( producer : IProducer < byte []>) =
432
+ client.NewProducer()
433
+ .Topic( topicName + " -2" )
434
+ .CreateAsync()
435
+
436
+ do ! producer.SendAsync([| 1 uy |])
437
+
438
+ let! ( msg : Message < byte []>) = task
439
+
440
+ Expect.equal " " [| 1 uy |] <| msg.GetValue()
441
+ Log.Debug( " Finished 'Delete topic subscribed by the pattern consumer should not throw error or recreate topic'" )
442
+ }
376
443
377
444
#if ! NOTLS
378
445
// Before running this test set 'maxMessageSize' for broker and 'nettyMaxFrameSizeBytes' for bookkeeper
0 commit comments