Search in sources :

Example 1 with BufferPullee

use of org.apache.hadoop.mapred.nativetask.handlers.BufferPullee in project hadoop by apache.

the class TestBufferPushPull method testPull.

@Test
public void testPull() throws Exception {
    final byte[] buff = new byte[BUFFER_LENGTH];
    final InputBuffer input = new InputBuffer(buff);
    final OutputBuffer out = new OutputBuffer(buff);
    final Class<BytesWritable> iKClass = BytesWritable.class;
    final Class<BytesWritable> iVClass = BytesWritable.class;
    final NativeHandlerForPull handler = new NativeHandlerForPull(input, out);
    final KeyValueIterator iter = new KeyValueIterator();
    final BufferPullee pullee = new BufferPullee(iKClass, iVClass, iter, handler);
    handler.setDataLoader(pullee);
    final BufferPuller puller = new BufferPuller(handler);
    handler.setDataReceiver(puller);
    int count = 0;
    while (puller.next()) {
        final DataInputBuffer key = puller.getKey();
        final DataInputBuffer value = puller.getValue();
        final BytesWritable keyBytes = new BytesWritable();
        final BytesWritable valueBytes = new BytesWritable();
        keyBytes.readFields(key);
        valueBytes.readFields(value);
        Assert.assertEquals(dataInput[count].key.toString(), keyBytes.toString());
        Assert.assertEquals(dataInput[count].value.toString(), valueBytes.toString());
        count++;
    }
    puller.close();
    pullee.close();
}
Also used : DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) RawKeyValueIterator(org.apache.hadoop.mapred.RawKeyValueIterator) BufferPullee(org.apache.hadoop.mapred.nativetask.handlers.BufferPullee) DataInputBuffer(org.apache.hadoop.io.DataInputBuffer) BytesWritable(org.apache.hadoop.io.BytesWritable) BufferPuller(org.apache.hadoop.mapred.nativetask.handlers.BufferPuller) Test(org.junit.Test)

Aggregations

BytesWritable (org.apache.hadoop.io.BytesWritable)1 DataInputBuffer (org.apache.hadoop.io.DataInputBuffer)1 RawKeyValueIterator (org.apache.hadoop.mapred.RawKeyValueIterator)1 BufferPullee (org.apache.hadoop.mapred.nativetask.handlers.BufferPullee)1 BufferPuller (org.apache.hadoop.mapred.nativetask.handlers.BufferPuller)1 Test (org.junit.Test)1