Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 68614 invoked from network); 23 Aug 2006 12:39:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 23 Aug 2006 12:39:32 -0000 Received: (qmail 50936 invoked by uid 500); 23 Aug 2006 12:39:32 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 50889 invoked by uid 500); 23 Aug 2006 12:39:31 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 50878 invoked by uid 99); 23 Aug 2006 12:39:31 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Aug 2006 05:39:31 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 23 Aug 2006 05:39:30 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id E39AC1A981D; Wed, 23 Aug 2006 05:39:09 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r434032 - in /cocoon/trunk/blocks: cocoon-repository/cocoon-repository-impl/ cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/ cocoon-repository/cocoon-repository-impl/src/test/ cocoon-reposito... Date: Wed, 23 Aug 2006 12:39:04 -0000 To: cvs@cocoon.apache.org From: vgritsenko@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060823123909.E39AC1A981D@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: vgritsenko Date: Wed Aug 23 05:39:03 2006 New Revision: 434032 URL: http://svn.apache.org/viewvc?rev=434032&view=rev Log: move caching source test to repository block. enhance the test. Added: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/ - copied from r433766, cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/test/ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/java/ - copied from r434017, cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/test/java/ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/resources/ - copied from r434017, cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/test/resources/ Removed: cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/test/java/ cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/src/test/resources/ Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/pom.xml cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/TraversableCachingSource.java cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/java/org/apache/cocoon/components/source/impl/CachingSourceTestCase.java cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/resources/org/apache/cocoon/components/source/impl/CachingSourceTestCase.xtest cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/pom.xml Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/pom.xml URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/pom.xml?rev=434032&r1=434031&r2=434032&view=diff ============================================================================== --- cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/pom.xml (original) +++ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/pom.xml Wed Aug 23 05:39:03 2006 @@ -17,9 +17,9 @@ specific language governing permissions and limitations under the License. --> + @@ -34,6 +34,7 @@ jar repository Block Implementation + org.apache.cocoon @@ -108,5 +109,38 @@ + + + javax.servlet + servlet-api + 2.3 + provided + + + org.apache.cocoon + cocoon-core + 2.2.0-M2-SNAPSHOT + test-jar + test + + + junit + junit + 3.8.2 + test + + + + + maven-surefire-plugin + + + **/*TestCase.class + **/*Test.class + + + + + Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java?rev=434032&r1=434031&r2=434032&view=diff ============================================================================== --- cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java (original) +++ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/CachingSource.java Wed Aug 23 05:39:03 2006 @@ -77,7 +77,7 @@ Source { // TODO: Decouple from eventcache block. - + // ---------------------------------------------------- Constants public static final String CACHE_EXPIRES_PARAM = "cache-expires"; Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/TraversableCachingSource.java URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/TraversableCachingSource.java?rev=434032&r1=434031&r2=434032&view=diff ============================================================================== --- cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/TraversableCachingSource.java (original) +++ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/main/java/org/apache/cocoon/components/source/impl/TraversableCachingSource.java Wed Aug 23 05:39:03 2006 @@ -77,6 +77,10 @@ } public Source getChild(String name) throws SourceException { + if (!isCollection()) { + throw new SourceException("Source is not a collection"); + } + Source child; try { getResponseMeta(); @@ -87,11 +91,12 @@ throw new SourceException("Failure getting child", e); } - if (!isCollection()) { - throw new SourceException("Source is not a collection"); + boolean isCollection = false; + if (child instanceof TraversableSource) { + isCollection = ((TraversableSource) child).isCollection(); } - return createSource(getChildURI(super.uri, name), getChildURI(super.sourceUri, name), child); + return createSource(getChildURI(super.uri, isCollection, name), getChildURI(super.sourceUri, isCollection, name), child); } public Collection getChildren() throws SourceException { @@ -117,7 +122,13 @@ } catch (IOException e) { throw new SourceException("Failure getting child", e); } - result.add(createSource(getChildURI(super.uri, children[i]), getChildURI(super.sourceUri, children[i]), child)); + + boolean isCollection = false; + if (child instanceof TraversableSource) { + isCollection = ((TraversableSource) child).isCollection(); + } + + result.add(createSource(getChildURI(super.uri, isCollection, children[i]), getChildURI(super.sourceUri, isCollection, children[i]), child)); } return result; @@ -153,7 +164,7 @@ * Calculate the cached child URI based on a parent URI * and a child name. */ - private static String getChildURI(String parentURI, String childName) { + private static String getChildURI(String parentURI, boolean isCollection, String childName) { // separate query string from rest of parentURI String rest, qs; int index = parentURI.indexOf('?'); @@ -165,15 +176,17 @@ qs = ""; } - // calculate qs-less child uri - String childURI; - if (rest.charAt(rest.length()-1) == '/') { - childURI = rest + childName; - } else { - childURI = rest + "/" + childName; + // calculate child uri + StringBuffer childURI = new StringBuffer(rest); + if (rest.charAt(rest.length()-1) != '/') { + childURI.append('/'); + } + childURI.append(childName); + if (isCollection) { + childURI.append('/'); } - - return childURI + qs; + childURI.append(qs); + return childURI.toString(); } /** @@ -186,19 +199,17 @@ if (index != -1) { rest = childURI.substring(0, index); qs = childURI.substring(index); - } - else { + } else { rest = childURI; qs = ""; } // calculate qs-less parent uri String parentUri; - index = rest.lastIndexOf('/',rest.length()-2); + index = rest.lastIndexOf('/', rest.length() - 2); if (index != -1) { - parentUri = rest.substring(0,index); - } - else { + parentUri = rest.substring(0, index + 1); + } else { parentUri = rest; } Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/java/org/apache/cocoon/components/source/impl/CachingSourceTestCase.java URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/java/org/apache/cocoon/components/source/impl/CachingSourceTestCase.java?rev=434032&r1=434017&r2=434032&view=diff ============================================================================== --- cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/java/org/apache/cocoon/components/source/impl/CachingSourceTestCase.java (original) +++ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/java/org/apache/cocoon/components/source/impl/CachingSourceTestCase.java Wed Aug 23 05:39:03 2006 @@ -21,7 +21,6 @@ import org.apache.avalon.framework.context.DefaultContext; import org.apache.cocoon.Constants; -import org.apache.cocoon.caching.IdentifierCacheKey; import org.apache.cocoon.core.container.ContainerTestCase; import org.apache.cocoon.environment.mock.MockContext; import org.apache.cocoon.xml.LoggingContentHandler; @@ -31,71 +30,155 @@ /** * TODO describe class - * */ public class CachingSourceTestCase extends ContainerTestCase { - public void testResolveURI() throws Exception { + private static final String URI = "resource://org/apache/cocoon/components/source/impl/cachingsourcetest.xml?foo=bar"; + + SourceResolver resolver; - SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE); + protected void setUp() throws Exception { + super.setUp(); + resolver = (SourceResolver) lookup(SourceResolver.ROLE); + } - String scheme = "async-caching"; - String uri = "resource://org/apache/cocoon/components/" + - "source/impl/cachingsourcetest.xml?foo=bar"; + public void testResolveURI() throws Exception { + testResolveURI("caching", URI); + } + public void testResolveAsyncURI() throws Exception { + testResolveURI("async-caching", URI); + } + + private void testResolveURI(final String scheme, final String uri) throws Exception { // resolve CachingSource - Source source = resolver.resolveURI( - scheme + ":" + uri + "&cocoon:cache-expires=10"); + Source source = resolver.resolveURI(scheme + ":" + uri + "&cocoon:cache-expires=10"); assertTrue(source instanceof CachingSource); CachingSource cachingSource = (CachingSource) source; assertEquals(uri, cachingSource.getSourceURI()); assertEquals(scheme, cachingSource.getScheme()); assertEquals(10 * 1000, cachingSource.getExpiration()); - assertEquals(new IdentifierCacheKey("source:" + uri, false), cachingSource.getCacheKey()); + assertEquals("source:" + uri, cachingSource.getCacheKey()); + resolver.release(source); + // resolve CachingSource with specified cache name cachingSource = (CachingSource) resolver.resolveURI(scheme + ":" + uri + "&cocoon:cache-name=test"); + assertEquals("source:" + uri + ":test", cachingSource.getCacheKey()); + resolver.release(source); + } + + public void testCachingURI() throws Exception { + String uri = "caching:http://www.google.com/?cocoon:cache-expires=1"; + + CachingSource source; + + source = (CachingSource) resolver.resolveURI(uri); + CachingSource.SourceMeta meta1 = source.getResponseMeta(); + resolver.release(source); + + source = (CachingSource) resolver.resolveURI(uri); + CachingSource.SourceMeta meta2 = source.getResponseMeta(); + resolver.release(source); + + assertTrue(meta1 == meta2); + + source = (CachingSource) resolver.resolveURI(uri); + source.refresh(); + CachingSource.SourceMeta meta3 = source.getResponseMeta(); + resolver.release(source); + + assertTrue(meta1 == meta3); + + Thread.sleep(1100); - assertEquals(cachingSource.getCacheKey(), new IdentifierCacheKey("source:"+uri+":test",false)); + source = (CachingSource) resolver.resolveURI(uri); + source.refresh(); + CachingSource.SourceMeta meta4 = source.getResponseMeta(); + resolver.release(source); + assertTrue(meta1 != meta4); + assertTrue(meta1.getContentLength() == meta4.getContentLength()); + assertTrue(meta1.getLastModified() != meta4.getLastModified()); + assertEquals(meta1.getMimeType(), meta4.getMimeType()); + } + + public void testRefreshSyncURI() throws Exception { + testRefreshURI("caching", "http://www.google.com/"); + } + +// public void testRefreshAsyncURI() throws Exception { +// testRefreshURI("async-caching", "http://www.google.com/"); +// } + private void testRefreshURI(final String scheme, final String uri) throws Exception { + CachingSource source; + + source = (CachingSource) resolver.resolveURI(scheme + ":" + uri + "?cocoon:cache-expires=1"); + CachingSource.SourceMeta meta1 = source.getResponseMeta(); + resolver.release(source); + + source = (CachingSource) resolver.resolveURI(scheme + ":" + uri + "?cocoon:cache-expires=1"); + CachingSource.SourceMeta meta2 = source.getResponseMeta(); resolver.release(source); - String parentURI = "file://c:/temp"; - String childURI = parentURI + "/test"; + assertTrue(meta1 == meta2); + assertTrue(meta1.getContentLength() == meta2.getContentLength()); + assertTrue(meta1.getLastModified() == meta2.getLastModified()); + + Thread.sleep(1200); + + source = (CachingSource) resolver.resolveURI(scheme + ":" + uri + "?cocoon:cache-expires=1"); + CachingSource.SourceMeta meta3 = source.getResponseMeta(); + resolver.release(source); + + assertTrue(meta1 != meta3); + assertTrue(meta1.getContentLength() == meta3.getContentLength()); + assertTrue(meta1.getLastModified() != meta3.getLastModified()); + assertEquals(meta1.getMimeType(), meta3.getMimeType()); + } + + public void testCachingTraversableSource() throws Exception { + String scheme = "caching"; + File cwd = new File(".").getCanonicalFile(); + String childURI = cwd.toURL().toString(); + String parentURI = cwd.getParentFile().toURL().toString(); + String childName = cwd.getName(); + String parentName = cwd.getParentFile().getName(); // resolve TraversableCachingSource - source = resolver.resolveURI(scheme + ":" + childURI + "?cocoon:cache-expires=1"); + Source source = resolver.resolveURI(scheme + ":" + childURI + "?cocoon:cache-expires=1"); assertTrue(source instanceof TraversableCachingSource); TraversableCachingSource child = (TraversableCachingSource) source; - assertEquals("test",child.getName()); + assertEquals(childName, child.getName()); + assertTrue(child.getParent() instanceof TraversableCachingSource); - assertTrue( child.getParent() instanceof TraversableCachingSource); TraversableCachingSource parent = (TraversableCachingSource) child.getParent(); - assertEquals("temp",parent.getName()); - //assertEquals(parentURI, parent.getSourceURI()); + assertEquals(parentName, parent.getName()); + assertEquals(parentURI, parent.getSourceURI()); assertTrue(parent.isCollection()); - child = (TraversableCachingSource) parent.getChild("test"); - assertEquals("test", child.getName()); - //assertEquals(childURI, child.getSourceURI()); + child = (TraversableCachingSource) parent.getChild(childName); + assertEquals(childName, child.getName()); + assertEquals(childURI, child.getSourceURI()); + boolean found = false; Iterator children = parent.getChildren().iterator(); while (children.hasNext()) { child = (TraversableCachingSource) children.next(); + if (child.getName().equals(childName)) { + found = true; + } } + assertTrue(found); resolver.release(source); } public void testGetContents() throws Exception { - - SourceResolver resolver = (SourceResolver) lookup(SourceResolver.ROLE); - - // resolve AsyncCachingSource + // resolve CachingSource String scheme = "caching"; - String uri = "resource://org/apache/cocoon/components/" + - "source/impl/cachingsourcetest.xml"; + String uri = "resource://org/apache/cocoon/components/source/impl/cachingsourcetest.xml"; CachingSource source = (CachingSource) resolver.resolveURI(scheme + ":" + uri); InputStream stream = source.getInputStream(); @@ -103,7 +186,7 @@ byte[] buffer = new byte[1024]; int len; while ((len = stream.read(buffer)) > 0) { - contents += new String(buffer,0,len); + contents += new String(buffer, 0, len); } resolver.release(source); @@ -112,7 +195,7 @@ source = (CachingSource) resolver.resolveURI(scheme + ":" + uri); SaxBuffer saxbuffer = new SaxBuffer(); - LoggingContentHandler handler = new LoggingContentHandler("test",saxbuffer); + LoggingContentHandler handler = new LoggingContentHandler("test", saxbuffer); handler.enableLogging(getLogger().getChildLogger("handler")); source.toSAX(handler); } @@ -128,19 +211,8 @@ // parameters); // } - //source.getSource(); -// InputStream stream = source.getInputStream(); -// String contents = new String(); -// byte[] buffer = new byte[1024]; -// int len; -// while((len = stream.read(buffer)) > 0) { -// contents += new String(buffer,0,len); -// } -// getLogger().debug("contents: " + contents); - //getLogger().debug(""); protected void addContext(DefaultContext ctx) { - ctx.put("work-directory",new File("build/work")); - ctx.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT,new MockContext()); + ctx.put("work-directory", new File("build/work")); + ctx.put(Constants.CONTEXT_ENVIRONMENT_CONTEXT, new MockContext()); } - } Modified: cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/resources/org/apache/cocoon/components/source/impl/CachingSourceTestCase.xtest URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/resources/org/apache/cocoon/components/source/impl/CachingSourceTestCase.xtest?rev=434032&r1=434017&r2=434032&view=diff ============================================================================== --- cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/resources/org/apache/cocoon/components/source/impl/CachingSourceTestCase.xtest (original) +++ cocoon/trunk/blocks/cocoon-repository/cocoon-repository-impl/src/test/resources/org/apache/cocoon/components/source/impl/CachingSourceTestCase.xtest Wed Aug 23 05:39:03 2006 @@ -70,7 +70,6 @@ - @@ -87,7 +86,7 @@ - + Modified: cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/pom.xml URL: http://svn.apache.org/viewvc/cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/pom.xml?rev=434032&r1=434031&r2=434032&view=diff ============================================================================== --- cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/pom.xml (original) +++ cocoon/trunk/blocks/cocoon-scratchpad/cocoon-scratchpad-impl/pom.xml Wed Aug 23 05:39:03 2006 @@ -121,9 +121,6 @@ **/*TestCase.class **/*Test.class - - **/CachingSourceTestCase.class -