Search in sources :

Example 1 with CellImporter

use of org.apache.hadoop.hbase.mapreduce.Import.CellImporter in project hbase by apache.

the class TestImportExport method testKeyValueImporter.

/**
 * Test map method of Importer
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testKeyValueImporter() throws Throwable {
    CellImporter importer = new CellImporter();
    Configuration configuration = new Configuration();
    Context ctx = mock(Context.class);
    when(ctx.getConfiguration()).thenReturn(configuration);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            ImmutableBytesWritable writer = (ImmutableBytesWritable) invocation.getArgument(0);
            MapReduceExtendedCell key = (MapReduceExtendedCell) invocation.getArgument(1);
            assertEquals("Key", Bytes.toString(writer.get()));
            assertEquals("row", Bytes.toString(CellUtil.cloneRow(key)));
            return null;
        }
    }).when(ctx).write(any(), any());
    importer.setup(ctx);
    Result value = mock(Result.class);
    KeyValue[] keys = { new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("qualifier"), Bytes.toBytes("value")), new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("family"), Bytes.toBytes("qualifier"), Bytes.toBytes("value1")) };
    when(value.rawCells()).thenReturn(keys);
    importer.map(new ImmutableBytesWritable(Bytes.toBytes("Key")), value, ctx);
}
Also used : Context(org.apache.hadoop.mapreduce.Mapper.Context) ObserverContext(org.apache.hadoop.hbase.coprocessor.ObserverContext) ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) MapReduceExtendedCell(org.apache.hadoop.hbase.util.MapReduceExtendedCell) KeyValue(org.apache.hadoop.hbase.KeyValue) Configuration(org.apache.hadoop.conf.Configuration) Result(org.apache.hadoop.hbase.client.Result) CellImporter(org.apache.hadoop.hbase.mapreduce.Import.CellImporter) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Aggregations

Configuration (org.apache.hadoop.conf.Configuration)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1 Result (org.apache.hadoop.hbase.client.Result)1 ObserverContext (org.apache.hadoop.hbase.coprocessor.ObserverContext)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 CellImporter (org.apache.hadoop.hbase.mapreduce.Import.CellImporter)1 MapReduceExtendedCell (org.apache.hadoop.hbase.util.MapReduceExtendedCell)1 Context (org.apache.hadoop.mapreduce.Mapper.Context)1 Test (org.junit.Test)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1