use of com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper in project wcomponents by BorderTech.
the class WServletPerformance_Test method timeWServlet.
/**
* Times the WServlet execution looping the given number of times and returns the elapsed time.
*
* @param count the number of times to loop.
* @return the elapsed time, in nanoseconds.
* @throws Exception an exception
*/
private long timeWServlet(final int count) throws Exception {
final SimpleWServlet servlet = new SimpleWServlet();
servlet.init(new MockServletConfig());
final MockHttpSession simpleWServletSession = new MockHttpSession();
// Do first request to get session token
sendWServletRequest(servlet, simpleWServletSession, 0, null);
// Get token
WServletHelper helper = new WServletHelper(servlet, new MockHttpServletRequest(simpleWServletSession), new MockHttpServletResponse());
String token = helper.getUIContext().getEnvironment().getSessionToken();
// JIT warm-up
for (int i = 1; i < count; i++) {
sendWServletRequest(servlet, simpleWServletSession, i, token);
}
simpleWServletSession.getAttributes().clear();
// Do first request to get session token
sendWServletRequest(servlet, simpleWServletSession, 0, null);
final String token2 = helper.getUIContext().getEnvironment().getSessionToken();
Runnable runnable = new Runnable() {
@Override
public void run() {
try {
for (int i = 1; i < count; i++) {
sendWServletRequest(servlet, simpleWServletSession, i, token2);
}
} catch (Exception e) {
LOG.error("Failed to execute test", e);
}
}
};
return time(runnable);
}
use of com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper in project wcomponents by BorderTech.
the class WServletPerformance_Test method testWServletAppCorrectness.
/**
* Basic sanity-test to ensure that the WComponent app is performing all the processing that it should.
*
* @throws Exception an exception
*/
@Test
public void testWServletAppCorrectness() throws Exception {
SimpleWServlet servlet = new SimpleWServlet();
servlet.init(new MockServletConfig());
MockHttpSession session = new MockHttpSession();
// First request
sendWServletRequest(servlet, session, 0, null);
// Second request
WServletHelper helper = new WServletHelper(servlet, new MockHttpServletRequest(session), new MockHttpServletResponse());
UIContext uic = helper.getUIContext();
SimpleApp app = (SimpleApp) uic.getUI();
sendWServletRequest(servlet, session, 1, uic.getEnvironment().getSessionToken());
setActiveContext(uic);
Assert.assertEquals("Incorrect step", 2, uic.getEnvironment().getStep());
Assert.assertEquals("Incorrect property1 value", "p1_1", ((SimpleFormBean) app.container.getBean()).getProperty1());
Assert.assertEquals("Incorrect property2 value", "p2_1", ((SimpleFormBean) app.container.getBean()).getProperty2());
}
Aggregations