Add verification methods to Process
All checks were successful
PRs & Pushes / test (push) Successful in 2m49s
PRs & Pushes / build-jars (push) Successful in 3m40s
PRs & Pushes / build-apidoc (push) Successful in 4m4s

This commit is contained in:
JeremyStar™ 2024-12-27 23:59:58 +01:00
parent 1cf6c9ac41
commit c3223f0add
Signed by: JeremyStarTM
GPG key ID: E366BAEF67E4704D

View file

@ -20,6 +20,7 @@
package de.staropensource.engine.base.utility
import de.staropensource.engine.base.Engine.Companion.logger
import de.staropensource.engine.base.exception.VerificationFailedException
import de.staropensource.engine.base.exception.io.IOAccessException
import de.staropensource.engine.base.implementable.stream.ReadStream
import de.staropensource.engine.base.implementable.stream.Stream
@ -277,6 +278,81 @@ class Process {
}
// -----> Verification
/**
* Verifies that this [Process]
* has the same PID as specified.
*
* @param pid pid to compare
* @return this instance
* @throws VerificationFailedException if verification fails
* @since v1-alpha10
*/
fun verifyPidEquals(pid: Long): Process {
if (getPid() != pid)
throw VerificationFailedException("Expected that PID ${getPid()} of Process[${hashCode()}] equals specified PID ${pid}")
return this
}
/**
* Verifies that this [Process]
* is alive and running.
*
* @return this instance
* @throws VerificationFailedException if verification fails
* @since v1-alpha10
*/
fun verifyAlive(): Process {
if (!isAlive())
throw VerificationFailedException("Expected that process ${getPid()} is alive")
return this
}
/**
* Verifies that this [Process]
* is not alive and running.
*
* @return this instance
* @throws VerificationFailedException if verification fails
* @since v1-alpha10
*/
fun verifyNotAlive(): Process {
if (isAlive())
throw VerificationFailedException("Expected that process ${getPid()} is not alive")
return this
}
/**
* Verifies that this [Process]
* has been launched with
* a fresh environment.
*
* @return this instance
* @throws VerificationFailedException if verification fails
* @since v1-alpha10
*/
fun verifyLaunchedWithFreshEnvironment(): Process {
if (!launchedWithFreshEnvironment)
throw VerificationFailedException("Expected that process ${getPid()} was launched with a fresh environment")
return this
}
/**
* Verifies that this [Process]
* has not been launched with
* a fresh environment.
*
* @return this instance
* @throws VerificationFailedException if verification fails
* @since v1-alpha10
*/
fun verifyNotLaunchedWithFreshEnvironment(): Process {
if (launchedWithFreshEnvironment)
throw VerificationFailedException("Expected that process ${getPid()} was not launched with a fresh environment")
return this
}
// -----> Inner classes
/**
* Used for the [standardInput]