1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.master.snapshot;
19
20 import static org.junit.Assert.assertFalse;
21
22 import java.io.IOException;
23
24 import org.apache.hadoop.conf.Configuration;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.hbase.HBaseTestingUtility;
28 import org.apache.hadoop.hbase.HConstants;
29 import org.apache.hadoop.hbase.testclassification.SmallTests;
30 import org.apache.hadoop.hbase.snapshot.SnapshotDescriptionUtils;
31 import org.apache.hadoop.hbase.util.Bytes;
32 import org.apache.hadoop.hbase.util.FSUtils;
33 import org.junit.AfterClass;
34 import org.junit.Test;
35 import org.junit.experimental.categories.Category;
36
37
38
39
40 @Category(SmallTests.class)
41 public class TestSnapshotLogCleaner {
42
43 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
44
45 @AfterClass
46 public static void cleanup() throws IOException {
47 Configuration conf = TEST_UTIL.getConfiguration();
48 Path rootDir = FSUtils.getRootDir(conf);
49 FileSystem fs = FileSystem.get(conf);
50
51 fs.delete(rootDir, true);
52 }
53
54 @Test
55 public void testFindsSnapshotFilesWhenCleaning() throws IOException {
56 Configuration conf = TEST_UTIL.getConfiguration();
57 FSUtils.setRootDir(conf, TEST_UTIL.getDataTestDir());
58 Path rootDir = FSUtils.getRootDir(conf);
59 FileSystem fs = FileSystem.get(conf);
60 SnapshotLogCleaner cleaner = new SnapshotLogCleaner();
61 cleaner.setConf(conf);
62
63
64 String snapshotName = "snapshot";
65 byte[] snapshot = Bytes.toBytes(snapshotName);
66 Path snapshotDir = SnapshotDescriptionUtils.getCompletedSnapshotDir(snapshotName, rootDir);
67 Path snapshotLogDir = new Path(snapshotDir, HConstants.HREGION_LOGDIR_NAME);
68 String timestamp = "1339643343027";
69 String hostFromMaster = "localhost%2C59648%2C1339643336601";
70
71 Path hostSnapshotLogDir = new Path(snapshotLogDir, hostFromMaster);
72 String snapshotlogfile = hostFromMaster + "." + timestamp + ".hbase";
73
74
75 fs.create(new Path(hostSnapshotLogDir, snapshotlogfile));
76
77
78 Path oldlogDir = new Path(rootDir, HConstants.HREGION_OLDLOGDIR_NAME);
79 Path logFile = new Path(oldlogDir, snapshotlogfile);
80 fs.create(logFile);
81
82
83 assertFalse(cleaner.isFileDeletable(fs.getFileStatus(logFile)));
84 }
85 }