-
Notifications
You must be signed in to change notification settings - Fork 73
/
PingPongTest.java
executable file
·35 lines (29 loc) · 1.18 KB
/
PingPongTest.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
package org.agilewiki.jactor.pingpong.stackoverflow;
import org.agilewiki.jactor.JAMailboxFactory;
import org.agilewiki.jactor.MailboxFactory;
import junit.framework.TestCase;
/**
* Tests the number of request/reply cycles per second.
*/
public class PingPongTest extends TestCase {
/** How many repeats? */
private static final int REPEATS = 10;
public void testRequestReplyCycleSpeed() throws Exception {
final MailboxFactory mailboxFactory = JAMailboxFactory.newMailboxFactory(2);
int count = 0;
double duration = 0.0d;
for (int i = 1; i <= REPEATS; i++) {
System.out.println("Run #" + i + "/" + REPEATS);
final Pinger pinger = new Pinger(mailboxFactory.createMailbox(),
"Pinger");
final Ponger ponger = new Ponger(mailboxFactory.createMailbox());
final Pinger.HammerResult2 result = pinger.hammer(ponger);
count += result.pings();
duration += result.duration();
System.out.println(result);
}
System.out.println("Average Request/Reply Cycles/sec = "
+ (count / duration));
mailboxFactory.close();
}
}