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 2021/02/25 13:42:00 UTC
[tomcat] branch master updated: Delete temporary files later to try
an avoid issues with locked files
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/master by this push:
new c70da52 Delete temporary files later to try an avoid issues with locked files
c70da52 is described below
commit c70da529fc98c47d3ed6b3beef2211062235edba
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Thu Feb 25 13:41:35 2021 +0000
Delete temporary files later to try an avoid issues with locked files
---
.../apache/catalina/connector/TestSendFile.java | 49 ++++++++++------------
.../apache/catalina/startup/LoggingBaseTest.java | 8 ++--
2 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/test/org/apache/catalina/connector/TestSendFile.java b/test/org/apache/catalina/connector/TestSendFile.java
index abfffac..a5e2fdb 100644
--- a/test/org/apache/catalina/connector/TestSendFile.java
+++ b/test/org/apache/catalina/connector/TestSendFile.java
@@ -60,38 +60,31 @@ public class TestSendFile extends TomcatBaseTest {
File[] files = new File[ITERATIONS];
for (int i = 0; i < ITERATIONS; i++) {
files[i] = generateFile(TEMP_DIR, "-" + i, EXPECTED_CONTENT_LENGTH * (i + 1));
+ addDeleteOnTearDown(files[i]);
}
- try {
- for (int i = 0; i < ITERATIONS; i++) {
- WritingServlet servlet = new WritingServlet(files[i]);
- Tomcat.addServlet(root, "servlet" + i, servlet);
- root.addServletMappingDecoded("/servlet" + i, "servlet" + i);
- }
-
- tomcat.start();
+ for (int i = 0; i < ITERATIONS; i++) {
+ WritingServlet servlet = new WritingServlet(files[i]);
+ Tomcat.addServlet(root, "servlet" + i, servlet);
+ root.addServletMappingDecoded("/servlet" + i, "servlet" + i);
+ }
- ByteChunk bc = new ByteChunk();
- Map<String, List<String>> respHeaders = new HashMap<>();
- for (int i = 0; i < ITERATIONS; i++) {
- long start = System.currentTimeMillis();
- int rc = getUrl("http://localhost:" + getPort() + "/servlet" + i, bc, null,
- respHeaders);
- Assert.assertEquals(HttpServletResponse.SC_OK, rc);
- System.out.println("Client received " + bc.getLength() + " bytes in "
- + (System.currentTimeMillis() - start) + " ms.");
- Assert.assertEquals("Expected [" + EXPECTED_CONTENT_LENGTH * (i + 1L) +
- "], was [" + bc.getLength() + "]",
- EXPECTED_CONTENT_LENGTH * (i + 1L), bc.getLength());
+ tomcat.start();
- bc.recycle();
- }
- } finally {
- for (File f : files) {
- boolean deleteResult = f.delete();
- System.out.println("Deleting [" + f.getAbsolutePath() + "] returned [" + deleteResult + "]");
- Assert.assertTrue("Failed to clean up [" + f + "]", deleteResult);
- }
+ ByteChunk bc = new ByteChunk();
+ Map<String, List<String>> respHeaders = new HashMap<>();
+ for (int i = 0; i < ITERATIONS; i++) {
+ long start = System.currentTimeMillis();
+ int rc = getUrl("http://localhost:" + getPort() + "/servlet" + i, bc, null,
+ respHeaders);
+ Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+ System.out.println("Client received " + bc.getLength() + " bytes in "
+ + (System.currentTimeMillis() - start) + " ms.");
+ Assert.assertEquals("Expected [" + EXPECTED_CONTENT_LENGTH * (i + 1L) +
+ "], was [" + bc.getLength() + "]",
+ EXPECTED_CONTENT_LENGTH * (i + 1L), bc.getLength());
+
+ bc.recycle();
}
}
diff --git a/test/org/apache/catalina/startup/LoggingBaseTest.java b/test/org/apache/catalina/startup/LoggingBaseTest.java
index 2e0b225..7949bbc 100644
--- a/test/org/apache/catalina/startup/LoggingBaseTest.java
+++ b/test/org/apache/catalina/startup/LoggingBaseTest.java
@@ -121,6 +121,8 @@ public abstract class LoggingBaseTest {
new File(System.getProperty("tomcat.test.basedir"),
"conf/logging.properties").toString());
+ // tempDir contains log files which will be open until JULI shuts down
+ deleteOnClassTearDown.add(tempDir);
}
@Before
@@ -131,13 +133,13 @@ public abstract class LoggingBaseTest {
@After
public void tearDown() throws Exception {
+ boolean deleted = true;
for (File file : deleteOnTearDown) {
- ExpandWar.delete(file);
+ deleted = deleted & ExpandWar.delete(file);
}
deleteOnTearDown.clear();
- // tempDir contains log files which will be open until JULI shuts down
- deleteOnClassTearDown.add(tempDir);
+ Assert.assertTrue("Failed to delete at least one file", deleted);
}
@AfterClass
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org