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.mapreduce; 019 020import static org.junit.jupiter.api.Assertions.assertFalse; 021 022import org.apache.commons.lang3.ArrayUtils; 023import org.apache.hadoop.hbase.HBaseTestingUtil; 024import org.apache.hadoop.hbase.TableName; 025import org.apache.hadoop.hbase.client.Table; 026import org.apache.hadoop.hbase.client.TableDescriptor; 027import org.junit.jupiter.api.AfterAll; 028import org.junit.jupiter.api.BeforeAll; 029import org.junit.jupiter.api.Test; 030import org.junit.jupiter.api.TestInfo; 031 032/** 033 * Test CopyTable between clusters 034 */ 035public abstract class CopyTableToPeerClusterTestBase extends CopyTableTestBase { 036 037 protected static final HBaseTestingUtil UTIL1 = new HBaseTestingUtil(); 038 039 protected static final HBaseTestingUtil UTIL2 = new HBaseTestingUtil(); 040 041 @BeforeAll 042 public static void beforeClass() throws Exception { 043 UTIL1.startMiniCluster(3); 044 UTIL2.startMiniCluster(3); 045 } 046 047 @AfterAll 048 public static void afterClass() throws Exception { 049 UTIL1.shutdownMiniCluster(); 050 UTIL2.shutdownMiniCluster(); 051 } 052 053 @Override 054 protected Table createSourceTable(TableDescriptor desc) throws Exception { 055 return UTIL1.createTable(desc, null); 056 } 057 058 @Override 059 protected Table createTargetTable(TableDescriptor desc) throws Exception { 060 return UTIL2.createTable(desc, null); 061 } 062 063 @Override 064 protected void dropSourceTable(TableName tableName) throws Exception { 065 UTIL1.deleteTable(tableName); 066 } 067 068 @Override 069 protected void dropTargetTable(TableName tableName) throws Exception { 070 UTIL2.deleteTable(tableName); 071 } 072 073 @Override 074 protected String[] getPeerClusterOptions() throws Exception { 075 return new String[] { "--peer.uri=" + UTIL2.getRpcConnnectionURI() }; 076 } 077 078 /** 079 * Simple end-to-end test 080 */ 081 @Test 082 public void testCopyTable(TestInfo testInfo) throws Exception { 083 doCopyTableTest(UTIL1.getConfiguration(), false, testInfo); 084 } 085 086 /** 087 * Simple end-to-end test on table with MOB 088 */ 089 @Test 090 public void testCopyTableWithMob(TestInfo testInfo) throws Exception { 091 doCopyTableTestWithMob(UTIL1.getConfiguration(), false, testInfo); 092 } 093 094 @Test 095 public void testStartStopRow(TestInfo testInfo) throws Exception { 096 testStartStopRow(UTIL1.getConfiguration(), testInfo); 097 } 098 099 /** 100 * Test copy of table from sourceTable to targetTable all rows from family a 101 */ 102 @Test 103 public void testRenameFamily(TestInfo testInfo) throws Exception { 104 testRenameFamily(UTIL1.getConfiguration(), testInfo); 105 } 106 107 @Test 108 public void testBulkLoadNotSupported(TestInfo testInfo) throws Exception { 109 TableName tableName1 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "1"); 110 TableName tableName2 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "2"); 111 try (Table t1 = UTIL1.createTable(tableName1, FAMILY_A); 112 Table t2 = UTIL2.createTable(tableName2, FAMILY_A)) { 113 String[] args = ArrayUtils.addAll(getPeerClusterOptions(), 114 "--new.name=" + tableName2.getNameAsString(), "--bulkload", tableName1.getNameAsString()); 115 assertFalse(runCopy(UTIL1.getConfiguration(), args)); 116 } finally { 117 UTIL1.deleteTable(tableName1); 118 UTIL2.deleteTable(tableName2); 119 } 120 } 121 122 @Test 123 public void testSnapshotNotSupported(TestInfo testInfo) throws Exception { 124 TableName tableName1 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "1"); 125 TableName tableName2 = TableName.valueOf(testInfo.getTestMethod().get().getName() + "2"); 126 String snapshot = tableName1.getNameAsString() + "_snapshot"; 127 try (Table t1 = UTIL1.createTable(tableName1, FAMILY_A); 128 Table t2 = UTIL2.createTable(tableName2, FAMILY_A)) { 129 UTIL1.getAdmin().snapshot(snapshot, tableName1); 130 String[] args = ArrayUtils.addAll(getPeerClusterOptions(), 131 "--new.name=" + tableName2.getNameAsString(), "--snapshot", snapshot); 132 assertFalse(runCopy(UTIL1.getConfiguration(), args)); 133 } finally { 134 UTIL1.getAdmin().deleteSnapshot(snapshot); 135 UTIL1.deleteTable(tableName1); 136 UTIL2.deleteTable(tableName2); 137 } 138 } 139}