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"),
053    hcd -> hcd.setValue(Bytes.toBytes("a"), Bytes.toBytes("a")),
054    hcd -> hcd.setConfiguration("aaa", "ccc"),
055    hcd -> hcd.remove(Bytes.toBytes("aaa")),
056    hcd -> hcd.removeConfiguration("xxx"),
057    hcd -> hcd.setBlockCacheEnabled(false),
058    hcd -> hcd.setBlocksize(10),
059    hcd -> hcd.setBloomFilterType(BloomType.NONE),
060    hcd -> hcd.setCacheBloomsOnWrite(false),
061    hcd -> hcd.setCacheDataOnWrite(true),
062    hcd -> hcd.setCacheIndexesOnWrite(true),
063    hcd -> hcd.setCompactionCompressionType(Compression.Algorithm.LZO),
064    hcd -> hcd.setCompressTags(true),
065    hcd -> hcd.setCompressionType(Compression.Algorithm.LZO),
066    hcd -> hcd.setDFSReplication((short) 10),
067    hcd -> hcd.setDataBlockEncoding(DataBlockEncoding.NONE),
068    hcd -> hcd.setEncryptionKey(Bytes.toBytes("xxx")),
069    hcd -> hcd.setEncryptionType("xxx"),
070    hcd -> hcd.setEvictBlocksOnClose(true),
071    hcd -> hcd.setInMemory(true),
072    hcd -> hcd.setInMemoryCompaction(MemoryCompactionPolicy.NONE),
073    hcd -> hcd.setKeepDeletedCells(KeepDeletedCells.FALSE),
074    hcd -> hcd.setMaxVersions(1000),
075    hcd -> hcd.setMinVersions(10),
076    hcd -> hcd.setMobCompactPartitionPolicy(MobCompactPartitionPolicy.DAILY),
077    hcd -> hcd.setMobEnabled(true),
078    hcd -> hcd.setMobThreshold(10),
079    hcd -> hcd.setPrefetchBlocksOnOpen(true),
080    hcd -> hcd.setScope(0),
081    hcd -> hcd.setStoragePolicy("aaa"),
082    hcd -> hcd.setTimeToLive(100),
083    hcd -> hcd.setVersions(1, 10)
084  );
085
086  @Test
087  public void testImmutable() {
088    ImmutableHColumnDescriptor hcd = new ImmutableHColumnDescriptor(
089      new HColumnDescriptor(Bytes.toBytes(name.getMethodName())));
090    for (int i = 0; i != TEST_FUNCTION.size(); ++i) {
091      try {
092        TEST_FUNCTION.get(i).accept(hcd);
093        fail("ImmutableHTableDescriptor can't be modified!!! The index of method is " + i);
094      } catch (UnsupportedOperationException e) {
095      }
096    }
097  }
098
099  @Test
100  public void testClassMethodsAreBuilderStyle() {
101    BuilderStyleTest.assertClassesAreBuilderStyle(ImmutableHColumnDescriptor.class);
102  }
103}