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