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.client;
019
020import static org.junit.Assert.fail;
021
022import java.util.Arrays;
023import java.util.List;
024import java.util.function.Consumer;
025import org.apache.hadoop.hbase.HBaseClassTestRule;
026import org.apache.hadoop.hbase.HColumnDescriptor;
027import org.apache.hadoop.hbase.KeepDeletedCells;
028import org.apache.hadoop.hbase.MemoryCompactionPolicy;
029import org.apache.hadoop.hbase.io.compress.Compression;
030import org.apache.hadoop.hbase.io.encoding.DataBlockEncoding;
031import org.apache.hadoop.hbase.regionserver.BloomType;
032import org.apache.hadoop.hbase.testclassification.ClientTests;
033import org.apache.hadoop.hbase.testclassification.SmallTests;
034import org.apache.hadoop.hbase.util.BuilderStyleTest;
035import org.apache.hadoop.hbase.util.Bytes;
036import org.junit.ClassRule;
037import org.junit.Rule;
038import org.junit.Test;
039import org.junit.experimental.categories.Category;
040import org.junit.rules.TestName;
041
042@Category({ ClientTests.class, SmallTests.class })
043public class TestImmutableHColumnDescriptor {
044
045  @ClassRule
046  public static final HBaseClassTestRule CLASS_RULE =
047    HBaseClassTestRule.forClass(TestImmutableHColumnDescriptor.class);
048
049  @Rule
050  public TestName name = new TestName();
051  private static final List<Consumer<ImmutableHColumnDescriptor>> TEST_FUNCTION = Arrays.asList(
052    hcd -> hcd.setValue("a", "a"), hcd -> hcd.setValue(Bytes.toBytes("a"), Bytes.toBytes("a")),
053    hcd -> hcd.setConfiguration("aaa", "ccc"), hcd -> hcd.remove(Bytes.toBytes("aaa")),
054    hcd -> hcd.removeConfiguration("xxx"), hcd -> hcd.setBlockCacheEnabled(false),
055    hcd -> hcd.setBlocksize(10), hcd -> hcd.setBloomFilterType(BloomType.NONE),
056    hcd -> hcd.setCacheBloomsOnWrite(false), hcd -> hcd.setCacheDataOnWrite(true),
057    hcd -> hcd.setCacheIndexesOnWrite(true),
058    hcd -> hcd.setCompactionCompressionType(Compression.Algorithm.LZO),
059    hcd -> hcd.setCompressTags(true), hcd -> hcd.setCompressionType(Compression.Algorithm.LZO),
060    hcd -> hcd.setDFSReplication((short) 10),
061    hcd -> hcd.setDataBlockEncoding(DataBlockEncoding.NONE),
062    hcd -> hcd.setEncryptionKey(Bytes.toBytes("xxx")), hcd -> hcd.setEncryptionType("xxx"),
063    hcd -> hcd.setEvictBlocksOnClose(true), hcd -> hcd.setInMemory(true),
064    hcd -> hcd.setInMemoryCompaction(MemoryCompactionPolicy.NONE),
065    hcd -> hcd.setKeepDeletedCells(KeepDeletedCells.FALSE), hcd -> hcd.setMaxVersions(1000),
066    hcd -> hcd.setMinVersions(10),
067    hcd -> hcd.setMobCompactPartitionPolicy(MobCompactPartitionPolicy.DAILY),
068    hcd -> hcd.setMobEnabled(true), hcd -> hcd.setMobThreshold(10),
069    hcd -> hcd.setPrefetchBlocksOnOpen(true), hcd -> hcd.setScope(0),
070    hcd -> hcd.setStoragePolicy("aaa"), hcd -> hcd.setTimeToLive(100),
071    hcd -> hcd.setVersions(1, 10));
072
073  @Test
074  public void testImmutable() {
075    ImmutableHColumnDescriptor hcd =
076      new ImmutableHColumnDescriptor(new HColumnDescriptor(Bytes.toBytes(name.getMethodName())));
077    for (int i = 0; i != TEST_FUNCTION.size(); ++i) {
078      try {
079        TEST_FUNCTION.get(i).accept(hcd);
080        fail("ImmutableHTableDescriptor can't be modified!!! The index of method is " + i);
081      } catch (UnsupportedOperationException e) {
082      }
083    }
084  }
085
086  @Test
087  public void testClassMethodsAreBuilderStyle() {
088    BuilderStyleTest.assertClassesAreBuilderStyle(ImmutableHColumnDescriptor.class);
089  }
090}