CacheStatsTest

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

<!--- 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: Peter J. Farrell(peter@mach-ii.com) $Id: $ 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 testActiveElements()

Tests active elements of the cache stats.

public void testCacheHits()

Tests cache hits of the cache stats.

public void testCacheMisses()

Tests cache misses of the cache stats.

public void testEvictions()

Tests evictions of the cache stats.

public void testExtraStats()

Test the extra stats functionality.

public void testTotalElements()

Tests total elements of the cache stats.

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 variables.cacheStats = CreateObject("component", "MachII.caching.CacheStats").init() />
	</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> 

testActiveElements

public void testActiveElements( )

Tests active elements of the cache stats.

Parameters:

Code:

	<cffunction name="testActiveElements" access="public" returntype="void"
		hint="Tests active elements of the cache stats.">

		
		<cfset variables.cacheStats.incrementActiveElements() />
		
		<cfset variables.cacheStats.incrementActiveElements(4) />

		
		<cfset variables.cacheStats.decrementActiveElements() />
		
		<cfset variables.cacheStats.decrementActiveElements(4) />
		
		<cfset assertEquals(variables.cacheStats.getActiveElements(), 0, 
			"Active elements should be '0' but returned '#variables.cacheStats.getActiveElements()#'") />
	</cffunction> 

testCacheHits

public void testCacheHits( )

Tests cache hits of the cache stats.

Parameters:

Code:

	<cffunction name="testCacheHits" access="public" returntype="void"
		hint="Tests cache hits of the cache stats.">

		
		<cfset variables.cacheStats.incrementCacheHits() />
		
		<cfset variables.cacheStats.incrementCacheHits(4) />
		
		<cfset assertEquals(variables.cacheStats.getCacheHits(), 5, 
			"Cache hits should be '5' but returned '#variables.cacheStats.getCacheHits()#'") />
	</cffunction> 

testCacheMisses

public void testCacheMisses( )

Tests cache misses of the cache stats.

Parameters:

Code:

	<cffunction name="testCacheMisses" access="public" returntype="void"
		hint="Tests cache misses of the cache stats.">

		
		<cfset variables.cacheStats.incrementCacheMisses() />
		
		<cfset variables.cacheStats.incrementCacheMisses(4) />
		
		<cfset assertEquals(variables.cacheStats.getCacheMisses(), 5, 
			"Cache misses should be '5' but returned '#variables.cacheStats.getCacheMisses()#'") />
	</cffunction> 

testEvictions

public void testEvictions( )

Tests evictions of the cache stats.

Parameters:

Code:

	<cffunction name="testEvictions" access="public" returntype="void"
		hint="Tests evictions of the cache stats.">

		
		<cfset variables.cacheStats.incrementEvictions() />
		
		<cfset variables.cacheStats.incrementEvictions(4) />
		
		<cfset assertEquals(variables.cacheStats.getEvictions(), 5, 
			"Evictions should be '5' but returned '#variables.cacheStats.getEvictions()#'") />
	</cffunction> 

testExtraStats

public void testExtraStats( )

Test the extra stats functionality.

Parameters:

Code:

	<cffunction name="testExtraStats" access="public" returntype="void"
		hint="Test the extra stats functionality.">
		
		<cfset var extraStats = "" />
		
		
		<cfset variables.cacheStats.setExtraStat("a", "a") />
		<cfset variables.cacheStats.setExtraStat("b", "b") />
		
		
		<cfset extraStats = variables.cacheStats.getExtraStats() />
		
		<cfset assertTrue(StructKeyExists(extraStats, "a"), "Key 'a' not in extra stats.") />
		<cfset assertEquals(extraStats.a, "a", "Value of key 'a' in extra stats should be 'a' but returned '#extraStats.a#'.") />
		<cfset assertTrue(StructKeyExists(extraStats, "b"), "Key 'b' not in extra stats.") />
		<cfset assertEquals(extraStats.b, "b", "Value of key 'b' in extra stats should be 'b' but returned '#extraStats.b#'.") />
	</cffunction> 

testTotalElements

public void testTotalElements( )

Tests total elements of the cache stats.

Parameters:

Code:

	<cffunction name="testTotalElements" access="public" returntype="void"
		hint="Tests total elements of the cache stats.">

		
		<cfset variables.cacheStats.incrementTotalElements() />
		
		<cfset variables.cacheStats.incrementTotalElements(4) />

		
		<cfset variables.cacheStats.decrementTotalElements() />
		
		<cfset variables.cacheStats.decrementTotalElements(4) />
		
		<cfset assertEquals(variables.cacheStats.getTotalElements(), 0, 
			"Total elements should be '0' but returned '#variables.cacheStats.getTotalElements()#'") />
	</cffunction>