1 /**
2 * Copyright 2003-2007 Greg Luck
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 package net.sf.ehcache.constructs.web.filter;
18
19 import com.meterware.httpunit.HttpInternalErrorException;
20 import net.sf.ehcache.constructs.web.AbstractWebTest;
21 import org.xml.sax.SAXException;
22
23 import java.io.IOException;
24
25 /**
26 * @author Greg Luck
27 * @version $Id: CachingFilterReentranceTest.java 512 2007-07-10 09:18:45Z gregluck $
28 */
29 public class CachingFilterReentranceTest extends AbstractWebTest {
30
31 /**
32 * The {@link CachingFilter} uses the {@link net.sf.ehcache.constructs.blocking.BlockingCache}. It blocks until the thread which
33 * did a get which results in a null does a put. {@link CachingFilter} is therefore
34 * not reentrant.
35 * <p/>
36 * Reentrant filters could result in a request never completing, where the request
37 * thread waits for monitor entry for ever. The {@link CachingFilter} includes a check for
38 * reentrancy. If detected it will throw an Exception.
39 * <p/>
40 * This test uses a deliberately reentrant filter chain to:
41 * <ol>
42 * <li>Demonstrate how the problem occurs
43 * <li>Check that an Exception is thrown rather than blocking forever.
44 * </ol>
45 */
46 public void testReentranceOfCachingFilterThrowsException() throws IOException, SAXException {
47 try {
48 getResponseFromAcceptGzipRequest("/reentrant/MainPageAndIncludeBothGoThroughCachingFilter.jsp");
49 fail();
50 } catch (HttpInternalErrorException e) {
51 //noop
52 }
53 }
54
55 /**
56 * Checks that reentrance via a forward is still caught.
57 *
58 * @see #testReentranceOfCachingFilterThrowsException()
59 */
60 public void testReentranceOfCachingFilterViaForwardThrowsException() throws IOException, SAXException {
61 try {
62 getResponseFromAcceptGzipRequest("/reentrant/MainPageAndForwardBothGoThroughCachingFilter.jsp");
63 fail();
64 } catch (HttpInternalErrorException e) {
65 //noop
66 }
67 }
68 }