1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.snapshot;
19
20 import java.io.IOException;
21 import java.util.HashSet;
22 import java.util.Set;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.fs.FileSystem;
28 import org.apache.hadoop.fs.Path;
29 import org.apache.hadoop.hbase.HBaseTestingUtility;
30 import org.apache.hadoop.hbase.HConstants;
31 import org.apache.hadoop.hbase.SmallTests;
32 import org.apache.hadoop.hbase.errorhandling.ForeignExceptionDispatcher;
33 import org.apache.hadoop.hbase.protobuf.generated.HBaseProtos.SnapshotDescription;
34 import org.apache.hadoop.hbase.snapshot.ReferenceServerWALsTask;
35 import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
36 import org.apache.hadoop.hbase.snapshot.TakeSnapshotUtils;
37 import org.apache.hadoop.hbase.util.FSUtils;
38 import org.junit.Test;
39 import org.junit.experimental.categories.Category;
40 import org.mockito.Mockito;
41
42
43
44
45 @Category(SmallTests.class)
46 public class TestWALReferenceTask {
47
48 private static final Log LOG = LogFactory.getLog(TestWALReferenceTask.class);
49 private static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
50
51 @Test
52 public void testRun() throws IOException {
53 Configuration conf = UTIL.getConfiguration();
54 FileSystem fs = UTIL.getTestFileSystem();
55
56 Path testDir = UTIL.getDataTestDir();
57 Set<String> servers = new HashSet<String>();
58 Path logDir = new Path(testDir, HConstants.HREGION_LOGDIR_NAME);
59 Path server1Dir = new Path(logDir, "Server1");
60 servers.add(server1Dir.getName());
61 Path server2Dir = new Path(logDir, "me.hbase.com,56073,1348618509968");
62 servers.add(server2Dir.getName());
63
64 Path log1_1 = new Path(server1Dir, "me.hbase.com%2C56073%2C1348618509968.1348618520536");
65 Path log1_2 = new Path(server1Dir, "me.hbase.com%2C56073%2C1348618509968.1234567890123");
66
67 Path log2_1 = new Path(server2Dir, "me.hbase.com%2C56074%2C1348618509998.1348618515589");
68 Path log2_2 = new Path(server2Dir, "me.hbase.com%2C56073%2C1348618509968.1234567890123");
69
70
71 fs.createNewFile(log1_1);
72 fs.createNewFile(log1_2);
73 fs.createNewFile(log2_1);
74 fs.createNewFile(log2_2);
75
76 FSUtils.logFileSystemState(fs, testDir, LOG);
77 FSUtils.setRootDir(conf, testDir);
78 SnapshotDescription snapshot = SnapshotDescription.newBuilder()
79 .setName("testWALReferenceSnapshot").build();
80 ForeignExceptionDispatcher listener = Mockito.mock(ForeignExceptionDispatcher.class);
81
82
83 ReferenceServerWALsTask task = new ReferenceServerWALsTask(snapshot, listener, server1Dir,
84 conf, fs);
85 task.call();
86
87
88 task = new ReferenceServerWALsTask(snapshot, listener, server2Dir, conf, fs);
89 task.call();
90
91
92 FSUtils.logFileSystemState(fs, testDir, LOG);
93 Path workingDir = SnapshotDescriptionUtils.getWorkingSnapshotDir(snapshot, testDir);
94 Path snapshotLogDir = new Path(workingDir, HConstants.HREGION_LOGDIR_NAME);
95
96
97 TakeSnapshotUtils.verifyAllLogsGotReferenced(fs, logDir, servers, snapshot, snapshotLogDir);
98
99
100 Mockito.verify(listener, Mockito.atLeastOnce()).rethrowException();
101 Mockito.verifyNoMoreInteractions(listener);
102 }
103 }