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