Author: julien_viet
Date: 2011-02-15 11:33:46 -0500 (Tue, 15 Feb 2011)
New Revision: 5896
Modified:
components/pc/trunk/test/core/src/test/java/org/gatein/pc/test/portlet/jsr286/ext/cache/CacheValidationTestCase.java
Log:
improve the cache validation test case
Modified:
components/pc/trunk/test/core/src/test/java/org/gatein/pc/test/portlet/jsr286/ext/cache/CacheValidationTestCase.java
===================================================================
---
components/pc/trunk/test/core/src/test/java/org/gatein/pc/test/portlet/jsr286/ext/cache/CacheValidationTestCase.java 2011-02-15
16:19:44 UTC (rev 5895)
+++
components/pc/trunk/test/core/src/test/java/org/gatein/pc/test/portlet/jsr286/ext/cache/CacheValidationTestCase.java 2011-02-15
16:33:46 UTC (rev 5896)
@@ -61,9 +61,6 @@
/** . */
private boolean cached;
- /** . */
- private String cachedMarkup;
-
public CacheValidationTestCase(PortletTestCase seq)
{
// Set two seconds of expiration
@@ -82,14 +79,45 @@
response.getCacheControl().setExpirationTime(2);
response.getCacheControl().setETag("footag");
- // Refresh
- return new InvokeGetResponse(response.createRenderURL().toString());
+ //
+ return null;
}
});
+ seq.bindAction(0, UTP2.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
+ {
+ // Trigger a resource so we are sure that the cached portlet will not be part
of the whole request
+ return new InvokeGetResponse(response.createResourceURL().toString());
+ }
+ });
//
- seq.bindAction(1, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ seq.bindAction(1, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
{
+ @Override
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ try
+ {
+ // Wait for one second so the cached content will be aged of 1 second
+ Thread.sleep(1000);
+
+ // Now render the full page
+ return new InvokeGetResponse(response.createRenderURL().toString());
+ }
+ catch (InterruptedException e)
+ {
+ return new FailureResponse(Failure.createFailure(e));
+ }
+ }
+ });
+
+ // Now make the request to the full page after one second, the goal is to test also
an issue whereby the request
+ // to the cached content extends the expiration out of the box, as we will wait
after that for one second, if that
+ // problem occur, then the revalidation would not occur at all
+ seq.bindAction(2, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
{
// Set cached to false to make test fail later
@@ -97,18 +125,17 @@
return null;
}
});
- seq.bindAction(1, UTP2.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ seq.bindAction(2, UTP2.RENDER_JOIN_POINT, new PortletRenderTestAction()
{
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
{
// Trigger a resource so we are sure that the cached portlet will not be part
of the whole request
- // and we can make the 2 seconds pause without messing with the invalid entry
we want to revalidate
return new InvokeGetResponse(response.createResourceURL().toString());
}
});
//
- seq.bindAction(2, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ seq.bindAction(3, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
{
@Override
protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
@@ -121,21 +148,23 @@
String cachedMarkup = new String(bytes, "UTF-8");
Assert.assertTrue("Was expected " + cachedMarkup + " to
contain foocached", cachedMarkup.contains("foocached"));
- // Wait at least 2 seconds so we are sure content will expire
+ // Wait for one second so the content should have just expired
try
{
- Thread.sleep(2000);
- return new InvokeGetResponse(response.createRenderURL().toString());
+ Thread.sleep(1000);
}
catch (InterruptedException e)
{
return new FailureResponse(Failure.createFailure(e));
}
+
+ //
+ return new InvokeGetResponse(response.createRenderURL().toString());
}
});
// Assert we have the etag and revalidate response for two seconds
- seq.bindAction(3, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ seq.bindAction(4, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
{
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
{
@@ -145,13 +174,44 @@
// Revalidate markup for two seconds and invoke again
response.getCacheControl().setUseCachedContent(true);
response.getCacheControl().setExpirationTime(2);
- return new InvokeGetResponse(response.createRenderURL().toString());
+
+ //
+ return null;
}
});
+ seq.bindAction(4, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
+ {
+ // Trigger a resource so we are sure that the cached portlet will not be part
of the whole request
+ return new InvokeGetResponse(response.createResourceURL().toString());
+ }
+ });
//
- seq.bindAction(4, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ seq.bindAction(5, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
{
+ @Override
+ protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
+ {
+ try
+ {
+ // Wait for one second so the cached content will be aged of 1 second
+ Thread.sleep(1000);
+
+ // Now render the full page
+ return new InvokeGetResponse(response.createRenderURL().toString());
+ }
+ catch (InterruptedException e)
+ {
+ return new FailureResponse(Failure.createFailure(e));
+ }
+ }
+ });
+
+ //
+ seq.bindAction(6, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
{
// Set cached to false to make test fail later
@@ -159,7 +219,7 @@
return null;
}
});
- seq.bindAction(4, UTP2.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ seq.bindAction(6, UTP2.RENDER_JOIN_POINT, new PortletRenderTestAction()
{
protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
{
@@ -170,7 +230,7 @@
});
//
- seq.bindAction(5, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
+ seq.bindAction(7, UTP2.RESOURCE_JOIN_POINT, new PortletResourceTestAction()
{
@Override
protected DriverResponse run(Portlet portlet, ResourceRequest request,
ResourceResponse response, PortletTestContext context) throws PortletException,
IOException
@@ -183,7 +243,30 @@
String cachedMarkup = new String(bytes, "UTF-8");
Assert.assertTrue("Was expected " + cachedMarkup + " to
contain foocached", cachedMarkup.contains("foocached"));
- // We are done
+ // Wait for one second so the content should have just expired
+ try
+ {
+ Thread.sleep(1000);
+ }
+ catch (InterruptedException e)
+ {
+ return new FailureResponse(Failure.createFailure(e));
+ }
+
+ //
+ return new InvokeGetResponse(response.createRenderURL().toString());
+ }
+ });
+
+ // Assert we have the etag and revalidate response for two seconds
+ seq.bindAction(8, UTP1.RENDER_JOIN_POINT, new PortletRenderTestAction()
+ {
+ protected DriverResponse run(Portlet portlet, RenderRequest request,
RenderResponse response, PortletTestContext context) throws IOException, PortletException
+ {
+ // Check everything is as espected
+ Assert.assertEquals("footag", request.getETag());
+
+ // Finish the test
return new EndTestResponse();
}
});