Skip to content

Commit

Permalink
improved testing for caches
Browse files Browse the repository at this point in the history
  • Loading branch information
lmajano committed Jan 11, 2025
1 parent 7ab84d8 commit a75b8ee
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 136 deletions.
2 changes: 1 addition & 1 deletion system/cache/providers/BoxLangProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ component
* @return coldbox.system.cache.util.IStats
*/
function getStats(){
return new "coldbox.system.cache.providers.boxlang-lib.BoxLangStats"( this );
return new "coldbox.system.cache.providers.stats.BoxLangStats"( this );
}

/**
Expand Down
3 changes: 1 addition & 2 deletions system/cache/providers/CFProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ component
* @return coldbox.system.cache.util.IStats
*/
function getStats(){
return new "coldbox.system.cache.providers.cf-lib.CFStats"( getObjectStore().getStatistics() );
return new "coldbox.system.cache.providers.stats.CFStats"( getObjectStore().getStatistics() );
}

/**
Expand Down Expand Up @@ -534,4 +534,3 @@ component
}

}

2 changes: 1 addition & 1 deletion system/cache/providers/LuceeProvider.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ component
* @return coldbox.system.cache.util.IStats
*/
function getStats(){
return new "coldbox.system.cache.providers.lucee-lib.LuceeStats"( this );
return new "coldbox.system.cache.providers.stats.LuceeStats"( this );
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
48 changes: 33 additions & 15 deletions tests/specs/cache/providers/CacheBoxProviderTest.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

this.loadColdBox = false;

// Default Config To Test
variables.config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "ConcurrentSoftReferenceStore",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
};

/**
* ------------------------------------------------------
* Life-Cycle Methods
* ------------------------------------------------------
*/

function setup(){
super.setup();

Expand Down Expand Up @@ -29,21 +50,6 @@
.$( "canError", true );
mockEventManager.$( "announce" );

// Config
config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "ConcurrentSoftReferenceStore",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
};

// Create Provider
cache = createMock( "coldbox.system.cache.providers.CacheBoxProvider" ).init();
// Decorate it
Expand All @@ -67,6 +73,18 @@
cache.clearAll();
}

/**
* ------------------------------------------------------
* Helpers
* ------------------------------------------------------
*/

/**
* ------------------------------------------------------
* Testing Methods
* ------------------------------------------------------
*/

function testShutdown(){
cache.shutdown();
}
Expand Down
53 changes: 15 additions & 38 deletions tests/specs/cache/providers/CacheBoxWithConcurrentStoreTest.cfc
Original file line number Diff line number Diff line change
@@ -1,43 +1,20 @@
component extends="CacheBoxProviderTest" {

function setup(){
super.setup();

// Config
config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 10,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "ConcurrentStore",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false,
resetTimeoutOnAccess : true
};

// Create Provider
cache = createMock( "coldbox.system.cache.providers.CacheBoxProvider" ).init();

// Decorate it
cache.setConfiguration( config );
cache.setCacheFactory( mockFactory );
cache.setEventManager( mockEventManager );
// Mock The Scheduler, we don't need any reaping async
var mockSchedule = prepareMock(
mockExecutor.newSchedule( function(){
debug( "In Mock Executor" );
} )
);
mockExecutor.$( "newSchedule", mockSchedule );
// Configure the provider
cache.configure();
// Clear everything first
cache.clearAll();
}
// Config
variables.config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 10,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "ConcurrentStore",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false,
resetTimeoutOnAccess : true
};

function testResetAccess(){
var testVal = { name : "luis", age : 32 };
Expand Down
54 changes: 15 additions & 39 deletions tests/specs/cache/providers/CacheBoxWithDiskSoreTest.cfc
Original file line number Diff line number Diff line change
@@ -1,43 +1,19 @@
component extends="CacheBoxProviderTest" {

function setup(){
super.setup();

// Config
config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "DiskStore",
directoryPath : "/coldbox/tests/tmp/cacheDepot",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
};

// Create Provider
cache = createMock( "coldbox.system.cache.providers.CacheBoxProvider" ).init();

// Decorate it
cache.setConfiguration( config );
cache.setCacheFactory( mockFactory );
cache.setEventManager( mockEventManager );

// Mock The Scheduler, we don't need any reaping async
var mockSchedule = prepareMock(
mockExecutor.newSchedule( function(){
debug( "In Mock Executor" );
} )
);
mockExecutor.$( "newSchedule", mockSchedule );
// Configure the provider
cache.configure();
// Clear everything first
cache.clearAll();
}
// Config
variables.config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "DiskStore",
directoryPath : "/coldbox/tests/tmp/cacheDepot",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
};

}
56 changes: 16 additions & 40 deletions tests/specs/cache/providers/CacheBoxWithJDBCSoreTest.cfc
Original file line number Diff line number Diff line change
@@ -1,44 +1,20 @@
component extends="CacheBoxProviderTest" {

function setup(){
super.setup();

// Config
config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "JDBCStore",
dsn : "coolblog",
table : "cacheBox",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
};

// Create Provider
cache = createMock( "coldbox.system.cache.providers.CacheBoxProvider" ).init();

// Decorate it
cache.setConfiguration( config );
cache.setCacheFactory( mockFactory );
cache.setEventManager( mockEventManager );

// Mock The Scheduler, we don't need any reaping async
var mockSchedule = prepareMock(
mockExecutor.newSchedule( function(){
debug( "In Mock Executor" );
} )
);
mockExecutor.$( "newSchedule", mockSchedule );
// Configure the provider
cache.configure();
// Clear everything first
cache.clearAll();
}
// Config
variables.config = {
objectDefaultTimeout : 60,
objectDefaultLastAccessTimeout : 30,
useLastAccessTimeouts : true,
reapFrequency : 2,
freeMemoryPercentageThreshold : 0,
evictionPolicy : "LRU",
evictCount : 1,
maxObjects : 200,
objectStore : "JDBCStore",
dsn : "coolblog",
table : "cacheBox",
// This switches the internal provider from normal cacheBox to coldbox enabled cachebox
coldboxEnabled : false
};

}

0 comments on commit a75b8ee

Please sign in to comment.