Package org.apache.wicket.page.persistent.disk

Source Code of org.apache.wicket.page.persistent.disk.PageWindowManagerTest

/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* 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.
*/
package org.apache.wicket.page.persistent.disk;

import org.apache.wicket.pageStore.PageWindowManager;
import org.apache.wicket.pageStore.PageWindowManager.PageWindow;
import org.junit.Assert;
import org.junit.Test;

/**
* @author Matej Knopp
*/
public class PageWindowManagerTest extends Assert
{
  /**
   *
   */
  @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);
  }

  /**
   *
   */
  @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);
  }


  private void assertWindow(PageWindow window, int pageId, int filePartOffset, int filePartSize)
  {
    assertTrue(window.getPageId() == pageId && window.getFilePartOffset() == filePartOffset &&
      window.getFilePartSize() == filePartSize);
  }
}
TOP

Related Classes of org.apache.wicket.page.persistent.disk.PageWindowManagerTest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.