Author: kkolinko
Date: Sun Jul 13 13:43:43 2014
New Revision: 1610197

URL: http://svn.apache.org/r1610197
Log:
Test for add/remove ContextVersion. The issue was reported for Tomcat 7 in 
"Time for 7.0.55" thread on dev mailing list.
I see no failures with Tomcat 8.

Modified:
    tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
    tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java

Modified: tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java?rev=1610197&r1=1610196&r2=1610197&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java Sun Jul 13 
13:43:43 2014
@@ -750,7 +750,7 @@ public final class Mapper {
 
         ContextVersion contextVersion = null;
         ContextVersion[] contextVersions = context.versions;
-        int versionCount = contextVersions.length;
+        final int versionCount = contextVersions.length;
         if (versionCount > 1) {
             Context[] contextObjects = new Context[contextVersions.length];
             for (int i = 0; i < contextObjects.length; i++) {

Modified: tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java?rev=1610197&r1=1610196&r2=1610197&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java (original)
+++ tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java Sun Jul 13 
13:43:43 2014
@@ -22,6 +22,7 @@ import java.util.concurrent.atomic.Atomi
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotSame;
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
@@ -257,6 +258,89 @@ public class TestMapper extends LoggingB
     }
 
     @Test
+    public void testAddRemoveContextVersion() throws Exception {
+        final String hostName = "iowejoiejfoiew";
+        final int iowPos = 3;
+        final String contextPath = "/foo/bar";
+        final int contextPos = 2;
+
+        MappingData mappingData = new MappingData();
+        MessageBytes hostMB = MessageBytes.newInstance();
+        MessageBytes uriMB = MessageBytes.newInstance();
+        hostMB.setString(hostName);
+        uriMB.setString("/foo/bar/blah/bobou/foo");
+
+        // Verifying configuration created by setUp()
+        Mapper.MappedHost mappedHost = mapper.hosts[iowPos];
+        assertEquals(hostName, mappedHost.name);
+        Mapper.MappedContext mappedContext = 
mappedHost.contextList.contexts[contextPos];
+        assertEquals(contextPath, mappedContext.name);
+        assertEquals(1, mappedContext.versions.length);
+        assertEquals("0", mappedContext.versions[0].name);
+        Host oldHost = mappedHost.object;
+        Context oldContext = mappedContext.versions[0].object;
+
+        mappingData.recycle();
+        mapper.map(hostMB, uriMB, null, mappingData);
+        assertEquals("blah7", mappingData.host.getName());
+        assertEquals("context2", mappingData.context.getName());
+
+        Context newContext = createContext("newContext");
+        mapper.addContextVersion(
+                hostName,
+                oldHost,
+                contextPath,
+                "1",
+                newContext,
+                null,
+                null,
+                Arrays.asList(new WrapperMappingInfo[] { new 
WrapperMappingInfo(
+                        "/", createWrapper("default"), false, false) }));
+
+        assertEquals(2, mappedContext.versions.length);
+        assertEquals("0", mappedContext.versions[0].name);
+        assertEquals("1", mappedContext.versions[1].name);
+        mappingData.recycle();
+        mapper.map(hostMB, uriMB, null, mappingData);
+        assertEquals("newContext", mappingData.context.getName());
+
+        mapper.removeContextVersion(oldContext, hostName, contextPath, "0");
+
+        assertEquals(1, mappedContext.versions.length);
+        assertEquals("1", mappedContext.versions[0].name);
+        mappingData.recycle();
+        mapper.map(hostMB, uriMB, null, mappingData);
+        assertEquals("newContext", mappingData.context.getName());
+
+        mapper.removeContextVersion(oldContext, hostName, contextPath, "1");
+
+        assertNotSame(mappedContext, 
mappedHost.contextList.contexts[contextPos]);
+        assertEquals("/foo/bar/bla", 
mappedHost.contextList.contexts[contextPos].name);
+        mappingData.recycle();
+        mapper.map(hostMB, uriMB, null, mappingData);
+        assertEquals("context1", mappingData.context.getName());
+
+        mapper.addContextVersion(
+                hostName,
+                oldHost,
+                contextPath,
+                "0",
+                newContext,
+                null,
+                null,
+                Arrays.asList(new WrapperMappingInfo[] { new 
WrapperMappingInfo(
+                        "/", createWrapper("default"), false, false) }));
+        mappedContext = mappedHost.contextList.contexts[contextPos];
+
+        assertEquals(contextPath, mappedContext.name);
+        assertEquals(1, mappedContext.versions.length);
+        assertEquals("0", mappedContext.versions[0].name);
+        mappingData.recycle();
+        mapper.map(hostMB, uriMB, null, mappingData);
+        assertEquals("newContext", mappingData.context.getName());
+    }
+
+    @Test
     public void testContextListConcurrencyBug56653() throws Exception {
         final Host host = createHost("localhost");
         final Context contextRoot = createContext("ROOT");



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

Reply via email to