@Test
public void testServerDisconnect()
throws Exception
{
try (ScopedNiftyServer server = makeServer()) {
final NiftyClient niftyClient = new NiftyClient();
scribe.Client client = makeNiftyClient(niftyClient, server);
new Thread()
{
@Override
public void run()
{
try {
sleep(1000L);
server.close();
}
catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (Exception e) {
Throwables.propagate(e);
}
}
}.start();
int max = (int) (Math.random() * 100) + 10;
int exceptionCount = 0;
for (int i = 0; i < max; i++) {
Thread.sleep(100L);
try {
client.Log(Arrays.asList(new LogEntry("hello", "world " + i)));
}
catch (TException e) {
log.info("caught expected exception " + e.toString());
exceptionCount++;
}
}
Assert.assertTrue(exceptionCount > 0);
niftyClient.close();
}
}