Commit 938af9ee by Madhan Neethiraj

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

parent 3b4ccb7f
...@@ -412,9 +412,13 @@ public class TypeSystem { ...@@ -412,9 +412,13 @@ public class TypeSystem {
private void validateAndSetupShallowTypes(boolean update) throws AtlasException { private void validateAndSetupShallowTypes(boolean update) throws AtlasException {
for (EnumTypeDefinition eDef : enumDefs) { for (EnumTypeDefinition eDef : enumDefs) {
assert eDef.name != null; assert eDef.name != null;
if (!update && isRegistered(eDef.name)) { if (!update) {
LOG.warn("Found duplicate definition of type {}. Ignoring..", eDef.name); if (TypeSystem.this.isRegistered(eDef.name)) {
continue; 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.version, eDef.enumValues); EnumType eT = new EnumType(this, eDef.name, eDef.description, eDef.version, eDef.enumValues);
...@@ -423,10 +427,15 @@ public class TypeSystem { ...@@ -423,10 +427,15 @@ public class TypeSystem {
for (StructTypeDefinition sDef : structDefs) { for (StructTypeDefinition sDef : structDefs) {
assert sDef.typeName != null; assert sDef.typeName != null;
if (!update && isRegistered(sDef.typeName)) { if (!update) {
LOG.warn("Found duplicate definition of type {}. Ignoring..", sDef.typeName); if (TypeSystem.this.isRegistered(sDef.typeName)) {
continue; 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.typeVersion, sDef.attributeDefinitions.length); StructType sT = new StructType(this, sDef.typeName, sDef.typeDescription, sDef.typeVersion, sDef.attributeDefinitions.length);
structNameToDefMap.put(sDef.typeName, sDef); structNameToDefMap.put(sDef.typeName, sDef);
transientTypes.put(sDef.typeName, sT); transientTypes.put(sDef.typeName, sT);
...@@ -434,10 +443,15 @@ public class TypeSystem { ...@@ -434,10 +443,15 @@ public class TypeSystem {
for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) { for (HierarchicalTypeDefinition<TraitType> traitDef : traitDefs) {
assert traitDef.typeName != null; assert traitDef.typeName != null;
if (!update && isRegistered(traitDef.typeName)) { if (!update) {
LOG.warn("Found duplicate definition of type {}. Ignoring..", traitDef.typeName); if (TypeSystem.this.isRegistered(traitDef.typeName)) {
continue; 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.typeVersion, traitDef.superTypes, TraitType tT = new TraitType(this, traitDef.typeName, traitDef.typeDescription, traitDef.typeVersion, traitDef.superTypes,
traitDef.attributeDefinitions.length); traitDef.attributeDefinitions.length);
traitNameToDefMap.put(traitDef.typeName, traitDef); traitNameToDefMap.put(traitDef.typeName, traitDef);
...@@ -446,9 +460,13 @@ public class TypeSystem { ...@@ -446,9 +460,13 @@ public class TypeSystem {
for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) { for (HierarchicalTypeDefinition<ClassType> classDef : classDefs) {
assert classDef.typeName != null; assert classDef.typeName != null;
if (!update && isRegistered(classDef.typeName)) { if (!update) {
LOG.warn("Found duplicate definition of type {}. Ignoring..", classDef.typeName); if (TypeSystem.this.isRegistered(classDef.typeName)) {
continue; 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.typeVersion, classDef.superTypes, ClassType cT = new ClassType(this, classDef.typeName, classDef.typeDescription, classDef.typeVersion, classDef.superTypes,
......
...@@ -275,7 +275,7 @@ public class TypeSystemTest extends BaseTest { ...@@ -275,7 +275,7 @@ public class TypeSystemTest extends BaseTest {
} }
@Test @Test
public void testDuplicateTypenames() throws Exception { public void testRedefineExistingType() throws Exception {
TypeSystem typeSystem = getTypeSystem(); TypeSystem typeSystem = getTypeSystem();
HierarchicalTypeDefinition<TraitType> trait = TypesUtil HierarchicalTypeDefinition<TraitType> trait = TypesUtil
.createTraitTypeDef(random(), "description", ImmutableSet.<String>of(), .createTraitTypeDef(random(), "description", ImmutableSet.<String>of(),
...@@ -290,6 +290,25 @@ public class TypeSystemTest extends BaseTest { ...@@ -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) @Test(expectedExceptions = ValueConversionException.class)
public void testConvertInvalidDate() throws Exception { public void testConvertInvalidDate() throws Exception {
DataTypes.DATE_TYPE.convert("", Multiplicity.OPTIONAL); DataTypes.DATE_TYPE.convert("", Multiplicity.OPTIONAL);
......
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