1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.regionserver.wal;
19  
20  import static org.junit.Assert.assertTrue;
21  
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.hbase.SmallTests;
24  import org.junit.Test;
25  import org.junit.experimental.categories.Category;
26  
27  /**
28   * Test that we can create, load, setup our own custom codec
29   */
30  @Category(SmallTests.class)
31  public class TestCustomWALEditCodec {
32  
33    public static class CustomWALEditCodec extends WALEditCodec {
34      public boolean initialized = false;
35      public boolean compressionSet = false;
36  
37      @Override
38      public void init(Configuration conf) {
39        this.initialized = true;
40      }
41  
42      @Override
43      public void setCompression(CompressionContext compression) {
44        this.compressionSet = true;
45      }
46    }
47  
48    /**
49     * Test that a custom WALEditCodec will be completely setup when it is instantiated via
50     * {@link WALEditCodec}
51     * @throws Exception on failure
52     */
53    @Test
54    public void testCreatePreparesCodec() throws Exception {
55      Configuration conf = new Configuration(false);
56      conf.setClass(WALEditCodec.WAL_EDIT_CODEC_CLASS_KEY, CustomWALEditCodec.class, WALEditCodec.class);
57      CustomWALEditCodec codec = (CustomWALEditCodec) WALEditCodec.create(conf, null);
58      assertTrue("Custom codec didn't get initialized", codec.initialized);
59      assertTrue("Custom codec didn't have compression set", codec.compressionSet);
60    }
61  }