@Test public void testLimit_Complex() { long limit = (REC_D_400K.getOldEntry().getUncompressedSize() - REC_D_400K.getOldEntry().getCompressedSize()) + (REC_B_200K.getOldEntry().getUncompressedSize() - REC_B_200K.getOldEntry().getCompressedSize()); DeltaFriendlyOldBlobSizeLimiter limiter = new DeltaFriendlyOldBlobSizeLimiter(limit); List<QualifiedRecommendation> expected = new ArrayList<QualifiedRecommendation>(); expected.add(REC_B_200K); expected.add(REC_D_400K); expected.addAll(suppressed(REC_A_100K, REC_C_300K)); expected.addAll(ALL_IGNORED_RECS); assertEquivalence(expected, limiter.getModifiedRecommendations(tempFile, tempFile, ALL_RECS)); }
@Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = sortRecommendations(originalRecommendations); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long bytesRemaining = maxSizeBytes - oldFile.length(); for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressOldEntry) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; }
DeltaFriendlyOldBlobSizeLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = sortRecommendations(originalRecommendations); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long bytesRemaining = maxSizeBytes - oldFile.length(); for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressOldEntry) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } }
DeltaFriendlyOldBlobSizeLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = sortRecommendations(originalRecommendations); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long bytesRemaining = maxSizeBytes - oldFile.length(); for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressOldEntry) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes); }
DeltaFriendlyOldBlobSizeLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = sortRecommendations(originalRecommendations); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long bytesRemaining = maxSizeBytes - oldFile.length(); for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressOldEntry) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes); @Override List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations); }
DeltaFriendlyOldBlobSizeLimiter implements RecommendationModifier { @Override public List<QualifiedRecommendation> getModifiedRecommendations( File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations) { List<QualifiedRecommendation> sorted = sortRecommendations(originalRecommendations); List<QualifiedRecommendation> result = new ArrayList<>(sorted.size()); long bytesRemaining = maxSizeBytes - oldFile.length(); for (QualifiedRecommendation originalRecommendation : sorted) { if (!originalRecommendation.getRecommendation().uncompressOldEntry) { result.add(originalRecommendation); } else { long extraBytesConsumed = originalRecommendation.getOldEntry().getUncompressedSize() - originalRecommendation.getOldEntry().getCompressedSize(); if (bytesRemaining - extraBytesConsumed >= 0) { result.add(originalRecommendation); bytesRemaining -= extraBytesConsumed; } else { result.add( new QualifiedRecommendation( originalRecommendation.getOldEntry(), originalRecommendation.getNewEntry(), Recommendation.UNCOMPRESS_NEITHER, RecommendationReason.RESOURCE_CONSTRAINED)); } } } return result; } DeltaFriendlyOldBlobSizeLimiter(long maxSizeBytes); @Override List<QualifiedRecommendation> getModifiedRecommendations(
      File oldFile, File newFile, List<QualifiedRecommendation> originalRecommendations);  }