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.master.procedure;
019
020import java.io.IOException;
021import java.util.Arrays;
022import java.util.List;
023import org.apache.hadoop.conf.Configuration;
024import org.apache.hadoop.hbase.DoNotRetryIOException;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.HConstants;
027import org.apache.hadoop.hbase.TableName;
028import org.apache.hadoop.hbase.master.HMaster;
029import org.apache.hadoop.hbase.testclassification.MasterTests;
030import org.apache.hadoop.hbase.testclassification.MediumTests;
031import org.junit.ClassRule;
032import org.junit.Test;
033import org.junit.experimental.categories.Category;
034
035@Category({ MasterTests.class, MediumTests.class })
036public class TestFlushTableProcedureWithDoNotSupportFlushTableMaster
037  extends TestFlushTableProcedureBase {
038
039  @ClassRule
040  public static final HBaseClassTestRule CLASS_RULE =
041    HBaseClassTestRule.forClass(TestFlushTableProcedureWithDoNotSupportFlushTableMaster.class);
042
043  @Override
044  protected void addConfiguration(Configuration config) {
045    super.addConfiguration(config);
046    config.set(HConstants.MASTER_IMPL, DoNotSupportFlushTableMaster.class.getName());
047  }
048
049  @Test
050  public void testFlushFallback() throws IOException {
051    assertTableMemStoreNotEmpty();
052    TEST_UTIL.getAdmin().flush(TABLE_NAME);
053    assertTableMemStoreEmpty();
054  }
055
056  @Test
057  public void testSingleColumnFamilyFlushFallback() throws IOException {
058    assertColumnFamilyMemStoreNotEmpty(FAMILY1);
059    TEST_UTIL.getAdmin().flush(TABLE_NAME, FAMILY1);
060    assertColumnFamilyMemStoreEmpty(FAMILY1);
061  }
062
063  @Test
064  public void testMultiColumnFamilyFlushFallback() throws IOException {
065    assertTableMemStoreNotEmpty();
066    TEST_UTIL.getAdmin().flush(TABLE_NAME, Arrays.asList(FAMILY1, FAMILY2, FAMILY3));
067    assertTableMemStoreEmpty();
068  }
069
070  public static final class DoNotSupportFlushTableMaster extends HMaster {
071
072    public DoNotSupportFlushTableMaster(Configuration conf) throws IOException {
073      super(conf);
074    }
075
076    @Override
077    public long flushTable(TableName tableName, List<byte[]> columnFamilies, long nonceGroup,
078      long nonce) throws IOException {
079      throw new DoNotRetryIOException("UnsupportedOperation: flushTable");
080    }
081  }
082}