use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasTypeRegistry method testClassificationDefInvalidHierarchy_CircularRef.
/*
* L2_3
* \
* L0
* / \
* / \
* L1_1---- L1_2
* / \ \ / \
* / \ \ / \
* L2_1 L2_2 L2_3 L2_4
*/
@Test
public void testClassificationDefInvalidHierarchy_CircularRef() {
AtlasClassificationDef classifiL0 = new AtlasClassificationDef("L0");
AtlasClassificationDef classifiL1_1 = new AtlasClassificationDef("L1-1");
AtlasClassificationDef classifiL1_2 = new AtlasClassificationDef("L1-2");
AtlasClassificationDef classifiL2_1 = new AtlasClassificationDef("L2-1");
AtlasClassificationDef classifiL2_2 = new AtlasClassificationDef("L2-2");
AtlasClassificationDef classifiL2_3 = new AtlasClassificationDef("L2-3");
AtlasClassificationDef classifiL2_4 = new AtlasClassificationDef("L2-4");
classifiL1_1.addSuperType(classifiL0.getName());
classifiL1_2.addSuperType(classifiL0.getName());
classifiL2_1.addSuperType(classifiL1_1.getName());
classifiL2_2.addSuperType(classifiL1_1.getName());
classifiL2_3.addSuperType(classifiL1_1.getName());
classifiL2_3.addSuperType(classifiL1_2.getName());
classifiL2_4.addSuperType(classifiL1_2.getName());
// circular-ref
classifiL0.addSuperType(classifiL2_3.getName());
AtlasTypesDef typesDef = new AtlasTypesDef();
typesDef.getClassificationDefs().add(classifiL0);
typesDef.getClassificationDefs().add(classifiL1_1);
typesDef.getClassificationDefs().add(classifiL1_2);
typesDef.getClassificationDefs().add(classifiL2_1);
typesDef.getClassificationDefs().add(classifiL2_2);
typesDef.getClassificationDefs().add(classifiL2_3);
typesDef.getClassificationDefs().add(classifiL2_4);
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
String failureMsg = null;
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(typesDef);
commit = true;
} catch (AtlasBaseException excp) {
failureMsg = excp.getMessage();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertNotNull(failureMsg, "expected invalid supertype failure");
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasEntityType method testConstraintInvalidOwnedRef_InvalidAttributeType.
@Test
public void testConstraintInvalidOwnedRef_InvalidAttributeType() {
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
List<AtlasEntityDef> entityDefs = new ArrayList<>();
AtlasErrorCode errorCode = null;
entityDefs.add(createTableEntityDefWithOwnedRefOnInvalidType());
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(entityDefs);
commit = true;
} catch (AtlasBaseException excp) {
errorCode = excp.getAtlasErrorCode();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_OWNED_REF_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - missing refAttribute");
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasEntityType method testConstraintInValidInverseRef_NonExistingAttribute.
@Test
public void testConstraintInValidInverseRef_NonExistingAttribute() {
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
List<AtlasEntityDef> entityDefs = new ArrayList<>();
AtlasErrorCode errorCode = null;
entityDefs.add(createTableEntityDef());
entityDefs.add(createColumnEntityDefWithNonExistingInverseAttribute());
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(entityDefs);
commit = true;
} catch (AtlasBaseException excp) {
errorCode = excp.getAtlasErrorCode();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_NON_EXISTING, "expected invalid constraint failure - non-existing refAttribute");
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class TestAtlasEntityType method testConstraintInValidInverseRef_InvalidAttributeType.
@Test
public void testConstraintInValidInverseRef_InvalidAttributeType() {
AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
List<AtlasEntityDef> entityDefs = new ArrayList<>();
AtlasErrorCode errorCode = null;
entityDefs.add(createTableEntityDef());
entityDefs.add(createColumnEntityDefWithInvalidInverseAttributeType());
try {
ttr = typeRegistry.lockTypeRegistryForUpdate();
ttr.addTypes(entityDefs);
commit = true;
} catch (AtlasBaseException excp) {
errorCode = excp.getAtlasErrorCode();
} finally {
typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_INVERSE_REF_INVERSE_ATTRIBUTE_INVALID_TYPE, "expected invalid constraint failure - invalid refAttribute type");
}
use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.
the class ModelTestUtil method newEnumDef.
public static AtlasEnumDef newEnumDef(AtlasTypeRegistry typesRegistry, boolean hasDefaultValue) {
int enumDefIdx = IDX_ENUM_DEF.getAndIncrement();
AtlasEnumDef ret = new AtlasEnumDef();
ret.setName(PREFIX_ENUM_DEF + enumDefIdx);
ret.setDescription(ret.getName());
int numElements = ThreadLocalRandom.current().nextInt(1, MAX_ENUM_ELEMENT_COUNT);
for (int i = 0; i < numElements; i++) {
String elementName = "element-" + i;
ret.addElement(new AtlasEnumElementDef(elementName, elementName.toUpperCase(), i));
}
if (hasDefaultValue) {
int idxDefault = ThreadLocalRandom.current().nextInt(0, numElements);
ret.setDefaultValue(ret.getElementDefs().get(idxDefault).getValue());
}
AtlasTransientTypeRegistry ttr = null;
boolean commit = false;
try {
ttr = typesRegistry.lockTypeRegistryForUpdate();
ttr.addType(ret);
commit = true;
} catch (AtlasBaseException excp) {
LOG.error("failed to create enum-def", excp);
ret = null;
} finally {
typesRegistry.releaseTypeRegistryForUpdate(ttr, commit);
}
return ret;
}
Aggregations