Return-Path: Delivered-To: apmail-incubator-abdera-commits-archive@locus.apache.org Received: (qmail 13654 invoked from network); 7 Aug 2006 18:17:10 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 7 Aug 2006 18:17:10 -0000 Received: (qmail 12349 invoked by uid 500); 7 Aug 2006 18:17:08 -0000 Delivered-To: apmail-incubator-abdera-commits-archive@incubator.apache.org Received: (qmail 12338 invoked by uid 500); 7 Aug 2006 18:17:08 -0000 Mailing-List: contact abdera-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: abdera-dev@incubator.apache.org Delivered-To: mailing list abdera-commits@incubator.apache.org Received: (qmail 12313 invoked by uid 99); 7 Aug 2006 18:17:08 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 07 Aug 2006 11:17:08 -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; Mon, 07 Aug 2006 11:17:07 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 5D8771A981A; Mon, 7 Aug 2006 11:16:47 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r429422 - in /incubator/abdera/java/trunk/client/src: main/java/org/apache/abdera/protocol/cache/ test/ test/java/ test/java/org/ test/java/org/apache/ test/java/org/apache/abdera/ test/java/org/apache/abdera/test/ test/java/org/apache/abde... Date: Mon, 07 Aug 2006 18:16:46 -0000 To: abdera-commits@incubator.apache.org From: jmsnell@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060807181647.5D8771A981A@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: jmsnell Date: Mon Aug 7 11:16:46 2006 New Revision: 429422 URL: http://svn.apache.org/viewvc?rev=429422&view=rev Log: First couple of unit tests for the caching. There will be more. For now, these are based on Mark Nottinghams set of caching tests, but we'll need to set up our own test endpoint (hopefully soon). no-cache, no-store and max-age are tested. Also, we need to check to see if the cache can store responses when the request is no-store. Added: incubator/abdera/java/trunk/client/src/test/ incubator/abdera/java/trunk/client/src/test/java/ incubator/abdera/java/trunk/client/src/test/java/org/ incubator/abdera/java/trunk/client/src/test/java/org/apache/ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java?rev=429422&r1=429421&r2=429422&view=diff ============================================================================== --- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java (original) +++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/cache/CacheBase.java Mon Aug 7 11:16:46 2006 @@ -122,8 +122,11 @@ RequestOptions options, Response response) { CacheKey key = getCacheKey(uri, options,response); - if ((response != null && response.isNoStore()) || - options != null && options.getNoStore()) { + if ((response != null && response.isNoStore())) { +// TODO: Need to get clarification on this.. if the request is no-store, can +// the response be cached. +// if ((response != null && response.isNoStore()) || +// options != null && options.getNoStore()) { remove(key); } else { try { Added: incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java?rev=429422&view=auto ============================================================================== --- incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java (added) +++ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/cache/CacheTests.java Mon Aug 7 11:16:46 2006 @@ -0,0 +1,135 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one or more +* contributor license agreements. The ASF licenses this file to You +* under the Apache License, Version 2.0 (the "License"); you may not +* use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. For additional information regarding +* copyright in this work, please see the NOTICE file in the top level +* directory of this distribution. +*/ +package org.apache.abdera.test.client.cache; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.abdera.protocol.client.Client; +import org.apache.abdera.protocol.client.CommonsClient; +import org.apache.abdera.protocol.client.RequestOptions; +import org.apache.abdera.protocol.client.Response; + +import junit.framework.TestCase; + +/** + * For now these are hitting Mark Nottingham's set of caching tests. We'll + * need to set up our own server. The hard part about testing caching is + * that we need a server endpoint to test against. Also, the test results + * can be affected by proxies and intermediate caches. If we want to run + * these tests in an offline configuration, we'll need to provide instructions + * on how to set up a local server and have a portable suite of tests. + */ +public class CacheTests extends TestCase { + + private final static String CHECK_CACHE_INVALIDATE = + "http://www.mnot.net/javascript/xmlhttprequest/check_cache_invalidate.s"; + + public static void testRequestNoStore() throws Exception { + + Client client = new CommonsClient(); + RequestOptions options = client.getDefaultRequestOptions(); + options.setHeader("x-reqnum", "1"); + Response response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp1 = getResponse(response.getInputStream()); + assertEquals(resp1, "1"); + + // Should not use the cache + options.setHeader("x-reqnum", "2"); + options.setNoStore(true); + response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp2 = getResponse(response.getInputStream()); + assertEquals(resp2, "2"); + + // Should use the cache + options.setHeader("x-reqnum", "3"); + options.setNoStore(false); + response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp3 = getResponse(response.getInputStream()); + assertEquals(resp3, "2"); + } + + public static void testRequestNoCache() throws Exception { + + Client client = new CommonsClient(); + RequestOptions options = client.getDefaultRequestOptions(); + options.setHeader("x-reqnum", "1"); + Response response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp1 = getResponse(response.getInputStream()); + assertEquals(resp1, "1"); + + // Should not use the cache + options.setHeader("x-reqnum", "2"); + options.setNoCache(true); + response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp2 = getResponse(response.getInputStream()); + assertEquals(resp2, "2"); + + // Should use the cache + options.setHeader("x-reqnum", "3"); + options.setNoCache(false); + response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp3 = getResponse(response.getInputStream()); + assertEquals(resp3, "2"); + } + + public static void testRequestMaxAge() throws Exception { + + Client client = new CommonsClient(); + RequestOptions options = client.getDefaultRequestOptions(); + options.setHeader("x-reqnum", "1"); + Response response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp1 = getResponse(response.getInputStream()); + assertEquals(resp1, "1"); + + // Should not use the cache + options.setHeader("x-reqnum", "2"); + options.setMaxAge(0); + response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp2 = getResponse(response.getInputStream()); + assertEquals(resp2, "2"); + + // Should use the cache + options.setHeader("x-reqnum", "3"); + options.setMaxAge(60); + response = client.get(CHECK_CACHE_INVALIDATE, options); + + String resp3 = getResponse(response.getInputStream()); + assertEquals(resp3, "2"); + } + + + private static String getResponse(InputStream in) throws IOException { + ByteArrayOutputStream out = new ByteArrayOutputStream(); + int m = -1; + while ((m = in.read()) != -1) { + out.write(m); + } + String resp = new String(out.toByteArray()); + return resp.trim(); + } +}