Author: knopp Date: Fri Aug 3 10:31:38 2007 New Revision: 562529 URL: http://svn.apache.org/viewvc?view=rev&rev=562529 Log: WICKET-736 bugfix
Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/pagestore/PageWindowManagerTest.java Modified: wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java?view=diff&rev=562529&r1=562528&r2=562529 ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java (original) +++ wicket/trunk/jdk-1.4/wicket/src/main/java/org/apache/wicket/protocol/http/pagestore/PageWindowManager.java Fri Aug 3 10:31:38 2007 @@ -54,7 +54,7 @@ } // list of PageWindowInternal objects - private List /* <PageWindowInternal> */windows = new ArrayList(); + private final List /* <PageWindowInternal> */windows = new ArrayList(); // map from page id to list of pagewindow indices (refering to the windows // list) - to improve searching speed @@ -127,7 +127,8 @@ else if (versionNumber == -1) { // we need to find last recently stored page window - that is page - // window with index closest to the left of the indexPointer or farthest + // window with index closest to the left of the indexPointer or + // farthest // to the right. for (Iterator i = indices.iterator(); i.hasNext();) { @@ -137,9 +138,9 @@ if (window.pageId == pageId) { if ((result == -1) || /**/ - (currentIndex <= indexPointer && result > indexPointer) || /**/ - (currentIndex > result && currentIndex <= indexPointer) || /**/ - (currentIndex > result && result > indexPointer)) + (currentIndex <= indexPointer && result > indexPointer) || /**/ + (currentIndex > result && currentIndex <= indexPointer) || /**/ + (currentIndex > result && result > indexPointer)) { result = currentIndex; } @@ -155,8 +156,8 @@ int currentIndex = ((Integer)i.next()).intValue(); PageWindowInternal window = (PageWindowInternal)windows.get(currentIndex); - if (window.pageId == pageId && window.versionNumber == versionNumber && - window.ajaxVersionNumber > lastAjaxVersion) + if (window.pageId == pageId && window.versionNumber == versionNumber && + window.ajaxVersionNumber > lastAjaxVersion) { result = currentIndex; lastAjaxVersion = window.ajaxVersionNumber; @@ -513,6 +514,10 @@ { windows.remove(index); totalSize -= window.filePartSize; + if (indexPointer == index) + { + --indexPointer; + } } else { Modified: wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/pagestore/PageWindowManagerTest.java URL: http://svn.apache.org/viewvc/wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/pagestore/PageWindowManagerTest.java?view=diff&rev=562529&r1=562528&r2=562529 ============================================================================== --- wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/pagestore/PageWindowManagerTest.java (original) +++ wicket/trunk/jdk-1.4/wicket/src/test/java/org/apache/wicket/protocol/http/pagestore/PageWindowManagerTest.java Fri Aug 3 10:31:38 2007 @@ -28,137 +28,142 @@ /** * */ - public void testAddRemove() + public void testAddRemove() { PageWindowManager manager = new PageWindowManager(300); PageWindow window; - + window = manager.createPageWindow(1, 1, 1, 50); assertWindow(window, 1, 1, 1, 0, 50); - + window = manager.createPageWindow(1, 1, 2, 40); assertWindow(window, 1, 1, 2, 50, 40); - + assertEquals(manager.getTotalSize(), 90); - + window = manager.createPageWindow(1, 1, 2, 30); assertWindow(window, 1, 1, 2, 50, 30); assertEquals(manager.getTotalSize(), 80); - + manager.removePage(1, 1, 2); assertEquals(manager.getTotalSize(), 50); + + window = manager.createPageWindow(1, 1, 3, 30); + assertWindow(window, 1, 1, 3, 50, 30); + assertEquals(manager.getTotalSize(), 80); } - + /** * */ - public void testPageWindowCycle() + public void testPageWindowCycle() { PageWindowManager manager = new PageWindowManager(100); PageWindow window; - + window = manager.createPageWindow(1, 1, 1, 30); - + window = manager.createPageWindow(1, 1, 2, 30); - + window = manager.createPageWindow(1, 1, 3, 30); - + assertWindow(window, 1, 1, 3, 60, 30); - + window = manager.createPageWindow(1, 1, 4, 30); - + assertWindow(window, 1, 1, 4, 90, 30); - + // should start at the beginging - + window = manager.createPageWindow(1, 1, 5, 20); - + assertWindow(window, 1, 1, 5, 0, 20); - + assertNull(manager.getPageWindow(1, 1, 1)); - + window = manager.getPageWindow(1, 1, 2); assertWindow(window, 1, 1, 2, 30, 30); - + window = manager.createPageWindow(1, 1, 6, 10); assertWindow(window, 1, 1, 6, 20, 10); - + window = manager.getPageWindow(1, 1, 2); assertWindow(window, 1, 1, 2, 30, 30); window = manager.createPageWindow(1, 1, 6, 30); assertWindow(window, 1, 1, 6, 20, 30); - + assertNull(manager.getPageWindow(1, 1, 2)); assertNotNull(manager.getPageWindow(1, 1, 3)); - + window = manager.createPageWindow(1, 1, 6, 60); assertWindow(window, 1, 1, 6, 20, 60); - + assertNull(manager.getPageWindow(1, 1, 3)); - + window = manager.createPageWindow(1, 1, 7, 20); assertWindow(window, 1, 1, 7, 80, 20); - + assertNotNull(manager.getPageWindow(1, 1, 7)); - + // should start at the beginning again - + window = manager.createPageWindow(1, 1, 8, 10); assertWindow(window, 1, 1, 8, 0, 10); - + assertNull(manager.getPageWindow(1, 1, 5)); assertNotNull(manager.getPageWindow(1, 1, 6)); - + window = manager.createPageWindow(1, 1, 9, 20); assertWindow(window, 1, 1, 9, 10, 20); - + assertNull(manager.getPageWindow(1, 1, 6)); assertNotNull(manager.getPageWindow(1, 1, 7)); - + window = manager.createPageWindow(1, 1, 10, 20); assertWindow(window, 1, 1, 10, 30, 20); - + assertNull(manager.getPageWindow(1, 1, 6)); assertNotNull(manager.getPageWindow(1, 1, 7)); - - // make sure when replacing a page that's not last the old "instance" is not valid anymore - + + // make sure when replacing a page that's not last the old "instance" is + // not valid anymore + manager.createPageWindow(1, 1, 8, 10); - + window = manager.getPageWindow(1, 1, 8); assertWindow(window, 1, 1, 8, 50, 10); - + } - + /** * */ - public void testLastVersions() + public void testLastVersions() { PageWindowManager manager = new PageWindowManager(100); PageWindow window; manager.createPageWindow(1, 1, 1, 10); - + manager.createPageWindow(1, 1, 2, 10); - + manager.createPageWindow(1, 1, 3, 10); - + window = manager.getPageWindow(1, -1, -1); - + assertWindow(window, 1, 1, 3); manager.createPageWindow(1, 1, 2, 10); - + window = manager.getPageWindow(1, -1, -1); assertWindow(window, 1, 1, 2); - + manager.createPageWindow(1, 1, 4, 60); - + window = manager.getPageWindow(1, -1, -1); assertWindow(window, 1, 1, 4); - + manager.createPageWindow(2, 1, 1, 20); window = manager.getPageWindow(1, -1, -1); @@ -166,25 +171,27 @@ manager.createPageWindow(1, 1, 5, 60); manager.createPageWindow(3, 1, 1, 20); - + window = manager.getPageWindow(1, -1, -1); assertWindow(window, 1, 1, 5); } - - private void assertWindow(PageWindow window, int pageId, int versionNumber, int ajaxVersionNumber, - int filePartOffset, int filePartSize) + + private void assertWindow(PageWindow window, int pageId, int versionNumber, + int ajaxVersionNumber, int filePartOffset, int filePartSize) { assertTrue(window.getPageId() == pageId && window.getVersionNumber() == versionNumber && - window.getAjaxVersionNumber() == ajaxVersionNumber && window.getFilePartOffset() == filePartOffset && - window.getFilePartSize() == filePartSize); + window.getAjaxVersionNumber() == ajaxVersionNumber && + window.getFilePartOffset() == filePartOffset && + window.getFilePartSize() == filePartSize); } - private void assertWindow(PageWindow window, int pageId, int versionNumber, int ajaxVersionNumber) + private void assertWindow(PageWindow window, int pageId, int versionNumber, + int ajaxVersionNumber) { assertTrue(window.getPageId() == pageId && window.getVersionNumber() == versionNumber && - window.getAjaxVersionNumber() == ajaxVersionNumber); - + window.getAjaxVersionNumber() == ajaxVersionNumber); + } }