Author: kkolinko
Date: Mon Jun 23 16:16:47 2014
New Revision: 1604846

URL: http://svn.apache.org/r1604846
Log:
Test for https://issues.apache.org/bugzilla/show_bug.cgi?id=56653
Test concurrency issue with Mapper$ContextList.nesting field.
It is backport of r1604309.

Modified:
    tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java

Modified: 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java?rev=1604846&r1=1604845&r2=1604846&view=diff
==============================================================================
--- 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java 
(original)
+++ 
tomcat/tc7.0.x/trunk/test/org/apache/tomcat/util/http/mapper/TestMapper.java 
Mon Jun 23 16:16:47 2014
@@ -19,6 +19,8 @@ package org.apache.tomcat.util.http.mapp
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
+import java.util.concurrent.atomic.AtomicBoolean;
+
 import org.junit.Before;
 import org.junit.Test;
 
@@ -174,6 +176,63 @@ public class TestMapper extends LoggingB
     }
 
     @Test
+    public void testContextListConcurrencyBug56653() throws Exception {
+        final Object host = new Object(); // "localhost";
+        final Object contextRoot = new Object(); // "ROOT";
+        final Object context1 = new Object(); // "foo";
+        final Object context2 = new Object(); // "foo#bar";
+        final Object context3 = new Object(); // "foo#bar#bla";
+        final Object context4 = new Object(); // "foo#bar#bla#baz";
+
+        mapper.addHost("localhost", new String[0], host);
+        mapper.setDefaultHostName("localhost");
+
+        mapper.addContextVersion("localhost", host, "", "0", contextRoot,
+                new String[0], null);
+        mapper.addContextVersion("localhost", host, "/foo", "0", context1,
+                new String[0], null);
+        mapper.addContextVersion("localhost", host, "/foo/bar", "0", context2,
+                new String[0], null);
+        mapper.addContextVersion("localhost", host, "/foo/bar/bla", "0",
+                context3, new String[0], null);
+        mapper.addContextVersion("localhost", host, "/foo/bar/bla/baz", "0",
+                context4, new String[0], null);
+
+        final AtomicBoolean running = new AtomicBoolean(true);
+        Thread t = new Thread() {
+            @Override
+            public void run() {
+                for (int i = 0; i < 100000; i++) {
+                    mapper.removeContextVersion("localhost",
+                            "/foo/bar/bla/baz", "0");
+                    mapper.addContextVersion("localhost", host,
+                            "/foo/bar/bla/baz", "0", context4, new String[0],
+                            null);
+                }
+                running.set(false);
+            }
+        };
+
+        MappingData mappingData = new MappingData();
+        MessageBytes hostMB = MessageBytes.newInstance();
+        hostMB.setString("localhost");
+        MessageBytes uriMB = MessageBytes.newInstance();
+        char[] uri = "/foo/bar/bla/bobou/foo".toCharArray();
+        uriMB.setChars(uri, 0, uri.length);
+
+        mapper.map(hostMB, uriMB, null, mappingData);
+        assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
+
+        t.start();
+        while (running.get()) {
+            mappingData.recycle();
+            uriMB.setChars(uri, 0, uri.length);
+            mapper.map(hostMB, uriMB, null, mappingData);
+            assertEquals("/foo/bar/bla", mappingData.contextPath.toString());
+        }
+    }
+
+    @Test
     public void testPerformance() throws Exception {
         // Takes ~1s on markt's laptop. If this takes more than 5s something
         // probably needs looking at. If this fails repeatedly then we may need



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

Reply via email to