import static org.junit.Assert.fail;
public class TestNettyTransceiverWhenServerStops {
// @Test // disable flakey test!
public void testNettyTransceiverWhenServerStops() throws Exception {
Mail mailService = new TestNettyServer.MailImpl();
Responder responder = new SpecificResponder(Mail.class, mailService);
NettyServer server = new NettyServer(responder, new InetSocketAddress(0));
server.start();
int serverPort = server.getPort();
final NettyTransceiver transceiver = new NettyTransceiver(new InetSocketAddress(serverPort), 60000L);
final Mail mail = SpecificRequestor.getClient(Mail.class, transceiver);
final AtomicInteger successes = new AtomicInteger();
final AtomicInteger failures = new AtomicInteger();
final AtomicBoolean quitOnFailure = new AtomicBoolean();
List<Thread> threads = new ArrayList<Thread>();
// Start a bunch of client threads that use the transceiver to send messages
for (int i = 0; i < 100; i++) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while (true) {
try {
mail.send(createMessage());
successes.incrementAndGet();
} catch (Exception e) {
failures.incrementAndGet();
if (quitOnFailure.get()) {
return;