exceptionfactory commented on code in PR #11761:
URL: https://github.com/apache/nifi/pull/11761#discussion_r4403072196
##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/record/sink/db/DatabaseRecordSinkTest.java:
##########
@@ -90,89 +92,102 @@ public class DatabaseRecordSinkTest {
private static final String SERVICE_ID =
DBCPConnectionPool.class.getName();
private static final String DRIVER_CLASS = "org.hsqldb.jdbc.JDBCDriver";
- private static final String CONNECTION_URL_FORMAT = "jdbc:hsqldb:file:%s";
+ private static final String CONNECTION_URL_FORMAT =
"jdbc:hsqldb:file:%s/nifi";
private String connectionUrl;
private DBCPConnectionPool dbcpService;
+ private TestRunner runner;
@BeforeEach
public void setService(@TempDir final Path tempDir) throws
InitializationException {
dbcpService = new DBCPConnectionPool();
- TestRunner runner = TestRunners.newTestRunner(NoOpProcessor.class);
+ runner = TestRunners.newTestRunner(NoOpProcessor.class);
runner.addControllerService(SERVICE_ID, dbcpService);
- connectionUrl = CONNECTION_URL_FORMAT.formatted(tempDir);
+ connectionUrl =
CONNECTION_URL_FORMAT.formatted(tempDir.toAbsolutePath());
runner.setProperty(dbcpService, DATABASE_URL, connectionUrl);
runner.setProperty(dbcpService, DB_USER, String.class.getSimpleName());
runner.setProperty(dbcpService, DB_PASSWORD, String.class.getName());
runner.setProperty(dbcpService, DB_DRIVERNAME, DRIVER_CLASS);
}
+ @AfterEach
+ public void shutdownDatabase() throws SQLException {
+ runner.shutdown();
+ dbcpService.shutdown();
+
+ try (Connection conn = DriverManager.getConnection(connectionUrl);
Review Comment:
Taking a closer look, the problem is that not all of the tests create the
database the same way. The `initTask()` method does not set a username and
password, so HSQLDB uses the default values, which do not match the String
values provided on shutdown. So the `initTask()` is conflicting with the
setService method in terms of property values.
The `setService()` method is not actually working as expected. It looks like
the setProperty calls for username and password should be removed from there,
and the MockPropertyValues in initTask should be changed to return the username
and password values.
--
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]