exceptionfactory commented on code in PR #11761:
URL: https://github.com/apache/nifi/pull/11761#discussion_r4290634711
##########
nifi-extension-bundles/nifi-standard-services/nifi-dbcp-service-bundle/nifi-dbcp-service/src/test/java/org/apache/nifi/dbcp/DBCPServiceTest.java:
##########
@@ -63,25 +66,55 @@ public class DBCPServiceTest {
private static final String NON_JDBC_URL =
"http://localhost:3306/database";
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_test_db";
private TestRunner runner;
private DBCPConnectionPool service;
+ private String connectionUrl;
+
+ private Path databasePath;
+
@BeforeEach
public void setService(@TempDir final Path tempDir) throws
InitializationException {
service = new DBCPConnectionPool();
runner = TestRunners.newTestRunner(NoOpProcessor.class);
runner.addControllerService(SERVICE_ID, service);
- final String url = CONNECTION_URL_FORMAT.formatted(tempDir);
- runner.setProperty(service, DBCPProperties.DATABASE_URL, url);
+ databasePath = tempDir.toAbsolutePath();
+ connectionUrl = CONNECTION_URL_FORMAT.formatted(databasePath);
+ runner.setProperty(service, DBCPProperties.DATABASE_URL,
connectionUrl);
runner.setProperty(service, DBCPProperties.DB_USER,
String.class.getSimpleName());
runner.setProperty(service, DBCPProperties.DB_PASSWORD,
String.class.getName());
runner.setProperty(service, DBCPProperties.DB_DRIVERNAME,
DRIVER_CLASS);
}
+ @AfterEach
+ public void shutdownDatabase() throws Exception {
+ runner.shutdown();
+
+ // Property validation tests may never create the database.
+ // Do not create it just to shut it down.
+ final Path propertiesFile =
databasePath.resolve("nifi_test_db.properties");
+ if (Files.exists(propertiesFile)) {
+ final Properties properties = new Properties();
+ properties.setProperty("user", String.class.getSimpleName());
+ properties.setProperty("password", String.class.getName());
Review Comment:
The DB_USER and DB_PASSWORD fields are not required, so if they can be
removed, that would be better. I know there are set now in `setService`, but it
is doesn't provide any additional value in this method, it is worth removing.
--
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]