[infinispan-commits] Infinispan SVN: r2590 - in trunk/server/rest/src: test/scala/org/infinispan/rest and 1 other directory.
infinispan-commits at lists.jboss.org
infinispan-commits at lists.jboss.org
Mon Oct 25 08:56:19 EDT 2010
Author: galder.zamarreno at jboss.com
Date: 2010-10-25 08:56:18 -0400 (Mon, 25 Oct 2010)
New Revision: 2590
Modified:
trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala
trunk/server/rest/src/main/scala/org/infinispan/rest/StartupListener.scala
trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
Log:
ISPN-732 - In REST, default values for maxIdleTimeSeconds and timeToLiveSeconds should be -1 - Merged from 4.2.x (rev 2589)
Modified: trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala
===================================================================
--- trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala 2010-10-25 12:49:09 UTC (rev 2589)
+++ trunk/server/rest/src/main/scala/org/infinispan/rest/Server.scala 2010-10-25 12:56:18 UTC (rev 2590)
@@ -16,7 +16,7 @@
* // TODO
*
* @author Michael Neale
- * @author Galder Zamarreno
+ * @author Galder Zamarreño
* @since 4.0
*/
@Path("/rest")
@@ -86,8 +86,8 @@
@Path("/{cacheName}/{cacheKey}")
def putEntry(@PathParam("cacheName") cacheName: String, @PathParam("cacheKey") key: String,
@HeaderParam("Content-Type") mediaType: String, data: Array[Byte],
- @HeaderParam("timeToLiveSeconds") ttl: Long,
- @HeaderParam("maxIdleTimeSeconds") idleTime: Long) = {
+ @DefaultValue("-1") @HeaderParam("timeToLiveSeconds") ttl: Long,
+ @DefaultValue("-1") @HeaderParam("maxIdleTimeSeconds") idleTime: Long) = {
val cache = ManagerInstance.getCache(cacheName)
if (request.getMethod == "POST" && cache.containsKey(key)) {
Response.status(Status.CONFLICT).build()
Modified: trunk/server/rest/src/main/scala/org/infinispan/rest/StartupListener.scala
===================================================================
--- trunk/server/rest/src/main/scala/org/infinispan/rest/StartupListener.scala 2010-10-25 12:49:09 UTC (rev 2589)
+++ trunk/server/rest/src/main/scala/org/infinispan/rest/StartupListener.scala 2010-10-25 12:56:18 UTC (rev 2590)
@@ -10,7 +10,7 @@
* requests are attempted to be serviced. Less kitten carnage.
*
* @author Michael Neale
- * @author Galder Zamarreno
+ * @author Galder Zamarreño
* @since 4.0
*/
class StartupListener extends HttpServlet {
Modified: trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala
===================================================================
--- trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala 2010-10-25 12:49:09 UTC (rev 2589)
+++ trunk/server/rest/src/test/scala/org/infinispan/rest/IntegrationTest.scala 2010-10-25 12:56:18 UTC (rev 2590)
@@ -11,6 +11,8 @@
import org.testng.Assert._
import java.lang.reflect.Method
import org.infinispan.manager.{CacheContainer, DefaultCacheManager}
+import scala.math._
+import org.infinispan.test.TestingUtil
/**
* This tests using the Apache HTTP commons client library - but you could use anything
@@ -18,7 +20,7 @@
* (Given that RESTEasy does most of the heavy lifting !).
*
* @author Michael Neale
- * @author Galder Zamarreno
+ * @author Galder Zamarreño
* @since 4.0
*/
@Test(groups = Array("functional"), testName = "rest.IntegrationTest")
@@ -175,19 +177,34 @@
assertEquals(HttpServletResponse.SC_OK, Client.call(put).getStatusCode)
}
- def testPutDataWithTimeToLive(m: Method) = {
+ def testPutDataWithTimeToLive(m: Method) = putAndAssertEphemeralData(m, "2", "3")
+
+ def testPutDataWithMaxIdleOnly(m: Method) = putAndAssertEphemeralData(m, "", "3")
+
+ def testPutDataWithTimeToLiveOnly(m: Method) = putAndAssertEphemeralData(m, "3", "")
+
+ private def putAndAssertEphemeralData(m: Method, timeToLiveSeconds: String, maxIdleTimeSeconds: String) {
val fullPathKey = fullPath + "/" + m.getName
val post = new PostMethod(fullPathKey)
post.setRequestHeader("Content-Type", "application/text")
- post.setRequestHeader("timeToLiveSeconds", "2")
- post.setRequestHeader("maxIdleTimeSeconds", "3")
+ var maxWaitTime = 0
+ if (!timeToLiveSeconds.isEmpty) {
+ maxWaitTime = max(maxWaitTime, timeToLiveSeconds.toInt)
+ post.setRequestHeader("timeToLiveSeconds", timeToLiveSeconds)
+ }
+
+ if (!maxIdleTimeSeconds.isEmpty) {
+ maxWaitTime = max(maxWaitTime, maxIdleTimeSeconds.toInt)
+ post.setRequestHeader("maxIdleTimeSeconds", maxIdleTimeSeconds)
+ }
+
post.setRequestBody("data")
Client.call(post)
val get = Client.call(new GetMethod(fullPathKey))
assertEquals("data", get.getResponseBodyAsString)
- Thread.sleep(3000)
+ TestingUtil.sleepThread((maxWaitTime + 1) * 1000)
Client.call(get)
assertEquals(HttpServletResponse.SC_NOT_FOUND, get.getStatusCode)
}
More information about the infinispan-commits
mailing list