Skip to content

Commit

Permalink
Merge pull request #3 from aws/feature/support-3.18.7-and-above
Browse files Browse the repository at this point in the history
Run update script, get rid of import/export bridge, and make sure v2 is always used
  • Loading branch information
jeskew committed May 20, 2016
2 parents fea079d + b24bdb2 commit 69c9094
Show file tree
Hide file tree
Showing 26 changed files with 1,323 additions and 1,168 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@
[![Apache 2 License](https://img.shields.io/packagist/l/aws/aws-sdk-php-v3-bridge.svg?style=flat)](http://aws.amazon.com/apache-2-0/)
[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/aws/aws-sdk-php?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)

This package provides support for using Amazon SimpleDB and Amazon Import/Export
with version 3 of the AWS SDK for PHP. It depends on the AWS SDK for PHP v3 and
allows users to construct SimpleDb and Import/Export clients as they would any
other v3 service:
This package provides support for using Amazon SimpleDB with version 3 of the
AWS SDK for PHP. It depends on the AWS SDK for PHP v3 and allows users to
construct SimpleDb clients as they would any other v3 service:
```php
<?php

Expand All @@ -20,8 +19,8 @@ $sdb = new \Aws\SimpleDb\SimpleDbClient([
$domains = $sdb->listDomains();
```

Please note that you cannot use the `Aws\Sdk` service locator with SimpleDb or
Import/Export. You must create clients using the `new` keyword.
Please note that you cannot use the `Aws\Sdk` service locator with SimpleDb.
You must create clients using the `new` keyword.

## Installation

Expand All @@ -31,7 +30,7 @@ This package can be installed via [Composer](http://getcomposer.org) by requirin
```json
{
"require": {
"aws/aws-sdk-php-v3-bridge": "~1.0"
"aws/aws-sdk-php-v3-bridge": "^0.2.0"
}
}
```
Expand Down
16 changes: 14 additions & 2 deletions build/JsonCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ class JsonCompiler
{
use PhpFileLinterTrait;

private static $tokensToReplace = [
'(' => '__OPEN_PARENTHESIS__',
')' => '__CLOSE_PARENTHESIS__',
];

/** @var string */
private $path;

Expand Down Expand Up @@ -66,7 +71,10 @@ private function getTranspiledPhp()

private function getDecodedData()
{
return json_decode(file_get_contents($this->path), true);
return json_decode(
strtr(file_get_contents($this->path), self::$tokensToReplace),
true
);
}

private function readPhpFile($path)
Expand All @@ -78,6 +86,10 @@ private function readPhpFile($path)

private function writeFile($path, $contents)
{
return file_put_contents($path, $contents, LOCK_EX);
return file_put_contents(
$path,
strtr($contents, array_flip(self::$tokensToReplace)),
LOCK_EX
);
}
}
7 changes: 4 additions & 3 deletions build/PhpFileLinterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ private function lintFile($path)
static $linter;

if (empty($linter)) {
$linter = !empty(opcache_get_status(false)['opcache_enabled'])
? [$this, 'opcacheLint']
: [$this, 'commandLineLint'];
$linter = function_exists('opcache_get_status')
&& !empty(opcache_get_status(false)['opcache_enabled'])
? [$this, 'opcacheLint']
: [$this, 'commandLineLint'];
}

return call_user_func($linter, $path);
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "aws/aws-sdk-php-v3-bridge",
"description": "A compatibility pack for services no longer supported in V3",
"description": "A compatibility pack for using Amazon SimpleDB with v3 of the AWS SDK for PHP",
"minimum-stability": "stable",
"keywords": ["aws","amazon","sdb","importexport","sdk","simpledb"],
"keywords": ["aws","amazon","sdb","sdk","simpledb"],
"type": "library",
"license": "Apache-2.0",
"authors": [
Expand All @@ -27,7 +27,7 @@
"classmap": ["build/"]
},
"require": {
"aws/aws-sdk-php": "^3.2.1"
"aws/aws-sdk-php": "^3.18.7"
},
"require-dev": {
"phpunit/phpunit": "^4.8",
Expand Down
227 changes: 227 additions & 0 deletions features/bootstrap/Aws/Test/Integ/BatchingContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
<?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()
. str_replace(' ', '-', strtolower($scope->getName()));

$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()
. preg_replace('/\W/', '-', strtolower($scope->getName()));

$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']
]);

self::$resource = null;
}

/**
* @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 at least (\d+) times$/
*/
public function theBatchShouldHaveBeenFlushedTimes($flushCount)
{
$this->assertGreaterThanOrEqual((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']));
}
}
Loading

0 comments on commit 69c9094

Please sign in to comment.