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  package org.apache.hadoop.hbase.io.hfile.slab;
20  
21  import org.apache.hadoop.hbase.MediumTests;
22  import org.apache.hadoop.hbase.io.hfile.CacheTestUtils;
23  import org.junit.After;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  /**
29   * Tests SingleSlabCache.
30   * <p>
31   *
32   * Tests will ensure that evictions operate when they're supposed to and do what
33   * they should, and that cached blocks are accessible when expected to be.
34   */
35  // Starts 100 threads, high variability of execution time => Medium
36  @Category(MediumTests.class)
37  public class TestSingleSizeCache {
38    SingleSizeCache cache;
39    final int CACHE_SIZE = 1000000;
40    final int NUM_BLOCKS = 100;
41    final int BLOCK_SIZE = CACHE_SIZE / NUM_BLOCKS;
42    final int NUM_THREADS = 100;
43    final int NUM_QUERIES = 10000;
44  
45    @Before
46    public void setup() {
47      cache = new SingleSizeCache(BLOCK_SIZE, NUM_BLOCKS, null);
48    }
49  
50    @After
51    public void tearDown() {
52      cache.shutdown();
53    }
54  
55    @Test
56    public void testCacheSimple() throws Exception {
57      CacheTestUtils.testCacheSimple(cache, BLOCK_SIZE, NUM_QUERIES);
58    }
59  
60    @Test
61    public void testCacheMultiThreaded() throws Exception {
62      CacheTestUtils.testCacheMultiThreaded(cache, BLOCK_SIZE,
63          NUM_THREADS, NUM_QUERIES, 0.80);
64    }
65  
66    @Test
67    public void testCacheMultiThreadedSingleKey() throws Exception {
68      CacheTestUtils.hammerSingleKey(cache, BLOCK_SIZE, NUM_THREADS, NUM_QUERIES);
69    }
70  
71    @Test
72    public void testCacheMultiThreadedEviction() throws Exception {
73      CacheTestUtils.hammerEviction(cache, BLOCK_SIZE, NUM_THREADS, NUM_QUERIES);
74    }
75  
76    @Test
77    public void testHeapSizeChanges(){
78      CacheTestUtils.testHeapSizeChanges(cache, BLOCK_SIZE);
79    }
80  
81  
82  }
83