Skip to content

Commit

Permalink
Added test that re-querying aged results will put them back into the …
Browse files Browse the repository at this point in the history
…cache
  • Loading branch information
rob-baillie-ortoo committed Apr 27, 2022
1 parent 97870e0 commit cb8cea0
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,33 @@ private without sharing class CachedSoqlExecutorTest
System.assertEquals( 2, soqlCalls, 'query with a maximum age on session cache, when called twice with the second outside the required age, will issue two SOQL statements' );
}

@isTest
private static void query_maxAge_session_whenAgeMeansAQueryReruns_willPutBackIntoCache() // NOPMD: Test method name format
{
TestLoggerService logger = TestLoggerUtils.registerTestLoggerService();

String soqlStatement = 'SELECT Id FROM Account';

setupAccessToSoqlCache( true );

CachedSoqlExecutor executor = new CachedSoqlExecutor().setScope( CachedSoqlExecutor.CacheScope.SESSION );

Test.startTest();
TestDateTimeUtils.setCurrentDateTime( 0 );
executor.query( soqlStatement, 100 );

TestDateTimeUtils.addToCurrentTime( 100 ); // it is now 100 seconds later
executor.query( soqlStatement, 50 ); // so this should result in a new query

TestDateTimeUtils.addToCurrentTime( 100 ); // it is now another 100 seconds later
executor.query( soqlStatement, 150 ); // this should get the results from the second query

Integer soqlCalls = Limits.getQueries();
Test.stopTest();

System.assertEquals( 2, soqlCalls, 'query with a maximum age on session cache, when the call results in ageing results out, the new results will be cached' );
}

@isTest
private static void query_whenPassedANullMaxAge_throwsAnException() // NOPMD: Test method name format
{
Expand Down

0 comments on commit cb8cea0

Please sign in to comment.