blob: 686536828461e8b41a3956eecb4e09e279debfb5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
# Protocol Tests Implementation Summary
## Overview
I have successfully implemented comprehensive tests for all non-Raft protocol simulations in DS-Sim using the headless testing framework.
## Implemented Test Classes
### JUnit Test Classes (in `/src/test/java/testing/protocols/`)
1. **PingPongProtocolTest.java** - Tests ping-pong message exchange
2. **PingPongSturmProtocolTest.java** - Tests ping-pong Sturm variant
3. **BroadcastProtocolTest.java** - Tests broadcast protocol
4. **BasicMulticastProtocolTest.java** - Tests basic multicast
5. **ReliableMulticastProtocolTest.java** - Tests reliable multicast with delivery guarantees
6. **BerkeleyProtocolTest.java** - Tests Berkeley time synchronization
7. **TimeSynchronizationProtocolTest.java** - Tests internal and external time sync
8. **CommitProtocolTest.java** - Tests one-phase and two-phase commit protocols
9. **SlowConnectionProtocolTest.java** - Tests slow connection simulation
10. **BaseProtocolTest.java** - Base class with common utilities
11. **AllProtocolsTestSuite.java** - JUnit suite to run all tests
### Standalone Test Runners
1. **ProtocolTestRunner.java** - Standalone test runner that doesn't require JUnit
2. **run-protocol-tests.sh** - Shell script for running tests
## Test Coverage
Each protocol test verifies:
- Protocol activation
- Message exchange patterns
- No errors occur
- Protocol-specific behavior
### Specific Verifications
- **Ping-Pong**: Message alternation, counter increments
- **Broadcast/Multicast**: One-to-many delivery
- **Reliable Multicast**: Delivery guarantees, acknowledgments
- **Time Sync**: Clock adjustments, synchronization messages
- **Commit Protocols**: Transaction phases, coordinator behavior
- **Slow Connection**: Message delays
## Running the Tests
### Option 1: Standalone Test Runner (Recommended)
```bash
mvn compile
java -cp target/classes testing.ProtocolTestRunner
```
### Option 2: Shell Script
```bash
./run-protocol-tests.sh
```
### Option 3: JUnit Tests (if Maven Surefire is properly configured)
```bash
mvn test
```
### Option 4: Individual Protocol Test
```bash
java -cp target/classes testing.examples.TestPingPongVerified
```
## Maven Configuration
Updated `pom.xml` with:
- JUnit Platform Suite dependency for test organization
- Surefire plugin configuration to include all test patterns
- Headless mode system property
## Key Features
1. **No GUI Required**: All tests run in headless mode
2. **Automated Verification**: Each test has specific verification rules
3. **Fast Execution**: Tests run for 1-2 seconds each
4. **Comprehensive Coverage**: All non-Raft protocols are tested
5. **Flexible Framework**: Easy to add new tests
## Example Test Structure
```java
@Test
@DisplayName("Test protocol activation")
public void testProtocolActivation() throws Exception {
SimulationResult result = runner.runSimulation(
"saved-simulations/protocol.dat",
2000
);
ProtocolVerifier verifier = new ProtocolVerifier()
.expectLog("Protocol.*activated")
.expectLog("Message sent")
.expectNoLog("ERROR");
VerificationResult verification = verifier.verify(result.getAllLogs());
assertTrue(verification.passed());
}
```
## Notes
- Raft protocol tests were excluded as requested
- Tests focus on basic functionality and error-free execution
- Each test runs the simulation for 1-2 seconds
- All tests use the headless testing framework developed earlier
## Future Enhancements
1. Add performance benchmarks
2. Test fault injection scenarios
3. Verify specific protocol properties (e.g., FIFO ordering)
4. Add parameterized tests for different configurations
5. Generate test reports with detailed logs
|