-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSendAndReceivePriorityMessagesFromQueueSpec.php
89 lines (70 loc) · 2.19 KB
/
SendAndReceivePriorityMessagesFromQueueSpec.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace Interop\Queue\Spec;
use Interop\Queue\Context;
use Interop\Queue\Message;
use Interop\Queue\Queue;
use PHPUnit\Framework\TestCase;
/**
* @group functional
*/
abstract class SendAndReceivePriorityMessagesFromQueueSpec extends TestCase
{
/**
* @var Context
*/
private $context;
protected function tearDown(): void
{
if ($this->context) {
$this->context->close();
}
parent::tearDown();
}
public function test()
{
$this->context = $context = $this->createContext();
$queue = $this->createQueue($context, 'send_and_receive_priority_messages_from_queue_spec');
$consumer = $context->createConsumer($queue);
// guard
$this->assertNull($consumer->receiveNoWait());
$expectedPriority5Body = __CLASS__.'_priority5_'.time();
$expectedPriority1Body = __CLASS__.'_priority1_'.time();
$producer = $context->createProducer();
$producer->setPriority(1);
$producer->send($queue, $this->createMessage($context, $expectedPriority1Body));
$producer->setPriority(5);
$producer->send($queue, $this->createMessage($context, $expectedPriority5Body));
$message = $consumer->receive(8000); // 8 sec
$this->assertInstanceOf(Message::class, $message);
$consumer->acknowledge($message);
$this->assertSame($expectedPriority5Body, $message->getBody());
$message = $consumer->receive(8000); // 8 sec
$this->assertInstanceOf(Message::class, $message);
$consumer->acknowledge($message);
$this->assertSame($expectedPriority1Body, $message->getBody());
}
/**
* @return Context
*/
abstract protected function createContext();
/**
* @param Context $context
* @param string $body
*
* @return Message
*/
protected function createMessage(Context $context, $body)
{
return $context->createMessage($body);
}
/**
* @param Context $context
* @param string $queueName
*
* @return Queue
*/
protected function createQueue(Context $context, $queueName)
{
return $context->createQueue($queueName);
}
}