Actual assertion for test

This commit is contained in:
dotasek 2023-11-29 10:35:49 -05:00
parent ff6ea47751
commit 84e456c5dc
1 changed files with 23 additions and 19 deletions

View File

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