final int timeout = 1000;
final int serverDelay = timeout * 15;
System.clearProperty(IHttpClient.SYSPROP_OPENSHIFT_READ_TIMEOUT);
String timeoutBackup = System.getProperty(IHttpClient.SYSPROP_DEFAULT_READ_TIMEOUT);
System.setProperty(IHttpClient.SYSPROP_DEFAULT_READ_TIMEOUT, String.valueOf(timeout));
WaitingHttpServerFake serverFake = startWaitingHttpServerFake(serverDelay);
long startTime = System.currentTimeMillis();
// operations
try {
httpClient.get(serverFake.getUrl(), IHttpClient.NO_TIMEOUT);
fail("Timeout expected.");
} catch (SocketTimeoutException e) {
// assert
assertThat(System.currentTimeMillis() - startTime).isGreaterThan(timeout)
.isLessThan(serverDelay)
.isLessThan(IHttpClient.DEFAULT_READ_TIMEOUT);
} finally {
serverFake.stop();
restoreSystemProperty(IHttpClient.SYSPROP_DEFAULT_READ_TIMEOUT, timeoutBackup);
}
}