Repository: atlas Updated Branches: refs/heads/master ece78ba09 -> 4128f5d2a
ATLAS-2890: Fix intermittent UT and IT failures for atlas in apache CI (cherry picked from commit 60104c18ab808eee2c777adea2795411c0d4de4b) Project: http://git-wip-us.apache.org/repos/asf/atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/atlas/commit/4128f5d2 Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/4128f5d2 Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/4128f5d2 Branch: refs/heads/master Commit: 4128f5d2aa1462b5462a94886fbd26c24cbb5a91 Parents: ece78ba Author: Sarath Subramanian <[email protected]> Authored: Tue Sep 25 10:27:31 2018 -0700 Committer: Sarath Subramanian <[email protected]> Committed: Tue Sep 25 11:19:02 2018 -0700 ---------------------------------------------------------------------- .../integration/TypedefsJerseyResourceIT.java | 42 +++++++++++++++----- 1 file changed, 33 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/atlas/blob/4128f5d2/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java b/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java index 219b4e3..331ea2c 100644 --- a/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java +++ b/webapp/src/test/java/org/apache/atlas/web/integration/TypedefsJerseyResourceIT.java @@ -20,7 +20,9 @@ package org.apache.atlas.web.integration; import com.sun.jersey.core.util.MultivaluedMapImpl; import org.apache.atlas.AtlasClientV2; +import org.apache.atlas.AtlasErrorCode; import org.apache.atlas.AtlasServiceException; +import org.apache.atlas.exception.AtlasBaseException; import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.typedef.AtlasBaseTypeDef; @@ -45,6 +47,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashSet; +import static org.apache.atlas.AtlasErrorCode.TYPE_NAME_NOT_FOUND; import static org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality; import static org.apache.atlas.type.AtlasTypeUtil.createClassTypeDef; import static org.testng.Assert.assertEquals; @@ -83,23 +86,22 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT { public void testCreate() throws Exception { createType(typeDefinitions); + // validate if all types created successfully for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) { - AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName()); - assertNotNull(byName); + checkIfTypeExists(enumDef.getName()); } + for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) { - AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName()); - assertNotNull(byName); + checkIfTypeExists(structDef.getName()); } + for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) { - AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName()); - assertNotNull(byName); + checkIfTypeExists(classificationDef.getName()); } + for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) { - AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName()); - assertNotNull(byName); + checkIfTypeExists(entityDef.getName()); } - } @Test @@ -367,4 +369,26 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT { def.getClassificationDefs().clear(); def.getEntityDefs().clear(); } + + private void checkIfTypeExists(String typeName) throws Exception { + int retryCount = 0; + int maxRetries = 3; + int sleepTime = 5000; + + while (true) { + try { + boolean typeExists = atlasClientV2.typeWithNameExists(typeName); + + if (!typeExists) { + throw new AtlasBaseException(TYPE_NAME_NOT_FOUND, typeName); + } else { + break; + } + } catch (AtlasBaseException e) { + Thread.sleep(sleepTime); + + if (++retryCount == maxRetries) throw e; + } + } + } }
