summaryrefslogtreecommitdiff
path: root/src/test/java/testing/protocols/ReliableMulticastProtocolTest.java
blob: ae9b4d7c3bfd1cb46e6eaab750fe0b722970d72b (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
package testing.protocols;

import testing.*;
import org.junit.jupiter.api.*;
import static org.junit.jupiter.api.Assertions.*;

/**
 * JUnit test for Reliable Multicast protocol.
 */
@DisplayName("Reliable Multicast Protocol Tests")
public class ReliableMulticastProtocolTest {
    private HeadlessSimulationRunner runner;
    
    @BeforeEach
    public void setup() {
        runner = new HeadlessSimulationRunner();
    }
    
    @AfterEach
    public void teardown() {
        runner.shutdown();
    }
    
    @Test
    @DisplayName("Test Reliable Multicast protocol activation")
    public void testProtocolActivation() throws Exception {
        SimulationResult result = runner.runSimulation(
            "saved-simulations/reliable-multicast.dat", 
            1000
        );
        
        ProtocolVerifier verifier = new ProtocolVerifier()
            .expectLog("Reliable Multicast.*activated")
            .expectNoLog("ERROR");
            
        VerificationResult verification = verifier.verify(result.getAllLogs());
        assertTrue(verification.passed(), verification.getFailureMessage());
    }
    
    @Test
    @DisplayName("Test reliable delivery guarantees")
    public void testReliableDelivery() throws Exception {
        SimulationResult result = runner.runSimulation(
            "saved-simulations/reliable-multicast.dat", 
            5000
        );
        
        // Reliable multicast should ensure delivery
        ProtocolVerifier verifier = new ProtocolVerifier()
            .expectLog("Message sent")
            .expectLog("Message received")
            .expectLog("Multicast|multicast")
            .expectNoLog("lost|Lost|LOST")
            .expectNoLog("failed delivery");
            
        VerificationResult verification = verifier.verify(result.getAllLogs());
        assertTrue(verification.passed(), verification.getFailureMessage());
        
        // Check for acknowledgments or reliability mechanisms
        boolean hasAck = result.countLogs("ack|ACK|acknowledge|Acknowledge") > 0;
        boolean hasSeq = result.countLogs("sequence|Sequence|seq|SEQ") > 0;
        boolean hasReliable = result.countLogs("reliable|Reliable") > 0;
        
        assertTrue(hasAck || hasSeq || hasReliable, 
                  "Should have reliability mechanisms");
    }
    
    @Test
    @DisplayName("Test message ordering in reliable multicast")
    public void testMessageOrdering() throws Exception {
        SimulationResult result = runner.runSimulation(
            "saved-simulations/reliable-multicast.dat", 
            3000
        );
        
        // Verify messages maintain order
        var messages = result.findAll("Message received");
        
        long lastTime = -1;
        for (LogEntry entry : messages) {
            assertTrue(entry.getTimestamp() >= lastTime, 
                      "Messages should be in order");
            lastTime = entry.getTimestamp();
        }
    }
}