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.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<Thread> 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());
}
}