NIFI-4147 Refactor RunNiFi for Testability

Class org.apache.nifi.bootstrap.RunNiFi is not designed with extensibility
in mind: changes to allow RunNiFi to be subclassed in a test harness

Signed-off-by: James Wing <jvwing@gmail.com>

This closes #1972.
This commit is contained in:
Peter G. Horvath 2017-07-22 11:39:24 +02:00 committed by James Wing
parent 3371e915cc
commit 082919f919
1 changed files with 8 additions and 8 deletions

View File

@ -207,7 +207,7 @@ public class RunNiFi {
return; return;
} }
final File configFile = getBootstrapConfFile(); final File configFile = getDefaultBootstrapConfFile();
final RunNiFi runNiFi = new RunNiFi(configFile, verbose); final RunNiFi runNiFi = new RunNiFi(configFile, verbose);
Integer exitStatus = null; Integer exitStatus = null;
@ -240,7 +240,7 @@ public class RunNiFi {
} }
} }
private static File getBootstrapConfFile() { private static File getDefaultBootstrapConfFile() {
String configFilename = System.getProperty("org.apache.nifi.bootstrap.config.file"); String configFilename = System.getProperty("org.apache.nifi.bootstrap.config.file");
if (configFilename == null) { if (configFilename == null) {
@ -261,7 +261,7 @@ public class RunNiFi {
} }
private NotificationServiceManager loadServices() throws IOException { private NotificationServiceManager loadServices() throws IOException {
final File bootstrapConfFile = getBootstrapConfFile(); final File bootstrapConfFile = this.bootstrapConfigFile;
final Properties properties = new Properties(); final Properties properties = new Properties();
try (final FileInputStream fis = new FileInputStream(bootstrapConfFile)) { try (final FileInputStream fis = new FileInputStream(bootstrapConfFile)) {
properties.load(fis); properties.load(fis);
@ -341,7 +341,7 @@ public class RunNiFi {
} }
private File getBootstrapFile(final Logger logger, String directory, String defaultDirectory, String fileName) throws IOException { protected File getBootstrapFile(final Logger logger, String directory, String defaultDirectory, String fileName) throws IOException {
final File confDir = bootstrapConfigFile.getParentFile(); final File confDir = bootstrapConfigFile.getParentFile();
final File nifiHome = confDir.getParentFile(); final File nifiHome = confDir.getParentFile();
@ -362,19 +362,19 @@ public class RunNiFi {
return statusFile; return statusFile;
} }
File getPidFile(final Logger logger) throws IOException { protected File getPidFile(final Logger logger) throws IOException {
return getBootstrapFile(logger, NIFI_PID_DIR_PROP, DEFAULT_PID_DIR, NIFI_PID_FILE_NAME); return getBootstrapFile(logger, NIFI_PID_DIR_PROP, DEFAULT_PID_DIR, NIFI_PID_FILE_NAME);
} }
File getStatusFile(final Logger logger) throws IOException { protected File getStatusFile(final Logger logger) throws IOException {
return getBootstrapFile(logger, NIFI_PID_DIR_PROP, DEFAULT_PID_DIR, NIFI_STATUS_FILE_NAME); return getBootstrapFile(logger, NIFI_PID_DIR_PROP, DEFAULT_PID_DIR, NIFI_STATUS_FILE_NAME);
} }
File getLockFile(final Logger logger) throws IOException { protected File getLockFile(final Logger logger) throws IOException {
return getBootstrapFile(logger, NIFI_PID_DIR_PROP, DEFAULT_PID_DIR, NIFI_LOCK_FILE_NAME); return getBootstrapFile(logger, NIFI_PID_DIR_PROP, DEFAULT_PID_DIR, NIFI_LOCK_FILE_NAME);
} }
File getStatusFile() throws IOException { protected File getStatusFile() throws IOException {
return getStatusFile(defaultLogger); return getStatusFile(defaultLogger);
} }