markap14 commented on code in PR #11686:
URL: https://github.com/apache/nifi/pull/11686#discussion_r4122428596
##########
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;
Review Comment:
It feels a bit weird to have one member variable that is a File while
another is a Path. Perhaps makes sense to use `File` here instead of `Path`?
##########
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());
Review Comment:
Optional but worth considering a simple `resolveDirectory` method here,
rather than repeating `instanceDirectory.resolve(...).toString()` so many times.
##########
nifi-connector-mock-bundle/nifi-connector-mock/src/test/java/org/apache/nifi/mock/connector/StandardConnectorTestRunnerTest.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.mock.connector;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandardConnectorTestRunnerTest {
+
+ @TempDir
+ private Path tempDirectory;
+
+ @Test
+ void testInstancePropertiesEmptyWithoutInstanceDirectory() {
+ final Properties properties =
StandardConnectorTestRunner.getInstanceProperties(null);
+
+ assertTrue(properties.isEmpty());
Review Comment:
Not really a necessary test.
##########
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:
Method names should not dictate how they are used. A better name might be
closeQuietly.
##########
nifi-connector-mock-bundle/nifi-connector-mock-test-bundle/nifi-connector-mock-integration-tests/src/test/java/org/apache/nifi/mock/connectors/tests/StandardConnectorTestRunnerIsolationIT.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.mock.connectors.tests;
+
+import org.apache.nifi.mock.connector.StandardConnectorTestRunner;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandardConnectorTestRunnerIsolationIT {
+
+ private static final String CONNECTOR_CLASS =
"org.apache.nifi.mock.connectors.GenerateAndLog";
+
+ @TempDir
+ private Path temporaryDirectory;
+
+ @Test
+ @Timeout(120)
+ void testConcurrentRunnersUseIndependentInstanceDirectories() throws
Exception {
+ final Path firstInstanceDirectory =
temporaryDirectory.resolve("first");
+ final Path secondInstanceDirectory =
temporaryDirectory.resolve("second");
+ final ExecutorService executorService =
Executors.newFixedThreadPool(2);
+ final Queue<StandardConnectorTestRunner> runners = new
ConcurrentLinkedQueue<>();
+
+ try {
+ final List<Callable<StandardConnectorTestRunner>> builders =
List.of(
+ () -> createRunner(firstInstanceDirectory, runners),
+ () -> createRunner(secondInstanceDirectory, runners)
+ );
+ final List<Future<StandardConnectorTestRunner>> runnerFutures =
executorService.invokeAll(builders);
+ final StandardConnectorTestRunner firstRunner =
runnerFutures.get(0).get();
+ final StandardConnectorTestRunner secondRunner =
runnerFutures.get(1).get();
+
+ final Future<?> firstRun = executorService.submit(() -> {
+ startAndStop(firstRunner);
+ return null;
+ });
+ final Future<?> secondRun = executorService.submit(() -> {
+ startAndStop(secondRunner);
+ return null;
+ });
+ firstRun.get();
+ secondRun.get();
+
+ addAsset(firstRunner, "first.txt", "first-runner");
+ addAsset(secondRunner, "second.txt", "second-runner");
+
+ assertEquals(Set.of("first-runner"), new
HashSet<>(readAssetContents(firstInstanceDirectory)));
+ assertEquals(Set.of("second-runner"), new
HashSet<>(readAssetContents(secondInstanceDirectory)));
+
+ firstRunner.close();
+ runners.remove(firstRunner);
+
+ assertDoesNotThrow(secondRunner::validate);
Review Comment:
Avoid calls to assertDoesNotThrow. It complicates the code and adds nothing.
Just call the method. If it throws the test fails with a clear indication why.
##########
nifi-connector-mock-bundle/nifi-connector-mock-test-bundle/nifi-connector-mock-integration-tests/src/test/java/org/apache/nifi/mock/connectors/tests/StandardConnectorTestRunnerIsolationIT.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.mock.connectors.tests;
+
+import org.apache.nifi.mock.connector.StandardConnectorTestRunner;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandardConnectorTestRunnerIsolationIT {
+
+ private static final String CONNECTOR_CLASS =
"org.apache.nifi.mock.connectors.GenerateAndLog";
+
+ @TempDir
+ private Path temporaryDirectory;
+
+ @Test
+ @Timeout(120)
+ void testConcurrentRunnersUseIndependentInstanceDirectories() throws
Exception {
+ final Path firstInstanceDirectory =
temporaryDirectory.resolve("first");
+ final Path secondInstanceDirectory =
temporaryDirectory.resolve("second");
+ final ExecutorService executorService =
Executors.newFixedThreadPool(2);
+ final Queue<StandardConnectorTestRunner> runners = new
ConcurrentLinkedQueue<>();
+
+ try {
+ final List<Callable<StandardConnectorTestRunner>> builders =
List.of(
+ () -> createRunner(firstInstanceDirectory, runners),
+ () -> createRunner(secondInstanceDirectory, runners)
+ );
+ final List<Future<StandardConnectorTestRunner>> runnerFutures =
executorService.invokeAll(builders);
+ final StandardConnectorTestRunner firstRunner =
runnerFutures.get(0).get();
+ final StandardConnectorTestRunner secondRunner =
runnerFutures.get(1).get();
+
+ final Future<?> firstRun = executorService.submit(() -> {
+ startAndStop(firstRunner);
+ return null;
+ });
+ final Future<?> secondRun = executorService.submit(() -> {
+ startAndStop(secondRunner);
+ return null;
+ });
+ firstRun.get();
+ secondRun.get();
+
+ addAsset(firstRunner, "first.txt", "first-runner");
+ addAsset(secondRunner, "second.txt", "second-runner");
+
+ assertEquals(Set.of("first-runner"), new
HashSet<>(readAssetContents(firstInstanceDirectory)));
+ assertEquals(Set.of("second-runner"), new
HashSet<>(readAssetContents(secondInstanceDirectory)));
+
+ firstRunner.close();
+ runners.remove(firstRunner);
+
+ assertDoesNotThrow(secondRunner::validate);
+ addAsset(secondRunner, "after-close.txt",
"second-runner-after-close");
+ assertEquals(Set.of("second-runner", "second-runner-after-close"),
new HashSet<>(readAssetContents(secondInstanceDirectory)));
+ } finally {
+ executorService.shutdownNow();
+ runners.forEach(StandardConnectorTestRunner::close);
+ }
+
+ assertTrue(Files.isDirectory(firstInstanceDirectory));
+ assertTrue(Files.isDirectory(secondInstanceDirectory));
+
assertTrue(Files.isDirectory(firstInstanceDirectory.resolve("work/framework")));
+
assertTrue(Files.isDirectory(firstInstanceDirectory.resolve("work/extensions")));
+
assertTrue(Files.isDirectory(secondInstanceDirectory.resolve("work/framework")));
+
assertTrue(Files.isDirectory(secondInstanceDirectory.resolve("work/extensions")));
+ }
+
+ @Test
+ void
testCallerOwnedInstanceDirectoryRetainedAndReusableAfterBootstrapFailure()
throws Exception {
+ final Path instanceDirectory = temporaryDirectory.resolve("failed");
+ Files.createDirectories(instanceDirectory);
+ final Path marker =
Files.writeString(instanceDirectory.resolve("marker"), "caller-owned");
+
+ assertThrows(RuntimeException.class, () -> new
StandardConnectorTestRunner.Builder()
+
.connectorClassName("org.apache.nifi.mock.connectors.DoesNotExist")
+ .narLibraryDirectory(new File("target/libDir"))
+ .instanceDirectory(instanceDirectory)
+ .build());
+
+ assertEquals("caller-owned", Files.readString(marker));
+ assertDoesNotThrow(() -> {
Review Comment:
Avoid calls to assertDoesNotThrow. It complicates the code and adds nothing.
Just call the method. If it throws the test fails with a clear indication why.
##########
nifi-connector-mock-bundle/nifi-connector-mock-test-bundle/nifi-connector-mock-integration-tests/src/test/java/org/apache/nifi/mock/connectors/tests/StandardConnectorTestRunnerIsolationIT.java:
##########
@@ -0,0 +1,169 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.mock.connectors.tests;
+
+import org.apache.nifi.mock.connector.StandardConnectorTestRunner;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.Timeout;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.time.Duration;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Queue;
+import java.util.Set;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ConcurrentLinkedQueue;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeoutException;
+import java.util.stream.Stream;
+
+import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandardConnectorTestRunnerIsolationIT {
+
+ private static final String CONNECTOR_CLASS =
"org.apache.nifi.mock.connectors.GenerateAndLog";
+
+ @TempDir
+ private Path temporaryDirectory;
+
+ @Test
+ @Timeout(120)
+ void testConcurrentRunnersUseIndependentInstanceDirectories() throws
Exception {
+ final Path firstInstanceDirectory =
temporaryDirectory.resolve("first");
+ final Path secondInstanceDirectory =
temporaryDirectory.resolve("second");
+ final ExecutorService executorService =
Executors.newFixedThreadPool(2);
+ final Queue<StandardConnectorTestRunner> runners = new
ConcurrentLinkedQueue<>();
+
+ try {
+ final List<Callable<StandardConnectorTestRunner>> builders =
List.of(
+ () -> createRunner(firstInstanceDirectory, runners),
+ () -> createRunner(secondInstanceDirectory, runners)
+ );
+ final List<Future<StandardConnectorTestRunner>> runnerFutures =
executorService.invokeAll(builders);
+ final StandardConnectorTestRunner firstRunner =
runnerFutures.get(0).get();
+ final StandardConnectorTestRunner secondRunner =
runnerFutures.get(1).get();
+
+ final Future<?> firstRun = executorService.submit(() -> {
+ startAndStop(firstRunner);
+ return null;
+ });
+ final Future<?> secondRun = executorService.submit(() -> {
+ startAndStop(secondRunner);
+ return null;
+ });
+ firstRun.get();
+ secondRun.get();
Review Comment:
There's nothing that makes these run concurrently. Need to either add
appropriate logic to ensure that they are truly run concurrently and that A
cannot finish before B, or else eliminate the complexity and simply call them
sequentially if that's adequate.
##########
nifi-connector-mock-bundle/nifi-connector-mock/src/test/java/org/apache/nifi/mock/connector/StandardConnectorTestRunnerTest.java:
##########
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.nifi.mock.connector;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.nio.file.Path;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+class StandardConnectorTestRunnerTest {
+
+ @TempDir
+ private Path tempDirectory;
+
+ @Test
+ void testInstancePropertiesEmptyWithoutInstanceDirectory() {
+ final Properties properties =
StandardConnectorTestRunner.getInstanceProperties(null);
+
+ assertTrue(properties.isEmpty());
+ }
+
+ @Test
+ void testInstancePropertiesDerivedFromInstanceDirectory() {
+ final Path instanceDirectory =
tempDirectory.resolve("runner").toAbsolutePath().normalize();
+
+ final Properties properties =
StandardConnectorTestRunner.getInstanceProperties(instanceDirectory);
+
+ final Map<String, String> expectedProperties = Map.ofEntries(
+ Map.entry("nifi.flow.configuration.file",
instanceDirectory.resolve("conf/flow.json.gz").toString()),
+ Map.entry("nifi.flow.configuration.archive.dir",
instanceDirectory.resolve("conf/archive").toString()),
+ Map.entry("nifi.state.management.configuration.file",
instanceDirectory.resolve("conf/state-management.xml").toString()),
+ Map.entry("nifi.database.directory",
instanceDirectory.resolve("database_repository").toString()),
+ Map.entry("nifi.flowfile.repository.directory",
instanceDirectory.resolve("flowfile_repository").toString()),
+ Map.entry("nifi.content.repository.directory.default",
instanceDirectory.resolve("content_repository").toString()),
+
Map.entry("nifi.nar.persistence.provider.properties.directory",
instanceDirectory.resolve("nar_repository").toString()),
+ Map.entry("nifi.asset.manager.properties.directory",
instanceDirectory.resolve("assets").toString()),
+ Map.entry("nifi.connector.asset.manager.properties.directory",
instanceDirectory.resolve("connector-assets").toString()),
+ Map.entry("nifi.nar.working.directory",
instanceDirectory.resolve("work").toString()),
+ Map.entry("nifi.nar.library.autoload.directory",
instanceDirectory.resolve("autoload").toString()),
+ Map.entry("nifi.web.jetty.working.directory",
instanceDirectory.resolve("work/jetty").toString())
+ );
+
+ assertEquals(expectedProperties, properties);
+ }
Review Comment:
This is not a valid test. It does not verify logic or a contract, it simply
repeats the code above; any valid change to the code under test where the
contract does not change would now fail with this test.
--
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]