public function testCanAddItemsToException()
 {
     $exception = new UnprocessedWriteRequestsException();
     $interface = 'Aws\\DynamoDb\\Model\\BatchRequest\\WriteRequestInterface';
     $unprocessed1 = $this->getMock($interface);
     $unprocessed2 = $this->getMock($interface);
     $exception->addItem($unprocessed1)->addItem($unprocessed2);
     try {
         throw $exception;
     } catch (UnprocessedWriteRequestsException $e) {
         $this->assertEquals(2, count($e));
         $this->assertInstanceOf('\\ArrayIterator', $e->getIterator());
     }
 }
 /**
  * Handles unprocessed items if the entire batch was rejected due to exceeding the provisioned throughput
  *
  * @param EntityEnclosingRequestInterface   $request             The failed request
  * @param UnprocessedWriteRequestsException $unprocessedRequests Collection of unprocessed items
  */
 protected function handleUnprocessedRequestsAfterException(EntityEnclosingRequestInterface $request, UnprocessedWriteRequestsException $unprocessedRequests)
 {
     $items = $this->extractItemsFromRequestObject($request);
     foreach ($items as $request) {
         $unprocessedRequests->addItem($request);
     }
 }
 /**
  * Handles unprocessed items from the executed commands. Unprocessed items
  * can be collected and thrown in an UnprocessedWriteRequestsException
  *
  * @param array                             $commands            Array of commands
  * @param UnprocessedWriteRequestsException $unprocessedRequests Collection of unprocessed items
  */
 protected function getUnprocessedRequestsFromCommands(array $commands, UnprocessedWriteRequestsException $unprocessedRequests)
 {
     /** @var $command CommandInterface */
     foreach ($commands as $command) {
         if ($command instanceof CommandInterface && $command->isExecuted()) {
             $result = $command->getResult();
             $items = $this->convertResultsToUnprocessedRequests($result['UnprocessedItems']);
             foreach ($items as $request) {
                 $unprocessedRequests->addItem($request);
             }
         }
     }
 }
 public function testFlushUnprocessedItems()
 {
     // Prepare the unprocessed items exception
     $item = new UnprocessedRequest(array('foo'), 'foo');
     $exceptionUnprocessed = new UnprocessedWriteRequestsException();
     $exceptionUnprocessed->addItem($item);
     $exceptionBatchTransfer = new BatchTransferException(array($item), array(), $exceptionUnprocessed, $this->getMock('Guzzle\\Batch\\BatchTransferInterface'), $this->getMock('Guzzle\\Batch\\BatchDivisorInterface'));
     $batch = $this->getWriteRequestBatchWithMockedBatch($this->throwException($exceptionBatchTransfer));
     $this->assertEquals(array(), $batch->flush());
 }