/**
  * {@inheritDoc}
  */
 public function batchWriteItemAsync(AwsDynamoDbRequest $request)
 {
     /* Create the command. */
     $command = $this->client->getCommand(self::COMMAND_TYPE_BATCH_WRITE_ITEM, $request->toArray());
     /* Execute the command. */
     return $this->executeAsyncCommand($command);
 }
 /**
  * @param string $pattern a pattern that table name should match, if emtpy, all tables will be returned
  *
  * @return array
  */
 public function listTables($pattern = '/.*/')
 {
     $tables = [];
     $lastEvaluatedTableName = null;
     do {
         $args = ["Limit" => 30];
         if ($lastEvaluatedTableName) {
             $args['ExclusiveStartTableName'] = $lastEvaluatedTableName;
         }
         $cmd = $this->db->getCommand('ListTables', $args);
         $result = $this->db->execute($cmd);
         if (isset($result['LastEvaluatedTableName'])) {
             $lastEvaluatedTableName = $result['LastEvaluatedTableName'];
         } else {
             $lastEvaluatedTableName = null;
         }
         foreach ($result['TableNames'] as $tableName) {
             if (preg_match($pattern, $tableName)) {
                 $tables[] = $tableName;
             }
         }
     } while ($lastEvaluatedTableName != null);
     return $tables;
 }
Пример #3
0
 /**
  * @depends testIteratesOverScan
  */
 public function testImplementsCustomExponentialBackoffStrategy()
 {
     self::log('Getting an item a bunch of times in parallel');
     $batch = BatchBuilder::factory()->transferCommands(100)->build();
     $s = microtime(true);
     $total = 300;
     for ($i = 0; $i < $total; $i++) {
         $command = $this->client->getCommand('GetItem', array('TableName' => $this->table, 'Key' => $this->client->formatAttributes(array('HashKeyElement' => 'Test', 'RangeKeyElement' => 10))));
         $batch->add($command);
     }
     $retries = 0;
     foreach ($batch->flush() as $command) {
         $retries += $command->getRequest()->getParams()->get(BackoffPlugin::RETRY_PARAM);
     }
     $elapsed = microtime(true) - $s;
     self::log("Got the item {$total} times with {$retries} retries in {$elapsed} seconds");
 }
Пример #4
0
 /**
  * Ensures that garbage collection functionality is working correctly
  */
 public function testGarbageCollection()
 {
     $currentCount = iterator_count($this->client->getIterator('Scan', array('TableName' => $this->table)));
     self::log('Put 10 expired items into the sessions table');
     $writeBatch = WriteRequestBatch::factory($this->client);
     for ($i = 1; $i <= 10; $i++) {
         $writeBatch->add(new PutRequest(Item::fromArray(array('id' => "example_{$i}", 'expires' => time() - 5 * Time::SECONDS)), $this->table));
     }
     $writeBatch->flush();
     self::log('Assert that all 10 items made it into the sessions table');
     $result = $this->client->getCommand('Scan', array('TableName' => $this->table))->execute();
     $this->assertEquals(10 + $currentCount, $result['Count'], 'Not all of the items were inserted.');
     self::log('Create a session handler to use with a lower batch size');
     $sh = SessionHandler::factory(array('dynamodb_client' => $this->client, 'table_name' => $this->table, 'gc_batch_size' => 3));
     self::log('Run the garbage collection');
     $sh->garbageCollect();
     self::log('Assert that all 10 items were deleted from the sessions table');
     $result = $this->client->getCommand('Scan', array('TableName' => $this->table))->execute();
     $this->assertEquals(0, $result['Count'], 'Not all of the items were removed.');
 }