PageRenderTime 244ms CodeModel.GetById 140ms app.highlight 3ms RepoModel.GetById 98ms app.codeStats 0ms

/wheels/vendor/memcached/memcachedtest.cfm

http://cfwheels.googlecode.com/
ColdFusion | 191 lines | 131 code | 28 blank | 32 comment | 11 complexity | de84e16f569c864d40bc3ef82c1328b7 MD5 | raw file
  1<!-----------
  2	This is a simple test file to show how to use memcached.  in order for this to work right, you should 
  3	have a memcached instances up.  It is initially set up to look for the memcached server on the localhost, 
  4	however, the server location can be changed by passing it in to the memcached factory.
  5	
  6	the default port for memcached is 11211.
  7	
  8	you can actually use this memcached client across multiple memcached servers. You can specify multiple 
  9	memcached servers by making them a comma delimited list and sending that in to the init function.
 10	You can also send in an array list of servers.
 11	
 12	Be aware, that changing the number of servers or dropping one of the servers out of the server list is likely to 
 13	cause a loss of all cached data because it will have to recalculate the positions and locations of the keys.
 14	this will only happen if you init the memcached factory again with more or less servers than you start out with.
 15------------>
 16<cfset variables.memcachedFactory = createObject("component","memcachedFactory").init("127.0.0.1:11211")>
 17<cfset variables.memcached = variables.memcachedFactory.getmemcached()>
 18
 19	<!--------- setting a long test ------------->
 20	<cfset set1 = variables.memcached.set(key="longTest",value=11111111111111111,expiry="5000")>
 21	<!----------- setting string test ----------->
 22	<cfset set2 = variables.memcached.set(key="simpleval",value="simpleval43466665532",expiry="5000")>
 23	<!------------ setting an int test ---------->
 24	<cfset set3 = variables.memcached.set(key="anothersimpleval",value=8,expiry="5000")>
 25	<!------------ setting array test ------------>
 26	<cfset arrTest = arrayNew(1)>
 27	<Cfset arrTest[1] = "someval">
 28	<Cfset arrTest[2] = "someotherval">
 29	<Cfset arrTest[3] = "someothersecondval">
 30
 31	<cfset set4 = variables.memcached.set(key="arrTest",value=arrTest,expiry="5000")>
 32	
 33	<!---------------setting a struct test -------->
 34	<Cfset structTest = structNew()>
 35	<cfset structTest["somekey"] = "someval">
 36	<cfset structTest["someotherkey"] = "someother val">
 37	<Cfset structTest["someothersecondkey"] = "some other second val">
 38
 39	<cfset set5 = variables.memcached.set(key="structTest",value=structTest,expiry="5000")>
 40	
 41	<!------------ setting a query test ---------->
 42	<cfset qTest = queryNew("col1,col2,col3")>
 43	<cfset queryAddRow(qTest,1)>
 44	<cfset querysetCell(qTest,"col1","yo")>
 45	<cfset querysetCell(qTest,"col2","adrian")>
 46	<cfset querysetCell(qTest,"col3",8888888)>
 47
 48	<cfset set6 = variables.memcached.set(key="queryTest",value=qTest,expiry="5000")>
 49	
 50	<cfoutput>
 51		Here are there responses that were returned. boolean values that are returned when the set completes<br><br>
 52	
 53	<br><br>this is the long test - did it set correctly?  - <cfdump var="#set1.get()#">
 54
 55	<br><br>this is the String test - did it set correctly?  - <cfdump var="#set2.get()#">
 56	<br><br>this is the Integer test - did it set correctly?  - <cfdump var="#set3.get()#">
 57	<br><br>this is the Array test - did it set correctly?  - <cfdump var="#set4.get()#">
 58	<br><br>this is the Struct test - did it set correctly?  - <cfdump var="#set5.get()#">
 59	<br><br>this is the query test - did it set correctly?  - <cfdump var="#set5.get()#">
 60	</cfoutput>
 61
 62<!------------- this is retrieval test to make sure we can get it back out --------->
 63
 64<!------------ long test ---------->
 65<cfset test1 = variables.memcached.get("longTest")>
 66	
 67<!------- simple string test ------------>
 68<cfset test2 = variables.memcached.get("simpleval")>
 69<!------- int test ------------->
 70<cfset test3 = variables.memcached.get("anothersimpleval")>
 71<!---------- array test ------------>
 72<cfset test4 = variables.memcached.get("arrTest")>
 73<!--------- struct test ------------>
 74<cfset test5 = variables.memcached.get("structTest")>
 75<!--------- query test ------------->
 76<Cfset test6 = variables.memcached.get("queryTest")>
 77<!-------- stats test just for fun ---------->
 78<!----
 79<Cfset test7 = variables.memcached.getStats()>
 80----->
 81<Cfset test7 = "">
 82
 83<cfoutput>
 84	--------------------------------------------------------
 85<br><br>this is the long test - did we retrieve it correctly?  - <cfdump var="#test1#">
 86<br><br>this is the string test - did we retrieve it correctly?  - <cfdump var="#test2#">
 87<br><br>this is the integer test - did we retrieve it correctly?  - <cfdump var="#test3#">
 88
 89<br><br>this is the array test - did we retrieve it correctly?  - <Cfdump var="#Test4#">
 90<br><br> as a comparison, this is what it should look like <br>
 91-------------------------------------- <br>
 92<cfdump var="#arrTest#">
 93<br>
 94
 95<br><br>this is the struct test - did we retrieve it correctly?  - <Cfdump var="#Test5#">
 96<br><br> as a comparison, this is what it should look like <br>
 97-------------------------------------- <br>
 98<cfdump var="#structTest#">
 99<br>
100<br><br>this is the query test - did we retrieve it correctly?  - <Cfdump var="#Test6#">
101<br><br> as a comparison, this is what it should look like <br>
102-------------------------------------- <br>
103<cfdump var="#qTest#">
104<br>
105<br><br>this is the stats test -  
106<Cfdump var="#Test7.toString()#">
107
108
109
110<cfscript>
111//	keyList = structKeylist(test7);
112	//newOne = mapToStruct(test7);
113</cfscript>
114
115
116<cfscript>
117	myendVal = "";
118	myFutureTask = variables.memcached.asyncGet("queryTest");
119	if (myFutureTask.isDone())	{
120		myendVal = myFutureTask.get();
121	} else {
122		customSleep(2000);
123		if (myFutureTask.isDone())	{
124			myEndVal = myFutureTask.get();
125		}
126	}
127</cfscript>
128<cfdump var="#myFutureTask#">
129<cfdump var="#myEndVal#">
130
131<Cfset arrTestVals = arraynew(1)>
132<cfset arrayAppend(arrTestVals,"longTest")>
133<cfset arrayAppend(arrTestVals,"queryTest")>
134<cfset arrayAppend(arrTestVals,"arrTest")>
135<cfset arrayAppend(arrTestVals,"structTest")>
136<cfset bulkvar = variables.memcached.getBulk(arrTestVals)>
137
138<cfdump var="#bulkvar#">
139
140<cfscript>
141	myendVal = "";
142	myFutureTask = variables.memcached.asyncGetBulk(arrTestVals);
143	if (myFutureTask.isDone())	{
144		myendVal = myFutureTask.get();
145	} else {
146		customSleep(2000);
147		if (myFutureTask.isDone())	{
148			myEndVal = myFutureTask.get();
149		}
150	}
151</cfscript>
152<cfdump var="#myFutureTask#">
153<cfdump var="#myEndVal#">
154
155</cfoutput>
156
157<cffunction name="customSleep" output="No" returntype="void" hint=
158		"Pauses execution for a number of milliseconds."
159	>
160		<cfargument name="milliseconds" required="Yes" type="numeric"/>
161		<cfset var thread = CreateObject("java", "java.lang.Thread")/>
162		<cfset thread.sleep(ARGUMENTS.milliseconds)/>
163</cffunction>
164
165<cfscript>
166	function GetClassHeirarchy(obj){
167		var thisClass = obj.GetClass();
168		var sReturn = thisClass.GetName();
169		do{  
170			thisClass = thisClass.GetSuperClass();  
171			sReturn = sReturn & " EXTENDS: #thisClass.GetName()#";
172		} while(CompareNoCase(thisClass.GetName(), 'java.lang.Object'));
173		
174		return sReturn;
175	}
176	
177	function mapToStruct(obj)	{
178		var ret = structNew();
179		if (not obj.isEmpty())	{
180			do {
181				key = obj.entrySet().iterator().next();
182				thisval = obj.get(key);
183				if (isdefined("thisval"))	{
184					ret[key.toString()] = thisval;
185				} else {
186					ret[key.toString()] = "";
187				}
188			} while ( obj.entrySet().iterator().hasNext() );
189		}
190	}
191</cfscript>