-
-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
BoxLang Providers
- Loading branch information
Showing
2 changed files
with
264 additions
and
0 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
tests/specs/cache/providers/BoxLangColdBoxProviderTest.cfc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
component | ||
extends="BoxLangProviderTest" | ||
output ="false" | ||
skip ="notBoxLang" | ||
{ | ||
|
||
function setup(){ | ||
super.setup(); | ||
// Mock Controller | ||
mockController = createEmptyMock( "coldbox.system.web.Controller" ); | ||
|
||
// Create Provider | ||
cache = createMock( "coldbox.system.cache.providers.BoxLangColdBoxProvider" ).init(); | ||
|
||
// Decorate it | ||
cache.setConfiguration( config ); | ||
cache.setCacheFactory( mockFactory ); | ||
cache.setEventManager( mockEventManager ); | ||
cache.setColdbox( mockController ); | ||
|
||
// Configure the provider | ||
cache.configure(); | ||
// Clear everything first | ||
cache.clearAll(); | ||
} | ||
|
||
function testPrefixes(){ | ||
assertTrue( len( cache.getEventCacheKeyPrefix() ) ); | ||
assertTrue( len( cache.getViewCacheKeyPrefix() ) ); | ||
} | ||
|
||
function testgetEventURLFacade(){ | ||
assertEquals( true, isInstanceOf( cache.getEventURLFacade(), "coldbox.system.cache.util.EventURLFacade" ) ); | ||
} | ||
|
||
function testClearAllEvents(){ | ||
cache.clearAllEvents(); | ||
} | ||
function testClearAllViews(){ | ||
cache.ClearAllViews(); | ||
} | ||
function testclearByKeySnippet(){ | ||
cache.clearByKeySnippet( "test", false ); | ||
} | ||
function testclearEvent(){ | ||
cache.clearEvent( "test" ); | ||
} | ||
function testclearEventMulti(){ | ||
cache.clearEventMulti( "test" ); | ||
} | ||
function testclearViewMulti(){ | ||
cache.clearViewMulti( "test" ); | ||
} | ||
function testclearView(){ | ||
cache.clearView( "test" ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,206 @@ | ||
component extends="tests.resources.BaseIntegrationTest" skip="notBoxlang" { | ||
|
||
this.loadColdBox = false; | ||
|
||
boolean function notBoxlang(){ | ||
return !isBoxLang(); | ||
} | ||
|
||
function setup(){ | ||
super.setup(); | ||
|
||
// Mocks | ||
mockFactory = createMock( "coldbox.system.cache.CacheFactory" ); | ||
mockEventManager = createMock( "coldbox.system.core.events.EventPoolManager" ); | ||
mockLogBox = createMock( "coldbox.system.logging.LogBox" ); | ||
mockLogger = createMock( "coldbox.system.logging.Logger" ); | ||
|
||
// Mock Methods | ||
mockFactory.setLogBox( mockLogBox ); | ||
mockLogBox.$( "getLogger", mockLogger ); | ||
mockLogger | ||
.$( "error" ) | ||
.$( "debug" ) | ||
.$( "info" ) | ||
.$( "canDebug", false ); | ||
mockEventManager.$( "announce" ); | ||
|
||
// Config | ||
config = {}; | ||
|
||
// Create Provider | ||
cache = createMock( "coldbox.system.cache.providers.BoxLangProvider" ).init(); | ||
|
||
// Decorate it | ||
cache.setConfiguration( config ); | ||
cache.setCacheFactory( mockFactory ); | ||
cache.setEventManager( mockEventManager ); | ||
|
||
// Configure the provider | ||
cache.configure(); | ||
// Clear everything first | ||
cache.clearAll(); | ||
} | ||
|
||
function teardown(){ | ||
cache.clearAll(); | ||
} | ||
|
||
function testShutdown(){ | ||
cache.shutdown(); | ||
} | ||
|
||
function testLookup(){ | ||
cache.set( "test", now(), 20 ); | ||
cache.clearStatistics(); | ||
|
||
assertEquals( false, cache.lookup( "invalid" ) ); | ||
assertEquals( true, cache.lookup( "test" ) ); | ||
} | ||
|
||
function testLookupQuiet(){ | ||
cache.set( "test", now(), 20 ); | ||
cache.clearStatistics(); | ||
|
||
assertEquals( false, cache.lookupQuiet( "invalid" ) ); | ||
assertEquals( true, cache.lookupQuiet( "test" ) ); | ||
} | ||
|
||
function testgetKeys(){ | ||
cacheClear(); | ||
cache.set( "test", now() ); | ||
cache.set( "test2", now() ); | ||
assertEquals( 2, arrayLen( cache.getKeys() ) ); | ||
} | ||
|
||
function testgetCachedObjectMetadata(){ | ||
cache.set( "test", now() ); | ||
md = cache.getCachedObjectMetadata( "test" ); | ||
// debug(md); | ||
assertEquals( false, structIsEmpty( md ) ); | ||
} | ||
|
||
function testGet(){ | ||
testVal = { name : "luis", age : 32 }; | ||
|
||
cache.set( "test", testVal, 20 ); | ||
cache.clearStatistics(); | ||
|
||
results = cache.get( "test" ); | ||
assertEquals( results, testval ); | ||
// assertEquals( 0, cache.getStats().getMisses() ); | ||
// assertEquals( 1, cache.getStats().getHits() ); | ||
|
||
results = cache.get( "test2" ); | ||
assertFalse( isDefined( "results" ) ); | ||
// assertEquals( 1, cache.getStats().getMisses() ); | ||
} | ||
|
||
function testGetOrSet(){ | ||
cache.clearStatistics(); | ||
|
||
results = cache.getOrSet( objectKey = "test", produce = cacheProducer ); | ||
assertTrue( structKeyExists( results, "name" ) ); | ||
|
||
results = cache.getOrSet( objectKey = "test", produce = cacheProducer ); | ||
assertTrue( structKeyExists( results, "name" ) ); | ||
} | ||
|
||
function testGetQuiet(){ | ||
testVal = { name : "luis", age : 32 }; | ||
|
||
cache.clearStatistics(); | ||
cache.set( "test", testVal, 20 ); | ||
|
||
results = cache.getQuiet( "test" ); | ||
// debug(results); | ||
assertEquals( testVal, results ); | ||
// assertEquals( 0, cache.getStats().getMisses() ); | ||
// assertEquals( 0, cache.getStats().getHits() ); | ||
} | ||
|
||
function testSet(){ | ||
testVal = { name : "luis", age : 32 }; | ||
cache.clearAll(); | ||
|
||
cache.set( | ||
"test", | ||
testVal, | ||
createTimespan( 0, 0, 2, 0 ), | ||
createTimespan( 0, 0, 1, 0 ) | ||
); | ||
assertEquals( testVal, cache.get( "test" ) ); | ||
md = cache.getCachedObjectMetadata( "test" ); | ||
assertEquals( 60 * 1000, md.idleTime ); | ||
assertEquals( 120 * 1000, md.timespan ); | ||
// debug(md); | ||
} | ||
|
||
function testSetQuiet(){ | ||
testVal = { name : "luis", age : 32 }; | ||
cache.clearAll(); | ||
|
||
cache.setQuiet( | ||
"test", | ||
testVal, | ||
createTimespan( 0, 0, 2, 0 ), | ||
createTimespan( 0, 0, 1, 0 ) | ||
); | ||
assertEquals( testVal, cache.get( "test" ) ); | ||
md = cache.getCachedObjectMetadata( "test" ); | ||
assertEquals( 60 * 1000, md.idleTime ); | ||
assertEquals( 120 * 1000, md.timespan ); | ||
// debug(md); | ||
} | ||
|
||
function testGetSize(){ | ||
testVal = { name : "luis", age : 32 }; | ||
cache.clearAll(); | ||
|
||
cache.setQuiet( | ||
"test", | ||
testVal, | ||
createTimespan( 0, 0, 2, 0 ), | ||
createTimespan( 0, 0, 1, 0 ) | ||
); | ||
|
||
assertEquals( 1, cache.getSize() ); | ||
} | ||
|
||
function testClear(){ | ||
testVal = { name : "luis", age : 32 }; | ||
cache.clearAll(); | ||
|
||
cache.set( | ||
"test", | ||
testVal, | ||
createTimespan( 0, 0, 2, 0 ), | ||
createTimespan( 0, 0, 1, 0 ) | ||
); | ||
|
||
assertEquals( 1, cache.getSize() ); | ||
cache.clear( "test" ); | ||
assertEquals( 0, cache.getSize() ); | ||
} | ||
|
||
function testClearQuiet(){ | ||
testVal = { name : "luis", age : 32 }; | ||
cache.clearAll(); | ||
|
||
cache.set( | ||
"test", | ||
testVal, | ||
createTimespan( 0, 0, 2, 0 ), | ||
createTimespan( 0, 0, 1, 0 ) | ||
); | ||
|
||
assertEquals( 1, cache.getSize() ); | ||
cache.clearQuiet( "test" ); | ||
assertEquals( 0, cache.getSize() ); | ||
} | ||
|
||
private function cacheProducer(){ | ||
return { date : now(), name : "luis majano", id : createUUID() }; | ||
} | ||
|
||
} |