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;
021
022import java.io.IOException;
023import java.util.Comparator;
024import org.apache.hadoop.fs.Path;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.testclassification.RegionServerTests;
027import org.apache.hadoop.hbase.testclassification.SmallTests;
028import org.junit.ClassRule;
029import org.junit.Test;
030import org.junit.experimental.categories.Category;
031
032@Category({ RegionServerTests.class, SmallTests.class })
033public class TestWALProvider {
034  @ClassRule
035  public static final HBaseClassTestRule CLASS_RULE =
036    HBaseClassTestRule.forClass(TestWALProvider.class);
037
038  /**
039   * Test start time comparator.
040   */
041  @Test
042  public void testWALStartTimeComparator() throws IOException {
043    Path metaPath1 = new Path("hdfs://localhost:59875/user/stack/test-data/"
044      + "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/"
045      + "localhost%2C59908%2C1600304600425.meta.1600304604319.meta");
046    Path metaPath2 = new Path("hdfs://localhost:59875/user/stack/test-data/"
047      + "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/"
048      + "localhost%2C59908%2C1600304600425.meta.1600304604320.meta");
049    Path path3 = new Path("hdfs://localhost:59875/user/stack/test-data/"
050      + "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/"
051      + "localhost%2C59908%2C1600304600425.1600304604321");
052    Path metaPath4 = new Path("hdfs://localhost:59875/user/stack/test-data/"
053      + "f4cb8ffa-6ff7-59a6-f167-6cc00f24899a/WALs/localhost,59908,1600304600425/"
054      + "localhost%2C59908%2C1600304600425.meta.1600304604321.meta");
055    Comparator c = new AbstractFSWALProvider.WALStartTimeComparator();
056    assertTrue(c.compare(metaPath1, metaPath1) == 0);
057    assertTrue(c.compare(metaPath2, metaPath2) == 0);
058    assertTrue(c.compare(metaPath1, metaPath2) < 0);
059    assertTrue(c.compare(metaPath2, metaPath1) > 0);
060    assertTrue(c.compare(metaPath2, path3) < 0);
061    assertTrue(c.compare(path3, metaPath4) == 0);
062  }
063}