blob: 34cf64efe52905209228955ab09c35d72d9a2afe (
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
|
package testing.protocols;
import testing.*;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;
/**
* JUnit test for Ping-Pong Sturm variant.
*/
@DisplayName("Ping-Pong Sturm Protocol Tests")
public class PingPongSturmProtocolTest {
private HeadlessSimulationRunner runner;
@BeforeEach
public void setup() {
runner = new HeadlessSimulationRunner();
}
@AfterEach
public void teardown() {
runner.shutdown();
}
@Test
@DisplayName("Test Ping-Pong Sturm protocol activation")
public void testProtocolActivation() throws Exception {
SimulationResult result = runner.runSimulation(
"saved-simulations/ping-pong-sturm.dat",
1000
);
ProtocolVerifier verifier = new ProtocolVerifier()
.expectLog("Ping-Pong.*activated")
.expectNoLog("ERROR");
VerificationResult verification = verifier.verify(result.getAllLogs());
assertTrue(verification.passed(), verification.getFailureMessage());
}
@Test
@DisplayName("Test Sturm variant message exchange")
public void testSturmMessageExchange() throws Exception {
SimulationResult result = runner.runSimulation(
"saved-simulations/ping-pong-sturm.dat",
3000
);
// Similar to regular ping-pong but may have different patterns
ProtocolVerifier verifier = new ProtocolVerifier()
.expectLog("Message sent")
.expectLog("Message received")
.expectLog("fromClient=true|fromServer=true");
VerificationResult verification = verifier.verify(result.getAllLogs());
assertTrue(verification.passed(), verification.getFailureMessage());
// Check for balanced communication
int sent = result.countLogs("Message sent");
int received = result.countLogs("Message received");
assertTrue(Math.abs(sent - received) <= 2,
"Messages should be roughly balanced");
}
}
|