skeossei commented on code in PR #11686:
URL: https://github.com/apache/nifi/pull/11686#discussion_r4124663839


##########
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:
   Removed. The methods are invoked directly



-- 
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]

Reply via email to