LRUCacheTest

Package: MachII.tests.caching.strategies
Inherits from: mxunit.framework.TestCase
Test cases for MachII.caching.strategies.LRUCache.

<!--- License: Copyright 2008 GreatBizTools, LLC Licensed 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. Copyright: GreatBizTools, LLC Author: Kurt Wiersma (kurt@mach-ii.com) $Id: LRUCacheTest.cfc 976 2008-08-15 02:15:36Z peterfarrell $ Created version: 1.6.0 Updated version: 1.6.0 Notes: --->

Method Summary
public void setup()

Logic to run to setup before each test case method.

public void tearDown()

Logic to run to tear down after each test case method.

public void testFlush()

Tests flushing the cache.

public void testPutExistsGet()

Tests put, exist and getting a piece of data from the cache.

public void testPutGetGet()

Tests put, exist and getting a piece of data from the cache.

public void testReap()

Tests reap by simulating load on LRU.

public void testRemove()

Tests removing cached data by key.

Method Detail
setup

public void setup( )

Logic to run to setup before each test case method.

Parameters:

Code:

	<cffunction name="setup" access="public" returntype="void" output="false"
		hint="Logic to run to setup before each test case method.">

		<cfset var parameters = StructNew() />

		<cfset parameters.size = 3 />
		<cfset parameters.scope = "application" />

		<cfset variables.cache = CreateObject("component", "MachII.caching.strategies.LRUCache").init(parameters) />
		<cfset variables.cache.configure() />
	</cffunction> 

tearDown

public void tearDown( )

Logic to run to tear down after each test case method.

Parameters:

Code:

	<cffunction name="tearDown" access="public" returntype="void" output="false"
		hint="Logic to run to tear down after each test case method.">
		
	</cffunction> 

testFlush

public void testFlush( )

Tests flushing the cache.

Parameters:

Code:

	<cffunction name="testFlush" access="public" returntype="void"
		hint="Tests flushing the cache.">
		
		<cfset var testKey = "productID=1" />
		
		<cfset variables.cache.put(testkey, "testing") />
		<cfset assertTrue(variables.cache.keyExists(testkey)) />
		
		<cfset variables.cache.flush() />
		<cfset assertFalse(variables.cache.keyExists(testkey)) />
	</cffunction> 

testPutExistsGet

public void testPutExistsGet( )

Tests put, exist and getting a piece of data from the cache.

Parameters:

Code:

	<cffunction name="testPutExistsGet" access="public" returntype="void"
		hint="Tests put, exist and getting a piece of data from the cache.">

		<cfset var testKey = "productID=1" />
		
		<cfset variables.cache.put(testkey, "testing") />
		
		<cfset assertTrue(variables.cache.keyExists(testkey)) />
		<cfset assertTrue(variables.cache.get(testkey) eq "testing") />
	</cffunction> 

testPutGetGet

public void testPutGetGet( )

Tests put, exist and getting a piece of data from the cache.

Parameters:

Code:

	<cffunction name="testPutGetGet" access="public" returntype="void"
		hint="Tests put, exist and getting a piece of data from the cache.">

		<cfset var testKey = "productID=1" />
		
		<cfset variables.cache.put(testkey, "testing") />
		<cfset assertTrue(variables.cache.get(testkey) eq "testing") />
		<cfset assertTrue(variables.cache.get(testkey) eq "testing") />
	</cffunction> 

testReap

public void testReap( )

Tests reap by simulating load on LRU.

Parameters:

Code:

	<cffunction name="testReap" access="public" returntype="void"
		hint="Tests reap by simulating load on LRU.">
		
		<cfset var i = 0 />
		<cfset var thread = CreateObject("java", "java.lang.Thread") />
		
		<cfloop from="1" to="10" index="i">
			<cfset variables.cache.put("productID=#i#", "testing #i#") />
			<cfset thread.sleep(50) />
		</cfloop>
		
		<cfset debug(variables.cache.getStorage()) />
		
		<cfset assertFalse(variables.cache.keyExists("productID=1")) />
		<cfset assertTrue(variables.cache.keyExists("productID=10")) />
	</cffunction> 

testRemove

public void testRemove( )

Tests removing cached data by key.

Parameters:

Code:

	<cffunction name="testRemove" access="public" returntype="void"
		hint="Tests removing cached data by key.">
		
		<cfset var testKey = "productID=1" />

		<cfset variables.cache.put(testkey, "testing") />
		<cfset assertTrue(variables.cache.keyExists(testkey)) />
		
		<cfset variables.cache.remove(testkey) />
		<cfset assertFalse(variables.cache.keyExists(testkey)) />
	</cffunction>