Commit 4128f5d2 by Sarath Subramanian

ATLAS-2890: Fix intermittent UT and IT failures for atlas in apache CI

(cherry picked from commit 60104c18ab808eee2c777adea2795411c0d4de4b)
parent ece78ba0
...@@ -20,7 +20,9 @@ package org.apache.atlas.web.integration; ...@@ -20,7 +20,9 @@ package org.apache.atlas.web.integration;
import com.sun.jersey.core.util.MultivaluedMapImpl; import com.sun.jersey.core.util.MultivaluedMapImpl;
import org.apache.atlas.AtlasClientV2; import org.apache.atlas.AtlasClientV2;
import org.apache.atlas.AtlasErrorCode;
import org.apache.atlas.AtlasServiceException; import org.apache.atlas.AtlasServiceException;
import org.apache.atlas.exception.AtlasBaseException;
import org.apache.atlas.model.SearchFilter; import org.apache.atlas.model.SearchFilter;
import org.apache.atlas.model.TypeCategory; import org.apache.atlas.model.TypeCategory;
import org.apache.atlas.model.typedef.AtlasBaseTypeDef; import org.apache.atlas.model.typedef.AtlasBaseTypeDef;
...@@ -45,6 +47,7 @@ import java.util.Arrays; ...@@ -45,6 +47,7 @@ import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; 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.model.typedef.AtlasStructDef.AtlasAttributeDef.Cardinality;
import static org.apache.atlas.type.AtlasTypeUtil.createClassTypeDef; import static org.apache.atlas.type.AtlasTypeUtil.createClassTypeDef;
import static org.testng.Assert.assertEquals; import static org.testng.Assert.assertEquals;
...@@ -83,23 +86,22 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT { ...@@ -83,23 +86,22 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
public void testCreate() throws Exception { public void testCreate() throws Exception {
createType(typeDefinitions); createType(typeDefinitions);
// validate if all types created successfully
for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) { for (AtlasEnumDef enumDef : typeDefinitions.getEnumDefs()) {
AtlasEnumDef byName = atlasClientV2.getEnumDefByName(enumDef.getName()); checkIfTypeExists(enumDef.getName());
assertNotNull(byName);
} }
for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) { for (AtlasStructDef structDef : typeDefinitions.getStructDefs()) {
AtlasStructDef byName = atlasClientV2.getStructDefByName(structDef.getName()); checkIfTypeExists(structDef.getName());
assertNotNull(byName);
} }
for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) { for (AtlasClassificationDef classificationDef : typeDefinitions.getClassificationDefs()) {
AtlasClassificationDef byName = atlasClientV2.getClassificationDefByName(classificationDef.getName()); checkIfTypeExists(classificationDef.getName());
assertNotNull(byName);
} }
for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) { for (AtlasEntityDef entityDef : typeDefinitions.getEntityDefs()) {
AtlasEntityDef byName = atlasClientV2.getEntityDefByName(entityDef.getName()); checkIfTypeExists(entityDef.getName());
assertNotNull(byName);
} }
} }
@Test @Test
...@@ -367,4 +369,26 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT { ...@@ -367,4 +369,26 @@ public class TypedefsJerseyResourceIT extends BaseResourceIT {
def.getClassificationDefs().clear(); def.getClassificationDefs().clear();
def.getEntityDefs().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;
}
}
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment