PathMetadataDynamoDBTranslation { static DDBPathMetadata itemToPathMetadata(Item item, String username) { if (item == null) { return null; } String parentStr = item.getString(PARENT); Preconditions.checkNotNull(parentStr, "No parent entry in item %s", item); String childStr = item.getString(CHILD); Preconditions.checkNotNull(childStr, "No child entry in item %s", item); Path rawPath = new Path(parentStr, childStr); if (!rawPath.isAbsoluteAndSchemeAuthorityNull()) { return null; } Path parent = new Path(Constants.FS_S3A + ":/" + parentStr + "/"); Path path = new Path(parent, childStr); boolean isDir = item.hasAttribute(IS_DIR) && item.getBoolean(IS_DIR); boolean isAuthoritativeDir = false; final S3AFileStatus fileStatus; long lastUpdated = 0; if (isDir) { isAuthoritativeDir = !IGNORED_FIELDS.contains(IS_AUTHORITATIVE) && item.hasAttribute(IS_AUTHORITATIVE) && item.getBoolean(IS_AUTHORITATIVE); fileStatus = DynamoDBMetadataStore.makeDirStatus(path, username); } else { long len = item.hasAttribute(FILE_LENGTH) ? item.getLong(FILE_LENGTH) : 0; long modTime = item.hasAttribute(MOD_TIME) ? item.getLong(MOD_TIME) : 0; long block = item.hasAttribute(BLOCK_SIZE) ? item.getLong(BLOCK_SIZE) : 0; String eTag = item.getString(ETAG); String versionId = item.getString(VERSION_ID); fileStatus = new S3AFileStatus( len, modTime, path, block, username, eTag, versionId); } lastUpdated = !IGNORED_FIELDS.contains(LAST_UPDATED) && item.hasAttribute(LAST_UPDATED) ? item.getLong(LAST_UPDATED) : 0; boolean isDeleted = item.hasAttribute(IS_DELETED) && item.getBoolean(IS_DELETED); return new DDBPathMetadata(fileStatus, Tristate.UNKNOWN, isDeleted, isAuthoritativeDir, lastUpdated); } private  PathMetadataDynamoDBTranslation(); @VisibleForTesting static String pathToParentKey(Path path);  }
@Test public void testItemToPathMetadata() throws IOException { final String user = UserGroupInformation.getCurrentUser().getShortUserName(); assertNull(itemToPathMetadata(null, user)); verify(testDirItem, itemToPathMetadata(testDirItem, user)); verify(testFileItem, itemToPathMetadata(testFileItem, user)); }
@Test public void testIsAuthoritativeCompatibilityItemToPathMetadata() throws Exception { Item item = Mockito.spy(testDirItem); item.withBoolean(IS_AUTHORITATIVE, true); PathMetadataDynamoDBTranslation.IGNORED_FIELDS.add(IS_AUTHORITATIVE); final String user = UserGroupInformation.getCurrentUser().getShortUserName(); DDBPathMetadata meta = itemToPathMetadata(item, user); Mockito.verify(item, Mockito.never()).getBoolean(IS_AUTHORITATIVE); assertFalse(meta.isAuthoritativeDir()); }
@Test public void testIsLastUpdatedCompatibilityItemToPathMetadata() throws Exception { Item item = Mockito.spy(testDirItem); item.withLong(LAST_UPDATED, 100); PathMetadataDynamoDBTranslation.IGNORED_FIELDS.add(LAST_UPDATED); final String user = UserGroupInformation.getCurrentUser().getShortUserName(); DDBPathMetadata meta = itemToPathMetadata(item, user); Mockito.verify(item, Mockito.never()).getLong(LAST_UPDATED); assertFalse(meta.isAuthoritativeDir()); }