deletion plan test coverage

This commit is contained in:
odain
2026-03-13 12:34:31 +01:00
parent 9b90ed3983
commit e8e842dcea
2 changed files with 50 additions and 21 deletions

View File

@@ -102,7 +102,7 @@ class DeletionPlanService
* @throws \CoreUnexpectedValue * @throws \CoreUnexpectedValue
* @throws \MySQLException * @throws \MySQLException
*/ */
public function ExecuteDeletionPlan(array $aClasses, int $iUnixTimeLimit = 0, int $iMaxExecutionCount=0): array public function ExecuteDeletionPlan(array $aClasses, int $iUnixTimeLimit = 0, int $iMaxExecutionCount = -1): array
{ {
$oDeletionPlan = $this->GetDeletionPlan($aClasses); $oDeletionPlan = $this->GetDeletionPlan($aClasses);
@@ -199,13 +199,12 @@ class DeletionPlanService
public function IsTimeLimitExceeded(int $iUnixTimeLimit, int $iMaxExecutionCount): bool public function IsTimeLimitExceeded(int $iUnixTimeLimit, int $iMaxExecutionCount): bool
{ {
throw new \Exception(""); if (($iMaxExecutionCount !== -1) && ($iMaxExecutionCount <= $this->iExecutionCount)) {
$this->iExecutionCount++; return true;
echo json_encode([$this->iExecutionCount, $iMaxExecutionCount]);
if ($iMaxExecutionCount === $this->iExecutionCount){
return false;
} }
$this->iExecutionCount++;
if ($iUnixTimeLimit === 0) { if ($iUnixTimeLimit === 0) {
return false; return false;
} }

View File

@@ -366,12 +366,10 @@ class DeletionPlanServiceTest extends ItopCustomDatamodelTestCase
EOF); EOF);
$aClasses = [ 'DFRToRemoveLeaf' ]; $aClasses = [ 'DFRToRemoveLeaf' ];
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 2); $aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 3);
$aExpected = [ $aExpected = [
['DFRToUpdate', 2, 0 ], ['DFRToUpdate', 3, 0 ],
['DFRToRemoveLeaf', 0, 0 ], ['DFRToRemoveLeaf', 0, 0 ],
['DFRRemovedCollateral', 0, 0 ],
['DFRRemovedCollateralCascade', 0, 0 ],
]; ];
$this->AssertSummaryEquals($aExpected, $aRes); $this->AssertSummaryEquals($aExpected, $aRes);
} }
@@ -393,16 +391,48 @@ class DeletionPlanServiceTest extends ItopCustomDatamodelTestCase
EOF); EOF);
$aClasses = [ 'DFRToRemoveLeaf' ]; $aClasses = [ 'DFRToRemoveLeaf' ];
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 5); $aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 8);
$aExpected = [ $aExpected = [
['DFRToUpdate', 3, 0 ], ['DFRToUpdate', 3, 0 ],
['DFRToRemoveLeaf', 2, 0 ], ['DFRToRemoveLeaf', 0, 3 ],
['DFRRemovedCollateral', 0, 0 ], ['DFRRemovedCollateral', 0, 2 ],
['DFRRemovedCollateralCascade', 0, 0 ],
]; ];
$this->AssertSummaryEquals($aExpected, $aRes); $this->AssertSummaryEquals($aExpected, $aRes);
} }
public function testExecuteDeletionPlan_WrongOrderDeletion()
{
$this->GivenDFRTreeInDB(<<<EOF
DFRToRemoveLeaf_1 <- DFRRemovedCollateral_1
DFRRemovedCollateral_1 <- DFRRemovedCollateralCascade_1
DFRToRemoveLeaf_2 <- DFRRemovedCollateral_2
DFRRemovedCollateral_2 <- DFRRemovedCollateralCascade_2
DFRToRemoveLeaf_3 <- DFRRemovedCollateral_3
DFRRemovedCollateral_3 <- DFRRemovedCollateralCascade_3
EOF);
$aClasses = [ 'DFRToRemoveLeaf' ];
$oSet = new \DBObjectSet(\DBObjectSearch::FromOQL("SELECT DFRRemovedCollateral WHERE name='DFRRemovedCollateral_3'"));
$oExpectedObj = $oSet->Fetch();
self::assertNotNull($oExpectedObj);
$aRes = DeletionPlanService::GetInstance()->ExecuteDeletionPlan($aClasses, 0, 5);
$aExpected = [
['DFRToRemoveLeaf', 0, 3 ],
['DFRRemovedCollateral', 0, 2 ],
];
$this->AssertSummaryEquals($aExpected, $aRes);
$oSet = new \DBObjectSet(\DBObjectSearch::FromOQL("SELECT DFRRemovedCollateral WHERE name='DFRRemovedCollateral_3'"));
$oActualObj = $oSet->Fetch();
self::assertNotNull($oActualObj, "Deletion plan executed in wrong order: DFRRemovedCollateralCascade/DFRRemovedCollateral are not valid anymore");
self::assertEquals($oExpectedObj->GetKey(), $oActualObj->GetKey());
}
public function GetDatamodelDeltaAbsPath(): string public function GetDatamodelDeltaAbsPath(): string
{ {
return __DIR__.'/deletionplan_delta.xml'; return __DIR__.'/deletionplan_delta.xml';