Skip to content

Commit e59a667

Browse files
Merge pull request #173 from OpenHFT/codex/ensure-lockcheck-returns-integer.min_value
Ensure EMPTY_PID returned when lock missing
2 parents c3d9ba0 + 67d5ad6 commit e59a667

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

affinity/src/main/java/net/openhft/affinity/LockCheck.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ private synchronized static boolean isLockFree(int id) {
7878
}
7979

8080
public static int getProcessForCpu(int core) throws IOException {
81+
if (!canOSSupportOperation())
82+
return EMPTY_PID;
83+
8184
String meta = lockChecker.getMetaInfo(core);
8285

8386
if (meta != null && !meta.isEmpty()) {

affinity/src/test/java/net/openhft/affinity/FileLockLockCheckTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,12 @@ public void lockFileDeletedWhileHeld() throws Exception {
9696
lockFile = lockChecker.doToFile(cpu);
9797
Assert.assertTrue("Lock file should be recreated", lockFile.exists());
9898
}
99+
100+
@Test
101+
public void getProcessForCpuReturnsEmptyPidWhenNoFile() throws IOException {
102+
int freeCpu = 99;
103+
File lockFile = lockChecker.doToFile(freeCpu);
104+
Assert.assertFalse(lockFile.exists());
105+
Assert.assertEquals(Integer.MIN_VALUE, LockCheck.getProcessForCpu(freeCpu));
106+
}
99107
}

0 commit comments

Comments
 (0)