Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSingleSizeCache.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSingleSizeCache.java?rev=1162207&view=auto ============================================================================== --- hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSingleSizeCache.java (added) +++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSingleSizeCache.java Fri Aug 26 18:53:00 2011 @@ -0,0 +1,67 @@ +/** + * Copyright 2011 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.io.hfile.slab; + +import org.apache.hadoop.hbase.io.hfile.CacheTestUtils; +import org.apache.hadoop.hbase.io.hfile.slab.SingleSizeCache; +import org.junit.*; + +/** + * Tests SingleSlabCache. + * <p> + * + * Tests will ensure that evictions operate when they're supposed to and do what + * they should, and that cached blocks are accessible when expected to be. + */ +public class TestSingleSizeCache { + SingleSizeCache cache; + final int CACHE_SIZE = 1000000; + final int NUM_BLOCKS = 100; + final int BLOCK_SIZE = CACHE_SIZE / NUM_BLOCKS; + final int NUM_THREADS = 100; + final int NUM_QUERIES = 10000; + + @Before + public void setup() { + cache = new SingleSizeCache(BLOCK_SIZE, NUM_BLOCKS, null); + } + + @After + public void tearDown() { + cache.shutdown(); + } + + @Test + public void testCacheSimple() throws Exception { + CacheTestUtils.testCacheSimple(cache, BLOCK_SIZE, NUM_QUERIES); + } + + @Test + public void testCacheMultiThreaded() throws Exception { + CacheTestUtils.testCacheMultiThreaded(cache, BLOCK_SIZE, + NUM_THREADS, NUM_QUERIES, 0.80); + } + + @Test + public void testCacheMultiThreadedSingleKey() throws Exception { + CacheTestUtils.hammerSingleKey(cache, BLOCK_SIZE, NUM_THREADS, NUM_QUERIES); + } + +}
Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlab.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlab.java?rev=1162207&view=auto ============================================================================== --- hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlab.java (added) +++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlab.java Fri Aug 26 18:53:00 2011 @@ -0,0 +1,72 @@ +/** + * Copyright 2011 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hadoop.hbase.io.hfile.slab; + +import static org.junit.Assert.*; +import java.nio.ByteBuffer; +import org.junit.*; + +/**Test cases for Slab.java*/ +public class TestSlab { + static final int BLOCKSIZE = 1000; + static final int NUMBLOCKS = 100; + Slab testSlab; + ByteBuffer[] buffers = new ByteBuffer[NUMBLOCKS]; + + @Before + public void setUp() { + testSlab = new Slab(BLOCKSIZE, NUMBLOCKS); + } + + @After + public void tearDown() { + testSlab.shutdown(); + } + + @Test + public void testBasicFunctionality() { + for (int i = 0; i < NUMBLOCKS; i++) { + buffers[i] = testSlab.alloc(BLOCKSIZE); + assertEquals(BLOCKSIZE, buffers[i].limit()); + } + + // write an unique integer to each allocated buffer. + for (int i = 0; i < NUMBLOCKS; i++) { + buffers[i].putInt(i); + } + + // make sure the bytebuffers remain unique (the slab allocator hasn't + // allocated the same chunk of memory twice) + for (int i = 0; i < NUMBLOCKS; i++) { + buffers[i].putInt(i); + } + + for (int i = 0; i < NUMBLOCKS; i++) { + testSlab.free(buffers[i]); // free all the buffers. + } + + for (int i = 0; i < NUMBLOCKS; i++) { + buffers[i] = testSlab.alloc(BLOCKSIZE); + assertEquals(BLOCKSIZE, buffers[i].limit()); + } + } + +} Added: hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlabCache.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlabCache.java?rev=1162207&view=auto ============================================================================== --- hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlabCache.java (added) +++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/io/hfile/slab/TestSlabCache.java Fri Aug 26 18:53:00 2011 @@ -0,0 +1,83 @@ +/** + * Copyright 2011 The Apache Software Foundation + * + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.hadoop.hbase.io.hfile.slab; + +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.io.hfile.CacheTestUtils; +import org.apache.hadoop.hbase.io.hfile.slab.SlabCache; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import static org.junit.Assert.*; + +/** + * Basic test of SlabCache. Puts and gets. + * <p> + * + * Tests will ensure that blocks that are uncached are identical to the ones + * being cached, and that the cache never exceeds its capacity. Note that its + * fine if the cache evicts before it reaches max capacity - Guava Mapmaker may + * choose to evict at any time. + * + */ +public class TestSlabCache { + static final int CACHE_SIZE = 1000000; + static final int NUM_BLOCKS = 101; + static final int BLOCK_SIZE = CACHE_SIZE / NUM_BLOCKS; + static final int NUM_THREADS = 1000; + static final int NUM_QUERIES = 10000; + SlabCache cache; + + @Before + public void setup() { + cache = new SlabCache(CACHE_SIZE + BLOCK_SIZE * 2, BLOCK_SIZE); + cache.addSlabByConf(new Configuration()); + } + + @After + public void tearDown() { + cache.shutdown(); + } + + @Test + public void testElementPlacement() { + assertEquals(cache.getHigherBlock((int) BLOCK_SIZE).getKey().intValue(), + (int) (BLOCK_SIZE * 11 / 10)); + assertEquals(cache.getHigherBlock((int) (BLOCK_SIZE * 2)).getKey() + .intValue(), (int) (BLOCK_SIZE * 21 / 10)); + } + + @Test + public void testCacheSimple() throws Exception { + CacheTestUtils.testCacheSimple(cache, BLOCK_SIZE, NUM_QUERIES); + } + + @Test + public void testCacheMultiThreaded() throws Exception { + CacheTestUtils.testCacheMultiThreaded(cache, BLOCK_SIZE, NUM_THREADS, + NUM_QUERIES, 0.80); + } + + @Test + public void testCacheMultiThreadedSingleKey() throws Exception { + CacheTestUtils.hammerSingleKey(cache, BLOCK_SIZE, NUM_THREADS, NUM_QUERIES); + } +} Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.java?rev=1162207&r1=1162206&r2=1162207&view=diff ============================================================================== --- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.java (original) +++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestMemStoreLAB.java Fri Aug 26 18:53:00 2011 @@ -24,7 +24,6 @@ import static org.junit.Assert.*; import java.util.List; import java.util.Map; import java.util.Random; -import java.util.TreeMap; import java.util.concurrent.atomic.AtomicInteger; import org.apache.hadoop.conf.Configuration; @@ -33,13 +32,10 @@ import org.apache.hadoop.hbase.Multithre import org.apache.hadoop.hbase.regionserver.MemStoreLAB.Allocation; import org.junit.Test; -import com.google.common.base.Function; import com.google.common.collect.Iterables; import com.google.common.collect.Lists; -import com.google.common.collect.MapMaker; import com.google.common.collect.Maps; import com.google.common.primitives.Ints; -import com.google.common.primitives.Longs; public class TestMemStoreLAB { Modified: hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java URL: http://svn.apache.org/viewvc/hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java?rev=1162207&r1=1162206&r2=1162207&view=diff ============================================================================== --- hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java (original) +++ hbase/trunk/src/test/java/org/apache/hadoop/hbase/regionserver/TestStoreFile.java Fri Aug 26 18:53:00 2011 @@ -40,9 +40,9 @@ import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.io.Reference.Range; import org.apache.hadoop.hbase.io.hfile.BlockCache; +import org.apache.hadoop.hbase.io.hfile.CacheStats; import org.apache.hadoop.hbase.io.hfile.HFile; import org.apache.hadoop.hbase.io.hfile.HFileScanner; -import org.apache.hadoop.hbase.io.hfile.LruBlockCache.CacheStats; import org.apache.hadoop.hbase.util.BloomFilterFactory; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hdfs.MiniDFSCluster;
