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