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 java.util.List;
022import org.apache.hadoop.conf.Configuration;
023import org.apache.hadoop.fs.FileSystem;
024import org.apache.hadoop.fs.Path;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.testclassification.MediumTests;
027import org.apache.hadoop.hbase.testclassification.RegionServerTests;
028import org.apache.hadoop.hbase.util.Threads;
029import org.junit.AfterClass;
030import org.junit.BeforeClass;
031import org.junit.ClassRule;
032import org.junit.experimental.categories.Category;
033
034import org.apache.hbase.thirdparty.io.netty.channel.Channel;
035import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup;
036import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
037import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioSocketChannel;
038
039/**
040 * Provides AsyncFSWAL test cases.
041 */
042@Category({ RegionServerTests.class, MediumTests.class })
043public class TestAsyncFSWAL extends AbstractTestFSWAL {
044
045  @ClassRule
046  public static final HBaseClassTestRule CLASS_RULE =
047      HBaseClassTestRule.forClass(TestAsyncFSWAL.class);
048
049  private static EventLoopGroup GROUP;
050
051  private static Class<? extends Channel> CHANNEL_CLASS;
052
053  @BeforeClass
054  public static void setUpBeforeClass() throws Exception {
055    GROUP = new NioEventLoopGroup(1, Threads.newDaemonThreadFactory("TestAsyncFSWAL"));
056    CHANNEL_CLASS = NioSocketChannel.class;
057    AbstractTestFSWAL.setUpBeforeClass();
058  }
059
060  @AfterClass
061  public static void tearDownAfterClass() throws Exception {
062    AbstractTestFSWAL.tearDownAfterClass();
063    GROUP.shutdownGracefully();
064  }
065
066  @Override
067  protected AbstractFSWAL<?> newWAL(FileSystem fs, Path rootDir, String logDir, String archiveDir,
068      Configuration conf, List<WALActionsListener> listeners, boolean failIfWALExists,
069      String prefix, String suffix) throws IOException {
070    return new AsyncFSWAL(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix,
071        suffix, GROUP, CHANNEL_CLASS);
072  }
073
074  @Override
075  protected AbstractFSWAL<?> newSlowWAL(FileSystem fs, Path rootDir, String logDir,
076      String archiveDir, Configuration conf, List<WALActionsListener> listeners,
077      boolean failIfWALExists, String prefix, String suffix, final Runnable action)
078      throws IOException {
079    return new AsyncFSWAL(fs, rootDir, logDir, archiveDir, conf, listeners, failIfWALExists, prefix,
080        suffix, GROUP, CHANNEL_CLASS) {
081
082      @Override
083      void atHeadOfRingBufferEventHandlerAppend() {
084        action.run();
085        super.atHeadOfRingBufferEventHandlerAppend();
086      }
087
088    };
089  }
090}