VIVO-213 smoke test to check JVM temp directory
If it isn't set, if it isn't a directory, if we can't access it, if we can't create a temp file, complain.
This commit is contained in:
parent
68284acd99
commit
8f336b3505
2 changed files with 81 additions and 0 deletions
|
@ -0,0 +1,79 @@
|
||||||
|
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||||
|
|
||||||
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
|
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test that the JVM is properly configured.
|
||||||
|
*
|
||||||
|
* For now, we just test the temp directory. Other
|
||||||
|
*/
|
||||||
|
public class JvmSmokeTests implements ServletContextListener {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
StartupStatus ss = StartupStatus.getBean(ctx);
|
||||||
|
|
||||||
|
checkTempDirectory(ss);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check the Java temp directory. Make sure that it exists, it is a
|
||||||
|
* directory, we can read it, we can write to it.
|
||||||
|
*
|
||||||
|
* Create a temp file, and delete it.
|
||||||
|
*/
|
||||||
|
private void checkTempDirectory(StartupStatus ss) {
|
||||||
|
String tempDirPath = System.getProperty("java.io.tmpdir", "");
|
||||||
|
if (tempDirPath.isEmpty()) {
|
||||||
|
ss.fatal(this, "Problem with Java temp directory: "
|
||||||
|
+ "System property 'java.io.tmpdir' is not set.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
File tempDir = new File(tempDirPath);
|
||||||
|
if (!tempDir.exists()) {
|
||||||
|
ss.fatal(this, "Problem with Java temp directory: '" + tempDirPath
|
||||||
|
+ "' does not exist.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!tempDir.isDirectory()) {
|
||||||
|
ss.fatal(this, "Problem with Java temp directory: '" + tempDirPath
|
||||||
|
+ "' exists, but is not a directory.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!tempDir.canRead()) {
|
||||||
|
ss.fatal(this, "Problem with Java temp directory: "
|
||||||
|
+ "No read access to '" + tempDirPath + "'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!tempDir.canWrite()) {
|
||||||
|
ss.fatal(this, "Problem with Java temp directory: "
|
||||||
|
+ "No write access to '" + tempDirPath + "'.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
File testFile = File.createTempFile("smoke", null);
|
||||||
|
testFile.delete();
|
||||||
|
} catch (Exception e) {
|
||||||
|
ss.fatal(this, "Problem with Java temp directory: "
|
||||||
|
+ "Failed to create a temporary file in '" + tempDirPath
|
||||||
|
+ "'.", e);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ss.info(this, "Java temp directory is '" + tempDirPath + "'");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
|
// Nothing to do at shutdown
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -5,6 +5,8 @@
|
||||||
# https://sourceforge.net/apps/mediawiki/vivo/index.php?title=The_StartupManager
|
# https://sourceforge.net/apps/mediawiki/vivo/index.php?title=The_StartupManager
|
||||||
#
|
#
|
||||||
|
|
||||||
|
edu.cornell.mannlib.vitro.webapp.servlet.setup.JvmSmokeTests
|
||||||
|
|
||||||
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSetup
|
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSetup
|
||||||
|
|
||||||
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests
|
edu.cornell.mannlib.vitro.webapp.config.ConfigurationPropertiesSmokeTests
|
||||||
|
|
Loading…
Add table
Reference in a new issue