HBASE-21843 RegionGroupingProvider breaks the meta wal file name pattern which may...
[hbase.git] / hbase-server / src / test / java / org / apache / hadoop / hbase / wal / TestReadWriteSeqIdFiles.java
blob8ae638ce9a4de4edc365e1e96a7ba442b39e8ef9
1 /**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org.apache.hadoop.hbase.wal;
20 import static org.junit.Assert.assertEquals;
22 import java.io.IOException;
23 import java.util.NavigableSet;
24 import org.apache.hadoop.fs.FileStatus;
25 import org.apache.hadoop.fs.FileSystem;
26 import org.apache.hadoop.fs.Path;
27 import org.apache.hadoop.fs.PathFilter;
28 import org.apache.hadoop.hbase.HBaseClassTestRule;
29 import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
30 import org.apache.hadoop.hbase.testclassification.RegionServerTests;
31 import org.apache.hadoop.hbase.testclassification.SmallTests;
32 import org.apache.hadoop.hbase.util.FSUtils;
33 import org.junit.AfterClass;
34 import org.junit.BeforeClass;
35 import org.junit.ClassRule;
36 import org.junit.Test;
37 import org.junit.experimental.categories.Category;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
41 @Category({ RegionServerTests.class, SmallTests.class })
42 public class TestReadWriteSeqIdFiles {
44 @ClassRule
45 public static final HBaseClassTestRule CLASS_RULE =
46 HBaseClassTestRule.forClass(TestReadWriteSeqIdFiles.class);
48 private static final Logger LOG = LoggerFactory.getLogger(TestReadWriteSeqIdFiles.class);
50 private static final HBaseCommonTestingUtility UTIL = new HBaseCommonTestingUtility();
52 private static FileSystem walFS;
54 private static Path REGION_DIR;
56 @BeforeClass
57 public static void setUp() throws IOException {
58 walFS = FileSystem.getLocal(UTIL.getConfiguration());
59 REGION_DIR = UTIL.getDataTestDir();
62 @AfterClass
63 public static void tearDown() throws IOException {
64 UTIL.cleanupTestDir();
67 @Test
68 public void test() throws IOException {
69 WALSplitter.writeRegionSequenceIdFile(walFS, REGION_DIR, 1000L);
70 assertEquals(1000L, WALSplitter.getMaxRegionSequenceId(walFS, REGION_DIR));
71 WALSplitter.writeRegionSequenceIdFile(walFS, REGION_DIR, 2000L);
72 assertEquals(2000L, WALSplitter.getMaxRegionSequenceId(walFS, REGION_DIR));
73 // can not write a sequence id which is smaller
74 try {
75 WALSplitter.writeRegionSequenceIdFile(walFS, REGION_DIR, 1500L);
76 } catch (IOException e) {
77 // expected
78 LOG.info("Expected error", e);
81 Path editsdir = WALSplitter.getRegionDirRecoveredEditsDir(REGION_DIR);
82 FileStatus[] files = FSUtils.listStatus(walFS, editsdir, new PathFilter() {
83 @Override
84 public boolean accept(Path p) {
85 return WALSplitter.isSequenceIdFile(p);
87 });
88 // only one seqid file should exist
89 assertEquals(1, files.length);
91 // verify all seqId files aren't treated as recovered.edits files
92 NavigableSet<Path> recoveredEdits = WALSplitter.getSplitEditFilesSorted(walFS, REGION_DIR);
93 assertEquals(0, recoveredEdits.size());