@Test public synchronized void deadline() { Timeout timeout = new Timeout(); timeout.deadline(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void timeoutBeforeDeadline() { Timeout timeout = new Timeout(); timeout.timeout(1000, TimeUnit.MILLISECONDS); timeout.deadline(5000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
@Test public synchronized void deadlineBeforeTimeout() { Timeout timeout = new Timeout(); timeout.timeout(5000, TimeUnit.MILLISECONDS); timeout.deadline(1000, TimeUnit.MILLISECONDS); double start = now(); try { timeout.waitUntilNotified(this); fail(); } catch (InterruptedIOException expected) { assertEquals("timeout", expected.getMessage()); } assertElapsed(1000.0, start); }
private String readResponseBody(Response response) { try { BufferedSource bufferedSource = response.body().source(); Timeout timeout = bufferedSource.timeout(); timeout.deadline(1, TimeUnit.SECONDS); return response.body().string(); } catch (IOException ioException) { return "<io exception while parsing body: " + ioException.toString() + ">"; } }
private String readResponseBody(Response response) { try { BufferedSource bufferedSource = response.body().source(); Timeout timeout = bufferedSource.timeout(); timeout.deadline(1, TimeUnit.SECONDS); return response.body().string(); } catch (IOException ioException) { return "<io exception while parsing body: " + ioException.toString() + ">"; } }
try (BufferedSource source = Okio.buffer(Okio.source(process.getInputStream()))) { source.timeout().timeout(30, TimeUnit.SECONDS); source.timeout().deadline(5, TimeUnit.MINUTES); source.readAll(buffer); } catch (IOException e) {