@@ -370,6 +370,91 @@ var _ = Describe("Resources", func() {
370370
371371 })
372372
373+ Context ("PulsarTopic Compaction Threshold" , Ordered , func () {
374+ var (
375+ compactionTopic * v1alphav1.PulsarTopic
376+ compactionTopicName string = "test-compaction-topic"
377+ compactionThreshold int64 = 104857600 // 100MB in bytes
378+ )
379+
380+ BeforeAll (func () {
381+ compactionTopic = utils .MakePulsarTopicWithCompactionThreshold (
382+ namespaceName ,
383+ compactionTopicName ,
384+ "persistent://public/default/compaction-test" ,
385+ pconnName ,
386+ compactionThreshold ,
387+ lifecyclePolicy ,
388+ )
389+ })
390+
391+ It ("should create topic with compaction threshold successfully" , func () {
392+ err := k8sClient .Create (ctx , compactionTopic )
393+ Expect (err == nil || apierrors .IsAlreadyExists (err )).Should (BeTrue ())
394+ })
395+
396+ It ("should be ready" , func () {
397+ Eventually (func () bool {
398+ t := & v1alphav1.PulsarTopic {}
399+ tns := types.NamespacedName {Namespace : namespaceName , Name : compactionTopicName }
400+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
401+ return v1alphav1 .IsPulsarResourceReady (t )
402+ }, "20s" , "100ms" ).Should (BeTrue ())
403+ })
404+
405+ It ("should update compaction threshold successfully" , func () {
406+ newThreshold := int64 (209715200 ) // 200MB in bytes
407+
408+ topic := & v1alphav1.PulsarTopic {}
409+ tns := types.NamespacedName {Namespace : namespaceName , Name : compactionTopicName }
410+ Expect (k8sClient .Get (ctx , tns , topic )).Should (Succeed ())
411+
412+ topic .Spec .CompactionThreshold = & newThreshold
413+ err := k8sClient .Update (ctx , topic )
414+ Expect (err ).Should (Succeed ())
415+ })
416+
417+ It ("should be ready after update" , func () {
418+ Eventually (func () bool {
419+ t := & v1alphav1.PulsarTopic {}
420+ tns := types.NamespacedName {Namespace : namespaceName , Name : compactionTopicName }
421+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
422+ return v1alphav1 .IsPulsarResourceReady (t )
423+ }, "20s" , "100ms" ).Should (BeTrue ())
424+ })
425+
426+ It ("should remove compaction threshold when set to nil" , func () {
427+ topic := & v1alphav1.PulsarTopic {}
428+ tns := types.NamespacedName {Namespace : namespaceName , Name : compactionTopicName }
429+ Expect (k8sClient .Get (ctx , tns , topic )).Should (Succeed ())
430+
431+ topic .Spec .CompactionThreshold = nil
432+ err := k8sClient .Update (ctx , topic )
433+ Expect (err ).Should (Succeed ())
434+ })
435+
436+ It ("should be ready after removing threshold" , func () {
437+ Eventually (func () bool {
438+ t := & v1alphav1.PulsarTopic {}
439+ tns := types.NamespacedName {Namespace : namespaceName , Name : compactionTopicName }
440+ Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
441+ return v1alphav1 .IsPulsarResourceReady (t )
442+ }, "20s" , "100ms" ).Should (BeTrue ())
443+ })
444+
445+ AfterAll (func () {
446+ // Clean up the compaction test topic after all tests complete
447+ if compactionTopic != nil {
448+ Eventually (func (g Gomega ) {
449+ t := & v1alphav1.PulsarTopic {}
450+ tns := types.NamespacedName {Namespace : namespaceName , Name : compactionTopicName }
451+ g .Expect (k8sClient .Get (ctx , tns , t )).Should (Succeed ())
452+ g .Expect (k8sClient .Delete (ctx , t )).Should (Succeed ())
453+ }).Should (Succeed ())
454+ }
455+ })
456+ })
457+
373458 Context ("PulsarPermission operation" , Label ("Permissions" ), func () {
374459 It ("should grant the pulsarpermission successfully" , func () {
375460 err := k8sClient .Create (ctx , ppermission )
0 commit comments