Skip to content

Commit d48925f

Browse files
committed
[sqs] Add support of delivery delayes, add specs
1 parent f4fffbd commit d48925f

9 files changed

Lines changed: 252 additions & 0 deletions

‎pkg/sqs/SqsProducer.php‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function send(PsrDestination $destination, PsrMessage $message)
6464
],
6565
'MessageBody' => $body,
6666
'QueueUrl' => $this->context->getQueueUrl($destination),
67+
'DelaySeconds' => (int) $this->deliveryDelay / 1000,
6768
];
6869

6970
if ($message->getDelaySeconds()) {
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Enqueue\Sqs\SqsConnectionFactory;
6+
use Interop\Queue\Spec\PsrProducerSpec;
7+
8+
/**
9+
* @group functional
10+
*/
11+
class SqsProducerTest extends PsrProducerSpec
12+
{
13+
/**
14+
* {@inheritdoc}
15+
*/
16+
protected function createProducer()
17+
{
18+
$factory = new SqsConnectionFactory([
19+
'key' => getenv('AWS__SQS__KEY'),
20+
'secret' => getenv('AWS__SQS__SECRET'),
21+
'region' => getenv('AWS__SQS__REGION'),
22+
]);
23+
24+
return $factory->createContext()->createProducer();
25+
}
26+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Enqueue\Sqs\SqsConnectionFactory;
6+
use Enqueue\Sqs\SqsContext;
7+
use Interop\Queue\PsrContext;
8+
use Interop\Queue\Spec\SendAndReceiveDelayedMessageFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class SqsSendAndReceiveDelayedMessageFromQueueTest extends SendAndReceiveDelayedMessageFromQueueSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new SqsConnectionFactory([
21+
'key' => getenv('AWS__SQS__KEY'),
22+
'secret' => getenv('AWS__SQS__SECRET'),
23+
'region' => getenv('AWS__SQS__REGION'),
24+
]);
25+
26+
return $factory->createContext();
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*
32+
* @param SqsContext $context
33+
*/
34+
protected function createQueue(PsrContext $context, $queueName)
35+
{
36+
$queueName = $queueName.time();
37+
38+
$queue = $context->createQueue($queueName);
39+
$context->declareQueue($queue);
40+
41+
return $queue;
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Enqueue\Sqs\SqsConnectionFactory;
6+
use Enqueue\Sqs\SqsContext;
7+
use Interop\Queue\PsrContext;
8+
use Interop\Queue\Spec\SendToAndReceiveFromQueueSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class SqsSendToAndReceiveFromQueueTest extends SendToAndReceiveFromQueueSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new SqsConnectionFactory([
21+
'key' => getenv('AWS__SQS__KEY'),
22+
'secret' => getenv('AWS__SQS__SECRET'),
23+
'region' => getenv('AWS__SQS__REGION'),
24+
]);
25+
26+
return $factory->createContext();
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*
32+
* @param SqsContext $context
33+
*/
34+
protected function createQueue(PsrContext $context, $queueName)
35+
{
36+
$queueName = $queueName.time();
37+
38+
$queue = $context->createQueue($queueName);
39+
$context->declareQueue($queue);
40+
41+
return $queue;
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Enqueue\Sqs\SqsConnectionFactory;
6+
use Enqueue\Sqs\SqsContext;
7+
use Interop\Queue\PsrContext;
8+
use Interop\Queue\Spec\SendToAndReceiveFromTopicSpec;
9+
10+
/**
11+
* @group functional
12+
*/
13+
class SqsSendToAndReceiveFromTopicTest extends SendToAndReceiveFromTopicSpec
14+
{
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
protected function createContext()
19+
{
20+
$factory = new SqsConnectionFactory([
21+
'key' => getenv('AWS__SQS__KEY'),
22+
'secret' => getenv('AWS__SQS__SECRET'),
23+
'region' => getenv('AWS__SQS__REGION'),
24+
]);
25+
26+
return $factory->createContext();
27+
}
28+
29+
/**
30+
* {@inheritdoc}
31+
*
32+
* @param SqsContext $context
33+
*/
34+
protected function createTopic(PsrContext $context, $topicName)
35+
{
36+
$topicName = $topicName.time();
37+
38+
$topic = $context->createTopic($topicName);
39+
$context->declareQueue($topic);
40+
41+
return $topic;
42+
}
43+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Interop\Queue\Spec\SendToAndReceiveNoWaitFromQueueSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class SqsSendToAndReceiveNoWaitFromQueueTest extends SendToAndReceiveNoWaitFromQueueSpec
11+
{
12+
public function test()
13+
{
14+
$this->markTestSkipped('The test is fragile. This is how SQS.');
15+
}
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function createContext()
21+
{
22+
throw new \LogicException('Should not be ever called');
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Interop\Queue\Spec\SendToAndReceiveNoWaitFromTopicSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class SqsSendToAndReceiveNoWaitFromTopicTest extends SendToAndReceiveNoWaitFromTopicSpec
11+
{
12+
public function test()
13+
{
14+
$this->markTestSkipped('The test is fragile. This is how SQS.');
15+
}
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function createContext()
21+
{
22+
throw new \LogicException('Should not be ever called');
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Interop\Queue\Spec\SendToTopicAndReceiveFromQueueSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class SqsSendToTopicAndReceiveFromQueueTest extends SendToTopicAndReceiveFromQueueSpec
11+
{
12+
public function test()
13+
{
14+
$this->markTestSkipped('The SQS does not support it');
15+
}
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function createContext()
21+
{
22+
throw new \LogicException('Should not be ever called');
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Enqueue\Sqs\Tests\Spec;
4+
5+
use Interop\Queue\Spec\SendToTopicAndReceiveNoWaitFromQueueSpec;
6+
7+
/**
8+
* @group functional
9+
*/
10+
class SqsSendToTopicAndReceiveNoWaitFromQueueTest extends SendToTopicAndReceiveNoWaitFromQueueSpec
11+
{
12+
public function test()
13+
{
14+
$this->markTestSkipped('The SQS does not support it');
15+
}
16+
17+
/**
18+
* {@inheritdoc}
19+
*/
20+
protected function createContext()
21+
{
22+
throw new \LogicException('Should not be ever called');
23+
}
24+
}

0 commit comments

Comments
 (0)