protected function removesPreviouslyCreatedData()
{
$aws = $this->getEnvironment()->aws(AwsTestCase::REGION);
//Removes previously created DBInstances if it isn't removed by some reason.
try {
/* @var $i DBInstanceData */
$i = $aws->rds->dbInstance->describe(self::getTestName(self::NAME_INSTANCE))->get();
$this->assertInstanceOf($this->getRdsClassName('DataType\\DBInstanceData'), $i);
$this->removeDBInstance($i);
unset($i);
} catch (ClientException $e) {
if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_INSTANCE_NOT_FOUND) {
throw $e;
}
}
//Removes previously created DBSnapshots if it isn't removed by some reason.
/* @var $snList DBSnapshotList */
$snList = $aws->rds->dbSnapshot->describe(self::getTestName(self::NAME_INSTANCE));
$this->assertInstanceOf($this->getRdsClassName('DataType\\DBSnapshotList'), $snList);
if ($snList->count() > 0) {
/* @var $sn DBSnapshotData */
foreach ($snList as $sn) {
$this->assertInstanceOf($this->getRdsClassName('DataType\\DBSnapshotData'), $sn);
$sn->delete();
}
$timeout = 0;
while (($timeout += static::SLEEP_TIMEOUT) < static::SLEEP_TIME) {
$snList->rewind();
while ($snList->valid()) {
$sn = $snList->current();
try {
sleep(static::SLEEP_TIMEOUT);
$sn->refresh();
} catch (ClientException $e) {
if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_SNAPSHOT_NOT_FOUND) {
throw $e;
}
$snList->offsetUnset($snList->key());
}
$snList->next();
}
if ($snList->count() === 0) {
break;
}
}
}
unset($snList);
//Removes previously created DBSecurityGroup if it isn't removed by some reason.
try {
/* @var $sg DBSecurityGroupData */
$sg = $aws->rds->dbSecurityGroup->describe(self::getTestName(self::NAME_SG))->get();
$this->assertInstanceOf($this->getRdsClassName('DataType\\DBSecurityGroupData'), $sg);
$this->assertTrue($sg->delete());
unset($sg);
} catch (ClientException $e) {
if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_SECURITY_GROUP_NOT_FOUND) {
throw $e;
}
}
//Removes previously created DBParameterGroup if it does exist
try {
/* @var $pg DBParameterGroupData */
$pg = $aws->rds->dbParameterGroup->describe(self::getTestName(self::NAME_DB_PARAMETER_GROUP))->get();
$this->assertInstanceOf($this->getRdsClassName('DataType\\DBParameterGroupData'), $pg);
$this->assertTrue($pg->delete());
unset($pg);
} catch (ClientException $e) {
if ($e->getErrorData()->getCode() != ErrorData::ERR_DB_PARAMETER_GROUP_NOT_FOUND) {
throw $e;
}
}
}