Search in sources :

Example 1 with WServletHelper

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);
}
Also used : WServletHelper(com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) ServletException(javax.servlet.ServletException)

Example 2 with WServletHelper

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());
}
Also used : WServletHelper(com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper) UIContext(com.github.bordertech.wcomponents.UIContext) MockHttpServletRequest(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest) MockServletConfig(com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig) MockHttpSession(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession) MockHttpServletResponse(com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse) Test(org.junit.Test)

Aggregations

WServletHelper (com.github.bordertech.wcomponents.servlet.WServlet.WServletHelper)2 MockHttpServletRequest (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletRequest)2 MockHttpServletResponse (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpServletResponse)2 MockHttpSession (com.github.bordertech.wcomponents.util.mock.servlet.MockHttpSession)2 MockServletConfig (com.github.bordertech.wcomponents.util.mock.servlet.MockServletConfig)2 UIContext (com.github.bordertech.wcomponents.UIContext)1 ServletException (javax.servlet.ServletException)1 Test (org.junit.Test)1