use of org.apache.apex.malhar.lib.util.comparator.SliceComparator in project apex-malhar by apache.
the class ManagedStateTestUtils method validateBucketOnFileSystem.
/**
* Validates the bucket data on the File System.
* @param fileAccess file access
* @param bucketId bucket id
* @param unsavedBucket bucket data to compare with.
* @param keysPerTimeBucket num keys per time bucket
* @throws IOException
*/
public static void validateBucketOnFileSystem(FileAccess fileAccess, long bucketId, Map<Slice, Bucket.BucketedValue> unsavedBucket, int keysPerTimeBucket) throws IOException {
RemoteIterator<LocatedFileStatus> iterator = fileAccess.listFiles(bucketId);
TreeMap<Slice, Slice> fromDisk = Maps.newTreeMap(new SliceComparator());
int size = 0;
while (iterator.hasNext()) {
LocatedFileStatus fileStatus = iterator.next();
String timeBucketStr = fileStatus.getPath().getName();
if (timeBucketStr.equals(BucketsFileSystem.META_FILE_NAME) || timeBucketStr.endsWith(".tmp")) {
// ignoring meta file
continue;
}
LOG.debug("bucket {} time-bucket {}", bucketId, timeBucketStr);
FileAccess.FileReader reader = fileAccess.getReader(bucketId, timeBucketStr);
reader.readFully(fromDisk);
size += keysPerTimeBucket;
Assert.assertEquals("size of bucket " + bucketId, size, fromDisk.size());
}
Assert.assertEquals("size of bucket " + bucketId, unsavedBucket.size(), fromDisk.size());
Map<Slice, Slice> testBucket = Maps.transformValues(unsavedBucket, new Function<Bucket.BucketedValue, Slice>() {
@Override
public Slice apply(@Nullable Bucket.BucketedValue input) {
assert input != null;
return input.getValue();
}
});
Assert.assertEquals("data of bucket" + bucketId, testBucket, fromDisk);
}
Aggregations