ATLAS-1550: fix for unit test failure in TypeSystemTest.testDuplicateTypenames()
(cherry picked from commit 938af9ee854c0c63b6de59d5ac1f4ddf7ad45eac)
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 @@
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 @@
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 @@
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 @@
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,
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 @@
}
@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 @@
}
}
+ @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);