Repository navigation
Expand file tree
/
Copy pathBug256Test.php
More file actions
125 lines (100 loc) · 2.95 KB
/
Copy pathBug256Test.php
File metadata and controls
125 lines (100 loc) · 2.95 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
namespace PhpAmqpLib\Tests\Functional;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Connection\AMQPSocketConnection;
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
use PhpAmqpLib\Wire\AMQPTable;
use PHPUnit\Framework\TestCase;
class Bug256Test extends TestCase
{
/**
* @var string
*/
protected $exchangeName = 'test_exchange';
/**
* @var string
*/
protected $queueName = null;
/**
* @var int
*/
protected $messageCount = 100;
/**
* @var int
*/
protected $consumedCount = 0;
/**
* @var AMQPConnection
*/
protected $connection;
/**
* @var AMQPConnection
*/
protected $connection2;
/**
* @var AMQPChannel
*/
protected $channel;
/**
* @var AMQPChannel
*/
protected $channel2;
public function setUp()
{
$this->connection = new AMQPSocketConnection(HOST, PORT, USER, PASS, VHOST);
$this->channel = $this->connection->channel();
$this->channel->exchange_declare($this->exchangeName, 'direct', false, true, false);
$this->connection2 = new AMQPStreamConnection(HOST, PORT, USER, PASS, VHOST);
$this->channel2 = $this->connection->channel();
list($this->queueName, ,) = $this->channel2->queue_declare();
$this->channel2->queue_bind($this->queueName, $this->exchangeName, $this->queueName);
}
public function testFrameOrder()
{
$msg = new AMQPMessage('');
$hdrs = new AMQPTable(array('x-foo' => 'bar'));
$msg->set('application_headers', $hdrs);
for ($i = 0; $i < $this->messageCount; $i++) {
$this->channel->basic_publish($msg, $this->exchangeName, $this->queueName);
}
$this->channel2->basic_consume(
$this->queueName,
'',
false,
true,
false,
false,
array($this, 'processMessage')
);
while (count($this->channel2->callbacks)) {
$this->channel2->wait();
}
}
public function processMessage(AMQPMessage $message)
{
$this->consumedCount++;
$this->assertEquals(array('x-foo' => 'bar'), $message->get('application_headers')->getNativeData());
if ($this->consumedCount >= $this->messageCount) {
$delivery_info = $message->delivery_info;
$delivery_info['channel']->basic_cancel($delivery_info['consumer_tag']);
}
}
public function tearDown()
{
if ($this->channel) {
$this->channel->exchange_delete($this->exchangeName);
$this->channel->close();
}
if ($this->connection) {
$this->connection->close();
}
if ($this->channel2) {
$this->channel2->close();
}
if ($this->connection2) {
$this->connection2->close();
}
}
}