This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new d4a1c6267c NIFI-15417 Enabled most TestFileSystemRepository methods on 
Windows (#10722)
d4a1c6267c is described below

commit d4a1c6267c022cded8cc5dfb05da27315962d303
Author: dan-s1 <[email protected]>
AuthorDate: Fri Jan 16 15:56:48 2026 -0500

    NIFI-15417 Enabled most TestFileSystemRepository methods on Windows (#10722)
    
    Signed-off-by: David Handermann <[email protected]>
---
 .../repository/TestFileSystemRepository.java       | 51 +++++++++++++---------
 1 file changed, 30 insertions(+), 21 deletions(-)

diff --git 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
index 21203c7fd5..ce4b571228 100644
--- 
a/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
+++ 
b/nifi-framework-bundle/nifi-framework/nifi-framework-core/src/test/java/org/apache/nifi/controller/repository/TestFileSystemRepository.java
@@ -21,7 +21,6 @@ import 
org.apache.nifi.controller.repository.claim.ResourceClaim;
 import org.apache.nifi.controller.repository.claim.StandardContentClaim;
 import org.apache.nifi.controller.repository.claim.StandardResourceClaim;
 import 
org.apache.nifi.controller.repository.claim.StandardResourceClaimManager;
-import org.apache.nifi.controller.repository.util.DiskUtils;
 import org.apache.nifi.events.EventReporter;
 import org.apache.nifi.processor.DataUnit;
 import org.apache.nifi.stream.io.StreamUtils;
@@ -33,6 +32,7 @@ import org.junit.jupiter.api.Timeout;
 import org.junit.jupiter.api.condition.DisabledOnOs;
 import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
 import org.junit.jupiter.api.condition.OS;
+import org.junit.jupiter.api.io.TempDir;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -68,23 +68,27 @@ import static 
org.junit.jupiter.api.Assertions.assertNotSame;
 import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertTrue;
 
-@DisabledOnOs(OS.WINDOWS)
 public class TestFileSystemRepository {
 
     public static final File helloWorldFile = new 
File("src/test/resources/hello.txt");
     private static final Logger logger = 
LoggerFactory.getLogger(TestFileSystemRepository.class);
 
+    @TempDir
+    private Path tempDir;
+
     private FileSystemRepository repository = null;
     private StandardResourceClaimManager claimManager = null;
-    private final File rootFile = new File("target/content_repository");
+    private Path originalNifiPropertiesFile;
+    private Path rootFile;
     private NiFiProperties nifiProperties;
 
     @BeforeEach
     public void setup() throws IOException {
-        nifiProperties = 
NiFiProperties.createBasicNiFiProperties(TestFileSystemRepository.class.getResource("/conf/nifi.properties").getFile());
-        if (rootFile.exists()) {
-            DiskUtils.deleteRecursively(rootFile);
-        }
+        originalNifiPropertiesFile = 
Paths.get("src/test/resources/conf/nifi.properties");
+        rootFile = tempDir.resolve("content_repository");
+        final String contentRepositoryDirectory = 
NiFiProperties.REPOSITORY_CONTENT_PREFIX.concat("default");
+        final Map<String, String> additionalProperties = 
Map.of(contentRepositoryDirectory, rootFile.toString());
+        nifiProperties = 
NiFiProperties.createBasicNiFiProperties(originalNifiPropertiesFile.toString(), 
additionalProperties);
         repository = new FileSystemRepository(nifiProperties);
         claimManager = new StandardResourceClaimManager();
         repository.initialize(new 
StandardContentRepositoryContext(claimManager, EventReporter.NO_OP));
@@ -285,12 +289,14 @@ public class TestFileSystemRepository {
     }
 
 
+    @DisabledOnOs(value = OS.WINDOWS,
+            disabledReason = "java.io.FileNotFoundException when there is an 
attempt to access file <temporary 
directory>\\content_repository\\0\\archive\\0.bin")
     @Test
     public void testContentNotFoundExceptionThrownIfResourceClaimTooShort() 
throws IOException {
-        final File contentFile = new File("target/content_repository/0/0.bin");
-        try (final OutputStream fos = new FileOutputStream(contentFile)) {
-            fos.write("Hello World".getBytes(StandardCharsets.UTF_8));
-        }
+        final Path contentDirectory = rootFile.resolve("0");
+        Files.createDirectories(contentDirectory);
+        final Path contentFile = contentDirectory.resolve("0.bin");
+        Files.writeString(contentFile, "Hello World", 
StandardOpenOption.CREATE_NEW);
 
         final ResourceClaim resourceClaim = new 
StandardResourceClaim(claimManager, "default", "0", "0.bin", false);
         final StandardContentClaim existingContentClaim = new 
StandardContentClaim(resourceClaim, 0);
@@ -324,21 +330,22 @@ public class TestFileSystemRepository {
         assertThrows(ContentNotFoundException.class, () -> 
repository.read(missingContentClaim));
     }
 
+    @DisabledOnOs(value = OS.WINDOWS, disabledReason = "java.io.File 
setReadable(false) does not work on Windows. See javadocs.")
     @Test
     public void testBogusFile() throws IOException {
         repository.shutdown();
-        System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, 
TestFileSystemRepository.class.getResource("/conf/nifi.properties").getFile());
+        System.setProperty(NiFiProperties.PROPERTIES_FILE_PATH, 
originalNifiPropertiesFile.toString());
 
-        File bogus = new File(rootFile, "bogus");
+        Path bogus = rootFile.resolve("bogus");
         try {
-            bogus.mkdir();
-            bogus.setReadable(false);
+            Files.createDirectories(bogus);
+            bogus.toFile().setReadable(false);
 
             repository = new FileSystemRepository(nifiProperties);
             repository.initialize(new StandardContentRepositoryContext(new 
StandardResourceClaimManager(), EventReporter.NO_OP));
         } finally {
-            bogus.setReadable(true);
-            assertTrue(bogus.delete());
+            bogus.toFile().setReadable(true);
+            Files.delete(bogus);
         }
     }
 
@@ -350,6 +357,8 @@ public class TestFileSystemRepository {
         assertEquals(1, repository.getClaimantCount(claim));
     }
 
+    @DisabledOnOs(value = OS.WINDOWS,
+            disabledReason = "JUnit 5 tempDir cannot be deleted since there is 
a file in the content repository which cannot be deleted.")
     @Test
     public void testReadClaimThenWriteThenReadMore() throws IOException {
         final ContentClaim claim = repository.create(false);
@@ -632,6 +641,8 @@ public class TestFileSystemRepository {
         }
     }
 
+    @DisabledOnOs(value = OS.WINDOWS,
+            disabledReason = "java.nio.file.Files.deleteIfExists fails on 
Windows if the file is open and in use by the same Java Virtual Machine process 
or another external process")
     @Test
     public void testReadWithContentArchived() throws IOException {
         final ContentClaim claim = repository.create(true);
@@ -653,10 +664,8 @@ public class TestFileSystemRepository {
         }
     }
 
-    private boolean isWindowsEnvironment() {
-        return 
System.getProperty("os.name").toLowerCase().startsWith("windows");
-    }
-
+    @DisabledOnOs(value = OS.WINDOWS,
+            disabledReason = "java.nio.file.Files.deleteIfExists fails on 
Windows if the file is open and in use by the same Java Virtual Machine process 
or another external process")
     @Test
     public void testReadWithNoContentArchived() throws IOException {
         final ContentClaim claim = repository.create(true);

Reply via email to