Search in sources :

Example 1 with SliceComparator

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);
}
Also used : FileAccess(org.apache.apex.malhar.lib.fileaccess.FileAccess) LocatedFileStatus(org.apache.hadoop.fs.LocatedFileStatus) SliceComparator(org.apache.apex.malhar.lib.util.comparator.SliceComparator) BufferSlice(org.apache.apex.malhar.lib.utils.serde.BufferSlice) Slice(com.datatorrent.netlet.util.Slice)

Aggregations

Slice (com.datatorrent.netlet.util.Slice)1 FileAccess (org.apache.apex.malhar.lib.fileaccess.FileAccess)1 SliceComparator (org.apache.apex.malhar.lib.util.comparator.SliceComparator)1 BufferSlice (org.apache.apex.malhar.lib.utils.serde.BufferSlice)1 LocatedFileStatus (org.apache.hadoop.fs.LocatedFileStatus)1