tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r1780120 - /tomcat/trunk/test/org/apache/catalina/core/TestDefaultInstanceManager.java
Date Tue, 24 Jan 2017 21:22:22 GMT
Author: markt
Date: Tue Jan 24 21:22:22 2017
New Revision: 1780120

URL: http://svn.apache.org/viewvc?rev=1780120&view=rev
Log:
Add unit test to investigate report of concurrency issues in DefaultInstanceManager.
https://github.com/apache/tomcat85/pull/5
Initial results indicate that there is an issue.

Modified:
    tomcat/trunk/test/org/apache/catalina/core/TestDefaultInstanceManager.java

Modified: tomcat/trunk/test/org/apache/catalina/core/TestDefaultInstanceManager.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestDefaultInstanceManager.java?rev=1780120&r1=1780119&r2=1780120&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestDefaultInstanceManager.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestDefaultInstanceManager.java Tue Jan 24
21:22:22 2017
@@ -17,14 +17,22 @@
 package org.apache.catalina.core;
 
 import java.io.File;
+import java.lang.reflect.InvocationTargetException;
+
+import javax.naming.NamingException;
 
 import static org.junit.Assert.assertEquals;
+
+import org.junit.Ignore;
 import org.junit.Test;
 
+import org.apache.catalina.Context;
 import org.apache.catalina.Wrapper;
+import org.apache.catalina.servlets.DefaultServlet;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.jasper.servlet.JasperInitializer;
+import org.apache.tomcat.InstanceManager;
 
 
 public class TestDefaultInstanceManager extends TomcatBaseTest {
@@ -86,4 +94,70 @@ public class TestDefaultInstanceManager
 
         return (DefaultInstanceManager) ctxt.getInstanceManager();
     }
+
+
+    /*
+     * Performance test. Comment out @Ignore to run the test.
+     */
+    @Ignore
+    @Test
+    public void testConcurrency() throws Exception {
+        // Create a populated InstanceManager
+        Tomcat tomcat = getTomcatInstance();
+        Context ctx = tomcat.addContext(null, "", null);
+
+        tomcat.start();
+
+        InstanceManager im = ctx.getInstanceManager();
+
+        for (int i = 1; i < 9; i++) {
+            doTestConcurrency(im, i);
+        }
+    }
+
+
+    private void doTestConcurrency(InstanceManager im, int threadCount) throws Exception
{
+        long start = System.nanoTime();
+
+        Thread[] threads = new Thread[threadCount];
+
+        for (int i = 0; i < threadCount; i++) {
+            threads[i] = new Thread(new InstanceManagerRunnable(im));
+        }
+
+        for (int i = 0; i < threadCount; i++) {
+            threads[i].start();
+        }
+
+        for (int i = 0; i < threadCount; i++) {
+            threads[i].join();
+        }
+
+        long duration = System.nanoTime() - start;
+
+        System.out.println(threadCount + " threads completed in " + duration + "ns");
+    }
+
+
+    private class InstanceManagerRunnable implements Runnable {
+
+        private final InstanceManager im;
+
+        private InstanceManagerRunnable(InstanceManager im) {
+            this.im = im;
+        }
+
+        @Override
+        public void run() {
+            try {
+                Object test = new DefaultServlet();
+                for (int i = 0; i < 200000; i++) {
+                    im.newInstance(test);
+                    im.destroyInstance(test);
+                }
+            } catch (NamingException | IllegalAccessException | InvocationTargetException
ne) {
+                ne.printStackTrace();
+            }
+        }
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message