@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"); }
@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"); }
@Test public void testConstraintInValidInverseRef_MissingParams() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithMissingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_MISSING_PARAMS, "expected invalid constraint failure - missing refAttribute"); }
@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"); }
@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"); }
@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"); }
@Test public void testConstraintInValidInverseRef_MissingParams() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); AtlasErrorCode errorCode = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDefWithMissingInverseAttribute()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); commit = true; } catch (AtlasBaseException excp) { errorCode = excp.getAtlasErrorCode(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertEquals(errorCode, AtlasErrorCode.CONSTRAINT_MISSING_PARAMS, "expected invalid constraint failure - missing refAttribute"); }
@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"); }
@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"); }
@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"); }
@Test public void testClassificationDefInvalidHierarchy_Self() { AtlasClassificationDef classifiDef1 = new AtlasClassificationDef("classifiDef-1"); classifiDef1.addSuperType(classifiDef1.getName()); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; String failureMsg = null; try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(classifiDef1); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNotNull(failureMsg, "expected invalid supertype failure"); }
@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())); }
@Test public void testClassificationDefInvalidHierarchy_Self() { AtlasClassificationDef classifiDef1 = new AtlasClassificationDef("classifiDef-1"); classifiDef1.addSuperType(classifiDef1.getName()); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; String failureMsg = null; try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addType(classifiDef1); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNotNull(failureMsg, "expected invalid supertype failure"); }
@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"); }
@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())); }
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
@Test public void testValidConstraints() { AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false; List<AtlasEntityDef> entityDefs = new ArrayList<>(); String failureMsg = null; entityDefs.add(createTableEntityDef()); entityDefs.add(createColumnEntityDef()); try { ttr = typeRegistry.lockTypeRegistryForUpdate(); ttr.addTypes(entityDefs); AtlasEntityType typeTable = ttr.getEntityTypeByName(TYPE_TABLE); AtlasEntityType typeColumn = ttr.getEntityTypeByName(TYPE_COLUMN); assertTrue(typeTable.getAttribute(ATTR_COLUMNS).isOwnedRef()); assertNull(typeTable.getAttribute(ATTR_COLUMNS).getInverseRefAttributeName()); assertFalse(typeColumn.getAttribute(ATTR_TABLE).isOwnedRef()); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttributeName(), ATTR_COLUMNS); assertEquals(typeColumn.getAttribute(ATTR_TABLE).getInverseRefAttribute(), typeTable.getAttribute(ATTR_COLUMNS)); commit = true; } catch (AtlasBaseException excp) { failureMsg = excp.getMessage(); } finally { typeRegistry.releaseTypeRegistryForUpdate(ttr, commit); } assertNull(failureMsg, "failed to create types " + TYPE_TABLE + " and " + TYPE_COLUMN); }
typesDef.getClassificationDefs().add(classifiL2_4); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false;
typesDef.getClassificationDefs().add(classifiL2_4); AtlasTypeRegistry typeRegistry = new AtlasTypeRegistry(); AtlasTransientTypeRegistry ttr = null; boolean commit = false;
private AtlasTypeRegistry getTypeRegistry() { AtlasTypeRegistry ret = new AtlasTypeRegistry(); AtlasEntityDef defReferenceable = new AtlasEntityDef(TYPENAME_REFERENCEABLE); AtlasEntityDef defAsset = new AtlasEntityDef(TYPENAME_ASSET); AtlasEntityDef defHdfsPath = new AtlasEntityDef(HDFS_PATH); AtlasEntityDef defHiveDb = new AtlasEntityDef(HIVE_DATABASE); AtlasEntityDef defHiveTable = new AtlasEntityDef(HIVE_TABLE); AtlasEntityDef defHiveColumn = new AtlasEntityDef(HIVE_COLUMN); AtlasEntityDef defHiveStorDesc = new AtlasEntityDef(HIVE_STORAGE_DESCRIPTOR); AtlasEntityDef defNonAsset = new AtlasEntityDef(TYPENAME_NON_ASSET); defAsset.addSuperType(TYPENAME_REFERENCEABLE); defHdfsPath.addSuperType(TYPENAME_ASSET); defHiveDb.addSuperType(TYPENAME_ASSET); defHiveTable.addSuperType(TYPENAME_ASSET); defHiveColumn.addSuperType(TYPENAME_ASSET); defNonAsset.addSuperType(TYPENAME_REFERENCEABLE); AtlasTypesDef typesDef = new AtlasTypesDef(); typesDef.setEntityDefs(Arrays.asList(defReferenceable, defAsset, defHdfsPath, defHiveDb, defHiveTable, defHiveColumn, defHiveStorDesc, defNonAsset)); try { AtlasTypeRegistry.AtlasTransientTypeRegistry ttr = ret.lockTypeRegistryForUpdate(); ttr.addTypes(typesDef); ret.releaseTypeRegistryForUpdate(ttr, true); } catch (AtlasBaseException excp) { LOG.warn("failed to initialize type-registry", excp); } return ret; }