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.regionserver.wal; 019 020import java.io.IOException; 021import org.apache.hadoop.conf.Configuration; 022import org.apache.hadoop.fs.FileSystem; 023import org.apache.hadoop.fs.Path; 024import org.apache.hadoop.hbase.HConstants; 025import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor; 026import org.apache.hadoop.hbase.testclassification.MediumTests; 027import org.apache.hadoop.hbase.testclassification.RegionServerTests; 028import org.apache.hadoop.hbase.util.Threads; 029import org.apache.hadoop.hbase.wal.WAL; 030import org.apache.hadoop.hbase.wal.WALFactory; 031import org.junit.jupiter.api.AfterAll; 032import org.junit.jupiter.api.BeforeAll; 033import org.junit.jupiter.api.Tag; 034import org.junit.jupiter.api.TestInfo; 035 036import org.apache.hbase.thirdparty.com.google.common.util.concurrent.ThreadFactoryBuilder; 037import org.apache.hbase.thirdparty.io.netty.channel.Channel; 038import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup; 039import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup; 040import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioSocketChannel; 041 042@Tag(RegionServerTests.TAG) 043@Tag(MediumTests.TAG) 044public class TestAsyncWALReplay extends AbstractTestWALReplay { 045 046 private static EventLoopGroup GROUP; 047 048 private static Class<? extends Channel> CHANNEL_CLASS; 049 050 @BeforeAll 051 public static void setUpBeforeClass(TestInfo testInfo) throws Exception { 052 if (testInfo.getTestClass().get() == TestAsyncWALReplay.class) { 053 setUpBeforeClass(); 054 } 055 } 056 057 public static void setUpBeforeClass() throws Exception { 058 GROUP = new NioEventLoopGroup(1, 059 new ThreadFactoryBuilder().setNameFormat("TestAsyncWALReplay-pool-%d").setDaemon(true) 060 .setUncaughtExceptionHandler(Threads.LOGGING_EXCEPTION_HANDLER).build()); 061 CHANNEL_CLASS = NioSocketChannel.class; 062 Configuration conf = AbstractTestWALReplay.TEST_UTIL.getConfiguration(); 063 conf.set(WALFactory.WAL_PROVIDER, "asyncfs"); 064 AbstractTestWALReplay.setUpBeforeClass(); 065 } 066 067 @AfterAll 068 public static void tearDownAfterClass() throws Exception { 069 if (GROUP != null) { 070 GROUP.shutdownGracefully(); 071 } 072 } 073 074 @Override 075 protected WAL createWAL(Configuration c, Path hbaseRootDir, String logName) throws IOException { 076 FileSystem fs = hbaseRootDir.getFileSystem(c); 077 fs.mkdirs(new Path(hbaseRootDir, logName)); 078 AsyncFSWAL wal = 079 new AsyncFSWAL(fs, null, hbaseRootDir, logName, HConstants.HREGION_OLDLOGDIR_NAME, c, null, 080 true, null, null, null, null, GROUP, CHANNEL_CLASS, StreamSlowMonitor.create(c, "monitor")); 081 wal.init(); 082 return wal; 083 } 084}