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