Example usage for org.apache.hadoop.mapreduce.lib.input SequenceFileRecordReader nextKeyValue

List of usage examples for org.apache.hadoop.mapreduce.lib.input SequenceFileRecordReader nextKeyValue

Introduction

In this page you can find the example usage for org.apache.hadoop.mapreduce.lib.input SequenceFileRecordReader nextKeyValue.

Prototype

@Override
    @SuppressWarnings("unchecked")
    public boolean nextKeyValue() throws IOException, InterruptedException 

Source Link

Usage

From source file:com.endgame.binarypig.loaders.AbstractExecutingLoaderTest.java

License:Apache License

public void testGetNext() throws IOException, InterruptedException {
    SequenceFileRecordReader reader = EasyMock.createMock(SequenceFileRecordReader.class);
    EasyMock.expect(reader.nextKeyValue()).andReturn(true);
    EasyMock.expect(reader.getCurrentKey()).andReturn(new Text("mykey1"));
    EasyMock.expect(reader.getCurrentValue()).andReturn(new BytesWritable("test123".getBytes()));
    EasyMock.replay(reader);//w  w w. j a va 2 s  .c  om

    underTest.script = "src/test/resources/echo.sh";
    underTest.prepareToRead(reader, null);
    Tuple tuple = underTest.getNext();
    assertEquals(4, tuple.size());
    assertEquals(tuple.get(0), new Text("mykey1"));
    assertEquals(tuple.get(1), new BytesWritable("test123".getBytes()));
    assertEquals(tuple.get(2), new File(underTest.dataDir, "mykey1").getAbsolutePath() + "\n");
    assertEquals(tuple.get(3), false);

    // returns null when no more tuples are available
    reader = EasyMock.createMock(SequenceFileRecordReader.class);
    EasyMock.expect(reader.nextKeyValue()).andReturn(false);
    EasyMock.replay(reader);
    underTest.reader = reader;

    tuple = underTest.getNext();
    assertNull(tuple);
}