-
Notifications
You must be signed in to change notification settings - Fork 470
/
DNS_PINGTest.java
82 lines (64 loc) · 2.43 KB
/
DNS_PINGTest.java
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
package org.jgroups.protocols.dns;
import org.jgroups.stack.IpAddress;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.net.InetAddress;
import java.util.concurrent.TimeUnit;
import java.util.logging.Level;
import java.util.logging.Logger;
public class DNS_PINGTest {
private static final int PORT_START = 1234;
private static final boolean FORCE_DEBUG_LOGGING = false;
@BeforeClass
public static void beforeClass() {
if (FORCE_DEBUG_LOGGING) {
Logger rootLog = Logger.getLogger("");
rootLog.setLevel(Level.FINE);
rootLog.getHandlers()[0].setLevel(Level.FINE);
}
}
@Test
public void test_failing_on_no_dns_query() throws Exception {
//given
DNS_PING ping = new DNS_PING();
ping.dns_address = "fake.com";
//when
try {
ping.validateProperties();
Assert.fail();
} catch (IllegalArgumentException e) {
//then
}
}
@Test
public void test_valid_dns_response() throws Exception {
//given
DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 500, TimeUnit.SECONDS)
.add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START))
.add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), PORT_START + 1));
//when
boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
//then
Assert.assertTrue(was_view_received);
}
@Test
public void test_empty_dns_response() throws Exception {
//given
DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 1, TimeUnit.SECONDS);
//when
boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
//then
Assert.assertFalse(was_view_received);
}
@Test
public void test_not_matching_dns_response() throws Exception {
//given
DNSDiscoveryTester dns_discovery_tester = new DNSDiscoveryTester(2, PORT_START, 1, TimeUnit.SECONDS)
.add("test", DNSResolver.DNSRecordType.A, new IpAddress(InetAddress.getLoopbackAddress(), 6666));
//when
boolean was_view_received = dns_discovery_tester.runTestAndCheckIfViewWasReceived("test", "A");
//then
Assert.assertFalse(was_view_received);
}
}