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.HRegionInfo; 027import org.apache.hadoop.hbase.TableName; 028import org.apache.hadoop.hbase.testclassification.ClientTests; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.junit.ClassRule; 031import org.junit.Rule; 032import org.junit.Test; 033import org.junit.experimental.categories.Category; 034import org.junit.rules.TestName; 035 036/** 037 * Test ImmutableHRegionInfo 038 */ 039@Category({ ClientTests.class, SmallTests.class }) 040public class TestImmutableHRegionInfo { 041 042 @ClassRule 043 public static final HBaseClassTestRule CLASS_RULE = 044 HBaseClassTestRule.forClass(TestImmutableHRegionInfo.class); 045 046 @Rule 047 public TestName name = new TestName(); 048 049 private final List<Consumer<ImmutableHRegionInfo>> TEST_FUNCTIONS = 050 Arrays.asList(hri -> hri.setOffline(true), hri -> hri.setSplit(true)); 051 052 @Test 053 public void testImmutable() { 054 HRegionInfo hri = new HRegionInfo(TableName.valueOf(name.getMethodName())); 055 ImmutableHRegionInfo immutableHri = new ImmutableHRegionInfo(hri); 056 057 TEST_FUNCTIONS.forEach(f -> { 058 try { 059 f.accept(immutableHri); 060 fail("ImmutableHRegionInfo can't be modified !!!"); 061 } catch (UnsupportedOperationException e) { 062 } 063 }); 064 } 065 066}