View Javadoc

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *     http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.hadoop.hbase;
18  
19  import static org.junit.Assert.assertTrue;
20  
21  import org.apache.hadoop.hbase.testclassification.SmallTests;
22  import org.apache.hadoop.hbase.util.Bytes;
23  import org.junit.Test;
24  import org.junit.experimental.categories.Category;
25  
26  @Category(SmallTests.class)
27  public class TestTagRewriteCell {
28  
29    @Test
30    public void testHeapSize() {
31      Cell originalCell = CellUtil.createCell(Bytes.toBytes("row"), Bytes.toBytes("value"));
32      final int fakeTagArrayLength = 10;
33      TagRewriteCell trCell = new TagRewriteCell(originalCell, new byte[fakeTagArrayLength]);
34  
35      // Get the heapSize before the internal tags array in trCell are nuked
36      long trCellHeapSize = trCell.heapSize();
37  
38      // Make another TagRewriteCell with the original TagRewriteCell
39      // This happens on systems with more than one RegionObserver/Coproc loaded (such as
40      // VisibilityController and AccessController)
41      TagRewriteCell trCell2 = new TagRewriteCell(trCell, new byte[fakeTagArrayLength]);
42  
43      assertTrue("TagRewriteCell containing a TagRewriteCell's heapsize should be larger than a " +
44          "single TagRewriteCell's heapsize", trCellHeapSize < trCell2.heapSize());
45      assertTrue("TagRewriteCell should have had nulled out tags array", trCell.heapSize() <
46          trCellHeapSize);
47    }
48  }