Author: hlship
Date: Mon Oct 13 14:01:29 2008
New Revision: 704248

URL: http://svn.apache.org/viewvc?rev=704248&view=rev
Log:
TAP5-256: Page Pool Limit exhausted when exception occurs (during PageAttached 
lifecycle) on a link

Added:
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageAttachFailure.java
Modified:
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePool.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolCache.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
    
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCacheImpl.java
    tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
    
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPageCacheImplTest.java

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePool.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePool.java?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePool.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePool.java
 Mon Oct 13 14:01:29 2008
@@ -35,7 +35,16 @@
     Page checkout(String logicalPageName);
 
     /**
+     * Releases a previously checked-out page.
+     *
      * @param page a previously checked-out page
      */
     void release(Page page);
+
+    /**
+     * Discards a page, which occurs when there are errors invoking lifecycle 
methods on the page.
+     *
+     * @param page a previously checked-out page
+     */
+    void discard(Page page);
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolCache.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolCache.java?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolCache.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolCache.java
 Mon Oct 13 14:01:29 2008
@@ -59,12 +59,12 @@
     /**
      * Pages that are available for use.
      */
-    private LinkedList<CachedPage> available = 
CollectionFactory.newLinkedList();
+    private final LinkedList<CachedPage> available = 
CollectionFactory.newLinkedList();
 
     /**
      * Pages that are currently in use.
      */
-    private LinkedList<CachedPage> inUse = CollectionFactory.newLinkedList();
+    private final LinkedList<CachedPage> inUse = 
CollectionFactory.newLinkedList();
 
     /**
      * Guards access to the available and in use lists.
@@ -264,7 +264,6 @@
                     i.remove();
                     break;
                 }
-
             }
 
             // This should not ever happen. The only scenario I can think of 
is if a page instance
@@ -282,7 +281,6 @@
             available.addFirst(cached);
 
             pageAvailable.signal();
-
         }
         finally
         {
@@ -347,6 +345,4 @@
             lock.unlock();
         }
     }
-
-
 }

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/PagePoolImpl.java
 Mon Oct 13 14:01:29 2008
@@ -109,7 +109,7 @@
 
     public void release(Page page)
     {
-        PagePoolCache cache = get(page.getLogicalName(), page.getLocale());
+        PagePoolCache cache = getPagePoolCache(page);
 
         // If the page is not "clean" of any request/client state, it can't go
         // back in the pool.
@@ -126,6 +126,16 @@
         cache.release(page);
     }
 
+    public void discard(Page page)
+    {
+        getPagePoolCache(page).remove(page);
+    }
+
+    private PagePoolCache getPagePoolCache(Page page)
+    {
+        return get(page.getLogicalName(), page.getLocale());
+    }
+
     private synchronized PagePoolCache get(String pageName, Locale locale)
     {
         PageLocator locator = new PageLocator(pageName, locale);

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCacheImpl.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCacheImpl.java?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCacheImpl.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/main/java/org/apache/tapestry5/internal/services/RequestPageCacheImpl.java
 Mon Oct 13 14:01:29 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -42,7 +42,16 @@
         {
             page = pagePool.checkout(logicalPageName);
 
-            page.attached();
+            try
+            {
+                page.attached();
+            }
+            catch (RuntimeException ex)
+            {
+                pagePool.discard(page);
+
+                throw ex;
+            }
 
             cache.put(logicalPageName, page);
         }

Modified: tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml (original)
+++ tapestry/tapestry5/trunk/tapestry-core/src/test/app1/Start.tml Mon Oct 13 
14:01:29 2008
@@ -80,6 +80,10 @@
             <a href="failedinjectdemo">Failed Field Injection Demo</a>
             -- demo failure when attempting to inject into a field
         </li>
+        <li>
+            <a href="pageAttachFailure">Page Attach Failure</a>
+            -- demo failure when attaching a page
+        </li>
 
     </ul>
 

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/IntegrationTests.java
 Mon Oct 13 14:01:29 2008
@@ -2307,4 +2307,14 @@
         assertText("//[EMAIL PROTECTED]'t-ajax-console']/[EMAIL 
PROTECTED]'t-err']",
                    "Communication with the server failed: Server-side 
exception.");
     }
+
+    /**
+     * TAP5-256
+     */
+    public void exception_when_attaching_page()
+    {
+        start("Page Attach Failure");
+
+        assertTextPresent("Failure inside pageAttached().");
+    }
 }

Added: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageAttachFailure.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageAttachFailure.java?rev=704248&view=auto
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageAttachFailure.java
 (added)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/integration/app1/pages/PageAttachFailure.java
 Mon Oct 13 14:01:29 2008
@@ -0,0 +1,23 @@
+//  Copyright 2008 The Apache Software Foundation
+//
+// Licensed 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.
+
+package org.apache.tapestry5.integration.app1.pages;
+
+public class PageAttachFailure
+{
+    void pageAttached()
+    {
+        throw new RuntimeException("Failure inside pageAttached().");
+    }
+}

Modified: 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPageCacheImplTest.java
URL: 
http://svn.apache.org/viewvc/tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPageCacheImplTest.java?rev=704248&r1=704247&r2=704248&view=diff
==============================================================================
--- 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPageCacheImplTest.java
 (original)
+++ 
tapestry/tapestry5/trunk/tapestry-core/src/test/java/org/apache/tapestry5/internal/services/RequestPageCacheImplTest.java
 Mon Oct 13 14:01:29 2008
@@ -1,4 +1,4 @@
-// Copyright 2006, 2007 The Apache Software Foundation
+// Copyright 2006, 2007, 2008 The Apache Software Foundation
 //
 // Licensed under the Apache License, Version 2.0 (the "License");
 // you may not use this file except in compliance with the License.
@@ -16,6 +16,7 @@
 
 import org.apache.tapestry5.internal.structure.Page;
 import org.apache.tapestry5.internal.test.InternalBaseTestCase;
+import org.easymock.EasyMock;
 import org.testng.annotations.Test;
 
 public class RequestPageCacheImplTest extends InternalBaseTestCase
@@ -57,4 +58,36 @@
 
         verify();
     }
+
+    @Test
+    public void failure_in_attach_will_discard_page()
+    {
+        PagePool pool = mockPagePool();
+        Page page = mockPage();
+        RuntimeException t = new RuntimeException("Failure in attach.");
+
+        expect(pool.checkout(PAGE_NAME)).andReturn(page);
+
+        page.attached();
+
+        EasyMock.expectLastCall().andThrow(t);
+
+        pool.discard(page);
+
+        replay();
+
+        RequestPageCacheImpl cache = new RequestPageCacheImpl(pool);
+
+        try
+        {
+            cache.get(PAGE_NAME);
+            unreachable();
+        }
+        catch (RuntimeException ex)
+        {
+            assertSame(ex, t);
+        }
+
+        verify();
+    }
 }


Reply via email to