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.snapshot;
019import static org.junit.Assert.assertTrue;
020import org.apache.hadoop.fs.FileSystem;
021import org.apache.hadoop.fs.LocalFileSystem;
022import org.apache.hadoop.fs.Path;
023import org.apache.hadoop.hbase.HBaseClassTestRule;
024import org.apache.hadoop.hbase.HBaseCommonTestingUtility;
025import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils.SnapshotMock;
026import org.apache.hadoop.hbase.testclassification.MapReduceTests;
027import org.apache.hadoop.hbase.testclassification.MediumTests;
028import org.junit.Before;
029import org.junit.ClassRule;
030import org.junit.Test;
031import org.junit.experimental.categories.Category;
032import org.slf4j.Logger;
033import org.slf4j.LoggerFactory;
034
035/**
036 * Test Export Snapshot Tool; tests v2 snapshots.
037 * @see TestExportSnapshotV1NoCluster
038 */
039@Category({MapReduceTests.class, MediumTests.class})
040public class TestExportSnapshotV2NoCluster {
041  @ClassRule
042  public static final HBaseClassTestRule CLASS_RULE =
043      HBaseClassTestRule.forClass(TestExportSnapshotV2NoCluster.class);
044
045  private static final Logger LOG = LoggerFactory.getLogger(TestExportSnapshotV2NoCluster.class);
046
047  private HBaseCommonTestingUtility testUtil = new HBaseCommonTestingUtility();
048  private Path testDir;
049  private FileSystem fs;
050
051  @Before
052  public void before() throws Exception {
053    // Make sure testDir is on LocalFileSystem
054    this.fs = FileSystem.getLocal(this.testUtil.getConfiguration());
055    this.testDir = TestExportSnapshotV1NoCluster.setup(this.fs, this.testUtil);
056    LOG.info("fs={}, testDir={}", this.fs, this.testDir);
057    assertTrue("FileSystem '" + fs + "' is not local", fs instanceof LocalFileSystem);
058  }
059
060  @Test
061  public void testSnapshotWithRefsExportFileSystemState() throws Exception {
062    final SnapshotMock snapshotMock = new SnapshotMock(testUtil.getConfiguration(),
063      testDir.getFileSystem(testUtil.getConfiguration()), testDir);
064    final SnapshotMock.SnapshotBuilder builder = snapshotMock.createSnapshotV2("tableWithRefsV2",
065      "tableWithRefsV2");
066    TestExportSnapshotV1NoCluster.testSnapshotWithRefsExportFileSystemState(this.fs, builder,
067      this.testUtil, this.testDir);
068  }
069}