Search in sources :

Example 1 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class TestAtlasTypeRegistry method testClassificationDefValidHierarchy.

/*
     *             L0
     *          /      \
     *         /         \
     *      L1_1----      L1_2
     *      /  \    \    /   \
     *     /    \    \  /     \
     *   L2_1  L2_2   L2_3   L2_4
     */
@Test
public void testClassificationDefValidHierarchy() {
    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());
    classifiL0.addAttribute(new AtlasAttributeDef("L0_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_1.addAttribute(new AtlasAttributeDef("L1-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL1_2.addAttribute(new AtlasAttributeDef("L1-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_1.addAttribute(new AtlasAttributeDef("L2-1_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_2.addAttribute(new AtlasAttributeDef("L2-2_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_3.addAttribute(new AtlasAttributeDef("L2-3_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    classifiL2_4.addAttribute(new AtlasAttributeDef("L2-4_a1", AtlasBaseTypeDef.ATLAS_TYPE_INT));
    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);
    }
    assertNull(failureMsg);
    validateSuperTypes(typeRegistry, "L0", new HashSet<String>());
    validateSuperTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0")));
    validateSuperTypes(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L1-1", "L0")));
    validateSuperTypes(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L1-1", "L0", "L1-2")));
    validateSuperTypes(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L1-2", "L0")));
    validateSubTypes(typeRegistry, "L0", new HashSet<>(Arrays.asList("L1-1", "L1-2", "L2-1", "L2-2", "L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L2-1", "L2-2", "L2-3")));
    validateSubTypes(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L2-3", "L2-4")));
    validateSubTypes(typeRegistry, "L2-1", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-2", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-3", new HashSet<String>());
    validateSubTypes(typeRegistry, "L2-4", new HashSet<String>());
    validateAttributeNames(typeRegistry, "L0", new HashSet<>(Arrays.asList("L0_a1")));
    validateAttributeNames(typeRegistry, "L1-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1")));
    validateAttributeNames(typeRegistry, "L1-2", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1")));
    validateAttributeNames(typeRegistry, "L2-1", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-1_a1")));
    validateAttributeNames(typeRegistry, "L2-2", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L2-2_a1")));
    validateAttributeNames(typeRegistry, "L2-3", new HashSet<>(Arrays.asList("L0_a1", "L1-1_a1", "L1-2_a1", "L2-3_a1")));
    validateAttributeNames(typeRegistry, "L2-4", new HashSet<>(Arrays.asList("L0_a1", "L1-2_a1", "L2-4_a1")));
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) Test(org.testng.annotations.Test)

Example 2 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class TestAtlasTypeRegistry method testNestedUpdates.

@Test
public void testNestedUpdates() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    String failureMsg = null;
    AtlasClassificationDef testTag1 = new AtlasClassificationDef("testTag1");
    AtlasClassificationDef testTag2 = new AtlasClassificationDef("testTag2");
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addType(testTag1);
        // changes should not be seen in typeRegistry until lock is released
        assertFalse(typeRegistry.isRegisteredType(testTag1.getName()), "type added should be seen in typeRegistry only after commit");
        boolean isNestedUpdateSuccess = addType(typeRegistry, testTag2);
        assertTrue(isNestedUpdateSuccess);
        // changes made in nested commit, inside addType(), should not be seen in typeRegistry until lock is released here
        assertFalse(typeRegistry.isRegisteredType(testTag2.getName()), "type added within nested commit should be seen in typeRegistry only after outer commit");
        commit = true;
    } catch (AtlasBaseException excp) {
        failureMsg = excp.getMessage();
    } finally {
        typeRegistry.releaseTypeRegistryForUpdate(ttr, commit);
    }
    assertNull(failureMsg);
    assertTrue(typeRegistry.isRegisteredType(testTag1.getName()));
    assertTrue(typeRegistry.isRegisteredType(testTag2.getName()));
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTransientTypeRegistry(org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry) Test(org.testng.annotations.Test)

Example 3 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class TestAtlasTypeRegistry method testEntityDefInvalidHierarchy_CircularRef.

/*
     *       L2_3
     *           \
     *             L0
     *          /      \
     *         /         \
     *      L1_1----      L1_2
     *      /  \    \    /   \
     *     /    \    \  /     \
     *   L2_1  L2_2   L2_3   L2_4
     */
@Test
public void testEntityDefInvalidHierarchy_CircularRef() {
    AtlasEntityDef entL0 = new AtlasEntityDef("L0");
    AtlasEntityDef entL1_1 = new AtlasEntityDef("L1-1");
    AtlasEntityDef entL1_2 = new AtlasEntityDef("L1-2");
    AtlasEntityDef entL2_1 = new AtlasEntityDef("L2-1");
    AtlasEntityDef entL2_2 = new AtlasEntityDef("L2-2");
    AtlasEntityDef entL2_3 = new AtlasEntityDef("L2-3");
    AtlasEntityDef entL2_4 = new AtlasEntityDef("L2-4");
    entL1_1.addSuperType(entL0.getName());
    entL1_2.addSuperType(entL0.getName());
    entL2_1.addSuperType(entL1_1.getName());
    entL2_2.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_1.getName());
    entL2_3.addSuperType(entL1_2.getName());
    entL2_4.addSuperType(entL1_2.getName());
    // circular-ref
    entL0.addSuperType(entL2_3.getName());
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.getEntityDefs().add(entL0);
    typesDef.getEntityDefs().add(entL1_1);
    typesDef.getEntityDefs().add(entL1_2);
    typesDef.getEntityDefs().add(entL2_1);
    typesDef.getEntityDefs().add(entL2_2);
    typesDef.getEntityDefs().add(entL2_3);
    typesDef.getEntityDefs().add(entL2_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 4 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class TestAtlasTypeRegistry method testEntityDefInvalidHierarchy_Self.

@Test
public void testEntityDefInvalidHierarchy_Self() {
    AtlasEntityDef entDef1 = new AtlasEntityDef("entDef-1");
    entDef1.addSuperType(entDef1.getName());
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    String failureMsg = null;
    try {
        ttr = typeRegistry.lockTypeRegistryForUpdate();
        ttr.addType(entDef1);
        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 5 with AtlasTransientTypeRegistry

use of org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry in project incubator-atlas by apache.

the class TestAtlasEntityType method testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute.

@Test
public void testConstraintInValidInverseRef_InvalidAttributeTypeForInverseAttribute() {
    AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry();
    AtlasTransientTypeRegistry ttr = null;
    boolean commit = false;
    List<AtlasEntityDef> entityDefs = new ArrayList<>();
    AtlasErrorCode errorCode = null;
    entityDefs.add(createTableEntityDef());
    entityDefs.add(createColumnEntityDefWithInvaidAttributeTypeForInverseAttribute());
    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_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)

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