You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@atlas.apache.org by ma...@apache.org on 2017/02/10 18:50:17 UTC
incubator-atlas git commit: ATLAS-1550: fix for unit test failure in
TypeSystemTest.testDuplicateTypenames()
Repository: incubator-atlas
Updated Branches:
refs/heads/master 3b4ccb7f9 -> 938af9ee8
ATLAS-1550: fix for unit test failure in TypeSystemTest.testDuplicateTypenames()
Project: http://git-wip-us.apache.org/repos/asf/incubator-atlas/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-atlas/commit/938af9ee
Tree: http://git-wip-us.apache.org/repos/asf/incubator-atlas/tree/938af9ee
Diff: http://git-wip-us.apache.org/repos/asf/incubator-atlas/diff/938af9ee
Branch: refs/heads/master
Commit: 938af9ee854c0c63b6de59d5ac1f4ddf7ad45eac
Parents: 3b4ccb7
Author: Madhan Neethiraj <ma...@apache.org>
Authored: Fri Feb 10 09:08:46 2017 -0800
Committer: Madhan Neethiraj <ma...@apache.org>
Committed: Fri Feb 10 09:15:49 2017 -0800
----------------------------------------------------------------------
.../atlas/typesystem/types/TypeSystem.java | 42 ++++++++++++++------
.../atlas/typesystem/types/TypeSystemTest.java | 21 +++++++++-
2 files changed, 50 insertions(+), 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/938af9ee/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 119a8d5..d847f1a 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
@@ -412,9 +412,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.version, eDef.enumValues);
@@ -423,10 +427,15 @@ 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.typeVersion, sDef.attributeDefinitions.length);
structNameToDefMap.put(sDef.typeName, sDef);
transientTypes.put(sDef.typeName, sT);
@@ -434,10 +443,15 @@ 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.typeVersion, traitDef.superTypes,
traitDef.attributeDefinitions.length);
traitNameToDefMap.put(traitDef.typeName, traitDef);
@@ -446,9 +460,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.typeVersion, classDef.superTypes,
http://git-wip-us.apache.org/repos/asf/incubator-atlas/blob/938af9ee/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 175ba7e..0ef5d10 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);