use of org.apache.wicket.page.IManageablePage in project wicket by apache.
the class AsynchronousPageStoreTest method runTest.
private List<Metrics> runTest(int sessions, int pages, long writeMillis, long readMillis, int asyncPageStoreCapacity) throws InterruptedException {
List<Metrics> results = new ArrayList<>();
final CountDownLatch lock = new CountDownLatch(pages * sessions);
// ISerializer serializer = new DummySerializer();
ISerializer serializer = new DeflatedJavaSerializer("applicationKey");
IDataStore dataStore = new DiskDataStore("applicationName", new File("./target"), Bytes.bytes(10000l));
// IPageStore pageStore = new DummyPageStore(new File("target/store")) {
IPageStore pageStore = new DefaultPageStore(serializer, dataStore, 0) {
@Override
public void storePage(String sessionId, IManageablePage page) {
super.storePage(sessionId, page);
lock.countDown();
}
};
IPageStore asyncPageStore = new AsynchronousPageStore(pageStore, asyncPageStoreCapacity);
Stopwatch stopwatch = Stopwatch.createUnstarted();
for (int pageId = 1; pageId <= pages; pageId++) {
for (int i = 1; i <= sessions; i++) {
String sessionId = String.valueOf(i);
Metrics metrics = new Metrics();
stopwatch.reset();
DummyPage page = new DummyPage(pageId, around(writeMillis), around(readMillis), sessionId);
stopwatch.start();
asyncPageStore.storePage(sessionId, page);
metrics.storedPage = page;
metrics.storingMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
stopwatch.reset();
stopwatch.start();
metrics.restoredPage = DummyPage.class.cast(asyncPageStore.getPage(sessionId, pageId));
metrics.restoringMillis = stopwatch.elapsed(TimeUnit.MILLISECONDS);
results.add(metrics);
}
}
lock.await(pages * sessions * (writeMillis + readMillis), TimeUnit.MILLISECONDS);
return results;
}
use of org.apache.wicket.page.IManageablePage in project wicket by apache.
the class AsynchronousPageStoreTest method storeReturnsRestoredInstanceOnDistantPageRequest.
/**
* Store returns the restored page instance from wrapped store when there is a distant request
* for it back again.
*
* @throws InterruptedException
*/
@Test
public void storeReturnsRestoredInstanceOnDistantPageRequest() throws InterruptedException {
ISerializer serializer = new DeflatedJavaSerializer("applicationKey");
// ISerializer serializer = new DummySerializer();
IDataStore dataStore = new DiskDataStore("applicationName", new File("./target"), Bytes.bytes(10000l));
// IPageStore pageStore = new DummyPageStore(new File("target/store"));
IPageStore pageStore = spy(new DefaultPageStore(serializer, dataStore, 0));
IPageStore asyncPageStore = new AsynchronousPageStore(pageStore, 100);
int pageId = 0;
String sessionId = "sessionId";
DummyPage page = new DummyPage(pageId, 1000, 1000, sessionId);
asyncPageStore.storePage(sessionId, page);
Thread.sleep(1500);
IManageablePage pageBack = asyncPageStore.getPage(sessionId, pageId);
verify(pageStore, times(1)).getPage(sessionId, pageId);
assertNotEquals(page, pageBack);
}
use of org.apache.wicket.page.IManageablePage in project wicket by apache.
the class WebPageTest method increaseNewlyCreatedPageId.
/**
* Asserting newly created pages get a new page id in order to be identified latter.
*
* @see <a href="https://issues.apache.org/jira/browse/WICKET-3892">WICKET-3892</a>
*/
@Test
public void increaseNewlyCreatedPageId() {
tester.startPage(MainPage.class);
int mainPageId = tester.getLastRenderedPage().getPageId();
tester.clickLink("mainLink");
tester.assertRenderedPage(TargetPage.class);
int targetPageId = tester.getLastRenderedPage().getPageId();
assertTrue(mainPageId != targetPageId);
IManageablePage mainPage = tester.getSession().getPageManager().getPage(mainPageId);
IManageablePage targetPage = tester.getSession().getPageManager().getPage(targetPageId);
assertThat(mainPage, instanceOf(MainPage.class));
assertThat(targetPage, instanceOf(TargetPage.class));
}
use of org.apache.wicket.page.IManageablePage in project wicket by apache.
the class DontStoreNotRenderedPageTestCase method newWicketTester.
@Override
protected WicketTester newWicketTester(WebApplication app) {
app.getComponentInstantiationListeners().add(new IComponentInstantiationListener() {
@Override
public void onInstantiation(Component component) {
// WICKET-5546 behavior added before Page#init()
component.add(new Behavior() {
});
}
});
return new WicketTester(app) {
@Override
protected IPageManagerProvider newTestPageManagerProvider() {
return new IPageManagerProvider() {
@Override
public IPageManager apply(IPageManagerContext context) {
return new MockPageManager() {
@Override
public void touchPage(IManageablePage page) {
Assert.assertFalse("PageB should not be touched!", page instanceof PageB);
super.touchPage(page);
}
};
}
};
}
};
}
Aggregations