/** * Times the WComponent 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 timeWComponentProcessing(final int count) throws Exception { final UIContext uic = createUIContext(); final SimpleApp app = new SimpleApp(); // JIT warm-up for (int i = 0; i < count; i++) { sendWComponentRequest(app, uic, i); } final UIContext uic2 = createUIContext(); Runnable runnable = new Runnable() { @Override public void run() { for (int i = 0; i < count; i++) { sendWComponentRequest(app, uic2, i); } } }; return time(runnable); }
/** * Creates a SimpleApp. */ public SimpleApp() { add(beanContainer); WTextField property1 = new WTextField(); WTextField property2 = new WTextField(); property1.setBeanProperty("property1"); property2.setBeanProperty("property2"); property1.setIdName("txt1"); property2.setIdName("txt2"); beanContainer.add(new WLabel("Property 1:", property1)); beanContainer.add(property1); beanContainer.add(new WLabel("Property 2:", property2)); beanContainer.add(property2); WButton submit = new WButton("Submit"); submit.setIdName("btn"); submit.setAction(new Action() { @Override public void execute(final ActionEvent event) { WebUtilities.updateBeanValue(beanContainer); } }); beanContainer.add(submit); }
@Override protected void preparePaintComponent(final Request request) { super.preparePaintComponent(request); if (!isInitialised()) { beanContainer.setBean(new SimpleFormBean()); setInitialised(true); } } }
/** * Basic sanity-test to ensure that the WComponent implementation is performing all the processing that it should. * * @throws java.lang.Exception an exception */ @Test public void testWComponentAppCorrectness() throws Exception { final UIContext uic = createUIContext(); final SimpleApp app = new SimpleApp(); sendWComponentRequest(app, uic, 0); sendWComponentRequest(app, uic, 1); setActiveContext(uic); Assert.assertEquals("Incorrect property1 value", "p1_1", ((SimpleFormBean) app.beanContainer.getBean()).getProperty1()); Assert.assertEquals("Incorrect property2 value", "p2_1", ((SimpleFormBean) app.beanContainer.getBean()).getProperty2()); }
/** * Invokes WComponent servlet processing. * * @param app the component to invoke request processing on. * @param uic the user context to use. * @param step the step count */ private void sendWComponentRequest(final SimpleApp app, final UIContext uic, final int step) { // The parameter names are hard-coded to avoid overhead during performance testing MockRequest request = new MockRequest(); request.setParameter("txt1", "p1_" + step); request.setParameter("txt2", "p2_" + step); request.setParameter("btn", "x"); setActiveContext(uic); app.serviceRequest(request); app.preparePaint(request); }