-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloClientTest.java
More file actions
executable file
·68 lines (57 loc) · 1.96 KB
/
HelloClientTest.java
File metadata and controls
executable file
·68 lines (57 loc) · 1.96 KB
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
package info.kgeorgiy.java.advanced.hello;
import info.kgeorgiy.java.advanced.base.BaseTest;
import org.junit.Assert;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import java.net.DatagramSocket;
import java.net.SocketException;
import java.util.concurrent.atomic.AtomicInteger;
/**
* @author Georgiy Korneev (kgeorgiy@kgeorgiy.info)
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class HelloClientTest extends BaseTest {
private static int port = 8888;
public static final String PREFIX = HelloClientTest.class.getName();
@Test
public void test01_singleRequest() throws SocketException {
test(1, 1, 1);
}
@Test
public void test02_sequence() throws SocketException {
test(100, 1, 1);
}
@Test
public void test03_singleWithFailures() throws SocketException {
test(1, 1, 0.1);
}
@Test
public void test04_sequenceWithFailures() throws SocketException {
test(20, 1, 0.5);
}
@Test
public void test05_singleMultithreaded() throws SocketException {
test(1, 10, 1);
}
@Test
public void test06_sequenceMultithreaded() throws SocketException {
test(10, 10, 1);
}
@Test
public void test07_sequenceMultithreadedWithFails() throws SocketException {
test(10, 10, 0.5);
}
private void test(final int requests, final int treads, final double p) throws SocketException {
final int port = HelloClientTest.port++;
final AtomicInteger[] expected;
try (final DatagramSocket socket = new DatagramSocket(port)) {
expected = Util.server(PREFIX, treads, p, socket);
final HelloClient client = createCUT();
client.run("localhost", port, PREFIX, treads, requests);
}
for (int i = 0; i < expected.length; i++) {
Assert.assertEquals("Invalid number of requests on thread " + i , requests, expected[i].get());
}
}
}