mirror of
https://github.com/apache/struts.git
synced 2026-08-06 07:06:58 +00:00
monitor file only if needed
See also: WW-4948
(cherry picked from commit b816cc1)
This commit is contained in:
@@ -70,7 +70,9 @@ public class DefaultFileManager implements FileManager {
|
||||
return null;
|
||||
}
|
||||
InputStream is = openFile(fileUrl);
|
||||
monitorFile(fileUrl);
|
||||
if (reloadingConfigs) {
|
||||
monitorFile(fileUrl);
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
|
||||
+50
-6
@@ -78,12 +78,14 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
|
||||
}
|
||||
|
||||
public void testNeedsReload() throws Exception {
|
||||
container.getInstance(FileManagerFactory.class).setReloadingConfigs("true");
|
||||
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
|
||||
ConfigurationProvider provider = buildConfigurationProvider(filename);
|
||||
container.getInstance(FileManagerFactory.class).setReloadingConfigs("true");
|
||||
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
|
||||
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
|
||||
container.inject(provider);
|
||||
provider.init(configuration);
|
||||
provider.loadPackages();
|
||||
|
||||
assertTrue(!provider.needsReload()); // Revision exists and timestamp didn't change
|
||||
assertFalse(provider.needsReload()); // Revision exists and timestamp didn't change
|
||||
|
||||
File file = new File(getClass().getResource("/" + filename).toURI());
|
||||
assertTrue("not exists: " + file.toString(), file.exists());
|
||||
@@ -92,6 +94,24 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
|
||||
assertTrue(provider.needsReload());
|
||||
}
|
||||
|
||||
public void testNeedsReloadNotReloadingConfigs() throws Exception {
|
||||
final String filename = "com/opensymphony/xwork2/config/providers/xwork-test-actions.xml";
|
||||
buildConfigurationProvider(filename);
|
||||
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
|
||||
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(false);
|
||||
container.inject(provider);
|
||||
provider.init(configuration);
|
||||
provider.loadPackages();
|
||||
|
||||
assertFalse(provider.needsReload()); // Revision exists and timestamp didn't change
|
||||
|
||||
File file = new File(getClass().getResource("/" + filename).toURI());
|
||||
assertTrue("not exists: " + file.toString(), file.exists());
|
||||
changeFileTime(file);
|
||||
|
||||
assertFalse(provider.needsReload());
|
||||
}
|
||||
|
||||
public void testInheritence() throws Exception {
|
||||
final String filename = "com/opensymphony/xwork2/config/providers/xwork-include-parent.xml";
|
||||
ConfigurationProvider provider = buildConfigurationProvider(filename);
|
||||
@@ -155,10 +175,13 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
|
||||
|
||||
public void testEmptySpaces() throws Exception {
|
||||
final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
|
||||
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
|
||||
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
|
||||
container.inject(provider);
|
||||
provider.init(configuration);
|
||||
provider.loadPackages();
|
||||
|
||||
ConfigurationProvider provider = buildConfigurationProvider(filename);
|
||||
assertTrue(!provider.needsReload());
|
||||
assertFalse(provider.needsReload());
|
||||
|
||||
URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
|
||||
|
||||
@@ -170,6 +193,27 @@ public class XmlConfigurationProviderTest extends ConfigurationTestBase {
|
||||
assertTrue(provider.needsReload());
|
||||
}
|
||||
|
||||
public void testEmptySpacesNotReloadingConfigs() throws Exception {
|
||||
final String filename = "com/opensymphony/xwork2/config/providers/xwork- test.xml";
|
||||
buildConfigurationProvider(filename);
|
||||
ConfigurationProvider provider = new XmlConfigurationProvider(filename, true);
|
||||
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(false);
|
||||
container.inject(provider);
|
||||
provider.init(configuration);
|
||||
provider.loadPackages();
|
||||
|
||||
assertFalse(provider.needsReload());
|
||||
|
||||
URI uri = ClassLoaderUtil.getResource(filename, ConfigurationProvider.class).toURI();
|
||||
|
||||
File file = new File(uri);
|
||||
|
||||
assertTrue(file.exists());
|
||||
changeFileTime(file);
|
||||
|
||||
assertFalse(provider.needsReload());
|
||||
}
|
||||
|
||||
public void testConfigsInJarFiles() throws Exception {
|
||||
container.getInstance(FileManagerFactory.class).getFileManager().setReloadingConfigs(true);
|
||||
testProvider("xwork-jar.xml");
|
||||
|
||||
@@ -21,16 +21,9 @@ package com.opensymphony.xwork2.util;
|
||||
import com.opensymphony.xwork2.FileManager;
|
||||
import com.opensymphony.xwork2.FileManagerFactory;
|
||||
import com.opensymphony.xwork2.XWorkTestCase;
|
||||
import com.opensymphony.xwork2.util.fs.DefaultFileManager;
|
||||
import org.apache.struts2.util.fs.JBossFileManager;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.net.URLConnection;
|
||||
import java.net.URLStreamHandler;
|
||||
import java.net.URLStreamHandlerFactory;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* FileManager Tester.
|
||||
@@ -49,23 +42,40 @@ public class DefaultFileManagerTest extends XWorkTestCase {
|
||||
fileManager = container.getInstance(FileManagerFactory.class).getFileManager();
|
||||
}
|
||||
|
||||
public void disabled_testGetFileInJar() throws Exception {
|
||||
testLoadFile("xwork-jar.xml");
|
||||
testLoadFile("xwork - jar.xml");
|
||||
testLoadFile("xwork-zip.xml");
|
||||
testLoadFile("xwork - zip.xml");
|
||||
testLoadFile("xwork-jar2.xml");
|
||||
testLoadFile("xwork - jar2.xml");
|
||||
testLoadFile("xwork-zip2.xml");
|
||||
testLoadFile("xwork - zip2.xml");
|
||||
public void testGetFileInJar() throws Exception {
|
||||
testLoadFile("xwork-jar.xml", false);
|
||||
testLoadFile("xwork - jar.xml", false);
|
||||
testLoadFile("xwork-zip.xml", false);
|
||||
testLoadFile("xwork - zip.xml", false);
|
||||
testLoadFile("xwork-jar2.xml", false);
|
||||
testLoadFile("xwork - jar2.xml", false);
|
||||
testLoadFile("xwork-zip2.xml", false);
|
||||
testLoadFile("xwork - zip2.xml", false);
|
||||
|
||||
testLoadFile("xwork-jar.xml", true);
|
||||
testLoadFile("xwork - jar.xml", true);
|
||||
testLoadFile("xwork-zip.xml", true);
|
||||
testLoadFile("xwork - zip.xml", true);
|
||||
testLoadFile("xwork-jar2.xml", true);
|
||||
testLoadFile("xwork - jar2.xml", true);
|
||||
testLoadFile("xwork-zip2.xml", true);
|
||||
testLoadFile("xwork - zip2.xml", true);
|
||||
}
|
||||
|
||||
private void testLoadFile(String fileName) {
|
||||
fileManager.setReloadingConfigs(true);
|
||||
private void testLoadFile(String fileName, boolean reloadConfigs) throws Exception {
|
||||
fileManager.setReloadingConfigs(reloadConfigs);
|
||||
URL url = ClassLoaderUtil.getResource(fileName, DefaultFileManagerTest.class);
|
||||
InputStream file = fileManager.loadFile(url);
|
||||
assertNotNull(file);
|
||||
assertTrue(fileManager.fileNeedsReloading(fileName));
|
||||
file.close();
|
||||
assertFalse(fileManager.fileNeedsReloading(url.toString()));
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
JarURLConnection conn = (JarURLConnection) url.openConnection();
|
||||
conn.getJarEntry().setTime(now + 60000);
|
||||
conn.getInputStream().close();
|
||||
|
||||
assertEquals(reloadConfigs, fileManager.fileNeedsReloading(url.toString()));
|
||||
}
|
||||
|
||||
public void testReloadingConfigs() throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user