Skip to content

Commit 84dc3d6

Browse files
committed
add ehcache test cases from lucee core test suite
Copies EHCache.cfc, ehcache/Application.cfc, and ticket tests LDEV0549, LDEV0875, LDEV1741, LDEV6136 — all carrying labels="cache,ehCache".
1 parent b2898be commit 84dc3d6

17 files changed

Lines changed: 546 additions & 0 deletions

File tree

tests/EHCache.cfc

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<!--- MUST fix the test case and enable again!
2+
*
3+
* Copyright (c) 2016, Lucee Association Switzerland. All rights reserved.*
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
---><cfscript>
19+
component extends="org.lucee.cfml.test.LuceeTestCase" labels="cache,ehCache" {
20+
21+
22+
//public function afterTests(){}
23+
24+
public function setUp(){
25+
defineCache();
26+
}
27+
28+
public void function test(){
29+
cachePut(id:'abc', value:'AAA', cacheName:'ehcache');
30+
var val=cacheget(id:'abc', cacheName:'ehcache');
31+
assertEquals("AAA",val);
32+
33+
}
34+
35+
36+
public void function testTimespan() {
37+
38+
var rightNow = Now();
39+
var testData = {"time": rightNow};
40+
var cacheId='jkijhiiuhkj';
41+
var cacheName='ehcache';
42+
43+
// first we store the data
44+
cachePut(id=cacheId, value=testData, timeSpan=createTimespan(0,0,0,1), cacheName=cacheName);
45+
46+
// getting back without waiting on it
47+
var theValue = cacheGet(id=cacheId, cacheName=cacheName);
48+
var wasFound = !isNull(theValue);
49+
assertTrue(wasFound);
50+
51+
// getting back after at least a second
52+
sleep(1500); // take a nap
53+
var theValue = cacheGet(id=cacheId, cacheName=cacheName);
54+
var wasFound = !isNull(theValue);
55+
assertFalse(wasFound);
56+
}
57+
58+
59+
/*public void function testLDEV1579() {
60+
61+
62+
var rightNow = Now();
63+
var testData = {"time": rightNow};
64+
var cacheId='jkijhiiuhkj';
65+
var cacheName='ehcache';
66+
67+
cachePut(id="testString", value=11111, cacheName=cacheName);
68+
cachePut(id="testNow", value=now(), cacheName=cacheName);
69+
CacheGetAll(cacheName=cacheName);
70+
}*/
71+
72+
private string function defineCache(){
73+
application action="update"
74+
caches="#{ehcache: {
75+
class: 'org.lucee.extension.cache.eh.EHCache'
76+
, maven: 'org.lucee:ehcache'
77+
, storage: false
78+
, custom: {"bootstrapAsynchronously":"true","replicatePuts":"true","automatic_hostName":"",
79+
"bootstrapType":"on","maxelementsinmemory":"10000","manual_rmiUrls":"","distributed":"off",
80+
"automatic_multicastGroupAddress":"230.0.0.1","memoryevictionpolicy":"LRU","replicatePutsViaCopy":"true",
81+
"timeToIdleSeconds":"1","timeToLiveSeconds":"1","maximumChunkSizeBytes":"5000000","automatic_multicastGroupPort":"4446",
82+
"listener_socketTimeoutMillis":"120000",
83+
"diskpersistent":"true","manual_addional":"","replicateRemovals":"true",
84+
"replicateUpdatesViaCopy":"true","automatic_addional":"","overflowtodisk":"true","replicateAsynchronously":"true",
85+
"maxelementsondisk":"10000000","listener_remoteObjectPort":"","asynchronousReplicationIntervalMillis":"1000",
86+
"listener_hostName":"","replicateUpdates":"true","manual_hostName":"","automatic_timeToLive":"unrestricted","listener_port":""
87+
}
88+
, default: ''
89+
}}#";
90+
91+
return true;
92+
}
93+
94+
public void function testCacheAsScope(){
95+
local.id=createUniqueId();
96+
local.urls={appName:id};
97+
local.uri=createURI("ehcache/index.cfm");
98+
99+
// on the first request everything is equal
100+
local.result=_InternalRequest(template:uri,urls:urls,addtoken:true);
101+
local.sct=evaluate(result.filecontent);
102+
loop list="client,session" item="local.scp" {
103+
assertEquals(sct[scp].lastvisit&"",sct[scp].timecreated&"");
104+
}
105+
106+
sleep(1000);
107+
108+
// on the second request time is different
109+
local.result=_InternalRequest(template:uri,urls:urls,addtoken:true);
110+
local.sct=evaluate(result.filecontent);
111+
loop list="client,session" item="local.scp" {
112+
assertEquals(sct[scp].lastvisit&"",sct[scp].timecreated&"");
113+
}
114+
115+
sleep(1000);
116+
/*
117+
// on the third everything is different
118+
local.result=_InternalRequest(template:uri,urls:urls,addtoken:true);
119+
local.sct=evaluate(result.filecontent);
120+
loop list="client,session" item="scp" {
121+
assertNotEquals(sct[scp].lastvisit&"",sct[scp].timecreated&""); fails
122+
}
123+
*/
124+
}
125+
126+
private string function createURI(string calledName){
127+
var baseURI="/test/#listLast(getDirectoryFromPath(getCurrenttemplatepath()),"\/")#/";
128+
return baseURI&""&calledName;
129+
}
130+
131+
132+
}
133+
</cfscript>

tests/LDEV0549.cfc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
component extends="org.lucee.cfml.test.LuceeTestCase" labels="cache,ehCache" {
2+
function run( testResults , testBox ) {
3+
describe( "Test suite for LDEV-549", function() {
4+
it(title="checking EHCache with the name 'default' ", body = function( currentSpec ) {
5+
var uri=createURI("LDEV0549/App1/test.cfm");
6+
var result = _InternalRequest(
7+
template:uri
8+
);
9+
expect(result.filecontent.trim()).toBe("AppA549");
10+
});
11+
12+
it(title="checking RamCache with the name 'default' ", body = function( currentSpec ) {
13+
var uri=createURI("LDEV0549/App2/test.cfm");
14+
var result = _InternalRequest(
15+
template:uri
16+
);
17+
expect(result.filecontent.trim()).toBe("AppB549");
18+
});
19+
});
20+
}
21+
// private Function//
22+
private string function createURI(string calledName){
23+
var baseURI="/test/#listLast(getDirectoryFromPath(getCurrenttemplatepath()),"\/")#/";
24+
return baseURI&""&calledName;
25+
}
26+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
component {
2+
this.name = 'AppA549';
3+
this.cache.connections["default"] = {
4+
class: 'org.lucee.extension.cache.eh.EHCache'
5+
, maven: 'org.lucee:ehcache'
6+
, storage: true
7+
, custom: {"bootstrapAsynchronously":"true","replicatePuts":"true","automatic_hostName":"","bootstrapType":"on","maxelementsinmemory":"10000","manual_rmiUrls":"","distributed":"off","automatic_multicastGroupAddress":"230.0.0.1","memoryevictionpolicy":"LRU","replicatePutsViaCopy":"true","timeToIdleSeconds":"86400","maximumChunkSizeBytes":"5000000","automatic_multicastGroupPort":"4446","listener_socketTimeoutMillis":"120000","timeToLiveSeconds":"86400","diskpersistent":"true","manual_addional":"","replicateRemovals":"true","replicateUpdatesViaCopy":"true","automatic_addional":"","overflowtodisk":"true","replicateAsynchronously":"true","maxelementsondisk":"10000000","listener_remoteObjectPort":"","asynchronousReplicationIntervalMillis":"1000","listener_hostName":"","replicateUpdates":"true","manual_hostName":"","automatic_timeToLive":"unrestricted","listener_port":""}
8+
, default: 'object'
9+
};
10+
this.cache.object = "default";
11+
12+
public function onRequestStart() {
13+
setting requesttimeout=10;
14+
}
15+
}

tests/LDEV0549/APP1/test.cfm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<cfscript>
2+
cachedVar = cacheGet("default");
3+
cachedVar = APPLICATION.ApplicationName;
4+
cachePut("default", cachedVar);
5+
writeOutput(cachedVar);
6+
</cfscript>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
component {
2+
this.name = 'AppB549';
3+
this.cache.connections["default"] = {
4+
class: 'lucee.runtime.cache.ram.RamCache'
5+
, storage: true
6+
, custom: {"timeToIdleSeconds":"0","timeToLiveSeconds":"0"}
7+
, default: 'object'
8+
};
9+
this.cache.object = "default";
10+
11+
public function onRequestStart() {
12+
setting requesttimeout=10;
13+
}
14+
}

tests/LDEV0549/App2/test.cfm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<cfscript>
2+
cachedVar = cacheGet("default");
3+
cachedVar = APPLICATION.ApplicationName;
4+
cachePut("default", cachedVar);
5+
writeOutput(cachedVar);
6+
</cfscript>

tests/LDEV0875.cfc

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2014, the Railo Company LLC. All rights reserved.
3+
*
4+
* This library is free software; you can redistribute it and/or
5+
* modify it under the terms of the GNU Lesser General Public
6+
* License as published by the Free Software Foundation; either
7+
* version 2.1 of the License, or (at your option) any later version.
8+
*
9+
* This library is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
* Lesser General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU Lesser General Public
15+
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
16+
*/
17+
component extends="org.lucee.cfml.test.LuceeTestCase" {
18+
variables.cacheName="Test"&ListFirst(ListLast(getCurrentTemplatePath(),"\/"),".");
19+
20+
public function testCachePutEHCache() {
21+
createRAMCache();
22+
23+
cachePut('abc','123',1);
24+
25+
deleteCache();
26+
}
27+
28+
29+
30+
31+
private function createRAMCache(){
32+
admin
33+
action="updateCacheConnection"
34+
type="web"
35+
password="#request.webadminpassword#"
36+
37+
38+
name="#cacheName#"
39+
class="lucee.runtime.cache.ram.RamCache"
40+
storage="false"
41+
default="object"
42+
custom="#{timeToLiveSeconds:86400
43+
,timeToIdleSeconds:86400}#";
44+
}
45+
46+
private function deleteCache(){
47+
admin
48+
action="removeCacheConnection"
49+
type="web"
50+
password="#request.webadminpassword#"
51+
name="#cacheName#";
52+
53+
}
54+
}

tests/LDEV1741.cfc

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
component extends="org.lucee.cfml.test.LuceeTestCase" labels="orm,cache,ehCache" {
2+
function run( testResults , testBox ) {
3+
describe( title="Test suite for LDEV-1741", body=function() {
4+
it( title='checking ORM secondary ehcache with this.ormsettings.cacheconfig = "ehcache.xml" ',skip=noOrm(),body=function( currentSpec ) {
5+
var uri = createURI("LDEV1741");
6+
var result1 = _InternalRequest(
7+
template:"#uri#/App1/index.cfm",
8+
urls:{appName:"MyAppOne"}
9+
);
10+
11+
var result2 = _InternalRequest(
12+
template:"#uri#/App1/index.cfm",
13+
urls:"appName=MyAppTwo"
14+
);
15+
16+
assertEquals(200, result2.status_code);
17+
18+
if( result2.status_code == 200 )
19+
assertEquals("Bar", result2.filecontent.trim());
20+
});
21+
22+
it( title='checking ORM secondary ehcache without cacheconfig',skip=noOrm(),body=function( currentSpec ) {
23+
var uri = createURI("LDEV1741");
24+
var result1 = _InternalRequest(
25+
template:"#uri#/App2/index.cfm",
26+
urls:{appName:"testOne"}
27+
);
28+
29+
var result2 = _InternalRequest(
30+
template:"#uri#/App2/index.cfm",
31+
urls:{appName:"testTwo"}
32+
);
33+
34+
assertEquals(200, result2.status_code);
35+
if( result2.status_code == 200 )
36+
assertEquals("Bar", result2.filecontent.trim());
37+
});
38+
});
39+
}
40+
41+
// private Function//
42+
private string function createURI(string calledName){
43+
var baseURI="/test/#listLast(getDirectoryFromPath(getCurrenttemplatepath()),"\/")#/";
44+
return baseURI&""&calledName;
45+
}
46+
47+
private function noOrm() {
48+
return ( structCount( server.getTestService("orm") ) eq 0 );
49+
}
50+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
component {
2+
3+
param name="url.appName" default="myAppOne";
4+
5+
this.name = "#url.appName#";
6+
7+
// any other application.cfc stuff goes below:
8+
this.sessionManagement = true;
9+
this.mappings[ "/model" ] = getDirectoryFromPath( getCurrentTemplatePath() ) & 'model';
10+
11+
12+
// DATASOURCE CONFIG
13+
dbname = 'testdb8';
14+
15+
this.datasources[dbname] = server.getDatasource( "h2", server._getTempDir( "LDEV1741-app1" ) );
16+
17+
18+
// ORM CONFIG
19+
this.defaultDatasource = "#dbname#";
20+
this.ormenabled = true; // turnm ORM on or this application
21+
this.ormsettings.dbcreate = 'update'; // valid settings: none | update | dropcreate
22+
this.ormsettings.flushatrequestend = false; // we are going to manually commit all transactions
23+
this.ormsettings.automanagesession = false; // we are going to manually commit all transactions
24+
this.ormsettings.secondarycacheenabled = true; // use secondary cache
25+
this.ormsettings.cacheProvider = 'ehcache'; // ehCache for now
26+
this.ormsettings.cfclocation = ['/model/']; // CFC location (s)
27+
this.ormsettings.datasource = "#dbname#"; // default DB for ORM
28+
this.ormsettings.dialect = "mysql";
29+
this.ormsettings.useDBForMapping = false; // false = do not walk the db on startup trying to create ORM definitions
30+
this.ormsettings.cacheconfig = "ehcache.xml"
31+
32+
33+
public function onRequestStart() {
34+
setting requesttimeout=10;
35+
}
36+
37+
}

tests/LDEV1741/App1/ehcache.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd" name="a">
3+
<defaultCache
4+
maxElementsInMemory="100"
5+
eternal="false"
6+
timeToIdleSeconds="15"
7+
timeToLiveSeconds="30"
8+
overflowToDisk="false"
9+
/>
10+
</ehcache>

0 commit comments

Comments
 (0)