|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one |
| 3 | + * or more contributor license agreements. See the NOTICE file |
| 4 | + * distributed with this work for additional information |
| 5 | + * regarding copyright ownership. The ASF licenses this file |
| 6 | + * to you under the Apache License, Version 2.0 (the |
| 7 | + * "License"); you may not use this file except in compliance |
| 8 | + * with the License. You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package org.apache.hadoop.hbase.client; |
| 19 | + |
| 20 | +import static org.junit.Assert.assertFalse; |
| 21 | +import static org.junit.Assert.assertThrows; |
| 22 | + |
| 23 | +import java.util.ArrayList; |
| 24 | +import java.util.List; |
| 25 | +import java.util.concurrent.CompletableFuture; |
| 26 | +import org.apache.hadoop.conf.Configuration; |
| 27 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 28 | +import org.apache.hadoop.hbase.HBaseTestingUtil; |
| 29 | +import org.apache.hadoop.hbase.TableName; |
| 30 | +import org.apache.hadoop.hbase.procedure.flush.MasterFlushTableProcedureManager; |
| 31 | +import org.apache.hadoop.hbase.regionserver.HRegion; |
| 32 | +import org.apache.hadoop.hbase.regionserver.NoSuchColumnFamilyException; |
| 33 | +import org.apache.hadoop.hbase.testclassification.ClientTests; |
| 34 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 35 | +import org.apache.hadoop.hbase.util.Bytes; |
| 36 | +import org.apache.hadoop.hbase.util.FutureUtils; |
| 37 | +import org.junit.After; |
| 38 | +import org.junit.AfterClass; |
| 39 | +import org.junit.Before; |
| 40 | +import org.junit.BeforeClass; |
| 41 | +import org.junit.ClassRule; |
| 42 | +import org.junit.Rule; |
| 43 | +import org.junit.Test; |
| 44 | +import org.junit.experimental.categories.Category; |
| 45 | +import org.junit.rules.TestName; |
| 46 | +import org.slf4j.Logger; |
| 47 | +import org.slf4j.LoggerFactory; |
| 48 | + |
| 49 | +import org.apache.hbase.thirdparty.com.google.common.io.Closeables; |
| 50 | + |
| 51 | +@Category({ MediumTests.class, ClientTests.class }) |
| 52 | +public class TestFlushFromClientWithDisabledFlushProcedure { |
| 53 | + |
| 54 | + @ClassRule |
| 55 | + public static final HBaseClassTestRule CLASS_RULE = |
| 56 | + HBaseClassTestRule.forClass(TestFlushFromClientWithDisabledFlushProcedure.class); |
| 57 | + |
| 58 | + private static final Logger LOG = |
| 59 | + LoggerFactory.getLogger(TestFlushFromClientWithDisabledFlushProcedure.class); |
| 60 | + private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); |
| 61 | + private static AsyncConnection asyncConn; |
| 62 | + private static final byte[] FAMILY = Bytes.toBytes("info"); |
| 63 | + private static final byte[] QUALIFIER = Bytes.toBytes("name"); |
| 64 | + |
| 65 | + @Rule |
| 66 | + public TestName name = new TestName(); |
| 67 | + |
| 68 | + private TableName tableName; |
| 69 | + |
| 70 | + @BeforeClass |
| 71 | + public static void setUpBeforeClass() throws Exception { |
| 72 | + Configuration configuration = TEST_UTIL.getConfiguration(); |
| 73 | + configuration.setBoolean(MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED, false); |
| 74 | + TEST_UTIL.startMiniCluster(1); |
| 75 | + asyncConn = ConnectionFactory.createAsyncConnection(TEST_UTIL.getConfiguration()).get(); |
| 76 | + } |
| 77 | + |
| 78 | + @AfterClass |
| 79 | + public static void tearDownAfterClass() throws Exception { |
| 80 | + Closeables.close(asyncConn, true); |
| 81 | + TEST_UTIL.shutdownMiniCluster(); |
| 82 | + } |
| 83 | + |
| 84 | + @Before |
| 85 | + public void setUp() throws Exception { |
| 86 | + tableName = TableName.valueOf(name.getMethodName()); |
| 87 | + try (Table t = TEST_UTIL.createTable(tableName, FAMILY)) { |
| 88 | + List<Put> puts = new ArrayList<>(); |
| 89 | + for (int i = 0; i <= 10; ++i) { |
| 90 | + Put put = new Put(Bytes.toBytes(i)); |
| 91 | + put.addColumn(FAMILY, QUALIFIER, Bytes.toBytes(i)); |
| 92 | + puts.add(put); |
| 93 | + } |
| 94 | + t.put(puts); |
| 95 | + } |
| 96 | + List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(tableName); |
| 97 | + assertFalse(regions.isEmpty()); |
| 98 | + } |
| 99 | + |
| 100 | + @After |
| 101 | + public void tearDown() throws Exception { |
| 102 | + for (TableDescriptor htd : TEST_UTIL.getAdmin().listTableDescriptors()) { |
| 103 | + LOG.info("Tear down, remove table=" + htd.getTableName()); |
| 104 | + TEST_UTIL.deleteTable(htd.getTableName()); |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + @Test |
| 109 | + public void flushTableWithNonExistingFamily() { |
| 110 | + AsyncAdmin admin = asyncConn.getAdmin(); |
| 111 | + List<byte[]> families = new ArrayList<>(); |
| 112 | + families.add(FAMILY); |
| 113 | + families.add(Bytes.toBytes("non_family01")); |
| 114 | + families.add(Bytes.toBytes("non_family02")); |
| 115 | + assertFalse(TEST_UTIL.getConfiguration().getBoolean( |
| 116 | + MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED, |
| 117 | + MasterFlushTableProcedureManager.FLUSH_PROCEDURE_ENABLED_DEFAULT)); |
| 118 | + CompletableFuture<Void> future = CompletableFuture.allOf(admin.flush(tableName, families)); |
| 119 | + assertThrows(NoSuchColumnFamilyException.class, () -> FutureUtils.get(future)); |
| 120 | + } |
| 121 | +} |
0 commit comments