summaryrefslogtreecommitdiffstats
path: root/src/test/java/derms/net/rmulticast/ReliableMulticastTest.java
blob: 9d272d53a4f086dfd3819d09621cb8cbf199fb79 (plain) (blame)
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
package derms.net.rmulticast;

import derms.net.StringMessage;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

import static org.junit.jupiter.api.Assertions.assertEquals;

class ReliableMulticastTest {
    static final InetSocketAddress group = new InetSocketAddress("225.1.2.3", 12345);

    static ReliableMulticast<StringMessage> sock;

    @BeforeAll
    static void setup() throws IOException {
        InetAddress laddr = InetAddress.getLocalHost();
        sock = new ReliableMulticast<StringMessage>(group, laddr);
    }

    @AfterAll
    static void teardown() throws IOException {
        sock.close();
    }

    // A process should receive its own messages that it sent to the group.
    @Test
    @Timeout(value = 3, unit = TimeUnit.SECONDS)
    void loopback() throws IOException, InterruptedException {
        StringMessage want = new StringMessage("foo");
        sock.send(want);
        StringMessage got = sock.receive();
        assertEquals(want, got);
    }
}