use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.
the class WWindowInterceptor_Test method testServiceRequest.
@Test
public void testServiceRequest() {
final int initialServletStep = 123;
final int initialWindowStep = 111;
// Create app
WApplication app = new WApplication();
WWindow window = new WWindow();
window.setContent(new MockLabel("dummy"));
app.add(window);
WContent content = new WContent();
content.setContentAccess(new InternalResource("/wcomponents-test.properties", "test"));
app.add(content);
app.setLocked(true);
// Set up servlet env
WServlet.WServletEnvironment servletEnvironment = new WServlet.WServletEnvironment("/app", "", "");
servletEnvironment.setStep(initialServletStep);
// Set user session
UIContext uic = createUIContext();
uic.setUI(app);
uic.setEnvironment(servletEnvironment);
setActiveContext(uic);
window.setStep(initialWindowStep);
window.display();
// Target the content first - should pass through and update the environment's step
WWindowInterceptor interceptor = new WWindowInterceptor(true);
TestInterceptor testInterceptor = new TestInterceptor();
interceptor.setBackingComponent(testInterceptor);
interceptor.attachUI(app);
MockRequest request = new MockRequest();
request.setParameter(Environment.TARGET_ID, content.getId());
interceptor.serviceRequest(request);
Assert.assertEquals("Servlet step should have changed after serviceRequest", initialServletStep + 1, servletEnvironment.getStep());
Assert.assertEquals("Window step should not have changed", initialWindowStep, window.getStep());
interceptor.preparePaint(request);
Assert.assertEquals("Servlet step should have changed after preparePaint", initialServletStep + 2, servletEnvironment.getStep());
Assert.assertEquals("Window step should not have changed", initialWindowStep, window.getStep());
interceptor.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
Assert.assertEquals("Servlet step should have changed after paint", initialServletStep + 3, servletEnvironment.getStep());
Assert.assertEquals("Window step should not have changed", initialWindowStep, window.getStep());
servletEnvironment.setStep(initialServletStep);
request = new MockRequest();
request.setParameter(WWindow.WWINDOW_REQUEST_PARAM_KEY, window.getId());
interceptor.serviceRequest(request);
Assert.assertEquals("Window step should have changed after serviceRequest", initialWindowStep + 1, window.getStep());
Assert.assertEquals("Servlet step should not have changed", initialServletStep, servletEnvironment.getStep());
interceptor.preparePaint(request);
Assert.assertEquals("Window step should have changed after preparePaintnot have changed", initialWindowStep + 2, window.getStep());
Assert.assertEquals("Servlet step should not have changed", initialServletStep, servletEnvironment.getStep());
interceptor.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
Assert.assertEquals("Window step should have changed after paint", initialWindowStep + 3, window.getStep());
Assert.assertEquals("Servlet step should not have changed", initialServletStep, servletEnvironment.getStep());
String actualTargetId = testInterceptor.hiddenParams.get(WWindow.WWINDOW_REQUEST_PARAM_KEY);
Assert.assertEquals("Hidden params target id should be window id", window.getId(), actualTargetId);
}
use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScalingWithInterceptorChain.
@Test
public void testRenderingScalingWithInterceptorChain() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
makeAllInputsMandatory(component1);
component1.setLocked(true);
final UIContext uic1 = createUIContext();
final UIContext uicChain = createUIContext();
sendRequest(component1, uic1);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Just paint component
component1.preparePaint(new MockRequest());
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uicChain);
for (int i = 0; i < NUM_REPETITIONS; i++) {
// Paint with the interceptor chain
WebUtilities.renderWithTransformToHTML(component1);
}
}
};
// JIT warm-up
runnable.run();
long renderTimeChain = time(runnable) / NUM_REPETITIONS;
LOG.info("Render Component time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render Component/Chain time: " + (renderTimeChain / 1000000.0) + "ms");
Assert.assertTrue("Render with Chain time scaling should not be more than 3x.", renderTimeChain < renderTime1 * 3);
}
use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.
the class WebXmlRenderingPerformance_Test method testRenderingScaling.
@Test
public void testRenderingScaling() throws Exception {
final RenderContext renderContext = new WebXmlRenderContext(new PrintWriter(new NullWriter()));
final AllComponents component1 = new AllComponents();
final UIContext uic1 = createUIContext();
sendRequest(component1, uic1);
final AllComponents component10 = new AllComponents(10);
final UIContext uic10 = createUIContext();
sendRequest(component10, uic10);
Runnable runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic1);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component1.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime1 = time(runnable) / NUM_REPETITIONS;
runnable = new Runnable() {
@Override
public void run() {
setActiveContext(uic10);
for (int i = 0; i < NUM_REPETITIONS; i++) {
component10.paint(renderContext);
}
}
};
// JIT warm-up
runnable.run();
long renderTime10 = time(runnable) / NUM_REPETITIONS;
LOG.info("Render 1x time: " + (renderTime1 / 1000000.0) + "ms");
LOG.info("Render 10x time: " + (renderTime10 / 1000000.0) + "ms");
Assert.assertTrue("Render time scaling should be O(n)", renderTime10 < renderTime1 * 12);
}
use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.
the class WPopup_Test method testNotVisibleAfterPaint.
@Test
public void testNotVisibleAfterPaint() {
WPopup popup = new WPopup();
// Should default to not visible
Assert.assertFalse("Popup should not be visible by default", popup.isVisible());
// Make visible
popup.setLocked(true);
setActiveContext(createUIContext());
popup.setVisible(true);
// Check not visible after paint
popup.paint(new WebXmlRenderContext(new PrintWriter(new NullWriter())));
Assert.assertFalse("Popup should not be visible after paint", popup.isVisible());
}
use of com.github.bordertech.wcomponents.util.NullWriter in project wcomponents by BorderTech.
the class WComponentRenderPerfTest method runRenderTest.
/**
* Runs the render test.
*/
private static void runRenderTest() {
UIContextImpl uic = new UIContextImpl();
PrintWriter printWriter = new PrintWriter(new NullWriter());
RenderContext renderContext = new WebXmlRenderContext(printWriter);
WComponent component = null;
long baseLineMemory = getHeapUsed();
try {
component = (WComponent) Class.forName(CLASS_TO_TEST).newInstance();
} catch (Exception e) {
String msg = "Unable to instantiate test component: " + CLASS_TO_TEST;
LOG.error(LINE_PREFIX + msg);
throw new SystemException(msg, e);
}
long memBeforePaint = getHeapUsed() - baseLineMemory;
// Set up velocity etc. to obtain a memory reading, and
// so that the performance results aren't skewed too much
UIContextHolder.pushContext(uic);
try {
component.paint(renderContext);
long memAfterOnePaint = getHeapUsed() - baseLineMemory;
long startTime = System.currentTimeMillis();
// Figure out the loop overhead
for (int i = 0; i < NUM_RENDERS; i++) {
}
long loopOverhead = System.currentTimeMillis() - startTime;
startTime = System.currentTimeMillis();
// Now run the render test
for (int i = 0; i < NUM_RENDERS; i++) {
component.paint(renderContext);
}
long elapsedTime = System.currentTimeMillis() - startTime - loopOverhead;
long memAfterAllPaints = getHeapUsed() - baseLineMemory;
LOG.info(LINE_PREFIX + "Memory use before paint: " + memBeforePaint);
LOG.info(LINE_PREFIX + "Memory use after 1 paint: " + memAfterOnePaint);
LOG.info(LINE_PREFIX + "Memory use after " + NUM_RENDERS + " paints: " + memAfterAllPaints);
LOG.info(LINE_PREFIX + "Render time: " + (elapsedTime / (double) NUM_RENDERS) + "ms");
Object[] treeAndSession = new Object[] { component, uic };
ObjectGraphNode root = ObjectGraphDump.dump(treeAndSession);
LOG.info(LINE_PREFIX + "Component mem use: " + ((ObjectGraphNode) root.getChildAt(0)).getSize());
LOG.info(LINE_PREFIX + "UIC mem use: " + ((ObjectGraphNode) root.getChildAt(1)).getSize());
} finally {
UIContextHolder.popContext();
}
}
Aggregations