This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
The following commit(s) were added to refs/heads/master by this push:
new 1119a4add Better test clean up, trying to address deletion failures on
GH CI (#748)
1119a4add is described below
commit 1119a4add5b5c364939be3620d5a3101a655d113
Author: Gary Gregory <[email protected]>
AuthorDate: Sun Dec 21 09:13:12 2025 -0500
Better test clean up, trying to address deletion failures on GH CI (#748)
* Better test clean up, trying to address deletion failures on GH CI
* Better test clean up, trying to address deletion failures on GH CI
* Enable tests
* Add comment
* Better tests, trying to address deletion failures on GH CI
---
commons-vfs2/pom.xml | 52 +++++++++++++---------
.../org/apache/commons/vfs2/PermissionsTests.java | 39 ++++++++--------
.../vfs2/provider/local/ConversionTest.java | 4 +-
.../local/LocalFileRandomAccessContentTest.java | 12 +++--
4 files changed, 57 insertions(+), 50 deletions(-)
diff --git a/commons-vfs2/pom.xml b/commons-vfs2/pom.xml
index e48eeb6fc..319e97563 100644
--- a/commons-vfs2/pom.xml
+++ b/commons-vfs2/pom.xml
@@ -16,8 +16,8 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<name>Apache Commons VFS</name>
<artifactId>commons-vfs2</artifactId>
@@ -144,16 +144,12 @@
<scope>test</scope>
</dependency>
</dependencies>
-
<properties>
<commons.parent.dir>${basedir}/..</commons.parent.dir>
- <commons.osgi.import>
- org.apache.hc.client5.http.*;resolution:=optional,
- *
+ <commons.osgi.import> org.apache.hc.client5.http.*;resolution:=optional, *
</commons.osgi.import>
<project.build.outputTimestamp>2025-02-14T13:36:40Z</project.build.outputTimestamp>
</properties>
-
<build>
<pluginManagement>
<plugins>
@@ -173,7 +169,6 @@
</includes>
</resource>
</resources>
-
<testResources>
<testResource>
<directory>src/test/resources</directory>
@@ -188,8 +183,34 @@
</includes>
</testResource>
</testResources>
-
<plugins>
+ <plugin>
+ <!-- HACK to workaround random failures when some tests don't delete
test fixtures. -->
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-clean-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>clean-test-directory</id>
+ <phase>test</phase>
+ <goals>
+ <goal>clean</goal>
+ </goals>
+ <configuration>
+ <force>true</force>
+ <excludeDefaultDirectories>true</excludeDefaultDirectories>
+ <filesets>
+ <fileset>
+
<directory>${project.build.directory}/test-classes/test-data/write-tests</directory>
+ <includes>
+ <include>**/*</include>
+ </includes>
+ <followSymlinks>false</followSymlinks>
+ </fileset>
+ </filesets>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -201,7 +222,6 @@
</execution>
</executions>
</plugin>
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
@@ -221,7 +241,6 @@
</execution>
</executions>
</plugin>
-
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
@@ -245,7 +264,6 @@
</plugin>
</plugins>
</build>
-
<profiles>
<profile>
<id>webdav</id>
@@ -266,7 +284,6 @@
</plugins>
</build>
</profile>
-
<profile>
<id>ftp</id>
<activation>
@@ -286,7 +303,6 @@
</plugins>
</build>
</profile>
-
<profile>
<id>sftp</id>
<activation>
@@ -306,7 +322,6 @@
</plugins>
</build>
</profile>
-
<profile>
<id>http</id>
<activation>
@@ -326,7 +341,6 @@
</plugins>
</build>
</profile>
-
<!-- On Windows we disable hdfs tests by default. -->
<profile>
<id>no-test-hdfs</id>
@@ -356,12 +370,10 @@
<!-- Profile to build and run the benchmarks. Use 'mvn test -Pbenchmark',
and add '-Dbenchmark=foo' to run only the foo benchmark -->
<profile>
<id>benchmark</id>
-
<properties>
<skipTests>true</skipTests>
<benchmark>org.apache</benchmark>
</properties>
-
<dependencies>
<dependency>
<groupId>org.openjdk.jmh</groupId>
@@ -369,7 +381,6 @@
<scope>test</scope>
</dependency>
</dependencies>
-
<build>
<plugins>
<!-- Enable the compilation of the benchmarks -->
@@ -414,5 +425,4 @@
</build>
</profile>
</profiles>
-
-</project>
+</project>
\ No newline at end of file
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/PermissionsTests.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/PermissionsTests.java
index 5c22b1946..82cf804b4 100644
--- a/commons-vfs2/src/test/java/org/apache/commons/vfs2/PermissionsTests.java
+++ b/commons-vfs2/src/test/java/org/apache/commons/vfs2/PermissionsTests.java
@@ -71,7 +71,7 @@ public class PermissionsTests extends
AbstractProviderTestCase {
/**
* Returns true if the file system is a LocalFileSystem on Windows
*/
- private boolean isWindows() {
+ private boolean isWindowsLocal() {
return SystemUtils.IS_OS_WINDOWS && getFileSystem() instanceof
LocalFileSystem;
}
@@ -81,30 +81,28 @@ public class PermissionsTests extends
AbstractProviderTestCase {
@AfterEach
public void tearDown() throws Exception {
final FileObject scratchFolder = getWriteFolder();
- final FileObject file = scratchFolder.resolveFile(FILE_NAME);
+ final FileObject fileObject = scratchFolder.resolveFile(FILE_NAME);
try {
- file.setReadable(true, false);
- file.getParent().setReadable(true, false);
+ fileObject.setReadable(true, false);
+ fileObject.getParent().setReadable(true, false);
} catch (final FileSystemException e) {
e.printStackTrace();
}
try {
- file.setWritable(true, false);
- file.getParent().setWritable(true, false);
+ fileObject.setWritable(true, false);
+ fileObject.getParent().setWritable(true, false);
} catch (final FileSystemException e) {
e.printStackTrace();
}
- if (!file.delete()) {
- final Path path = file.getPath();
- if ((getFileSystem() instanceof LocalFileSystem)
- && (PathUtils.deleteFile(path,
StandardDeleteOption.OVERRIDE_READ_ONLY).getFileCounter().get() == 0)) {
- File f = path.toFile();
- if (!f.delete()) {
- f.deleteOnExit();
- }
- if (f.exists()) {
- System.err.println("Test tear down can't delete " + path);
- }
+ final Path path = fileObject.getPath();
+ if ((getFileSystem() instanceof LocalFileSystem) &&
(PathUtils.deleteFile(path,
StandardDeleteOption.OVERRIDE_READ_ONLY).getFileCounter().get() == 0)) {
+ File file = path.toFile();
+ if (!file.delete()) {
+ System.err.println("\tTest deleteOnExit: " + path);
+ file.deleteOnExit();
+ }
+ if (file.exists()) {
+ System.err.println("\tTest tear down can't delete " + path);
}
}
}
@@ -116,7 +114,7 @@ public class PermissionsTests extends
AbstractProviderTestCase {
public void testExecutable() throws Exception {
final FileObject file = createTestFile();
// On Windows, all files are executable
- if (isWindows()) {
+ if (isWindowsLocal()) {
assertTrue(file.isExecutable(), "File expected to be executable: "
+ file);
} else {
// Set the executable flag for owner
@@ -137,7 +135,7 @@ public class PermissionsTests extends
AbstractProviderTestCase {
@Test
public void testReadable() throws Exception {
final FileObject file = createTestFile();
- if (isWindows()) {
+ if (isWindowsLocal()) {
// On Windows, all owned files are readable
assertTrue(file.isReadable(), "File expected to be readable: " +
file);
} else {
@@ -168,6 +166,9 @@ public class PermissionsTests extends
AbstractProviderTestCase {
// Clear the write permission
assertTrue(file.setWritable(false, true), "Setting write permission
failed: " + file);
assertFalse(file.isWriteable(), "File expected to be not writable: " +
file);
+ // Set the write permission for all
+ assertTrue(file.setWritable(true, false), "Setting write permission
failed: " + file);
+ assertTrue(file.isWriteable(), "File expected to be writable: " +
file);
}
}
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/ConversionTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/ConversionTest.java
index b8837463c..9e7429c50 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/ConversionTest.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/ConversionTest.java
@@ -28,18 +28,17 @@ import java.nio.file.Files;
import org.apache.commons.vfs2.FileObject;
import org.apache.commons.vfs2.FileSystemManager;
import org.apache.commons.vfs2.VFS;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
/**
* Tests conversion from VFS to File.
* <p>
* VFS-443 Need an easy way to convert from a FileObject to a File.
+ * </p>
*/
public class ConversionTest {
@Test
- @Disabled("Ignored pre JUnit v5")
public void testFileNameWithCharacters() throws URISyntaxException,
IOException {
final File file = new File("target", "+# %&.txt");
final String fileURL = file.toURI().toURL().toExternalForm();
@@ -59,7 +58,6 @@ public class ConversionTest {
}
@Test
- @Disabled("Ignored pre JUnit v5")
public void testFileNameWithSpaces() throws URISyntaxException,
IOException {
final File file = new File("target", "a name.txt");
final String fileURL = file.toURI().toURL().toExternalForm();
diff --git
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContentTest.java
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContentTest.java
index 083712107..f9a56d8c7 100644
---
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContentTest.java
+++
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/local/LocalFileRandomAccessContentTest.java
@@ -23,6 +23,7 @@ import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.vfs2.util.RandomAccessMode;
import org.junit.jupiter.api.Test;
@@ -30,8 +31,6 @@ import org.junit.jupiter.api.Test;
*/
public class LocalFileRandomAccessContentTest {
- private final int EOF = -1;
-
/**
* test LocalFileRandomAccessContent InputStream read one byte 0xff; see
VFS-624.
**/
@@ -39,16 +38,15 @@ public class LocalFileRandomAccessContentTest {
public void testInputStreamRead0xff() throws IOException {
// open test file,this file has only one byte data 0xff
final File file = new
File("src/test/resources/test-data/0xff_file.txt");
-
// read test data,first data should be 0xFF instead of -1. Will read
-1 finally (EOF)
- try (InputStream in = new LocalFileRandomAccessContent(file,
RandomAccessMode.READ).getInputStream()) {
+ try (@SuppressWarnings("resource") // acccess an ivar that closes the
same resource.
+ InputStream in = new LocalFileRandomAccessContent(file,
RandomAccessMode.READ).getInputStream()) {
// read first data
final int read = in.read();
- assertNotEquals(EOF, read);
+ assertNotEquals(IOUtils.EOF, read);
assertEquals(0xFF, read);
-
// read EOF
- assertEquals(EOF, in.read());
+ assertEquals(IOUtils.EOF, in.read());
}
}