Search in sources :

Example 1 with RenderContext

use of com.github.bordertech.wcomponents.RenderContext in project wcomponents by BorderTech.

the class ProfileContainer_Test method testAfterPaint.

/**
 * Test afterPaint.
 */
@Test
public void testAfterPaint() {
    ProfileContainer app = new ProfileContainer();
    app.setLocked(true);
    UIContext uic = new UIContextImpl();
    uic.setUI(app);
    setActiveContext(uic);
    WButton button = new WButton("PUSH");
    app.add(button);
    WLabel label = new WLabel("HERE");
    app.add(label);
    StringWriter outStr = new StringWriter();
    PrintWriter writer = new PrintWriter(outStr);
    RenderContext renderContext = new WebXmlRenderContext(writer);
    app.afterPaint(renderContext);
    // expecting 1 root class, 3 components, class names as shown, profiler
    // class
    String profileLine0 = PROFILER_UIC_HEADER;
    String profileLine1 = PROFILER_LINE1.replaceAll("<<NUM_ROOTS>>", "1");
    String profileLine2 = PROFILER_LINE2.replaceAll("<<NUM_COMPONENTS>>", "4");
    String profileLine31 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WButton");
    String profileLine32 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.monitor.ProfileContainer");
    String profileLine33 = PROFILER_LINE3.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.WLabel");
    String profileLine4 = PROFILER_PROFILE_HEADER.replaceAll("<<CLASS_NAME>>", "com.github.bordertech.wcomponents.monitor.ProfileContainer");
    String[] expectedResults = { profileLine0, profileLine1, profileLine2, profileLine31, profileLine32, profileLine33, profileLine4 };
    String result = outStr.toString();
    for (int i = 0; i < expectedResults.length; i++) {
        Assert.assertTrue("result should contain substring " + i + "  ", result.indexOf(expectedResults[i]) != -1);
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) StringWriter(java.io.StringWriter) UIContext(com.github.bordertech.wcomponents.UIContext) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) WButton(com.github.bordertech.wcomponents.WButton) WLabel(com.github.bordertech.wcomponents.WLabel) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 2 with RenderContext

use of com.github.bordertech.wcomponents.RenderContext 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);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 3 with RenderContext

use of com.github.bordertech.wcomponents.RenderContext 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);
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) UIContext(com.github.bordertech.wcomponents.UIContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) PrintWriter(java.io.PrintWriter) AllComponents(com.github.bordertech.wcomponents.AllComponents) Test(org.junit.Test)

Example 4 with RenderContext

use of com.github.bordertech.wcomponents.RenderContext 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();
    }
}
Also used : WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) RenderContext(com.github.bordertech.wcomponents.RenderContext) WebXmlRenderContext(com.github.bordertech.wcomponents.servlet.WebXmlRenderContext) NullWriter(com.github.bordertech.wcomponents.util.NullWriter) IOException(java.io.IOException) SystemException(com.github.bordertech.wcomponents.util.SystemException) WComponent(com.github.bordertech.wcomponents.WComponent) SystemException(com.github.bordertech.wcomponents.util.SystemException) UIContextImpl(com.github.bordertech.wcomponents.UIContextImpl) ObjectGraphNode(com.github.bordertech.wcomponents.util.ObjectGraphNode) PrintWriter(java.io.PrintWriter)

Example 5 with RenderContext

use of com.github.bordertech.wcomponents.RenderContext in project wcomponents by BorderTech.

the class InterceptorComponent_Test method testAttachUIBadBacking.

@Test(expected = IllegalStateException.class)
public void testAttachUIBadBacking() {
    InterceptorComponent interceptor = new InterceptorComponent(new WebComponent() {

        /**
         * {@inheritDoc}
         */
        @Override
        public void serviceRequest(final Request request) {
        // NO-OP
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void preparePaint(final Request request) {
        // NO-OP
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public void paint(final RenderContext renderContext) {
        // NO-OP
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String getName() {
            return null;
        }

        /**
         * {@inheritDoc}
         */
        @Override
        public String getId() {
            return null;
        }
    });
    // This should throw an exception, as it doesn't know how to attach the UI
    // to the anonymous WebComponent implementation.
    interceptor.attachUI(new WLabel());
}
Also used : WebComponent(com.github.bordertech.wcomponents.WebComponent) RenderContext(com.github.bordertech.wcomponents.RenderContext) MockRequest(com.github.bordertech.wcomponents.util.mock.MockRequest) Request(com.github.bordertech.wcomponents.Request) WLabel(com.github.bordertech.wcomponents.WLabel) Test(org.junit.Test)

Aggregations

RenderContext (com.github.bordertech.wcomponents.RenderContext)6 WebXmlRenderContext (com.github.bordertech.wcomponents.servlet.WebXmlRenderContext)5 PrintWriter (java.io.PrintWriter)5 Test (org.junit.Test)5 UIContext (com.github.bordertech.wcomponents.UIContext)3 NullWriter (com.github.bordertech.wcomponents.util.NullWriter)3 AllComponents (com.github.bordertech.wcomponents.AllComponents)2 UIContextImpl (com.github.bordertech.wcomponents.UIContextImpl)2 WLabel (com.github.bordertech.wcomponents.WLabel)2 MockRequest (com.github.bordertech.wcomponents.util.mock.MockRequest)2 StringWriter (java.io.StringWriter)2 Request (com.github.bordertech.wcomponents.Request)1 WButton (com.github.bordertech.wcomponents.WButton)1 WComponent (com.github.bordertech.wcomponents.WComponent)1 WebComponent (com.github.bordertech.wcomponents.WebComponent)1 ObjectGraphNode (com.github.bordertech.wcomponents.util.ObjectGraphNode)1 SystemException (com.github.bordertech.wcomponents.util.SystemException)1 IOException (java.io.IOException)1