Search in sources :

Example 1 with PageWindow

use of org.apache.wicket.pageStore.PageWindowManager.PageWindow in project wicket by apache.

the class PageWindowManagerTest method pageWindowCycle.

/**
 */
@Test
public void pageWindowCycle() {
    PageWindowManager manager = new PageWindowManager(100);
    PageWindow window;
    window = manager.createPageWindow(1, 30);
    window = manager.createPageWindow(2, 30);
    window = manager.createPageWindow(3, 30);
    assertWindow(window, 3, 60, 30);
    window = manager.createPageWindow(4, 30);
    assertWindow(window, 4, 90, 30);
    // should start at the beginging
    window = manager.createPageWindow(5, 20);
    assertWindow(window, 5, 0, 20);
    assertNull(manager.getPageWindow(1));
    window = manager.getPageWindow(2);
    assertWindow(window, 2, 30, 30);
    window = manager.createPageWindow(6, 10);
    assertWindow(window, 6, 20, 10);
    window = manager.getPageWindow(2);
    assertWindow(window, 2, 30, 30);
    window = manager.createPageWindow(6, 30);
    assertWindow(window, 6, 20, 30);
    assertNull(manager.getPageWindow(2));
    assertNotNull(manager.getPageWindow(3));
    window = manager.createPageWindow(6, 60);
    assertWindow(window, 6, 20, 60);
    assertNull(manager.getPageWindow(3));
    window = manager.createPageWindow(7, 20);
    assertWindow(window, 7, 80, 20);
    assertNotNull(manager.getPageWindow(7));
    // should start at the beginning again
    window = manager.createPageWindow(8, 10);
    assertWindow(window, 8, 0, 10);
    assertNull(manager.getPageWindow(5));
    assertNotNull(manager.getPageWindow(6));
    window = manager.createPageWindow(9, 20);
    assertWindow(window, 9, 10, 20);
    assertNull(manager.getPageWindow(6));
    assertNotNull(manager.getPageWindow(7));
    window = manager.createPageWindow(10, 20);
    assertWindow(window, 10, 30, 20);
    assertNull(manager.getPageWindow(6));
    assertNotNull(manager.getPageWindow(7));
    // make sure when replacing a page that's not last the old "instance" is
    // not valid anymore
    manager.createPageWindow(8, 10);
    window = manager.getPageWindow(8);
    assertWindow(window, 8, 50, 10);
}
Also used : PageWindowManager(org.apache.wicket.pageStore.PageWindowManager) PageWindow(org.apache.wicket.pageStore.PageWindowManager.PageWindow) Test(org.junit.Test)

Example 2 with PageWindow

use of org.apache.wicket.pageStore.PageWindowManager.PageWindow in project wicket by apache.

the class PageWindowManagerTest method addRemove.

/**
 */
@Test
public void addRemove() {
    PageWindowManager manager = new PageWindowManager(300);
    PageWindow window;
    window = manager.createPageWindow(1, 50);
    assertWindow(window, 1, 0, 50);
    window = manager.createPageWindow(2, 40);
    assertWindow(window, 2, 50, 40);
    assertEquals(manager.getTotalSize(), 90);
    window = manager.createPageWindow(2, 30);
    assertWindow(window, 2, 50, 30);
    assertEquals(manager.getTotalSize(), 80);
    manager.removePage(2);
    assertEquals(manager.getTotalSize(), 50);
    window = manager.createPageWindow(3, 30);
    assertWindow(window, 3, 50, 30);
    assertEquals(manager.getTotalSize(), 80);
}
Also used : PageWindowManager(org.apache.wicket.pageStore.PageWindowManager) PageWindow(org.apache.wicket.pageStore.PageWindowManager.PageWindow) Test(org.junit.Test)

Example 3 with PageWindow

use of org.apache.wicket.pageStore.PageWindowManager.PageWindow in project wicket by apache.

the class PageWindowManagerTest method removeObsoleteIndices.

/**
 * https://issues.apache.org/jira/browse/WICKET-4572
 */
@Test
public void removeObsoleteIndices() {
    int page0id = 0, page1id = 1, page2id = 2;
    int maxSize = 10;
    PageWindowManager manager = new PageWindowManager(maxSize);
    // Add few pages.
    // All of them fully occupy the max space in the pageWindowManager.
    // So adding N+1st page removes the Nth page.
    manager.createPageWindow(page0id, maxSize);
    PageWindow page0Window = manager.getPageWindow(page0id);
    assertWindow(page0Window, page0id, page0Window.getFilePartOffset(), page0Window.getFilePartSize());
    manager.createPageWindow(page1id, maxSize);
    PageWindow page1Window = manager.getPageWindow(page1id);
    assertWindow(page1Window, page1id, page1Window.getFilePartOffset(), page1Window.getFilePartSize());
    // Try to get a page which has been lost with the adding of page1
    assertNull("Page0 must be lost when Page1 has been added.", manager.getPageWindow(page0id));
    manager.createPageWindow(page2id, maxSize);
    PageWindow page2Window = manager.getPageWindow(page2id);
    assertWindow(page2Window, page2id, page2Window.getFilePartOffset(), page2Window.getFilePartSize());
    // Try to get a page which has been lost with the adding of page2
    assertNull("Page1 must be lost when Page2 has been added.", manager.getPageWindow(page1id));
}
Also used : PageWindowManager(org.apache.wicket.pageStore.PageWindowManager) PageWindow(org.apache.wicket.pageStore.PageWindowManager.PageWindow) Test(org.junit.Test)

Example 4 with PageWindow

use of org.apache.wicket.pageStore.PageWindowManager.PageWindow in project wicket by apache.

the class PageWindowProvider method iterator.

@Override
public Iterator<? extends PageWindowDescription> iterator(long first, long count) {
    List<PageWindow> lastPageWindows = getPageWindows();
    List<PageWindow> subList = lastPageWindows.subList((int) first, (int) (first + count));
    List<PageWindowDescription> pageDescriptions = new ArrayList<>();
    for (PageWindow pw : subList) {
        pageDescriptions.add(new PageWindowDescription(pw, sessionId.getObject()));
    }
    return pageDescriptions.iterator();
}
Also used : ArrayList(java.util.ArrayList) PageWindow(org.apache.wicket.pageStore.PageWindowManager.PageWindow)

Example 5 with PageWindow

use of org.apache.wicket.pageStore.PageWindowManager.PageWindow in project wicket by apache.

the class PageWindowProvider method getPageWindows.

private List<PageWindow> getPageWindows() {
    List<PageWindow> lastPageWindows = new ArrayList<>();
    if (sessionId != null && sessionId.getObject() != null) {
        String sessId = sessionId.getObject();
        DebugDiskDataStore dataStore = DataStoreHelper.getDataStore();
        List<PageWindow> pageWindows = dataStore.getLastPageWindows(sessId, MAX_PAGES_TO_READ);
        lastPageWindows.addAll(pageWindows);
    }
    return lastPageWindows;
}
Also used : ArrayList(java.util.ArrayList) PageWindow(org.apache.wicket.pageStore.PageWindowManager.PageWindow) DebugDiskDataStore(org.apache.wicket.devutils.diskstore.DebugDiskDataStore)

Aggregations

PageWindow (org.apache.wicket.pageStore.PageWindowManager.PageWindow)6 PageWindowManager (org.apache.wicket.pageStore.PageWindowManager)4 ArrayList (java.util.ArrayList)3 Test (org.junit.Test)3 DebugDiskDataStore (org.apache.wicket.devutils.diskstore.DebugDiskDataStore)1