use of org.apache.hadoop.hbase.util.MapReduceExtendedCell 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);
}
use of org.apache.hadoop.hbase.util.MapReduceExtendedCell in project hbase by apache.
the class CellSortReducer method reduce.
protected void reduce(ImmutableBytesWritable row, Iterable<Cell> kvs, Reducer<ImmutableBytesWritable, Cell, ImmutableBytesWritable, Cell>.Context context) throws java.io.IOException, InterruptedException {
TreeSet<Cell> map = new TreeSet<>(CellComparator.getInstance());
for (Cell kv : kvs) {
try {
map.add(PrivateCellUtil.deepClone(kv));
} catch (CloneNotSupportedException e) {
throw new IOException(e);
}
}
context.setStatus("Read " + map.getClass());
int index = 0;
for (Cell kv : map) {
context.write(row, new MapReduceExtendedCell(kv));
if (++index % 100 == 0)
context.setStatus("Wrote " + index);
}
}
use of org.apache.hadoop.hbase.util.MapReduceExtendedCell in project hbase by apache.
the class TestWALPlayer method testWALKeyValueMapper.
private void testWALKeyValueMapper(final String tableConfigKey) throws Exception {
Configuration configuration = new Configuration();
configuration.set(tableConfigKey, "table");
WALKeyValueMapper mapper = new WALKeyValueMapper();
WALKey key = mock(WALKey.class);
when(key.getTableName()).thenReturn(TableName.valueOf("table"));
@SuppressWarnings("unchecked") Mapper<WALKey, WALEdit, ImmutableBytesWritable, Cell>.Context context = mock(Context.class);
when(context.getConfiguration()).thenReturn(configuration);
WALEdit value = mock(WALEdit.class);
ArrayList<Cell> values = new ArrayList<>();
KeyValue kv1 = new KeyValue(Bytes.toBytes("row"), Bytes.toBytes("family"), null);
values.add(kv1);
when(value.getCells()).thenReturn(values);
mapper.setup(context);
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("row", Bytes.toString(writer.get()));
assertEquals("row", Bytes.toString(CellUtil.cloneRow(key)));
return null;
}
}).when(context).write(any(), any());
mapper.map(key, value, context);
}
Aggregations