Skip to content

Commit

Permalink
Minor fix: Do not re-run migration for properly formed native test su… (
Browse files Browse the repository at this point in the history
open-metadata#13124)

* Minor fix: Do not re-run migration for properly formed native test suites

* rename 1.1.3 to 1.1.5

* rename 1.1.3 to 1.1.5 and add 1.1.4

* Fix table -> native testsuite migration
  • Loading branch information
harshach authored Sep 12, 2023
1 parent 3afb521 commit 1af4941
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.openmetadata.service.migration.utils.V114;

import static org.openmetadata.service.Entity.TEST_CASE;
import static org.openmetadata.service.Entity.TEST_SUITE;
import static org.openmetadata.service.Entity.*;
import static org.openmetadata.service.migration.utils.v110.MigrationUtil.groupTestCasesByTable;

import java.util.ArrayList;
Expand Down Expand Up @@ -41,7 +40,8 @@ public static void fixTestSuites(CollectionDAO collectionDAO) {
List<TestSuite> testSuites =
testSuiteRepository.listAll(new EntityUtil.Fields(Set.of("id")), new ListFilter(Include.ALL));
for (TestSuite suite : testSuites) {
if (suite.getExecutableEntityReference() != null) {
if (suite.getExecutableEntityReference() != null
&& (!suite.getExecutable() || !suite.getFullyQualifiedName().contains("testSuite"))) {
String tableFQN = suite.getExecutableEntityReference().getFullyQualifiedName();
String suiteFQN = tableFQN + ".testSuite";
suite.setName(suiteFQN);
Expand Down Expand Up @@ -69,11 +69,11 @@ public static void fixTestSuites(CollectionDAO collectionDAO) {
TestSuite existingTestSuite = testSuiteRepository.getDao().findEntityById(existingTestSuiteRel.getId());
if (existingTestSuite.getExecutable()
&& existingTestSuite.getFullyQualifiedName().equals(executableTestSuiteFQN)) {
// remove the existing relation
// There is a native test suite associated with this testCase.
relationWithExecutableTestSuiteExists = true;
}
} catch (EntityNotFoundException ex) {
// if testsuite cannot be retrieved but the relation exists, then this is orphaned realtion, we will
// if testsuite cannot be retrieved but the relation exists, then this is orphaned relation, we will
// delete the relation
testSuiteRepository.deleteRelationship(
existingTestSuiteRel.getId(), TEST_SUITE, testCase.getId(), TEST_CASE, Relationship.CONTAINS);
Expand All @@ -86,6 +86,25 @@ public static void fixTestSuites(CollectionDAO collectionDAO) {
executableTestSuite.getId(), testCase.getId(), TEST_SUITE, TEST_CASE, Relationship.CONTAINS);
}
}

// check from table -> nativeTestSuite there should only one relation
List<CollectionDAO.EntityRelationshipRecord> testSuiteRels =
testSuiteRepository.findToRecords(
executableTestSuite.getExecutableEntityReference().getId(), TABLE, Relationship.CONTAINS, TEST_SUITE);
for (CollectionDAO.EntityRelationshipRecord testSuiteRel : testSuiteRels) {
try {
TestSuite existingTestSuite = testSuiteRepository.getDao().findEntityById(testSuiteRel.getId());
} catch (EntityNotFoundException ex) {
// if testsuite cannot be retrieved but the relation exists, then this is orphaned relation, we will
// delete the relation
testSuiteRepository.deleteRelationship(
executableTestSuite.getExecutableEntityReference().getId(),
TABLE,
testSuiteRel.getId(),
TEST_SUITE,
Relationship.CONTAINS);
}
}
}
}
}

0 comments on commit 1af4941

Please sign in to comment.