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.io.asyncfs;
019
020import java.io.IOException;
021import java.util.concurrent.ExecutionException;
022import org.apache.hadoop.fs.FileSystem;
023import org.apache.hadoop.fs.Path;
024import org.apache.hadoop.hbase.HBaseCommonTestingUtil;
025import org.apache.hadoop.hbase.io.asyncfs.monitor.StreamSlowMonitor;
026import org.apache.hadoop.hbase.testclassification.MiscTests;
027import org.apache.hadoop.hbase.testclassification.SmallTests;
028import org.apache.hadoop.hbase.util.CommonFSUtils;
029import org.junit.jupiter.api.AfterAll;
030import org.junit.jupiter.api.Tag;
031import org.junit.jupiter.api.Test;
032
033import org.apache.hbase.thirdparty.io.netty.channel.Channel;
034import org.apache.hbase.thirdparty.io.netty.channel.EventLoopGroup;
035import org.apache.hbase.thirdparty.io.netty.channel.nio.NioEventLoopGroup;
036import org.apache.hbase.thirdparty.io.netty.channel.socket.nio.NioSocketChannel;
037
038@Tag(MiscTests.TAG)
039@Tag(SmallTests.TAG)
040public class TestLocalAsyncOutput {
041
042  private static EventLoopGroup GROUP = new NioEventLoopGroup();
043
044  private static Class<? extends Channel> CHANNEL_CLASS = NioSocketChannel.class;
045
046  private static final HBaseCommonTestingUtil TEST_UTIL = new HBaseCommonTestingUtil();
047
048  private static StreamSlowMonitor MONITOR;
049
050  @AfterAll
051  public static void tearDownAfterClass() throws Exception {
052    TEST_UTIL.cleanupTestDir();
053    GROUP.shutdownGracefully().get();
054    MONITOR = StreamSlowMonitor.create(TEST_UTIL.getConfiguration(), "testMonitor");
055  }
056
057  @Test
058  public void test() throws IOException, InterruptedException, ExecutionException,
059    CommonFSUtils.StreamLacksCapabilityException {
060    Path f = new Path(TEST_UTIL.getDataTestDir(), "test");
061    FileSystem fs = FileSystem.getLocal(TEST_UTIL.getConfiguration());
062    AsyncFSOutput out = AsyncFSOutputHelper.createOutput(fs, f, false, true,
063      fs.getDefaultReplication(f), fs.getDefaultBlockSize(f), GROUP, CHANNEL_CLASS, MONITOR, true);
064    TestFanOutOneBlockAsyncDFSOutput.writeAndVerify(fs, f, out);
065  }
066}