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.KeyValue.KVComparator;
25  import org.apache.hadoop.hbase.regionserver.compactions.RatioBasedCompactionPolicy;
26  import org.apache.hadoop.hbase.regionserver.compactions.DefaultCompactor;
27  import org.apache.hadoop.hbase.testclassification.SmallTests;
28  import org.junit.Assert;
29  import org.junit.Test;
30  import org.junit.experimental.categories.Category;
31  import org.mockito.Mockito;
32  
33  @Category(SmallTests.class)
34  public class TestDefaultStoreEngine {
35    public static class DummyStoreFlusher extends DefaultStoreFlusher {
36      public DummyStoreFlusher(Configuration conf, Store store) {
37        super(conf, store);
38      }
39    }
40  
41    public static class DummyCompactor extends DefaultCompactor {
42      public DummyCompactor(Configuration conf, Store store) {
43        super(conf, store);
44      }
45    }
46  
47    public static class DummyCompactionPolicy extends RatioBasedCompactionPolicy {
48      public DummyCompactionPolicy(Configuration conf, StoreConfigInformation storeConfigInfo) {
49        super(conf, storeConfigInfo);
50      }
51    }
52  
53    @Test
54    public void testCustomParts() throws Exception {
55      Configuration conf = HBaseConfiguration.create();
56      conf.set(DefaultStoreEngine.DEFAULT_COMPACTOR_CLASS_KEY, DummyCompactor.class.getName());
57      conf.set(DefaultStoreEngine.DEFAULT_COMPACTION_POLICY_CLASS_KEY,
58          DummyCompactionPolicy.class.getName());
59      conf.set(DefaultStoreEngine.DEFAULT_STORE_FLUSHER_CLASS_KEY,
60          DummyStoreFlusher.class.getName());
61      Store mockStore = Mockito.mock(Store.class);
62      StoreEngine<?, ?, ?, ?> se = StoreEngine.create(mockStore, conf, new KVComparator());
63      Assert.assertTrue(se instanceof DefaultStoreEngine);
64      Assert.assertTrue(se.getCompactionPolicy() instanceof DummyCompactionPolicy);
65      Assert.assertTrue(se.getStoreFlusher() instanceof DummyStoreFlusher);
66      Assert.assertTrue(se.getCompactor() instanceof DummyCompactor);
67    }
68  }