use of okhttp3.OkUrlFactory in project okhttp by square.
the class ResponseCacheTest method setUp.
@Before
public void setUp() throws Exception {
server.setProtocolNegotiationEnabled(false);
cache = AndroidShimResponseCache.create(cacheRule.getRoot(), 10 * 1024 * 1024);
urlFactory = new OkUrlFactory(new OkHttpClient());
AndroidInternal.setResponseCache(urlFactory, cache);
cookieManager = new CookieManager();
}
use of okhttp3.OkUrlFactory in project okhttp by square.
the class DisconnectTest method interruptReadingResponseBody.
@Test
public void interruptReadingResponseBody() throws Exception {
// 2 MiB
int responseBodySize = 2 * 1024 * 1024;
server.enqueue(new MockResponse().setBody(new Buffer().write(new byte[responseBodySize])).throttleBody(64 * 1024, 125, // 500 Kbps
TimeUnit.MILLISECONDS));
server.start();
HttpURLConnection connection = new OkUrlFactory(client).open(server.url("/").url());
disconnectLater(connection, 500);
InputStream responseBody = connection.getInputStream();
byte[] buffer = new byte[1024];
try {
while (responseBody.read(buffer) != -1) {
}
fail("Expected connection to be closed");
} catch (IOException expected) {
}
responseBody.close();
}
use of okhttp3.OkUrlFactory in project okhttp by square.
the class ThreadInterruptTest method interruptWritingRequestBody.
@Test
public void interruptWritingRequestBody() throws Exception {
// 2 MiB
int requestBodySize = 2 * 1024 * 1024;
server.enqueue(new MockResponse().throttleBody(64 * 1024, 125, // 500 Kbps
TimeUnit.MILLISECONDS));
server.start();
interruptLater(500);
HttpURLConnection connection = new OkUrlFactory(client).open(server.url("/").url());
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(requestBodySize);
OutputStream requestBody = connection.getOutputStream();
byte[] buffer = new byte[1024];
try {
for (int i = 0; i < requestBodySize; i += buffer.length) {
requestBody.write(buffer);
requestBody.flush();
}
fail("Expected thread to be interrupted");
} catch (InterruptedIOException expected) {
}
connection.disconnect();
}
Aggregations