View Javadoc

1   /*
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.regionserver;
21  
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.hbase.HBaseConfiguration;
24  import org.apache.hadoop.hbase.HColumnDescriptor;
25  import org.apache.hadoop.hbase.KeyValue.KVComparator;
26  import org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy;
27  import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor;
28  import org.apache.hadoop.hbase.testclassification.SmallTests;
29  import org.junit.Assert;
30  import org.junit.Test;
31  import org.junit.experimental.categories.Category;
32  import org.mockito.Mockito;
33  
34  @Category(SmallTests.class)
35  public class TestDefaultStoreEngine {
36    public static class DummyStoreFlusher extends DefaultStoreFlusher {
37      public DummyStoreFlusher(Configuration conf, Store store) {
38        super(conf, store);
39      }
40    }
41  
42    public static class DummyCompactor extends DefaultCompactor {
43      public DummyCompactor(Configuration conf, Store store) {
44        super(conf, store);
45      }
46    }
47  
48    public static class DummyCompactionPolicy extends RatioBasedCompactionPolicy {
49      public DummyCompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) {
50        super(conf, storeConfigInfo);
51      }
52    }
53  
54    @Test
55    public void testCustomParts() throws Exception {
56      Configuration conf = HBaseConfiguration.create();
57      conf.set(DefaultStoreEngine.DEFAULT_COMPACTOR_CLASS_KEY, DummyCompactor.class.getName());
58      conf.set(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY,
59          DummyCompactionPolicy.class.getName());
60      conf.set(DefaultStoreEngine.DEFAULT_STORE_FLUSHER_CLASS_KEY,
61          DummyStoreFlusher.class.getName());
62      Store mockStore = Mockito.mock(Store.class);
63      StoreEngine<?, ?, ?, ?> se = StoreEngine.create(mockStore, conf, new KVComparator());
64      Assert.assertTrue(se instanceof DefaultStoreEngine);
65      Assert.assertTrue(se.getCompactionPolicy() instanceof DummyCompactionPolicy);
66      Assert.assertTrue(se.getStoreFlusher() instanceof DummyStoreFlusher);
67      Assert.assertTrue(se.getCompactor() instanceof DummyCompactor);
68    }
69  }