001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.wal;
019
020import static org.junit.Assert.assertTrue;
021import java.io.IOException;
022import java.util.Comparator;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.testclassification.RegionServerTests;
026import org.apache.hadoop.hbase.testclassification.SmallTests;
027import org.junit.ClassRule;
028import org.junit.Test;
029import org.junit.experimental.categories.Category;
030
031@Category({ RegionServerTests.class, SmallTests.class})
032public class TestWALProvider {
033  @ClassRule
034  public static final HBaseClassTestRule CLASS_RULE =
035    HBaseClassTestRule.forClass(TestWALProvider.class);
036
037  /**
038   * Test start time comparator.
039   */
040  @Test
041  public void testWALStartTimeComparator() throws IOException {
042    Path metaPath1 = new Path("hdfs://localhost:59875/user/stack/test-data/" +
043      "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/" +
044      "localhost%2C59908%2C1600304600425.meta.1600304604319.meta");
045    Path metaPath2 = new Path("hdfs://localhost:59875/user/stack/test-data/" +
046      "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/" +
047      "localhost%2C59908%2C1600304600425.meta.1600304604320.meta");
048    Path path3 = new Path("hdfs://localhost:59875/user/stack/test-data/" +
049      "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/" +
050      "localhost%2C59908%2C1600304600425.1600304604321");
051    Path metaPath4 = new Path("hdfs://localhost:59875/user/stack/test-data/" +
052      "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/" +
053      "localhost%2C59908%2C1600304600425.meta.1600304604321.meta");
054    Comparator c = new AbstractFSWALProvider.WALStartTimeComparator();
055    assertTrue(c.compare(metaPath1, metaPath1) == 0);
056    assertTrue(c.compare(metaPath2, metaPath2) == 0);
057    assertTrue(c.compare(metaPath1, metaPath2) < 0);
058    assertTrue(c.compare(metaPath2, metaPath1) > 0);
059    assertTrue(c.compare(metaPath2, path3) < 0);
060    assertTrue(c.compare(path3, metaPath4) == 0);
061  }
062}