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.coprocessor.example;
019
020import static org.junit.jupiter.api.Assertions.assertEquals;
021
022import org.apache.hadoop.hbase.MemoryCompactionPolicy;
023import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder;
024import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
025import org.apache.hadoop.hbase.regionserver.CompactingMemStore;
026import org.apache.hadoop.hbase.regionserver.HStore;
027import org.apache.hadoop.hbase.testclassification.CoprocessorTests;
028import org.apache.hadoop.hbase.testclassification.MediumTests;
029import org.junit.jupiter.api.AfterAll;
030import org.junit.jupiter.api.BeforeAll;
031import org.junit.jupiter.api.Tag;
032import org.junit.jupiter.api.Test;
033
034@Tag(CoprocessorTests.TAG)
035@Tag(MediumTests.TAG)
036public class TestWriteHeavyIncrementObserverWithMemStoreCompaction
037  extends WriteHeavyIncrementObserverTestBase {
038
039  @BeforeAll
040  public static void setUp() throws Exception {
041    WriteHeavyIncrementObserverTestBase.setUp();
042    UTIL.getAdmin()
043      .createTable(TableDescriptorBuilder.newBuilder(NAME)
044        .setCoprocessor(WriteHeavyIncrementObserver.class.getName())
045        .setValue(CompactingMemStore.COMPACTING_MEMSTORE_TYPE_KEY,
046          MemoryCompactionPolicy.EAGER.name())
047        .setColumnFamily(ColumnFamilyDescriptorBuilder.of(FAMILY)).build());
048    TABLE = UTIL.getConnection().getTable(NAME);
049  }
050
051  @AfterAll
052  public static void tearDown() throws Exception {
053    if (TABLE != null) {
054      TABLE.close();
055    }
056    UTIL.shutdownMiniCluster();
057  }
058
059  @Test
060  public void test() throws Exception {
061    // sleep every 10 loops to give memstore compaction enough time to finish before reaching the
062    // flush size.
063    doIncrement(10);
064    assertSum();
065    HStore store = UTIL.getHBaseCluster().findRegionsForTable(NAME).get(0).getStore(FAMILY);
066    // should have no store files created as we have done aggregating all in memory
067    assertEquals(0, store.getStorefilesCount());
068  }
069}