Repository: atlas
Updated Branches:
  refs/heads/branch-1.0 52719937a -> 42e7b50f7


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/42e7b50f
Tree: http://git-wip-us.apache.org/repos/asf/atlas/tree/42e7b50f
Diff: http://git-wip-us.apache.org/repos/asf/atlas/diff/42e7b50f

Branch: refs/heads/branch-1.0
Commit: 42e7b50f73f90c47b6cd414cc430dddda91f1c3a
Parents: 5271993
Author: Sarath Subramanian <[email protected]>
Authored: Tue Sep 25 10:27:31 2018 -0700
Committer: Sarath Subramanian <[email protected]>
Committed: Tue Sep 25 11:14:20 2018 -0700

----------------------------------------------------------------------
 .../integration/TypedefsJerseyResourceIT.java   | 42 +++++++++++++++-----
 1 file changed, 33 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/atlas/blob/42e7b50f/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;
+            }
+        }
+    }
 }

Reply via email to