exceptionfactory commented on a change in pull request #5794:
URL: https://github.com/apache/nifi/pull/5794#discussion_r813520418



##########
File path: 
nifi-nar-bundles/nifi-mqtt-bundle/nifi-mqtt-processors/src/test/java/org/apache/nifi/processors/mqtt/TestPublishMQTT.java
##########
@@ -65,4 +67,16 @@ public void init() {
         topic = "testTopic";
         testRunner.setProperty(PublishMQTT.PROP_TOPIC, topic);
     }
+
+
+    @AfterEach
+    public void tearDown() {
+        final File folder =  new File("./target");
+        final File[] files = folder.listFiles((dir, name) -> name.matches( 
"moquette_store.mapdb.*" ));
+        for ( final File file : files ) {
+            if ( !file.delete() ) {
+                System.err.println( "Can't remove " + file.getAbsolutePath() );
+            }
+        }
+    }

Review comment:
       With recent refactoring of this module, this method and related changes 
in this file should not be necessary.

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcCommon.java
##########
@@ -84,23 +83,20 @@
     private static final Logger LOGGER = 
LoggerFactory.getLogger(TestJdbcCommon.class);
     static final String createTable = "create table restaurants(id integer, 
name varchar(20), city varchar(50))";
 
-    @ClassRule
-    public static TemporaryFolder folder = new TemporaryFolder();
-
     /**
      * Setting up Connection is expensive operation.
      * So let's do this only once and reuse Connection in each test.
      */
     static protected Connection con;
 
-    @BeforeClass
-    public static void setup() throws ClassNotFoundException, SQLException {
+    @BeforeAll
+    public static void setup() throws ClassNotFoundException, SQLException, 
IOException {
         System.setProperty("derby.stream.error.file", "target/derby.log");
         Class.forName("org.apache.derby.jdbc.EmbeddedDriver");
-        // remove previous test database, if any
-        folder.delete();
 
-        String location = folder.getRoot().getAbsolutePath();
+        String location = 
Files.createTempDirectory(String.valueOf(System.currentTimeMillis()))
+                .resolve("db")
+                .toFile().getAbsolutePath();

Review comment:
       As mentioned in related tests, see `DBCPServiceTest` for an approach to 
handle database directory creation and clearing.

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcTypesH2.java
##########
@@ -16,33 +16,29 @@
  */
 package org.apache.nifi.util.db;
 
-import static org.junit.Assert.assertNotNull;
+import org.apache.avro.file.DataFileStream;
+import org.apache.avro.generic.GenericDatumReader;
+import org.apache.avro.generic.GenericRecord;
+import org.apache.avro.io.DatumReader;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.file.Files;
 import java.sql.Connection;
 import java.sql.DriverManager;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.sql.Statement;
 
-import org.apache.avro.file.DataFileStream;
-import org.apache.avro.generic.GenericDatumReader;
-import org.apache.avro.generic.GenericRecord;
-import org.apache.avro.io.DatumReader;
-import org.junit.BeforeClass;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.TemporaryFolder;
-
 public class TestJdbcTypesH2 {
 
-    @Rule
-    public TemporaryFolder folder = new TemporaryFolder();
-
-    @BeforeClass
+    @BeforeAll
     public static void setup() {
         System.setProperty("derby.stream.error.file", "target/derby.log");
     }

Review comment:
       It looks like this test uses H2 instead of Derby, so this entire method 
can be removed.

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcTypesH2.java
##########
@@ -75,9 +71,19 @@ public static void setup() {
 
     String dropTable = "drop table users";
 
+    String dbPath;
+
+    @BeforeEach
+    public void beforeEach() throws IOException {
+        dbPath = 
Files.createTempDirectory(String.valueOf(System.currentTimeMillis()))
+                .resolve("db")
+                .toFile()
+                .getAbsolutePath();

Review comment:
       This approaches creates a temporary directory, but does not appear to 
delete the contents after test completion.  There should be a corresponding 
`@AfterEach` method to remove the directory contents. See 
`FileUtils.deleteFile(File, boolean)` in `nifi-utils` for recursive deletion of 
a directory and contents.

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcClobReadable.java
##########
@@ -83,9 +80,10 @@ public void testDriverLoad() throws ClassNotFoundException {
     }
 
     private void validateClob(String someClob) throws SQLException, 
ClassNotFoundException, IOException {
-        folder.delete();
-
-        final Connection con = 
createConnection(folder.getRoot().getAbsolutePath());
+        File folder = 
Files.createTempDirectory(String.valueOf(System.currentTimeMillis()))
+                .resolve("db")
+                .toFile();
+        final Connection con = createConnection(folder.getAbsolutePath());

Review comment:
       See `DBCPServiceTest` for handling `derby.log` and temporary database 
directory lifecycle.

##########
File path: 
nifi-nar-bundles/nifi-extension-utils/nifi-database-utils/src/test/java/org/apache/nifi/util/db/TestJdbcHugeStream.java
##########
@@ -53,21 +52,18 @@
  */
 public class TestJdbcHugeStream {
 
-    @Rule
-    public TemporaryFolder folder = new TemporaryFolder();
-
-    @BeforeClass
+    @BeforeAll
     public static void setup() {
         System.setProperty("derby.stream.error.file", "target/derby.log");
     }
 
     @Test
     public void readSend2StreamHuge_FileBased() throws ClassNotFoundException, 
SQLException, IOException {
-
-        // remove previous test database, if any
-        folder.delete();
-
-        try (final Connection con = 
createConnection(folder.getRoot().getAbsolutePath())) {
+        String path = 
Files.createTempDirectory(String.valueOf(System.currentTimeMillis()))
+                .resolve("db")
+                .toFile()
+                .getAbsolutePath();

Review comment:
       This test appears to have issues similar to those in `DBCPServiceTest`. 
See the approach in that test class where `derby.log` is placed in one 
location, and the database is placed in another empty directory, which is 
cleared after test completion.

##########
File path: 
nifi-nar-bundles/nifi-ranger-bundle/nifi-ranger-plugin/src/test/java/org/apache/nifi/ranger/authorization/TestRangerNiFiAuthorizer.java
##########
@@ -140,7 +140,7 @@ public void testKerberosEnabledWithoutKeytab() {
 
         try {
             authorizer.onConfigured(configurationContext);
-            Assert.fail("Should have thrown exception");
+            fail("Should have thrown exception");

Review comment:
       The `fail()` calls should be replaced `assertThrows()` throughout this 
class.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to