Repository: incubator-atlas
Updated Branches:
  refs/heads/0.7-incubating 80f9e73ca -> 76f25fb09


ATLAS-1550: fix for unit test failure in TypeSystemTest.testDuplicateTypenames()

(cherry picked from commit 938af9ee854c0c63b6de59d5ac1f4ddf7ad45eac)


Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/76f25fb0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/76f25fb0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/76f25fb0

Branch: refs/heads/0.7-incubating
Commit: 76f25fb0921a3b125278e019be0a0c2fa7c0e622
Parents: 80f9e73
Author: Madhan Neethiraj <[email protected]>
Authored: Fri Feb 10 09:08:46 2017 -0800
Committer: Madhan Neethiraj <[email protected]>
Committed: Fri Feb 10 11:08:40 2017 -0800

----------------------------------------------------------------------
 .../atlas/typesystem/types/TypeSystem.java      | 40 ++++++++++++++------
 .../atlas/typesystem/types/TypeSystemTest.java  | 21 +++++++++-
 2 files changed, 48 insertions(+), 13 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/76f25fb0/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
----------------------------------------------------------------------
diff --git 
a/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java 
b/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
index e6c1f99..e0d3733 100755
--- a/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
+++ b/typesystem/src/main/java/org/apache/atlas/typesystem/types/TypeSystem.java
@@ -404,9 +404,13 @@ public class TypeSystem {
         private void validateAndSetupShallowTypes(boolean update) throws 
AtlasException {
             for (EnumTypeDefinition eDef : enumDefs) {
                 assert eDef.name != null;
-                if (!update && isRegistered(eDef.name)) {
-                    LOG.warn("Found duplicate definition of type {}. 
Ignoring..", eDef.name);
-                    continue;
+                if (!update) {
+                    if (TypeSystem.this.isRegistered(eDef.name)) {
+                        throw new 
TypeExistsException(String.format("Redefinition of type %s is not supported", 
eDef.name));
+                    } else if (transientTypes.containsKey(eDef.name)) {
+                        LOG.warn("Found duplicate definition of type {}. 
Ignoring..", eDef.name);
+                        continue;
+                    }
                 }
 
                 EnumType eT = new EnumType(this, eDef.name, eDef.description, 
eDef.enumValues);
@@ -415,9 +419,13 @@ public class TypeSystem {
 
             for (StructTypeDefinition sDef : structDefs) {
                 assert sDef.typeName != null;
-                if (!update && isRegistered(sDef.typeName)) {
-                    LOG.warn("Found duplicate definition of type {}. 
Ignoring..", sDef.typeName);
-                    continue;
+                if (!update) {
+                    if (TypeSystem.this.isRegistered(sDef.typeName)) {
+                        throw new 
TypeExistsException(String.format("Redefinition of type %s is not supported", 
sDef.typeName));
+                    } else if (transientTypes.containsKey(sDef.typeName)) {
+                        LOG.warn("Found duplicate definition of type {}. 
Ignoring..", sDef.typeName);
+                        continue;
+                    }
                 }
                 StructType sT = new StructType(this, sDef.typeName, 
sDef.typeDescription, sDef.attributeDefinitions.length);
                 structNameToDefMap.put(sDef.typeName, sDef);
@@ -426,9 +434,13 @@ public class TypeSystem {
 
             for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) {
                 assert traitDef.typeName != null;
-                if (!update && isRegistered(traitDef.typeName)) {
-                    LOG.warn("Found duplicate definition of type {}. 
Ignoring..", traitDef.typeName);
-                    continue;
+                if (!update) {
+                    if (TypeSystem.this.isRegistered(traitDef.typeName)) {
+                        throw new 
TypeExistsException(String.format("Redefinition of type %s is not supported", 
traitDef.typeName));
+                    } else if (transientTypes.containsKey(traitDef.typeName)) {
+                        LOG.warn("Found duplicate definition of type {}. 
Ignoring..", traitDef.typeName);
+                        continue;
+                    }
                 }
                 TraitType tT = new TraitType(this, traitDef.typeName, 
traitDef.typeDescription, traitDef.superTypes,
                         traitDef.attributeDefinitions.length);
@@ -438,9 +450,13 @@ public class TypeSystem {
 
             for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) {
                 assert classDef.typeName != null;
-                if (!update && isRegistered(classDef.typeName)) {
-                    LOG.warn("Found duplicate definition of type {}. 
Ignoring..", classDef.typeName);
-                    continue;
+                if (!update) {
+                    if (TypeSystem.this.isRegistered(classDef.typeName)) {
+                        throw new 
TypeExistsException(String.format("Redefinition of type %s is not supported", 
classDef.typeName));
+                    } else if (transientTypes.containsKey(classDef.typeName)) {
+                        LOG.warn("Found duplicate definition of type {}. 
Ignoring..", classDef.typeName);
+                        continue;
+                    }
                 }
 
                 ClassType cT = new ClassType(this, classDef.typeName, 
classDef.typeDescription, classDef.superTypes,

http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/76f25fb0/typesystem/src/test/java/org/apache/atlas/typesystem/types/TypeSystemTest.java
----------------------------------------------------------------------
diff --git 
a/typesystem/src/test/java/org/apache/atlas/typesystem/types/TypeSystemTest.java
 
b/typesystem/src/test/java/org/apache/atlas/typesystem/types/TypeSystemTest.java
index 96946ea..7038a74 100755
--- 
a/typesystem/src/test/java/org/apache/atlas/typesystem/types/TypeSystemTest.java
+++ 
b/typesystem/src/test/java/org/apache/atlas/typesystem/types/TypeSystemTest.java
@@ -275,7 +275,7 @@ public class TypeSystemTest extends BaseTest {
     }
 
     @Test
-    public void testDuplicateTypenames() throws Exception {
+    public void testRedefineExistingType() throws Exception {
         TypeSystem typeSystem = getTypeSystem();
         HierarchicalTypeDefinition<TraitType> trait = TypesUtil
                 .createTraitTypeDef(random(), "description", 
ImmutableSet.<String>of(),
@@ -290,6 +290,25 @@ public class TypeSystemTest extends BaseTest {
         }
     }
 
+    @Test
+    public void testDuplicateNewTypenames() throws Exception {
+        TypeSystem typeSystem = getTypeSystem();
+        HierarchicalTypeDefinition<TraitType> trait1 = TypesUtil
+                .createTraitTypeDef(random(), "description", 
ImmutableSet.<String>of(),
+                        TypesUtil.createRequiredAttrDef("type", 
DataTypes.STRING_TYPE));
+        // create another trait with the same name
+        HierarchicalTypeDefinition<TraitType> trait2 = TypesUtil
+                .createTraitTypeDef(trait1.typeName, "description", 
ImmutableSet.<String>of(),
+                        TypesUtil.createRequiredAttrDef("type", 
DataTypes.STRING_TYPE));
+
+        try {
+            typeSystem.defineTypes(ImmutableList.<EnumTypeDefinition>of(), 
ImmutableList.<StructTypeDefinition>of(),
+                    ImmutableList.of(trait1, trait2), 
ImmutableList.<HierarchicalTypeDefinition<ClassType>>of());
+        } catch(AtlasException e) {
+            fail("Exception unexpected");
+        }
+    }
+
     @Test(expectedExceptions = ValueConversionException.class)
     public void testConvertInvalidDate() throws Exception {
        DataTypes.DATE_TYPE.convert("", Multiplicity.OPTIONAL);

Reply via email to