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.jupiter.api.Assertions.assertFalse; 021import static org.junit.jupiter.api.Assertions.assertThrows; 022 023import java.util.ArrayList; 024import java.util.List; 025import java.util.concurrent.CompletableFuture; 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.hbase.HBaseTestingUtil; 028import org.apache.hadoop.hbase.TableName; 029import org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager; 030import org.apache.hadoop.hbase.regionserver.HRegion; 031import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException; 032import org.apache.hadoop.hbase.testclassification.ClientTests; 033import org.apache.hadoop.hbase.testclassification.MediumTests; 034import org.apache.hadoop.hbase.util.Bytes; 035import org.apache.hadoop.hbase.util.FutureUtils; 036import org.junit.jupiter.api.AfterAll; 037import org.junit.jupiter.api.AfterEach; 038import org.junit.jupiter.api.BeforeAll; 039import org.junit.jupiter.api.BeforeEach; 040import org.junit.jupiter.api.Tag; 041import org.junit.jupiter.api.Test; 042import org.junit.jupiter.api.TestInfo; 043import org.slf4j.Logger; 044import org.slf4j.LoggerFactory; 045 046import org.apache.hbase.thirdparty.com.google.common.io.Closeables; 047 048@Tag(MediumTests.TAG) 049@Tag(ClientTests.TAG) 050public class TestFlushFromClientWithDisabledFlushProcedure { 051 052 private static final Logger LOG = 053 LoggerFactory.getLogger(TestFlushFromClientWithDisabledFlushProcedure.class); 054 private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); 055 private static AsyncConnection asyncConn; 056 private static final byte[] FAMILY = Bytes.toBytes("info"); 057 private static final byte[] QUALIFIER = Bytes.toBytes("name"); 058 059 private TableName tableName; 060 061 @BeforeAll 062 public static void setUpBeforeClass() throws Exception { 063 Configuration configuration = TEST_UTIL.getConfiguration(); 064 configuration.setBoolean(MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED, false); 065 TEST_UTIL.startMiniCluster(1); 066 asyncConn = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); 067 } 068 069 @AfterAll 070 public static void tearDownAfterClass() throws Exception { 071 Closeables.close(asyncConn, true); 072 TEST_UTIL.shutdownMiniCluster(); 073 } 074 075 @BeforeEach 076 public void setUp(TestInfo testInfo) throws Exception { 077 tableName = TableName.valueOf(testInfo.getTestMethod().get().getName()); 078 try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) { 079 List<Put> puts = new ArrayList<>(); 080 for (int i = 0; i <= 10; ++i) { 081 Put put = new Put(Bytes.toBytes(i)); 082 put.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(i)); 083 puts.add(put); 084 } 085 t.put(puts); 086 } 087 List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(tableName); 088 assertFalse(regions.isEmpty()); 089 } 090 091 @AfterEach 092 public void tearDown() throws Exception { 093 for (TableDescriptor htd : TEST_UTIL.getAdmin().listTableDescriptors()) { 094 LOG.info("Tear down, remove table=" + htd.getTableName()); 095 TEST_UTIL.deleteTable(htd.getTableName()); 096 } 097 } 098 099 @Test 100 public void flushTableWithNonExistingFamily() { 101 AsyncAdmin admin = asyncConn.getAdmin(); 102 List<byte[]> families = new ArrayList<>(); 103 families.add(FAMILY); 104 families.add(Bytes.toBytes("non_family01")); 105 families.add(Bytes.toBytes("non_family02")); 106 assertFalse(TEST_UTIL.getConfiguration().getBoolean( 107 MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED, 108 MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED_DEFAULT)); 109 CompletableFuture<Void> future = CompletableFuture.allOf(admin.flush(tableName, families)); 110 assertThrows(NoSuchColumnFamilyException.class, () -> FutureUtils.get(future)); 111 } 112}