use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class FileLockServiceTest method testTimeout.
@Test
public void testTimeout() throws Exception {
File testFile = newTestFile();
FileLocker locker = subject.getFileLocker(testFile);
long waitTime = 1000L;
LockProcess lockProcess = new LockProcess(testFile, waitTime);
long start = System.currentTimeMillis();
lockProcess.lockFileInForkedProcess();
locker.lock(20000L);
try {
long duration = System.currentTimeMillis() - start;
assertTrue(duration >= waitTime);
} finally {
lockProcess.cleanup();
locker.release();
}
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class FileLockServiceTest method testURLEncoding.
@Test
public void testURLEncoding() throws IOException {
File testFile = new File(tempFolder.getRoot(), "file with spaces" + new Random().nextInt());
File markerFile = new File(testFile.getAbsolutePath() + ".tycholock");
FileLocker fileLocker = subject.getFileLocker(testFile);
assertFalse(markerFile.isFile());
fileLocker.lock();
try {
assertTrue(markerFile.isFile());
} finally {
fileLocker.release();
}
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class FileLockServiceTest method testRelease.
@Test
public void testRelease() throws Exception {
FileLocker locker = subject.getFileLocker(newTestFile());
assertFalse(locker.isLocked());
// releasing without holding the lock should do nothing
locker.release();
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class FileLockServiceTest method testLockedByOtherProcess.
@Test
public void testLockedByOtherProcess() throws Exception {
File testFile = newTestFile();
FileLocker locker = subject.getFileLocker(testFile);
LockProcess lockProcess = new LockProcess(testFile, 200L);
lockProcess.lockFileInForkedProcess();
assertTrue(locker.isLocked());
try {
locker.lock(0L);
fail("lock already held by other VM but could be acquired a second time");
} catch (LockTimeoutException e) {
// expected
}
lockProcess.cleanup();
}
use of org.eclipse.tycho.locking.facade.FileLocker in project tycho by eclipse.
the class LocalMavenRepositoryTool method filterLinesFromIndex.
private void filterLinesFromIndex(File indexFile, Set<String> toBeRemoved) throws UnsupportedEncodingException, FileNotFoundException, IOException {
FileLocker locker = fileLockService.getFileLocker(indexFile);
locker.lock();
try {
Set<String> currentLines = readLines(indexFile);
currentLines.removeAll(toBeRemoved);
writeLines(indexFile, currentLines);
} finally {
locker.release();
}
}
Aggregations