skeossei commented on code in PR #11686:
URL: https://github.com/apache/nifi/pull/11686#discussion_r4124652902
##########
nifi-connector-mock-bundle/nifi-connector-mock/src/main/java/org/apache/nifi/mock/connector/StandardConnectorTestRunner.java:
##########
@@ -43,47 +43,95 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
import java.nio.file.Path;
import java.time.Duration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeoutException;
public class StandardConnectorTestRunner implements ConnectorTestRunner,
Closeable {
private final File narLibraryDirectory;
private final int httpPort;
+ private final Path instanceDirectory;
private ConnectorMockServer mockServer;
+ static Properties getInstanceProperties(final Path instanceDirectory) {
+ final Properties properties = new Properties();
+ if (instanceDirectory == null) {
+ return properties;
+ }
+
+ properties.setProperty(NiFiProperties.FLOW_CONFIGURATION_FILE,
instanceDirectory.resolve("conf/flow.json.gz").toString());
+ properties.setProperty(NiFiProperties.FLOW_CONFIGURATION_ARCHIVE_DIR,
instanceDirectory.resolve("conf/archive").toString());
+ properties.setProperty(NiFiProperties.STATE_MANAGEMENT_CONFIG_FILE,
instanceDirectory.resolve("conf/state-management.xml").toString());
+ properties.setProperty(NiFiProperties.REPOSITORY_DATABASE_DIRECTORY,
instanceDirectory.resolve("database_repository").toString());
+ properties.setProperty(NiFiProperties.FLOWFILE_REPOSITORY_DIRECTORY,
instanceDirectory.resolve("flowfile_repository").toString());
+ properties.setProperty(NiFiProperties.REPOSITORY_CONTENT_PREFIX +
"default", instanceDirectory.resolve("content_repository").toString());
+
properties.setProperty(NiFiProperties.NAR_PERSISTENCE_PROVIDER_PROPERTIES_PREFIX
+ "directory", instanceDirectory.resolve("nar_repository").toString());
+ properties.setProperty(NiFiProperties.ASSET_MANAGER_PREFIX +
"directory", instanceDirectory.resolve("assets").toString());
+ properties.setProperty(NiFiProperties.CONNECTOR_ASSET_MANAGER_PREFIX +
"directory", instanceDirectory.resolve("connector-assets").toString());
+ properties.setProperty(NiFiProperties.NAR_WORKING_DIRECTORY,
instanceDirectory.resolve("work").toString());
+ properties.setProperty(NiFiProperties.NAR_LIBRARY_AUTOLOAD_DIRECTORY,
instanceDirectory.resolve("autoload").toString());
+ properties.setProperty(NiFiProperties.WEB_WORKING_DIR,
instanceDirectory.resolve("work/jetty").toString());
+ return properties;
+ }
+
private StandardConnectorTestRunner(final Builder builder) {
this.narLibraryDirectory = builder.narLibraryDirectory;
this.httpPort = builder.httpPort;
+ this.instanceDirectory = builder.instanceDirectory;
try {
bootstrapInstance();
} catch (final Exception e) {
+ closeAfterFailure(e);
throw new RuntimeException("Failed to bootstrap
ConnectorTestRunner", e);
}
- // It is important that we register the processor and controller
service mocks before instantiating the connector.
- // Otherwise, the call to instantiateConnector will initialize the
Connector, which may update the flow.
- // If the flow is updated before the mocks are registered, the
components will be created without
- // using the mocks. Subsequent updates to the flow will not replace
the components already created because
- // these are not recognized as updates to the flow, since the
framework assumes that the type of a component
- // with a given ID does not change.
- builder.processorMocks.forEach(mockServer::mockProcessor);
-
builder.controllerServiceMocks.forEach(mockServer::mockControllerService);
+ try {
+ // It is important that we register the processor and controller
service mocks before instantiating the connector.
+ // Otherwise, the call to instantiateConnector will initialize the
Connector, which may update the flow.
+ // If the flow is updated before the mocks are registered, the
components will be created without
+ // using the mocks. Subsequent updates to the flow will not
replace the components already created because
+ // these are not recognized as updates to the flow, since the
framework assumes that the type of a component
+ // with a given ID does not change.
+ builder.processorMocks.forEach(mockServer::mockProcessor);
+
builder.controllerServiceMocks.forEach(mockServer::mockControllerService);
+
+ mockServer.instantiateConnector(builder.connectorClassName);
+ } catch (final RuntimeException e) {
+ closeAfterFailure(e);
+ throw e;
+ }
+ }
- mockServer.instantiateConnector(builder.connectorClassName);
+ private void closeAfterFailure(final Exception failure) {
Review Comment:
Renamed to closeQuietly
--
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]