1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.apache.hadoop.hbase.mapreduce;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import org.apache.hadoop.conf.Configuration;
22 import org.apache.hadoop.hbase.Cell;
23 import org.apache.hadoop.hbase.KeyValue;
24 import org.apache.hadoop.hbase.testclassification.SmallTests;
25 import org.apache.hadoop.hbase.client.Result;
26 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
27 import org.apache.hadoop.hbase.util.Bytes;
28 import org.apache.hadoop.mapreduce.Mapper;
29 import org.junit.Test;
30 import org.junit.experimental.categories.Category;
31
32 import static org.mockito.Mockito.*;
33
34 @Category(SmallTests.class)
35 public class TestGroupingTableMapper {
36
37
38
39
40 @Test
41 public void testGroupingTableMapper() throws Exception {
42
43 GroupingTableMapper mapper = new GroupingTableMapper();
44 Configuration configuration = new Configuration();
45 configuration.set(GroupingTableMapper.GROUP_COLUMNS, "family1:clm family2:clm");
46 mapper.setConf(configuration);
47
48 Result result = mock(Result.class);
49 @SuppressWarnings("unchecked")
50 Mapper<ImmutableBytesWritable, Result, ImmutableBytesWritable, Result>.Context context =
51 mock(Mapper.Context.class);
52 context.write(any(ImmutableBytesWritable.class), any(Result.class));
53 List<Cell> keyValue = new ArrayList<Cell>();
54 byte[] row = {};
55 keyValue.add(new KeyValue(row, Bytes.toBytes("family2"), Bytes.toBytes("clm"), Bytes
56 .toBytes("value1")));
57 keyValue.add(new KeyValue(row, Bytes.toBytes("family1"), Bytes.toBytes("clm"), Bytes
58 .toBytes("value2")));
59 when(result.listCells()).thenReturn(keyValue);
60 mapper.map(null, result, context);
61
62 byte[][] data = { Bytes.toBytes("value1"), Bytes.toBytes("value2") };
63 ImmutableBytesWritable ibw = mapper.createGroupKey(data);
64 verify(context).write(ibw, result);
65 }
66
67 }