diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java index 470e3cde8..3d4bd0dda 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/npm/FilesystemPackageManagerTests.java @@ -7,6 +7,7 @@ import java.io.IOException; import java.nio.file.Files; import java.util.ArrayList; import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; import javax.annotation.Nonnull; @@ -104,32 +105,35 @@ public class FilesystemPackageManagerTests { } @Test - public void multithreadTest() throws IOException { - String pcmPath = Files.createTempDirectory("pcm-multithreadTest").toFile().getAbsolutePath(); + public void multithreadingTest() throws IOException { + String pcmPath = Files.createTempDirectory("fpcm-multithreadingTest").toFile().getAbsolutePath(); FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(pcmPath); - + + final AtomicInteger totalSuccessful = new AtomicInteger(); + List threads = new ArrayList<>(); - for (int i = 0 ; i < 3 ; i++) { + for (int i = 0; i < 3; i++) { final int index = i; Thread t = new Thread(() -> { - - try { - pcm.loadPackage("hl7.fhir.r4.core#4.0.1"); - System.out.println("Thread " + index + " completed"); - } catch (Exception e) { - e.printStackTrace(); - System.err.println("Thread " + index + " failed"); - } - }); + try { + pcm.loadPackage("hl7.fhir.r4.core#4.0.1"); + totalSuccessful.incrementAndGet(); + System.out.println("Thread " + index + " completed"); + } catch (Exception e) { + e.printStackTrace(); + System.err.println("Thread " + index + " failed"); + } + }); t.start(); threads.add(t); } - threads.forEach(t -> { - try { - t.join(); - } catch (InterruptedException e) { + threads.forEach(t -> { + try { + t.join(); + } catch (InterruptedException e) { - } - }); + } + }); + assertEquals(3, totalSuccessful.get()); } }