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.client;
019
020import static org.junit.Assert.assertEquals;
021import static org.junit.Assert.assertThrows;
022
023import java.io.IOException;
024import org.apache.hadoop.hbase.HBaseClassTestRule;
025import org.apache.hadoop.hbase.TableName;
026import org.apache.hadoop.hbase.regionserver.storefiletracker.StoreFileTrackerFactory;
027import org.apache.hadoop.hbase.testclassification.ClientTests;
028import org.apache.hadoop.hbase.testclassification.LargeTests;
029import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
030import org.junit.ClassRule;
031import org.junit.Test;
032import org.junit.experimental.categories.Category;
033
034@Category({ LargeTests.class, ClientTests.class })
035public class TestCloneSnapshotFromClientCustomSFT extends CloneSnapshotFromClientTestBase {
036
037  @ClassRule
038  public static final HBaseClassTestRule CLASS_RULE =
039    HBaseClassTestRule.forClass(TestCloneSnapshotFromClientCustomSFT.class);
040
041  public static final String CLONE_SFT = "FILE";
042
043  @Test
044  public void testCloneSnapshotWithCustomSFT() throws IOException, InterruptedException {
045    TableName clonedTableName =
046      TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime());
047
048    admin.cloneSnapshot(snapshotName1, clonedTableName, false, CLONE_SFT);
049    verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);
050
051    TableDescriptor td = admin.getDescriptor(clonedTableName);
052    assertEquals(CLONE_SFT, td.getValue(StoreFileTrackerFactory.TRACKER_IMPL));
053
054    TEST_UTIL.deleteTable(clonedTableName);
055  }
056
057  @Test
058  public void testCloneSnapshotWithIncorrectCustomSFT() throws IOException, InterruptedException {
059    TableName clonedTableName =
060      TableName.valueOf(getValidMethodName() + "-" + EnvironmentEdgeManager.currentTime());
061
062    IOException ioException = assertThrows(IOException.class, () -> {
063      admin.cloneSnapshot(snapshotName1, clonedTableName, false, "IncorrectSFT");
064    });
065
066    assertEquals(
067      "java.lang.RuntimeException: java.lang.RuntimeException: "
068        + "java.lang.ClassNotFoundException: Class IncorrectSFT not found",
069      ioException.getMessage());
070  }
071}