More testing
This commit is contained in:
parent
48066859d5
commit
048aa2abe5
|
@ -1,6 +1,7 @@
|
|||
package org.hl7.fhir.utilities.npm;
|
||||
|
||||
import org.hl7.fhir.utilities.filesystem.ManagedFileAccess;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
@ -16,6 +17,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
public class FilesystemPackageManagerLockTests {
|
||||
|
@ -116,6 +118,23 @@ public class FilesystemPackageManagerLockTests {
|
|||
}
|
||||
}
|
||||
|
||||
@Test void testWhenLockIsntHeld_canLockFileBeHeldByThisProcessIsTrue() throws IOException {
|
||||
File lockFile = getPackageLockFile();
|
||||
lockFile.createNewFile();
|
||||
Assertions.assertTrue(filesystemPackageCacheLockManager.getCacheLock().canLockFileBeHeldByThisProcess(lockFile));
|
||||
}
|
||||
|
||||
@Test void testWhenLockIsHelp_canLockFileBeHeldByThisProcessIsFalse() throws IOException, InterruptedException, TimeoutException {
|
||||
File lockFile = getPackageLockFile();
|
||||
Thread lockThread = LockfileTestUtility.lockWaitAndDeleteInNewProcess(cachePath, DUMMY_PACKAGE + ".lock", 2);
|
||||
|
||||
LockfileTestUtility.waitForLockfileCreation(cacheDirectory.getAbsolutePath(), DUMMY_PACKAGE + ".lock");
|
||||
|
||||
Assertions.assertFalse(filesystemPackageCacheLockManager.getCacheLock().canLockFileBeHeldByThisProcess(lockFile));
|
||||
|
||||
lockThread.join();
|
||||
}
|
||||
|
||||
@Test void testSinglePackageWriteMultiPackageRead() throws IOException {
|
||||
final FilesystemPackageCacheManagerLocks.PackageLock packageLock = filesystemPackageCacheLockManager.getPackageLock(DUMMY_PACKAGE);
|
||||
AtomicInteger writeCounter = new AtomicInteger(0);
|
||||
|
|
|
@ -134,6 +134,29 @@ public class FilesystemPackageManagerTests {
|
|||
assertThat(dummyLockFile).doesNotExist();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLockedPackageIsntCleanedUp() throws IOException, InterruptedException, TimeoutException {
|
||||
File cacheDirectory = ManagedFileAccess.fromPath(Files.createTempDirectory("fpcm-multithreadingTest"));
|
||||
|
||||
File dummyPackage = createDummyPackage(cacheDirectory, "example.fhir.uv.myig", "1.2.3");
|
||||
|
||||
Thread lockThread = LockfileTestUtility.lockWaitAndDeleteInNewProcess(cacheDirectory.getAbsolutePath(), "example.fhir.uv.myig#1.2.3.lock", 2);
|
||||
|
||||
LockfileTestUtility.waitForLockfileCreation(cacheDirectory.getAbsolutePath(), "example.fhir.uv.myig#1.2.3.lock");
|
||||
File dummyLockFile = ManagedFileAccess.file(cacheDirectory.getAbsolutePath(), "example.fhir.uv.myig#1.2.3.lock");
|
||||
|
||||
assertThat(dummyPackage).isDirectory();
|
||||
assertThat(dummyPackage).exists();
|
||||
assertThat(dummyLockFile).exists();
|
||||
|
||||
FilesystemPackageCacheManager filesystemPackageCacheManager = new FilesystemPackageCacheManager.Builder().withCacheFolder(cacheDirectory.getAbsolutePath()).build();
|
||||
|
||||
assertThat(dummyPackage).exists();
|
||||
assertThat(dummyLockFile).exists();
|
||||
|
||||
lockThread.join();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTimeoutForLockedPackageRead() throws IOException, InterruptedException, TimeoutException {
|
||||
String pcmPath = ManagedFileAccess.fromPath(Files.createTempDirectory("fpcm-multithreadingTest")).getAbsolutePath();
|
||||
|
|
Loading…
Reference in New Issue