ASF Bugzilla – Attachment 29587 Details for
Bug 53869
Performance tuning solution to resolve too many cascaded JspContextWrapper issue
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
Test case comparison for performance tuning
JspContextWrapperTest.java (text/plain), 6.46 KB, created by
Sheldon Shao
on 2012-11-12 05:56:42 UTC
(
hide
)
Description:
Test case comparison for performance tuning
Filename:
MIME Type:
Creator:
Sheldon Shao
Created:
2012-11-12 05:56:42 UTC
Size:
6.46 KB
patch
obsolete
>package org.apache.jasper.runtime; > >import java.io.IOException; >import java.util.Enumeration; >import java.util.HashMap; >import java.util.Map; > >import javax.el.ELContext; >import javax.servlet.Servlet; >import javax.servlet.ServletConfig; >import javax.servlet.ServletContext; >import javax.servlet.ServletException; >import javax.servlet.ServletRequest; >import javax.servlet.ServletResponse; >import javax.servlet.http.HttpSession; >import javax.servlet.jsp.JspContext; >import javax.servlet.jsp.JspWriter; >import javax.servlet.jsp.PageContext; >import javax.servlet.jsp.el.ExpressionEvaluator; >import javax.servlet.jsp.el.VariableResolver; > >import org.junit.Assert; >import org.junit.Test; > >public class JspContextWrapperTest { > > @Test > public void test() throws Exception { > findAttribute(); > findAttributeOld(); > findAttribute(); > findAttributeOld(); > findAttribute(); > findAttributeOld(); > findAttribute(); > findAttributeOld(); > } > > private static final int COUNT = 10000000; > > > public void findAttribute() throws Exception { > JspContext jspContext = new MockJspContext(); > > JspContextWrapper wrapper = new JspContextWrapper(jspContext, null, null, null, null); > for (int i = 0; i < 5; i++) { > wrapper = new JspContextWrapper(new JspContextWrapper(wrapper, null, null, null, null), null, null, null, null); > } > > Object value = wrapper.findAttribute("name"); > Assert.assertEquals("tom", value); > > long start = System.currentTimeMillis(); > for (int i = 0; i < COUNT; i++) { > value = wrapper.findAttribute("name"); > } > long duration = System.currentTimeMillis() - start; > Assert.assertEquals("tom", value); > System.out.println("Duration:" + duration); > } > public void findAttributeOld() throws Exception { > JspContext jspContext = new MockJspContext(); > > JspContextWrapperOld wrapper = new JspContextWrapperOld(jspContext, null, null, null, null); > for (int i = 0; i < 5; i++) { > wrapper = new JspContextWrapperOld(new JspContextWrapperOld(wrapper, null, null, null, null), null, null, > null, null); > } > > Object value = wrapper.findAttribute("name"); > Assert.assertEquals("tom", value); > > long start = System.currentTimeMillis(); > for (int i = 0; i < COUNT; i++) { > value = wrapper.findAttribute("name"); > } > long duration = System.currentTimeMillis() - start; > System.out.println("DurationOld:" + duration); > Assert.assertEquals("tom", value); > } > > private static class MockJspContext extends PageContext { > Map<String, Object> attributes = new HashMap<String, Object>(); > > public MockJspContext() { > attributes.put("name", "tom"); > attributes.put("test", "test"); > } > > @Override > public Object findAttribute(String name) { > // TODO Auto-generated method stub > return null; > } > > @Override > public void forward(String relativeUrlPath) throws ServletException, IOException { > // TODO Auto-generated method stub > > } > > @Override > public Object getAttribute(String name) { > return attributes.get(name); > } > > @Override > public Object getAttribute(String name, int scope) { > return attributes.get(name); > } > > @Override > public Enumeration<String> getAttributeNamesInScope(int scope) { > // TODO Auto-generated method stub > return null; > } > > @Override > public int getAttributesScope(String name) { > // TODO Auto-generated method stub > return 0; > } > > @Override > public ELContext getELContext() { > // TODO Auto-generated method stub > return null; > } > > @Override > public Exception getException() { > // TODO Auto-generated method stub > return null; > } > > @Override > public ExpressionEvaluator getExpressionEvaluator() { > // TODO Auto-generated method stub > return null; > } > > @Override > public JspWriter getOut() { > // TODO Auto-generated method stub > return null; > } > > @Override > public Object getPage() { > // TODO Auto-generated method stub > return null; > } > > @Override > public ServletRequest getRequest() { > // TODO Auto-generated method stub > return null; > } > > @Override > public ServletResponse getResponse() { > // TODO Auto-generated method stub > return null; > } > > @Override > public ServletConfig getServletConfig() { > // TODO Auto-generated method stub > return null; > } > > @Override > public ServletContext getServletContext() { > // TODO Auto-generated method stub > return null; > } > > @Override > public HttpSession getSession() { > return null; > } > > @Override > public VariableResolver getVariableResolver() { > // TODO Auto-generated method stub > return null; > } > > @Override > public void handlePageException(Exception e) throws ServletException, IOException { > // TODO Auto-generated method stub > > } > > @Override > public void handlePageException(Throwable t) throws ServletException, IOException { > // TODO Auto-generated method stub > > } > > @Override > public void include(String relativeUrlPath) throws ServletException, IOException { > // TODO Auto-generated method stub > > } > > @Override > public void include(String relativeUrlPath, boolean flush) throws ServletException, IOException { > // TODO Auto-generated method stub > > } > > @Override > public void initialize(Servlet servlet, ServletRequest request, ServletResponse response, String errorPageURL, > boolean needsSession, int bufferSize, boolean autoFlush) throws IOException, IllegalStateException, > IllegalArgumentException { > } > > @Override > public void release() { > } > > @Override > public void removeAttribute(String name) { > // TODO Auto-generated method stub > > } > > @Override > public void removeAttribute(String name, int scope) { > // TODO Auto-generated method stub > > } > > @Override > public void setAttribute(String name, Object value) { > // TODO Auto-generated method stub > > } > > @Override > public void setAttribute(String name, Object value, int scope) { > // TODO Auto-generated method stub > > } > } >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 53869
:
29372
|
29373
|
29586
| 29587 |
29604