forked from aws/aws-sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move batching tests to cucumber suite
- Loading branch information
Showing
6 changed files
with
242 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
@sqs | ||
Feature: SQS Batch Serialization | ||
|
||
Scenario: Deleting Message Batches | ||
Given I have a "sqs" client | ||
And I have put 10 messages in a queue | ||
When I delete a batch of 10 messages | ||
Then 10 messages should have been deleted from the queue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
@dynamodb | ||
Feature: DynamoDB Write Request Batch | ||
Scenario: Batching | ||
Given I have a "dynamodb" client | ||
When I create a WriteRequestBatch with a batch size of 3 and a pool size of 2 | ||
And I put 20 items in the batch | ||
And I flush the batch | ||
Then 20 items should have been written | ||
And the batch should have been flushed 7 times |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,222 @@ | ||
<?php | ||
|
||
namespace Aws\Test\Integ; | ||
|
||
use Aws\DynamoDb\DynamoDbClient; | ||
use Aws\DynamoDb\WriteRequestBatch; | ||
use Aws\Exception\AwsException; | ||
use Aws\Result; | ||
use Aws\Sqs\SqsClient; | ||
use Behat\Behat\Hook\Scope\AfterFeatureScope; | ||
use Behat\Behat\Hook\Scope\BeforeFeatureScope; | ||
use Behat\Behat\Tester\Exception\PendingException; | ||
use Behat\Behat\Context\Context; | ||
use Behat\Behat\Context\SnippetAcceptingContext; | ||
use Behat\Gherkin\Node\PyStringNode; | ||
use Behat\Gherkin\Node\TableNode; | ||
|
||
class BatchingContext extends \PHPUnit_Framework_Assert implements | ||
Context, | ||
SnippetAcceptingContext | ||
{ | ||
use IntegUtils; | ||
|
||
private static $resource; | ||
|
||
/** @var DynamoDbClient|SqsClient */ | ||
private $client; | ||
/** @var WriteRequestBatch */ | ||
private $batch; | ||
/** @var int */ | ||
private $flushCount; | ||
/** @var Result */ | ||
private $response; | ||
|
||
/** | ||
* @Given I have a :service client | ||
*/ | ||
public function iHaveAClient($service) | ||
{ | ||
$this->client = self::getSdk()->createClient($service); | ||
} | ||
|
||
/** | ||
* @BeforeFeature @dynamodb | ||
* | ||
* @param BeforeFeatureScope $scope | ||
*/ | ||
public static function setUpDynamoTable(BeforeFeatureScope $scope) | ||
{ | ||
self::$resource = self::getResourcePrefix() . '-wrb-test'; | ||
$client = self::getSdk()->createDynamoDb(); | ||
$client->createTable([ | ||
'TableName' => self::$resource, | ||
'AttributeDefinitions' => [ | ||
['AttributeName' => 'id', 'AttributeType' => 'N'] | ||
], | ||
'KeySchema' => [ | ||
['AttributeName' => 'id', 'KeyType' => 'HASH'] | ||
], | ||
'ProvisionedThroughput' => [ | ||
'ReadCapacityUnits' => 1, | ||
'WriteCapacityUnits' => 1 | ||
] | ||
]); | ||
|
||
$client->waitUntil('TableExists', ['TableName' => self::$resource]); | ||
} | ||
|
||
/** | ||
* @AfterFeature @dynamodb | ||
* | ||
* @param AfterFeatureScope $scope | ||
*/ | ||
public static function tearDownDynamoTable(AfterFeatureScope $scope) | ||
{ | ||
self::getSdk() | ||
->createDynamoDb() | ||
->deleteTable(['TableName' => self::$resource]); | ||
|
||
self::$resource = null; | ||
} | ||
|
||
/** | ||
* @BeforeFeature @sqs | ||
* | ||
* @param BeforeFeatureScope $scope | ||
*/ | ||
public static function setUpQueue(BeforeFeatureScope $scope) | ||
{ | ||
$sqs = self::getSdk()->createSqs(); | ||
self::$resource = self::getResourcePrefix() . '-batch-test'; | ||
|
||
$sqs->createQueue(['QueueName' => self::$resource]); | ||
$sqs->waitUntil('QueueExists', ['QueueName' => self::$resource]); | ||
} | ||
|
||
/** | ||
* @AfterFeature @sqs | ||
* | ||
* @param AfterFeatureScope $scope | ||
*/ | ||
public static function tearDownQueue(AfterFeatureScope $scope) | ||
{ | ||
$sqs = self::getSdk() | ||
->createSqs(); | ||
|
||
$sqs->deleteQueue([ | ||
'QueueUrl' => $sqs->getQueueUrl([ | ||
'QueueName' => self::$resource, | ||
])['QueueUrl'] | ||
]); | ||
} | ||
|
||
/** | ||
* @When /^I create a WriteRequestBatch with a batch size of (\d+) and a pool size of (\d+)$/ | ||
*/ | ||
public function iCreateAWriteRequestBatch($batchSize, $poolSize) | ||
{ | ||
$this->batch = new WriteRequestBatch($this->client, [ | ||
'table' => self::$resource, | ||
'batch_size' => $batchSize, | ||
'pool_size' => $poolSize, | ||
'before' => function () { | ||
$this->flushCount++; | ||
}, | ||
'error' => function (AwsException $e) { | ||
trigger_error($e->getMessage(), E_USER_WARNING); | ||
} | ||
]); | ||
} | ||
|
||
/** | ||
* @When /^I put (\d+) items in the batch$/ | ||
*/ | ||
public function iPutItemsInTheBatch($itemCount) | ||
{ | ||
for ($i = 0; $i < $itemCount; $i++) { | ||
$this->batch->put(['id' => ['N' => (string) $i]]); | ||
} | ||
} | ||
|
||
/** | ||
* @When I flush the batch | ||
*/ | ||
public function iFlushTheBatch() | ||
{ | ||
$this->batch->flush(); | ||
} | ||
|
||
/** | ||
* @Then /^(\d+) items should have been written$/ | ||
*/ | ||
public function itemsShouldHaveBeenWritten($itemCount) | ||
{ | ||
$actualItems = $this->client->getIterator('Scan', [ | ||
'TableName' => self::$resource, | ||
]); | ||
|
||
$this->assertSame((int) $itemCount, iterator_count($actualItems)); | ||
} | ||
|
||
/** | ||
* @Then /^the batch should have been flushed (\d+) times$/ | ||
*/ | ||
public function theBatchShouldHaveBeenFlushedTimes($flushCount) | ||
{ | ||
$this->assertSame((int) $flushCount, $this->flushCount); | ||
} | ||
|
||
/** | ||
* @Given /^I have put (\d+) messages in a queue$/ | ||
*/ | ||
public function iHavePutMessagesInAQueue($messageCount) | ||
{ | ||
$queueUrl = $this->client | ||
->getQueueUrl(['QueueName' => self::$resource])['QueueUrl']; | ||
for ($i = 0; $i < $messageCount; $i++) { | ||
$this->client->sendMessage([ | ||
'QueueUrl' => $queueUrl, | ||
'MessageBody' => json_encode(['testing' => 'testing']), | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
* @When /^I delete a batch of (\d+) messages$/ | ||
*/ | ||
public function iDeleteABatchOfMessages($messageCount) | ||
{ | ||
$queueUrl = $this->client | ||
->getQueueUrl(['QueueName' => self::$resource])['QueueUrl']; | ||
$messages = []; | ||
while (count($messages) < $messageCount) { | ||
$result = $this->client->receiveMessage([ | ||
'QueueUrl' => $queueUrl, | ||
'MaxNumberOfMessages' => $messageCount, | ||
]); | ||
|
||
foreach ($result['Messages'] as $message) { | ||
$messages[$message['MessageId']] = [ | ||
'Id' => $message['MessageId'], | ||
'ReceiptHandle' => $message['ReceiptHandle'], | ||
]; | ||
} | ||
} | ||
|
||
$this->response = $this->client | ||
->deleteMessageBatch([ | ||
'QueueUrl' => $queueUrl, | ||
'Entries' => array_values($messages), | ||
]); | ||
} | ||
|
||
/** | ||
* @Then /^(\d+) messages should have been deleted from the queue$/ | ||
*/ | ||
public function messagesShouldHaveBeenDeletedFromTheQueue($messageCount) | ||
{ | ||
$this->assertSame((int) $messageCount, count($this->response['Failed']) | ||
+ count($this->response['Successful'])); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.