Repository: incubator-atlas Updated Branches: refs/heads/master 7ed6b02c4 -> 03684a056
ATLAS-1540: fix for unit test failures in TestEntityREST Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/03684a05 Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/03684a05 Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/03684a05 Branch: refs/heads/master Commit: 03684a0568f8569eca44573c791fc090d9a9a8b5 Parents: 7ed6b02 Author: Madhan Neethiraj <[email protected]> Authored: Wed Feb 8 10:14:27 2017 -0800 Committer: Madhan Neethiraj <[email protected]> Committed: Wed Feb 8 10:14:27 2017 -0800 ---------------------------------------------------------------------- .../java/org/apache/atlas/RequestContext.java | 9 +++- .../atlas/web/adapters/TestEntityREST.java | 55 ++++++++++---------- 2 files changed, 36 insertions(+), 28 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/03684a05/server-api/src/main/java/org/apache/atlas/RequestContext.java ---------------------------------------------------------------------- diff --git a/server-api/src/main/java/org/apache/atlas/RequestContext.java b/server-api/src/main/java/org/apache/atlas/RequestContext.java index 09cdc37..d35f456 100644 --- a/server-api/src/main/java/org/apache/atlas/RequestContext.java +++ b/server-api/src/main/java/org/apache/atlas/RequestContext.java @@ -94,7 +94,14 @@ public class RequestContext { } public static void clear() { - CURRENT_CONTEXT.get().entityCache.clear(); + RequestContext instance = CURRENT_CONTEXT.get(); + + if (instance != null) { + if (instance.entityCache != null) { + instance.entityCache.clear(); + } + } + CURRENT_CONTEXT.remove(); } http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/03684a05/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java ---------------------------------------------------------------------- diff --git a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java index 354722f..fd110cd 100644 --- a/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java +++ b/webapp/src/test/java/org/apache/atlas/web/adapters/TestEntityREST.java @@ -58,16 +58,12 @@ public class TestEntityREST { private AtlasEntity dbEntity; - private String dbGuid; - private AtlasClassification testClassification; @BeforeClass public void setUp() throws Exception { AtlasTypesDef typesDef = TestUtilsV2.defineHiveTypes(); typeStore.createTypesDef(typesDef); - Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity(); - dbEntity = dbEntityMap.values().iterator().next(); } @AfterClass @@ -80,9 +76,12 @@ public class TestEntityREST { RequestContext.clear(); } - public void createOrUpdateEntity() throws Exception { - Map<String, AtlasEntity> dbEntityMap = new HashMap<>(); + private void createTestEntity() throws Exception { + Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity(); + AtlasEntity dbEntity = dbEntityMap.values().iterator().next(); + dbEntityMap.put(dbEntity.getGuid(), dbEntity); + final EntityMutationResponse response = entitiesREST.createOrUpdate(dbEntityMap); Assert.assertNotNull(response); @@ -91,37 +90,37 @@ public class TestEntityREST { Assert.assertNotNull(entitiesMutated); Assert.assertEquals(entitiesMutated.size(), 1); Assert.assertNotNull(entitiesMutated.get(0)); - dbGuid = entitiesMutated.get(0).getGuid(); - Assert.assertEquals(entitiesMutated.size(), 1); + dbEntity.setGuid(entitiesMutated.get(0).getGuid()); + + this.dbEntity = dbEntity; } @Test public void testGetEntityById() throws Exception { - createOrUpdateEntity(); - AtlasEntityWithExtInfo response = entityREST.getById(dbGuid); + createTestEntity(); + AtlasEntityWithExtInfo response = entityREST.getById(dbEntity.getGuid()); Assert.assertNotNull(response); Assert.assertNotNull(response.getEntity()); TestEntitiesREST.verifyAttributes(response.getEntity().getAttributes(), dbEntity.getAttributes()); } - @Test + @Test(dependsOnMethods = "testGetEntityById") public void testAddAndGetClassification() throws Exception { - createOrUpdateEntity(); List<AtlasClassification> classifications = new ArrayList<>(); testClassification = new AtlasClassification(TestUtilsV2.CLASSIFICATION, new HashMap<String, Object>() {{ put("tag", "tagName"); }}); classifications.add(testClassification); - entityREST.addClassifications(dbGuid, classifications); + entityREST.addClassifications(dbEntity.getGuid(), classifications); - final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbGuid); + final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbEntity.getGuid()); Assert.assertNotNull(retrievedClassifications); final List<AtlasClassification> retrievedClassificationsList = retrievedClassifications.getList(); Assert.assertNotNull(retrievedClassificationsList); Assert.assertEquals(classifications, retrievedClassificationsList); - final AtlasClassification retrievedClassification = entityREST.getClassification(dbGuid, TestUtilsV2.CLASSIFICATION); + final AtlasClassification retrievedClassification = entityREST.getClassification(dbEntity.getGuid(), TestUtilsV2.CLASSIFICATION); Assert.assertNotNull(retrievedClassification); Assert.assertEquals(retrievedClassification, testClassification); @@ -131,7 +130,7 @@ public class TestEntityREST { @Test(dependsOnMethods = "testAddAndGetClassification") public void testGetEntityWithAssociations() throws Exception { - AtlasEntityWithExtInfo entity = entityREST.getById(dbGuid); + AtlasEntityWithExtInfo entity = entityREST.getById(dbEntity.getGuid()); final List<AtlasClassification> retrievedClassifications = entity.getEntity().getClassifications(); Assert.assertNotNull(retrievedClassifications); @@ -141,8 +140,8 @@ public class TestEntityREST { @Test(dependsOnMethods = "testGetEntityWithAssociations") public void testDeleteClassification() throws Exception { - entityREST.deleteClassification(dbGuid, TestUtilsV2.CLASSIFICATION); - final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbGuid); + entityREST.deleteClassification(dbEntity.getGuid(), TestUtilsV2.CLASSIFICATION); + final AtlasClassification.AtlasClassifications retrievedClassifications = entityREST.getClassifications(dbEntity.getGuid()); Assert.assertNotNull(retrievedClassifications); Assert.assertEquals(retrievedClassifications.getList().size(), 0); @@ -151,26 +150,28 @@ public class TestEntityREST { @Test(dependsOnMethods = "testDeleteClassification") public void testDeleteEntityById() throws Exception { - EntityMutationResponse response = entityREST.deleteByGuid(dbGuid); + EntityMutationResponse response = entityREST.deleteByGuid(dbEntity.getGuid()); List<AtlasEntityHeader> entitiesMutated = response.getEntitiesByOperation(EntityMutations.EntityOperation.DELETE); Assert.assertNotNull(entitiesMutated); - Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbGuid); + Assert.assertEquals(entitiesMutated.get(0).getGuid(), dbEntity.getGuid()); } @Test public void testUpdateGetDeleteEntityByUniqueAttribute() throws Exception { - Map<String, AtlasEntity> dbEntityMap = TestUtilsV2.createDBEntity(); - entitiesREST.createOrUpdate(dbEntityMap); + AtlasEntity dbEntity = dbEntityMap.values().iterator().next(); + EntityMutationResponse response = entitiesREST.createOrUpdate(dbEntityMap); + String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.CREATE).get(0).getGuid(); - final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME); - final String updatedDBName = "updatedDBName"; + Assert.assertTrue(AtlasEntity.isAssigned(dbGuid)); + + final String prevDBName = (String) dbEntity.getAttribute(TestUtilsV2.NAME); + final String updatedDBName = prevDBName + ":updated"; dbEntity.setAttribute(TestUtilsV2.NAME, updatedDBName); - final EntityMutationResponse response = entityREST.partialUpdateByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, prevDBName, dbEntity); - String dbGuid = response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0).getGuid(); - Assert.assertTrue(AtlasEntity.isAssigned(dbGuid)); + response = entityREST.partialUpdateByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, prevDBName, dbEntity); + Assert.assertEquals(response.getEntitiesByOperation(EntityMutations.EntityOperation.UPDATE).get(0).getGuid(), dbGuid); //Get By unique attribute List<AtlasEntity> entities = entityREST.getByUniqueAttribute(TestUtilsV2.DATABASE_TYPE, TestUtilsV2.NAME, updatedDBName);
