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