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.regionserver; 019 020import static org.junit.jupiter.api.Assertions.assertTrue; 021 022import org.apache.hadoop.conf.Configuration; 023import org.apache.hadoop.hbase.CellComparatorImpl; 024import org.apache.hadoop.hbase.HBaseConfiguration; 025import org.apache.hadoop.hbase.client.RegionInfoBuilder; 026import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor; 027import org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy; 028import org.apache.hadoop.hbase.testclassification.RegionServerTests; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.junit.jupiter.api.Tag; 031import org.junit.jupiter.api.Test; 032import org.mockito.Mockito; 033 034@Tag(RegionServerTests.TAG) 035@Tag(SmallTests.TAG) 036public class TestDefaultStoreEngine { 037 038 public static class DummyStoreFlusher extends DefaultStoreFlusher { 039 public DummyStoreFlusher(Configuration conf, HStore store) { 040 super(conf, store); 041 } 042 } 043 044 public static class DummyCompactor extends DefaultCompactor { 045 public DummyCompactor(Configuration conf, HStore store) { 046 super(conf, store); 047 } 048 } 049 050 public static class DummyCompactionPolicy extends RatioBasedCompactionPolicy { 051 public DummyCompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) { 052 super(conf, storeConfigInfo); 053 } 054 } 055 056 @Test 057 public void testCustomParts() throws Exception { 058 Configuration conf = HBaseConfiguration.create(); 059 conf.set(DefaultStoreEngine.DEFAULT_COMPACTOR_CLASS_KEY, DummyCompactor.class.getName()); 060 conf.set(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY, 061 DummyCompactionPolicy.class.getName()); 062 conf.set(DefaultStoreEngine.DEFAULT_STORE_FLUSHER_CLASS_KEY, DummyStoreFlusher.class.getName()); 063 HRegion mockRegion = Mockito.mock(HRegion.class); 064 HStore mockStore = Mockito.mock(HStore.class); 065 mockStore.conf = conf; 066 Mockito.when(mockStore.getRegionInfo()).thenReturn(RegionInfoBuilder.FIRST_META_REGIONINFO); 067 Mockito.when(mockStore.getHRegion()).thenReturn(mockRegion); 068 StoreEngine<?, ?, ?, ?> se = StoreEngine.create(mockStore, conf, CellComparatorImpl.COMPARATOR); 069 assertTrue(se instanceof DefaultStoreEngine); 070 assertTrue(se.getCompactionPolicy() instanceof DummyCompactionPolicy); 071 assertTrue(se.getStoreFlusher() instanceof DummyStoreFlusher); 072 assertTrue(se.getCompactor() instanceof DummyCompactor); 073 } 074}