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 org.apache.hadoop.hbase.HBaseClassTestRule;
023import org.apache.hadoop.hbase.TableNotEnabledException;
024import org.apache.hadoop.hbase.TableNotFoundException;
025import org.apache.hadoop.hbase.client.Admin;
026import org.apache.hadoop.hbase.testclassification.MasterTests;
027import org.apache.hadoop.hbase.testclassification.MediumTests;
028import org.junit.Assert;
029import org.junit.ClassRule;
030import org.junit.Test;
031import org.junit.experimental.categories.Category;
032
033@Category({ MasterTests.class, MediumTests.class })
034public class TestFlushTableProcedure extends TestFlushTableProcedureBase {
035
036  @ClassRule
037  public static final HBaseClassTestRule CLASS_RULE =
038    HBaseClassTestRule.forClass(TestFlushTableProcedure.class);
039
040  @Test
041  public void testSimpleFlush() throws IOException {
042    assertTableMemStoreNotEmpty();
043    TEST_UTIL.getAdmin().flush(TABLE_NAME);
044    assertTableMemStoreEmpty();
045  }
046
047  @Test
048  public void testFlushTableExceptionally() throws IOException {
049    Admin admin = TEST_UTIL.getAdmin();
050    admin.disableTable(TABLE_NAME);
051    Assert.assertThrows(TableNotEnabledException.class, () -> admin.flush(TABLE_NAME));
052    admin.deleteTable(TABLE_NAME);
053    Assert.assertThrows(TableNotFoundException.class, () -> admin.flush(TABLE_NAME));
054  }
055
056  @Test
057  public void testSingleColumnFamilyFlush() throws IOException {
058    assertTableMemStoreNotEmpty();
059    TEST_UTIL.getAdmin().flush(TABLE_NAME, Arrays.asList(FAMILY1, FAMILY2, FAMILY3));
060    assertTableMemStoreEmpty();
061  }
062
063  @Test
064  public void testMultiColumnFamilyFlush() throws IOException {
065    assertTableMemStoreNotEmpty();
066    TEST_UTIL.getAdmin().flush(TABLE_NAME, Arrays.asList(FAMILY1, FAMILY2, FAMILY3));
067    assertTableMemStoreEmpty();
068  }
069}