Search in sources :

Example 21 with AtlasTransientTypeRegistry

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");
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) Test(org.testng.annotations.Test)

Example 22 with AtlasTransientTypeRegistry

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");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Example 23 with AtlasTransientTypeRegistry

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");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Example 24 with AtlasTransientTypeRegistry

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");
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) ArrayList(java.util.ArrayList) AtlasErrorCode(org.apache.atlas.AtlasErrorCode) Test(org.testng.annotations.Test)

Example 25 with AtlasTransientTypeRegistry

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;
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Aggregations

AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)34 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)20 Test (org.testng.annotations.Test)14 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)12 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)9 ArrayList (java.util.ArrayList)7 AtlasErrorCode (org.apache.atlas.AtlasErrorCode)5 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)4 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)3 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)3 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)3 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)3 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)1 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)1