Search in sources :

Example 1 with Uploader

use of org.apache.hadoop.hbase.mapreduce.SampleUploader.Uploader in project hbase by apache.

the class TestMapReduceExamples method testSampleUploader.

/**
   * Test SampleUploader from examples
   */
@SuppressWarnings("unchecked")
@Test
public void testSampleUploader() throws Exception {
    Configuration configuration = new Configuration();
    Uploader uploader = new Uploader();
    Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context<LongWritable, Text, ImmutableBytesWritable, Put> ctx = mock(Context.class);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArguments()[0];
            Put put = (Put) invocation.getArguments()[1];
            assertEquals("row", Bytes.toString(writer.get()));
            assertEquals("row", Bytes.toString(put.getRow()));
            return null;
        }
    }).when(ctx).write(any(ImmutableBytesWritable.class), any(Put.class));
    uploader.map(null, new Text("row,family,qualifier,value"), ctx);
    Path dir = util.getDataTestDirOnTestFS("testSampleUploader");
    String[] args = { dir.toString(), "simpleTable" };
    Job job = SampleUploader.configureJob(configuration, args);
    assertEquals(SequenceFileInputFormat.class, job.getInputFormatClass());
}
Also used : Path(org.apache.hadoop.fs.Path) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) Configuration(org.apache.hadoop.conf.Configuration) Text(org.apache.hadoop.io.Text) Put(org.apache.hadoop.hbase.client.Put) Mapper(org.apache.hadoop.mapreduce.Mapper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) LongWritable(org.apache.hadoop.io.LongWritable) Job(org.apache.hadoop.mapreduce.Job) Uploader(org.apache.hadoop.hbase.mapreduce.SampleUploader.Uploader) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)1 Path (org.apache.hadoop.fs.Path)1 Put (org.apache.hadoop.hbase.client.Put)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 Uploader (org.apache.hadoop.hbase.mapreduce.SampleUploader.Uploader)1 LongWritable (org.apache.hadoop.io.LongWritable)1 Text (org.apache.hadoop.io.Text)1 Job (org.apache.hadoop.mapreduce.Job)1 Mapper (org.apache.hadoop.mapreduce.Mapper)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1