|
| 1 | +# Running PObserve Java Unit Test on Lock Server Example |
| 2 | + |
| 3 | +This page demonstrates how to use PObserve with Java JUnit tests to verify system correctness in real-time during test execution using a lock server as an example. |
| 4 | + |
| 5 | +## Prerequisites: Building and Publishing LockServerPObserve Package |
| 6 | + |
| 7 | +Before running the lock server package that has PObserve integrated JUnit tests, you need to build and publish the `LockServerPObserve` package to your local Maven repository. The JUnit tests depend on this package for the parser and specification classes. |
| 8 | + |
| 9 | +**1. Clone P repository** |
| 10 | +```bash |
| 11 | +git clone https://github.com/p-org/P.git |
| 12 | +``` |
| 13 | + |
| 14 | +**2. Navigate to the LockServerPObserve Directory** |
| 15 | + |
| 16 | +```bash |
| 17 | +cd P/Src/PObserve/Examples/LockServerPObserve/ |
| 18 | +``` |
| 19 | + |
| 20 | +**3. Build and Publish to Local Maven Repository** |
| 21 | + |
| 22 | +```bash |
| 23 | +# Initialize Gradle wrapper if not present |
| 24 | +gradle wrapper |
| 25 | + |
| 26 | +# Build the project |
| 27 | +./gradlew build |
| 28 | + |
| 29 | +# Publish to local Maven repository |
| 30 | +./gradlew publishToMavenLocal |
| 31 | +``` |
| 32 | + |
| 33 | +??? info "What happens during the build process" |
| 34 | + - **P Specification Compilation**: The `compilePSpec` task compiles the P specification files in `src/main/PSpec/` using the P compiler |
| 35 | + - **Java Compilation**: Compiles the Java parser and related classes |
| 36 | + - **Maven Publication**: Publishes the artifact `io.github.p-org:LockServerPObserve:1.0.0` to your local Maven repository (`~/.m2/repository/`) |
| 37 | + - **Dependencies Available**: The lock server package will now be able to resolve the dependency: `implementation("io.github.p-org:LockServerPObserve:1.0.0")`. This provides access to: |
| 38 | + |
| 39 | + * Parser class: `lockserver.pobserve.parser.LockServerParser` |
| 40 | + |
| 41 | + * MutualExclusion specification class: `lockserver.pobserve.spec.PMachines.MutualExclusion.Supplier` |
| 42 | + |
| 43 | + * ResponseOnlyOnRequest specification class: `lockserver.pobserve.spec.PMachines.ResponseOnlyOnRequest.Supplier` |
| 44 | + |
| 45 | + |
| 46 | +## Running JUnit Tests in Lock Server Package |
| 47 | + |
| 48 | +**1. Navigate to the Lock Server Package** |
| 49 | + |
| 50 | +```bash |
| 51 | +cd P/Src/PObserve/Examples/LockServer/ |
| 52 | +``` |
| 53 | + |
| 54 | +**2. Build the Project** |
| 55 | + |
| 56 | +The PObserve integrated JUnit tests are executed during the build process: |
| 57 | +```bash |
| 58 | +gradle wrapper |
| 59 | +./gradlew build |
| 60 | +``` |
| 61 | + |
| 62 | +**2. Running Unit Tests** |
| 63 | +```bash |
| 64 | +./gradlew test |
| 65 | +``` |
| 66 | + |
| 67 | +??? success "Expected Output" |
| 68 | + Running `./gradlew test` runs all the pobserve integrated unit tests in the LockServer package. The console output looks as follows: |
| 69 | + ``` |
| 70 | + > Task :test |
| 71 | + |
| 72 | + LockServerExtendCustomBaseTest > basicTest() PASSED |
| 73 | + |
| 74 | + LockServerExtendCustomBaseTest > multipleRandomClients() PASSED |
| 75 | + |
| 76 | + LockServerExtendCustomBaseTest > randomClient() PASSED |
| 77 | + |
| 78 | + LockServerExtendCustomBaseTest > expectFail() PASSED |
| 79 | + |
| 80 | + LockServerExtendPObserveBaseTest > basicTest() PASSED |
| 81 | + |
| 82 | + LockServerExtendPObserveBaseTest > multipleRandomClients() PASSED |
| 83 | + |
| 84 | + LockServerExtendPObserveBaseTest > randomClient() PASSED |
| 85 | + |
| 86 | + LockServerExtendPObserveBaseTest > expectFail() PASSED |
| 87 | + |
| 88 | + LockServerTest > testReleaseLockFail() PASSED |
| 89 | + |
| 90 | + LockServerTest > testAcquireLockFail() PASSED |
| 91 | + |
| 92 | + LockServerTest > testAcquireAndReleaseLock() PASSED |
| 93 | + |
| 94 | + LockServerTest > testReleaseLockNotHeldByClient() PASSED |
| 95 | + |
| 96 | + LockTest > testReleaseLock() PASSED |
| 97 | + |
| 98 | + LockTest > testAcquireLock() PASSED |
| 99 | + |
| 100 | + LockTest > testAcquireLockAlreadyHeld() PASSED |
| 101 | + |
| 102 | + LockTest > testReleaseLockNotHeldByClient() PASSED |
| 103 | + |
| 104 | + LockTest > testReleaseLockWhenNotLocked() PASSED |
| 105 | + |
| 106 | + > Task :test |
| 107 | + |
| 108 | + StructuredLoggerTest > testAllValuesFilled() PASSED |
| 109 | + |
| 110 | + StructuredLoggerTest > testValuesNull() PASSED |
| 111 | + |
| 112 | + TransactionLoggerTest > testLogReleaseRequest() PASSED |
| 113 | + |
| 114 | + TransactionLoggerTest > testLogLockResp() PASSED |
| 115 | + |
| 116 | + TransactionLoggerTest > testLogReleaseResp() PASSED |
| 117 | + |
| 118 | + TransactionLoggerTest > testLogLockRequest() PASSED |
| 119 | + |
| 120 | + BUILD SUCCESSFUL in 6s |
| 121 | + 4 actionable tasks: 4 executed |
| 122 | + ``` |
| 123 | + |
| 124 | +!!! success "" |
| 125 | + :confetti_ball: Congratulations! You have successfully set up and run PObserve with Java JUnit integration for real-time specification monitoring on a Lock Server Example! |
0 commit comments