You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2013/11/26 00:12:02 UTC
svn commit: r1545450 - in /tomcat/tc7.0.x/trunk: ./
java/org/apache/catalina/startup/HostConfig.java
test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
Author: markt
Date: Mon Nov 25 23:12:02 2013
New Revision: 1545450
URL: http://svn.apache.org/r1545450
Log:
Backport automatic deployment changes part 12
More tests for addition
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1483786-1483787
Modified: tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java?rev=1545450&r1=1545449&r2=1545450&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/catalina/startup/HostConfig.java Mon Nov 25 23:12:02 2013
@@ -1095,7 +1095,7 @@ public class HostConfig
Context context = null;
File xml = new File(dir, Constants.ApplicationContextXml);
- File xmlCopy = null;
+ File xmlCopy = new File(configBase(), cn.getBaseName() + ".xml");
DeployedApplication deployedApp = new DeployedApplication(cn.getName(),
xml.exists() && deployXML && copyXML);
@@ -1115,7 +1115,6 @@ public class HostConfig
}
}
if (copyXML) {
- xmlCopy = new File(configBase(), cn.getBaseName() + ".xml");
InputStream is = null;
OutputStream os = null;
try {
@@ -1158,18 +1157,33 @@ public class HostConfig
log.error(sm.getString("hostConfig.deployDir.error",
dir.getAbsolutePath()), t);
} finally {
+ // Fake re-deploy resource to detect if a WAR is added at a later
+ // point
+ deployedApp.redeployResources.put(dir.getAbsolutePath() + ".war",
+ Long.valueOf(0));
deployedApp.redeployResources.put(dir.getAbsolutePath(),
Long.valueOf(dir.lastModified()));
if (deployXML && xml.exists()) {
- if (xmlCopy == null) {
+ if (copyXML) {
+ deployedApp.redeployResources.put(
+ xmlCopy.getAbsolutePath(),
+ Long.valueOf(xmlCopy.lastModified()));
+ } else {
deployedApp.redeployResources.put(
xml.getAbsolutePath(),
Long.valueOf(xml.lastModified()));
- } else {
+ // Fake re-deploy resource to detect if a context.xml file is
+ // added at a later point
deployedApp.redeployResources.put(
xmlCopy.getAbsolutePath(),
- Long.valueOf(xmlCopy.lastModified()));
+ Long.valueOf(0));
}
+ } else {
+ // Fake re-deploy resource to detect if a context.xml file is
+ // added at a later point
+ deployedApp.redeployResources.put(
+ xmlCopy.getAbsolutePath(),
+ Long.valueOf(0));
}
addWatchedResources(deployedApp, dir.getAbsolutePath(), context);
// Add the global redeploy resources (which are never deleted) at
@@ -1262,9 +1276,9 @@ public class HostConfig
if (log.isDebugEnabled())
log.debug("Checking context[" + app.name +
"] redeploy resource " + resource);
- if (resource.exists()) {
- long lastModified =
+ long lastModified =
app.redeployResources.get(resources[i]).longValue();
+ if (resource.exists() || lastModified == 0) {
if (resource.lastModified() > lastModified) {
if (resource.isDirectory()) {
// No action required for modified directory
@@ -1313,8 +1327,6 @@ public class HostConfig
if (resource.exists()) {
continue;
}
- long lastModified =
- app.redeployResources.get(resources[i]).longValue();
if (lastModified == 0L) {
continue;
}
Modified: tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java?rev=1545450&r1=1545449&r2=1545450&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java (original)
+++ tomcat/tc7.0.x/trunk/test/org/apache/catalina/startup/TestHostConfigAutomaticDeployment.java Mon Nov 25 23:12:02 2013
@@ -108,71 +108,60 @@ public class TestHostConfigAutomaticDepl
*/
@Test
public void testDeploymentXmlFFF() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(false, false, false,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlFFT() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(false, false, true,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlFTF() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(false, true, false,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlFTT() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(false, true, true,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlTFF() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(true, false, false,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlTFT() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(true, false, true,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlTTF() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(true, true, false,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
@Test
public void testDeploymentXmlTTT() throws Exception {
- initTestDeploymentXml();
+ createXmlInConfigBaseForAppbase();
doTestDeployment(true, true, true,
LifecycleState.FAILED, XML_COOKIE_NAME, true, false, false);
}
- private void initTestDeploymentXml() throws IOException {
- File xml = new File(getConfigBaseFile(getTomcatInstance().getHost()),
- APP_NAME + ".xml");
- File parent = xml.getParentFile();
- if (!parent.isDirectory()) {
- Assert.assertTrue(parent.mkdirs());
- }
-
- copy(XML_SOURCE, xml);
- }
-
/*
* Expected behaviour for deployment of an XML file that points to an
@@ -371,67 +360,60 @@ public class TestHostConfigAutomaticDepl
*/
@Test
public void testDeploymentWarXmlFFF() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(false, false, false,
LifecycleState.STARTED, null, false, true, false);
}
@Test
public void testDeploymentWarXmlFFT() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(false, false, true,
LifecycleState.STARTED, null, false, true, true);
}
@Test
public void testDeploymentWarXmlFTF() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(false, true, false,
LifecycleState.STARTED, null, false, true, false);
}
@Test
public void testDeploymentWarXmlFTT() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(false, true, true,
LifecycleState.STARTED, null, false, true, true);
}
@Test
public void testDeploymentWarXmlTFF() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(true, false, false,
LifecycleState.STARTED, WAR_COOKIE_NAME, false, true, false);
}
@Test
public void testDeploymentWarXmlTFT() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(true, false, true,
LifecycleState.STARTED, WAR_COOKIE_NAME, false, true, true);
}
@Test
public void testDeploymentWarXmlTTF() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(true, true, false,
LifecycleState.STARTED, WAR_COOKIE_NAME, true, true, false);
}
@Test
public void testDeploymentWarXmlTTT() throws Exception {
- initTestDeploymentWarXml();
+ createWarInAppbase(true);
doTestDeployment(true, true, true,
LifecycleState.STARTED, WAR_COOKIE_NAME, true, true, true);
}
- private void initTestDeploymentWarXml() throws IOException {
- // Copy the test WAR file to the appBase
- File dest = new File(getAppBaseFile(getTomcatInstance().getHost()),
- APP_NAME.getBaseName() + ".war");
- copy(WAR_XML_SOURCE, dest);
- }
-
/*
* Expected behaviour for deployment of a WAR without an embedded XML file.
@@ -441,67 +423,60 @@ public class TestHostConfigAutomaticDepl
*/
@Test
public void testDeploymentWarFFF() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(false, false, false,
LifecycleState.STARTED, null, false, true, false);
}
@Test
public void testDeploymentWarFFT() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(false, false, true,
LifecycleState.STARTED, null, false, true, true);
}
@Test
public void testDeploymentWarFTF() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(false, true, false,
LifecycleState.STARTED, null, false, true, false);
}
@Test
public void testDeploymentWarFTT() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(false, true, true,
LifecycleState.STARTED, null, false, true, true);
}
@Test
public void testDeploymentWarTFF() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(true, false, false,
LifecycleState.STARTED, null, false, true, false);
}
@Test
public void testDeploymentWarTFT() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(true, false, true,
LifecycleState.STARTED, null, false, true, true);
}
@Test
public void testDeploymentWarTTF() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(true, true, false,
LifecycleState.STARTED, null, false, true, false);
}
@Test
public void testDeploymentWarTTT() throws Exception {
- initTestDeploymentWar();
+ createWarInAppbase(false);
doTestDeployment(true, true, true,
LifecycleState.STARTED, null, false, true, true);
}
- private void initTestDeploymentWar() throws IOException {
- // Copy the test WAR file to the appBase
- File dest = new File(getAppBaseFile(getTomcatInstance().getHost()),
- APP_NAME.getBaseName() + ".war");
- copy(WAR_SOURCE, dest);
- }
-
/*
* Expected behaviour for deployment of a DIR with an embedded XML file.
@@ -871,12 +846,7 @@ public class TestHostConfigAutomaticDepl
File dir = null;
if (startXml && !startExternalWar && !startExternalDir) {
- xml = new File(getConfigBaseFile(host), APP_NAME + ".xml");
- File parent = xml.getParentFile();
- if (!parent.isDirectory()) {
- Assert.assertTrue(parent.mkdirs());
- }
- copy(XML_SOURCE, xml);
+ xml = createXmlInConfigBaseForAppbase();
}
if (startExternalWar) {
// Copy the test WAR file to the external directory
@@ -928,10 +898,7 @@ public class TestHostConfigAutomaticDepl
}
}
if (startWar) {
- // Copy the test WAR file to the appBase
- war = new File(getAppBaseFile(getTomcatInstance().getHost()),
- APP_NAME.getBaseName() + ".war");
- copy(WAR_XML_SOURCE, war);
+ war = createWarInAppbase(true);
}
if (startDir) {
dir = createDirInAppbase(true);
@@ -1087,7 +1054,8 @@ public class TestHostConfigAutomaticDepl
@Test
public void testModifyXmlUpdateXml() throws Exception {
doTestModify(true, false, false, false, false, XML,
- true, false, false, XML_COOKIE_NAME, REDEPLOY);
+ true, false, false, XML_COOKIE_NAME, REDEPLOY,
+ LifecycleState.FAILED);
}
@Test
@@ -1179,6 +1147,16 @@ public class TestHostConfigAutomaticDepl
int toModify, boolean resultXml, boolean resultWar,
boolean resultDir, String resultCookieName, int resultAction)
throws Exception {
+ doTestModify(startXml, startExternalWar, startExternalDir, startWar,
+ startDir, toModify, resultXml, resultWar, resultDir,
+ resultCookieName, resultAction, LifecycleState.STARTED);
+ }
+
+ private void doTestModify(boolean startXml, boolean startExternalWar,
+ boolean startExternalDir, boolean startWar, boolean startDir,
+ int toModify, boolean resultXml, boolean resultWar,
+ boolean resultDir, String resultCookieName, int resultAction,
+ LifecycleState resultState) throws Exception {
Tomcat tomcat = getTomcatInstance();
StandardHost host = (StandardHost) tomcat.getHost();
@@ -1190,12 +1168,7 @@ public class TestHostConfigAutomaticDepl
File dir = null;
if (startXml && !startExternalWar && !startExternalDir) {
- xml = new File(getConfigBaseFile(host), APP_NAME + ".xml");
- File parent = xml.getParentFile();
- if (!parent.isDirectory()) {
- Assert.assertTrue(parent.mkdirs());
- }
- copy(XML_SOURCE, xml);
+ xml = createXmlInConfigBaseForAppbase();
}
if (startExternalWar) {
// Copy the test WAR file to the external directory
@@ -1247,10 +1220,7 @@ public class TestHostConfigAutomaticDepl
}
}
if (startWar) {
- // Copy the test WAR file to the appBase
- war = new File(getAppBaseFile(getTomcatInstance().getHost()),
- APP_NAME.getBaseName() + ".war");
- copy(WAR_XML_SOURCE, war);
+ war = createWarInAppbase(true);
}
if (startDir) {
dir = createDirInAppbase(true);
@@ -1350,6 +1320,7 @@ public class TestHostConfigAutomaticDepl
if (newContext != null) {
Assert.assertEquals(resultCookieName,
newContext.getSessionCookieName());
+ Assert.assertEquals(resultState, newContext.getState());
}
if (resultAction == NONE) {
@@ -1404,12 +1375,30 @@ public class TestHostConfigAutomaticDepl
* the previous bullet point.
*/
@Test
- public void testWarAddDir() throws Exception {
- doTestAdd(false, false, false, true, false, DIR,
+ public void testAdditionWarAddDir() throws Exception {
+ doTestAddition(false, false, false, true, false, DIR,
false, true, true, WAR_COOKIE_NAME, NONE);
}
- private void doTestAdd(boolean startXml, boolean startExternalWar,
+ @Test
+ public void testAdditionDirAddWar() throws Exception {
+ doTestAddition(false, false, false, false, true, WAR,
+ false, true, true, WAR_COOKIE_NAME, REDEPLOY);
+ }
+
+ @Test
+ public void testAdditionXmlAddDir() throws Exception {
+ doTestAddition(true, false, false, false, false, DIR,
+ true, false, true, XML_COOKIE_NAME, NONE);
+ }
+
+ @Test
+ public void testAdditionDirAddXml() throws Exception {
+ doTestAddition(false, false, false, false, true, XML,
+ true, false, true, XML_COOKIE_NAME, REDEPLOY);
+ }
+
+ private void doTestAddition(boolean startXml, boolean startExternalWar,
boolean startExternalDir, boolean startWar, boolean startDir,
int toAdd, boolean resultXml, boolean resultWar,
boolean resultDir, String resultCookieName, int resultAction)
@@ -1425,12 +1414,7 @@ public class TestHostConfigAutomaticDepl
File dir = null;
if (startXml && !startExternalWar && !startExternalDir) {
- xml = new File(getConfigBaseFile(host), APP_NAME + ".xml");
- File parent = xml.getParentFile();
- if (!parent.isDirectory()) {
- Assert.assertTrue(parent.mkdirs());
- }
- copy(XML_SOURCE, xml);
+ xml = createXmlInConfigBaseForAppbase();
}
if (startExternalWar) {
// Copy the test WAR file to the external directory
@@ -1482,10 +1466,7 @@ public class TestHostConfigAutomaticDepl
}
}
if (startWar) {
- // Copy the test WAR file to the appBase
- war = new File(getAppBaseFile(getTomcatInstance().getHost()),
- APP_NAME.getBaseName() + ".war");
- copy(WAR_XML_SOURCE, war);
+ war = createWarInAppbase(true);
}
if (startDir) {
dir = createDirInAppbase(true);
@@ -1503,9 +1484,9 @@ public class TestHostConfigAutomaticDepl
switch (toAdd) {
case XML:
if (xml == null) {
- Assert.fail();
+ xml = createXmlInConfigBaseForAppbase();
} else {
- xml.setLastModified(System.currentTimeMillis());
+ Assert.fail();
}
break;
case EXT:
@@ -1517,9 +1498,9 @@ public class TestHostConfigAutomaticDepl
break;
case WAR:
if (war == null) {
- Assert.fail();
+ war = createWarInAppbase(true);
} else {
- war.setLastModified(System.currentTimeMillis());
+ Assert.fail();
}
break;
case DIR:
@@ -1594,6 +1575,12 @@ public class TestHostConfigAutomaticDepl
Assert.assertSame(oldContext, newContext);
Assert.assertEquals("stopstart", tracker.getHistory());
} else if (resultAction == REDEPLOY) {
+ if (newContext == null) {
+ Assert.fail();
+ } else {
+ Assert.assertEquals(
+ LifecycleState.STARTED, newContext.getState());
+ }
Assert.assertNotSame(oldContext, newContext);
// No init or start as that will be in a new context object
Assert.assertEquals("stopafter_destroy", tracker.getHistory());
@@ -1615,6 +1602,29 @@ public class TestHostConfigAutomaticDepl
}
+ private File createWarInAppbase(boolean withXml) throws IOException {
+ File war = new File(getAppBaseFile(getTomcatInstance().getHost()),
+ APP_NAME.getBaseName() + ".war");
+ if (withXml) {
+ copy(WAR_XML_SOURCE, war);
+ } else {
+ copy(WAR_SOURCE, war);
+ }
+ return war;
+ }
+
+ private File createXmlInConfigBaseForAppbase() throws IOException {
+ Host host = getTomcatInstance().getHost();
+ File xml = new File(getConfigBaseFile(host), APP_NAME + ".xml");
+ File parent = xml.getParentFile();
+ if (!parent.isDirectory()) {
+ Assert.assertTrue(parent.mkdirs());
+ }
+ copy(XML_SOURCE, xml);
+ return xml;
+ }
+
+
@Test
public void testSetContextClassName() throws Exception {
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org