public void testPidFileContainsPid() throws Exception { final File pidFile = new File(getClass().getSimpleName() + File.separator + "testPidFileContainsPid.pid"); final LocalProcessLauncher launcher = new LocalProcessLauncher(pidFile, false); assertNotNull(launcher); assertTrue(pidFile.exists()); final FileReader fr = new FileReader(pidFile); final BufferedReader br = new BufferedReader(fr); final int pid = Integer.parseInt(br.readLine()); br.close(); assertTrue(pid > 0); assertEquals(launcher.getPid(), pid); assertEquals(ProcessUtils.identifyPid(), pid); }
public void testStalePidFileIsReplaced() throws Exception { final File pidFile = new File(getClass().getSimpleName() + File.separator + "testStalePidFileIsReplaced.pid"); assertTrue(pidFile.createNewFile()); assertTrue(pidFile.exists()); final FileWriter writer = new FileWriter(pidFile); writer.write(String.valueOf(Integer.MAX_VALUE)); writer.close(); try { new LocalProcessLauncher(pidFile, false); } catch (FileAlreadyExistsException e) { fail("LocalProcessLauncher should not have thrown FileAlreadyExistsException"); } final FileReader fr = new FileReader(pidFile); final BufferedReader br = new BufferedReader(fr); final int pid = Integer.parseInt(br.readLine()); br.close(); assertTrue(pid > 0); assertEquals(ProcessUtils.identifyPid(), pid); }
public void testForceReplacesExistingPidFile() throws Exception { assertTrue("testForceReplacesExistingPidFile is broken if PID == Integer.MAX_VALUE", ProcessUtils.identifyPid() != Integer.MAX_VALUE); final File pidFile = new File(getClass().getSimpleName() + File.separator + "testForceReplacesExistingPidFile.pid"); assertTrue(pidFile.createNewFile()); assertTrue(pidFile.exists()); final FileWriter writer = new FileWriter(pidFile); writer.write(String.valueOf(Integer.MAX_VALUE)); writer.close(); try { new LocalProcessLauncher(pidFile, true); } catch (FileAlreadyExistsException e) { fail("LocalProcessLauncher should not have thrown FileAlreadyExistsException"); } final FileReader fr = new FileReader(pidFile); final BufferedReader br = new BufferedReader(fr); final int pid = Integer.parseInt(br.readLine()); br.close(); assertTrue(pid > 0); assertEquals(ProcessUtils.identifyPid(), pid); }
public void testPidAccuracy() throws PidUnavailableException { int pid = ProcessUtils.identifyPid(); assertTrue(pid > 0); int osProcessPid = OSProcess.getId(); if (osProcessPid > 0) { assertEquals(OSProcess.getId(), pid); } else { // not much to test if OSProcess native code is unusable } }