1   /**
2    * Copyright 2011 The Apache Software Foundation
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *     http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing, software
15   * distributed under the License is distributed on an "AS IS" BASIS,
16   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17   * See the License for the specific language governing permissions and
18   * limitations under the License.
19   */
20  
21  package org.apache.hadoop.hbase.io.hfile;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertTrue;
25  
26  import java.util.HashMap;
27  import java.util.Map;
28  
29  import org.apache.hadoop.hbase.SmallTests;
30  import org.junit.Test;
31  import org.junit.experimental.categories.Category;
32  
33  /**
34   * Tests the BlockCacheColumnFamilySummary class
35   * 
36   */
37  @Category(SmallTests.class)
38  public class TestBlockCacheColumnFamilySummary {
39  
40  
41    /**
42     * 
43     */
44    @Test
45    public void testEquals()  {
46  
47      BlockCacheColumnFamilySummary e1 = new BlockCacheColumnFamilySummary();
48      e1.setTable("table1");
49      e1.setColumnFamily("cf1");
50      
51      BlockCacheColumnFamilySummary e2 = new BlockCacheColumnFamilySummary();
52      e2.setTable("table1");
53      e2.setColumnFamily("cf1");
54  
55      assertEquals("bcse", e1, e2);
56    }
57  
58    /**
59     * 
60     */
61    @Test
62    public void testNotEquals() {
63  
64      BlockCacheColumnFamilySummary e1 = new BlockCacheColumnFamilySummary();
65      e1.setTable("table1");
66      e1.setColumnFamily("cf1");
67      
68      BlockCacheColumnFamilySummary e2 = new BlockCacheColumnFamilySummary();
69      e2.setTable("tablexxxxxx");
70      e2.setColumnFamily("cf1");
71  
72      assertTrue("bcse", ! e1.equals(e2));
73    }
74  
75    /**
76     * 
77     */
78    @Test
79    public void testMapLookup() {
80      
81      Map<BlockCacheColumnFamilySummary, BlockCacheColumnFamilySummary> bcs = 
82        new HashMap<BlockCacheColumnFamilySummary, BlockCacheColumnFamilySummary>();
83  
84      BlockCacheColumnFamilySummary e1 = new BlockCacheColumnFamilySummary("table1","cf1");
85  
86      BlockCacheColumnFamilySummary lookup = bcs.get(e1);
87  
88      if (lookup == null) {
89        lookup = BlockCacheColumnFamilySummary.create(e1);
90        bcs.put(e1,lookup);
91        lookup.incrementBlocks();
92        lookup.incrementHeapSize(100L);
93      }
94  
95      BlockCacheColumnFamilySummary e2 = new BlockCacheColumnFamilySummary("table1","cf1");
96  
97      BlockCacheColumnFamilySummary l2 = bcs.get(e2);
98      assertEquals("blocks",1,l2.getBlocks());
99      assertEquals("heap",100L,l2.getHeapSize());
100   }
101 
102   /**
103    * 
104    */
105   @Test
106   public void testMapEntry() {
107     
108     Map<BlockCacheColumnFamilySummary, BlockCacheColumnFamilySummary> bcs = 
109       new HashMap<BlockCacheColumnFamilySummary, BlockCacheColumnFamilySummary>();
110 
111     BlockCacheColumnFamilySummary e1 = new BlockCacheColumnFamilySummary("table1","cf1");
112     bcs.put(e1, e1);
113     
114     BlockCacheColumnFamilySummary e2 = new BlockCacheColumnFamilySummary("table1","cf1");
115     bcs.put(e2, e2);
116     
117     BlockCacheColumnFamilySummary e3 = new BlockCacheColumnFamilySummary("table1","cf1");
118     bcs.put(e3, e3);
119     
120     assertEquals("mapSize",1,bcs.size());
121   }
122 
123 
124   @org.junit.Rule
125   public org.apache.hadoop.hbase.ResourceCheckerJUnitRule cu =
126     new org.apache.hadoop.hbase.ResourceCheckerJUnitRule();
127 }
128