Package edu.brown.hstore.util

Source Code of edu.brown.hstore.util.TestArrayCache

package edu.brown.hstore.util;

import java.util.Arrays;

import edu.brown.hstore.util.ArrayCache.IntArrayCache;
import edu.brown.hstore.util.ArrayCache.LongArrayCache;
import junit.framework.TestCase;

public class TestArrayCache extends TestCase {

    private static final int INITIAL_SIZE = 11;
    private static final int MAX_SIZE = 33;
   
    /**
     * testIntArrayCache
     */
    public void testIntArrayCache() throws Exception {
        IntArrayCache cache = new IntArrayCache(INITIAL_SIZE);
        for (int i = 1; i < MAX_SIZE; i++) {
            int arr[] = cache.getArray(i);
            assertNotNull(arr);
            assertEquals(i, arr.length);
            Arrays.fill(arr, i);
        } // FOR
       
        // Make sure that we are reusing the arrays
        for (int i = 1; i < MAX_SIZE; i++) {
            int arr[] = cache.getArray(i);
            assertNotNull(arr);
            assertEquals(i, arr.length);
            for (int ii = 0; ii < arr.length; ii++)
                assertEquals(i, arr[ii]);
        } // FOR
    }
   
    /**
     * testLongArrayCache
     */
    public void testLongArrayCache() throws Exception {
        LongArrayCache cache = new LongArrayCache(INITIAL_SIZE);
        for (int i = 1; i < MAX_SIZE; i++) {
            long arr[] = cache.getArray(i);
            assertNotNull(arr);
            assertEquals(i, arr.length);
            Arrays.fill(arr, i);
        } // FOR
       
        // Make sure that we are reusing the arrays
        for (int i = 1; i < MAX_SIZE; i++) {
            long arr[] = cache.getArray(i);
            assertNotNull(arr);
            assertEquals(i, arr.length);
            for (int ii = 0; ii < arr.length; ii++)
                assertEquals(i, arr[ii]);
        } // FOR
    }
   
}
TOP

Related Classes of edu.brown.hstore.util.TestArrayCache

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.