1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.mapreduce;
19
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertTrue;
22 import static org.junit.Assert.assertNull;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.fs.Path;
26 import org.apache.hadoop.hbase.CellUtil;
27 import org.apache.hadoop.hbase.TableName;
28 import org.apache.hadoop.hbase.HBaseTestingUtility;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.LargeTests;
31 import org.apache.hadoop.hbase.MiniHBaseCluster;
32 import org.apache.hadoop.hbase.client.Delete;
33 import org.apache.hadoop.hbase.client.Get;
34 import org.apache.hadoop.hbase.client.HTable;
35 import org.apache.hadoop.hbase.client.Put;
36 import org.apache.hadoop.hbase.client.Result;
37 import org.apache.hadoop.hbase.regionserver.wal.HLog;
38 import org.apache.hadoop.hbase.util.Bytes;
39 import org.junit.AfterClass;
40 import org.junit.BeforeClass;
41 import org.junit.Test;
42 import org.junit.experimental.categories.Category;
43
44
45
46
47 @Category(LargeTests.class)
48 public class TestWALPlayer {
49 private static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
50 private static MiniHBaseCluster cluster;
51
52 @BeforeClass
53 public static void beforeClass() throws Exception {
54 cluster = TEST_UTIL.startMiniCluster();
55 TEST_UTIL.startMiniMapReduceCluster();
56 }
57
58 @AfterClass
59 public static void afterClass() throws Exception {
60 TEST_UTIL.shutdownMiniMapReduceCluster();
61 TEST_UTIL.shutdownMiniCluster();
62 }
63
64
65
66
67
68 @Test
69 public void testWALPlayer() throws Exception {
70 final byte[] TABLENAME1 = Bytes.toBytes("testWALPlayer1");
71 final byte[] TABLENAME2 = Bytes.toBytes("testWALPlayer2");
72 final byte[] FAMILY = Bytes.toBytes("family");
73 final byte[] COLUMN1 = Bytes.toBytes("c1");
74 final byte[] COLUMN2 = Bytes.toBytes("c2");
75 final byte[] ROW = Bytes.toBytes("row");
76 HTable t1 = TEST_UTIL.createTable(TABLENAME1, FAMILY);
77 HTable t2 = TEST_UTIL.createTable(TABLENAME2, FAMILY);
78
79
80 Put p = new Put(ROW);
81 p.add(FAMILY, COLUMN1, COLUMN1);
82 p.add(FAMILY, COLUMN2, COLUMN2);
83 t1.put(p);
84
85 Delete d = new Delete(ROW);
86 d.deleteColumns(FAMILY, COLUMN1);
87 t1.delete(d);
88
89
90 HLog log = cluster.getRegionServer(0).getWAL();
91 log.rollWriter();
92 String walInputDir = new Path(cluster.getMaster().getMasterFileSystem()
93 .getRootDir(), HConstants.HREGION_LOGDIR_NAME).toString();
94
95 WALPlayer player = new WALPlayer(TEST_UTIL.getConfiguration());
96 assertEquals(0, player.run(new String[] { walInputDir, Bytes.toString(TABLENAME1),
97 Bytes.toString(TABLENAME2) }));
98
99
100 Get g = new Get(ROW);
101 Result r = t2.get(g);
102 assertEquals(1, r.size());
103 assertTrue(CellUtil.matchingQualifier(r.rawCells()[0], COLUMN2));
104 }
105 }