/** * Delete the table * * @param boolean $wait Wait until the table is deleted */ protected static function deleteTable($wait = false) { self::$dynamodb->deleteTable(['TableName' => self::TABLE_NAME]); if (!$wait) { return; } self::$dynamodb->waitUntil('TableNotExists', ['TableName' => self::TABLE_NAME, 'waiter.interval' => 1, 'waiter.max_attempts' => 5]); }
protected function execute(InputInterface $input, OutputInterface $output) { $this->dynamoDbClient = $this->getContainer()->get('queue.dynamodb_client'); $this->tableName = $this->getContainer()->getParameter('container_stats_dynamodb.table_name'); try { $this->dynamoDbClient->describeTable(['TableName' => $this->tableName]); echo 'Table ' . $this->tableName . ' already exists.' . "\n"; } catch (DynamoDbException $e) { if (strpos($e->getMessage(), 'ResourceNotFoundException') !== false) { echo 'Creating ' . $this->tableName . ' table ...'; $this->dynamoDbClient->createTable($this->getTableConfiguration()); $this->dynamoDbClient->waitUntil('TableExists', ['TableName' => $this->tableName, '@waiter' => ['delay' => 3, 'maxAttempts' => 20]]); echo ' done!' . "\n"; } else { throw $e; } } }
/** * @depends testCreatesTable */ public function testUpdatesTable() { self::log('Updating table'); // Need to wait until the table is active $this->client->waitUntil('TableExists', $this->table, array('status' => 'active')); $this->client->updateTable(array('TableName' => $this->table, 'ProvisionedThroughput' => array('ReadCapacityUnits' => 20, 'WriteCapacityUnits' => 20))); // Wait until the table is active self::log('Waiting for the table to become active after updating'); $this->client->waitUntil('table_exists', $this->table, array('status' => 'ACTIVE')); // Ensure the table is updated $result = $this->client->describeTable(array('TableName' => $this->table)); // Ensure that the updates took effect $this->assertEquals(20, $result['Table']['ProvisionedThroughput']['ReadCapacityUnits']); $this->assertEquals(20, $result['Table']['ProvisionedThroughput']['WriteCapacityUnits']); }
/** * Delete the test table after tests complete. */ protected static function deleteTable() { self::$client->deleteTable(['TableName' => self::$tableName]); self::$client->waitUntil('TableNotExists', ['TableName' => self::$tableName]); }