View Javadoc

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