@@ -63,6 +63,26 @@ public function testGetSetBackgroundBatching()
63
63
$ this ->assertTrue ($ adapter ->isBackgroundBatchingEnabled ());
64
64
}
65
65
66
+ public function testGetSetReturnImmediately ()
67
+ {
68
+ $ client = Mockery::mock (PubSubClient::class);
69
+ $ adapter = new GoogleCloudPubSubAdapter ($ client );
70
+ $ this ->assertFalse ($ adapter ->getReturnImmediately ());
71
+
72
+ $ adapter ->setReturnImmediately (true );
73
+ $ this ->assertTrue ($ adapter ->getReturnImmediately ());
74
+ }
75
+
76
+ public function testGetSetReturnImmediatelyPause ()
77
+ {
78
+ $ client = Mockery::mock (PubSubClient::class);
79
+ $ adapter = new GoogleCloudPubSubAdapter ($ client );
80
+ $ this ->assertEquals (500000 , $ adapter ->getReturnImmediatelyPause ());
81
+
82
+ $ adapter ->setReturnImmediatelyPause (1000000 );
83
+ $ this ->assertEquals (1000000 , $ adapter ->getReturnImmediatelyPause ());
84
+ }
85
+
66
86
public function testPublishWhenTopicMustBeCreated ()
67
87
{
68
88
$ topic = Mockery::mock (Topic::class);
@@ -320,6 +340,7 @@ public function testSubscribeWhenSubscriptionMustBeCreated()
320
340
'timeoutMillis ' => null ,
321
341
],
322
342
'maxMessages ' => 1000 ,
343
+ 'returnImmediately ' => false
323
344
])
324
345
->once ()
325
346
->andReturn ($ messageBatch1 );
@@ -336,6 +357,7 @@ public function testSubscribeWhenSubscriptionMustBeCreated()
336
357
'timeoutMillis ' => null ,
337
358
],
338
359
'maxMessages ' => 1000 ,
360
+ 'returnImmediately ' => false
339
361
])
340
362
->once ()
341
363
->andReturn ($ messageBatch2 );
@@ -397,6 +419,7 @@ public function testSubscribeWhenSubscriptionExists()
397
419
'timeoutMillis ' => null ,
398
420
],
399
421
'maxMessages ' => 1000 ,
422
+ 'returnImmediately ' => false
400
423
])
401
424
->once ()
402
425
->andReturn ($ messageBatch1 );
@@ -412,6 +435,7 @@ public function testSubscribeWhenSubscriptionExists()
412
435
'timeoutMillis ' => null ,
413
436
],
414
437
'maxMessages ' => 1000 ,
438
+ 'returnImmediately ' => false
415
439
])
416
440
->once ()
417
441
->andReturn ($ messageBatch2 );
@@ -471,6 +495,7 @@ public function testSubscribeWhenAutoTopicCreationIsDisabled()
471
495
'timeoutMillis ' => null ,
472
496
],
473
497
'maxMessages ' => 1000 ,
498
+ 'returnImmediately ' => false
474
499
])
475
500
->once ()
476
501
->andReturn ($ messageBatch1 );
@@ -486,6 +511,7 @@ public function testSubscribeWhenAutoTopicCreationIsDisabled()
486
511
'timeoutMillis ' => null ,
487
512
],
488
513
'maxMessages ' => 1000 ,
514
+ 'returnImmediately ' => false
489
515
])
490
516
->once ()
491
517
->andReturn ($ messageBatch2 );
@@ -521,4 +547,81 @@ public function testSubscribeWhenAutoTopicCreationIsDisabled()
521
547
522
548
$ adapter ->subscribe ('channel_name ' , [$ handler1 , 'handle ' ]);
523
549
}
550
+
551
+ public function testSubscribeWhenReturnImmediatelyIsEnabled ()
552
+ {
553
+ $ message1 = new Message (['data ' => '{"hello":"world"} ' ], ['ackId ' => 1 ]);
554
+ $ message2 = new Message (['data ' => '"this is a string" ' ], ['ackId ' => 2 ]);
555
+ $ message3 = new Message (['data ' => '"unsubscribe" ' ], ['ackId ' => 3 ]);
556
+
557
+ $ messageBatch1 = [
558
+ $ message1 ,
559
+ $ message2 ,
560
+ ];
561
+
562
+ $ messageBatch2 = [
563
+ $ message3 ,
564
+ ];
565
+
566
+ $ subscription = Mockery::mock (Subscription::class);
567
+ $ subscription ->shouldReceive ('exists ' )
568
+ ->once ()
569
+ ->andReturn (true );
570
+ $ subscription ->shouldNotHaveReceived ('create ' );
571
+
572
+ $ expectedPullOptions = [
573
+ 'grpcOptions ' => [
574
+ 'timeoutMillis ' => null ,
575
+ ],
576
+ 'maxMessages ' => 1000 ,
577
+ 'returnImmediately ' => true
578
+ ];
579
+
580
+ $ subscription ->shouldReceive ('pull ' )
581
+ ->with ($ expectedPullOptions )
582
+ ->once ()
583
+ ->andReturn ($ messageBatch1 );
584
+ $ subscription ->shouldReceive ('acknowledge ' )
585
+ ->with ($ message1 )
586
+ ->once ();
587
+ $ subscription ->shouldReceive ('acknowledge ' )
588
+ ->with ($ message2 )
589
+ ->once ();
590
+
591
+ $ subscription ->shouldReceive ('pull ' )
592
+ ->with ($ expectedPullOptions )
593
+ ->once ()
594
+ ->andReturn ($ messageBatch2 );
595
+ $ subscription ->shouldReceive ('acknowledge ' )
596
+ ->with ($ message3 )
597
+ ->once ();
598
+
599
+ $ topic = Mockery::mock (Topic::class);
600
+ $ topic ->shouldReceive ('exists ' )
601
+ ->once ()
602
+ ->andReturn (true );
603
+ $ topic ->shouldNotHaveReceived ('create ' );
604
+ $ topic ->shouldReceive ('subscription ' )
605
+ ->with ('default.channel_name ' )
606
+ ->once ()
607
+ ->andReturn ($ subscription );
608
+
609
+ $ client = Mockery::mock (PubSubClient::class);
610
+ $ client ->shouldReceive ('topic ' )
611
+ ->with ('channel_name ' )
612
+ ->once ()
613
+ ->andReturn ($ topic );
614
+
615
+ $ handler1 = Mockery::mock (\stdClass::class);
616
+ $ handler1 ->shouldReceive ('handle ' )
617
+ ->with (['hello ' => 'world ' ])
618
+ ->once ();
619
+ $ handler1 ->shouldReceive ('handle ' )
620
+ ->with ('this is a string ' )
621
+ ->once ();
622
+
623
+ $ adapter = new GoogleCloudPubSubAdapter ($ client );
624
+ $ adapter ->setReturnImmediately (true );
625
+ $ adapter ->subscribe ('channel_name ' , [$ handler1 , 'handle ' ]);
626
+ }
524
627
}
0 commit comments