Search in sources :

Example 1 with WALKeyValueMapper

use of org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper 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, KeyValue>.Context<WALKey, WALEdit, ImmutableBytesWritable, KeyValue> 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.getArguments()[0];
            KeyValue key = (KeyValue) invocation.getArguments()[1];
            assertEquals("row", Bytes.toString(writer.get()));
            assertEquals("row", Bytes.toString(CellUtil.cloneRow(key)));
            return null;
        }
    }).when(context).write(any(ImmutableBytesWritable.class), any(KeyValue.class));
    mapper.map(key, value, context);
}
Also used : ImmutableBytesWritable(org.apache.hadoop.hbase.io.ImmutableBytesWritable) KeyValue(org.apache.hadoop.hbase.KeyValue) Configuration(org.apache.hadoop.conf.Configuration) ArrayList(java.util.ArrayList) WALKey(org.apache.hadoop.hbase.wal.WALKey) Mapper(org.apache.hadoop.mapreduce.Mapper) WALKeyValueMapper(org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper) WALEdit(org.apache.hadoop.hbase.regionserver.wal.WALEdit) WALKeyValueMapper(org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Cell(org.apache.hadoop.hbase.Cell)

Aggregations

ArrayList (java.util.ArrayList)1 Configuration (org.apache.hadoop.conf.Configuration)1 Cell (org.apache.hadoop.hbase.Cell)1 KeyValue (org.apache.hadoop.hbase.KeyValue)1 ImmutableBytesWritable (org.apache.hadoop.hbase.io.ImmutableBytesWritable)1 WALKeyValueMapper (org.apache.hadoop.hbase.mapreduce.WALPlayer.WALKeyValueMapper)1 WALEdit (org.apache.hadoop.hbase.regionserver.wal.WALEdit)1 WALKey (org.apache.hadoop.hbase.wal.WALKey)1 Mapper (org.apache.hadoop.mapreduce.Mapper)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1