Search in sources :

Example 1 with Reader

use of org.apache.hadoop.mapred.IFile.Reader in project hadoop by apache.

the class TestMerger method getKeyAnswer.

private Answer<?> getKeyAnswer(final String segmentName, final boolean isCompressedInput) {
    return new Answer<Object>() {

        int i = 0;

        @SuppressWarnings("unchecked")
        public Boolean answer(InvocationOnMock invocation) {
            if (i++ == 3) {
                return false;
            }
            Reader<Text, Text> mock = (Reader<Text, Text>) invocation.getMock();
            int multiplier = isCompressedInput ? 100 : 1;
            mock.bytesRead += 10 * multiplier;
            Object[] args = invocation.getArguments();
            DataInputBuffer key = (DataInputBuffer) args[0];
            key.reset(("Segment Key " + segmentName + i).getBytes(), 20);
            return true;
        }
    };
}
Also used : Answer(org.mockito.stubbing.Answer) Mockito.doAnswer(org.mockito.Mockito.doAnswer) DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Reader(org.apache.hadoop.mapred.IFile.Reader) Text(org.apache.hadoop.io.Text)

Example 2 with Reader

use of org.apache.hadoop.mapred.IFile.Reader in project hadoop by apache.

the class TestMerger method readOnDiskMapOutput.

private void readOnDiskMapOutput(Configuration conf, FileSystem fs, Path path, List<String> keys, List<String> values) throws IOException {
    FSDataInputStream in = CryptoUtils.wrapIfNecessary(conf, fs.open(path));
    IFile.Reader<Text, Text> reader = new IFile.Reader<Text, Text>(conf, in, fs.getFileStatus(path).getLen(), null, null);
    DataInputBuffer keyBuff = new DataInputBuffer();
    DataInputBuffer valueBuff = new DataInputBuffer();
    Text key = new Text();
    Text value = new Text();
    while (reader.nextRawKey(keyBuff)) {
        key.readFields(keyBuff);
        keys.add(key.toString());
        reader.nextRawValue(valueBuff);
        value.readFields(valueBuff);
        values.add(value.toString());
    }
}
Also used : IFile(org.apache.hadoop.mapred.IFile) DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) Reader(org.apache.hadoop.mapred.IFile.Reader) Text(org.apache.hadoop.io.Text)

Aggregations

DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)2 Text (org.apache.hadoop.io.Text)2 Reader (org.apache.hadoop.mapred.IFile.Reader)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 IFile (org.apache.hadoop.mapred.IFile)1 Mockito.doAnswer (org.mockito.Mockito.doAnswer)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1