@Test
public void testRequestResourceLeakage() throws InterruptedException, ExecutionException {

    ExecutorService threadPool = Executors.newFixedThreadPool(200);
    // Hang on to each DXHTTPRequest. This is our proxy to simulate a system where GC is not
    // happening often enough to free up the file handles in a timely manner
    List<DXHTTPRequest> requests = Lists.newArrayList();
    List<Future<String>> futures = Lists.newArrayList();
    for (int i = 0; i < 5000; ++i) {
        final DXHTTPRequest req = new DXHTTPRequest();
        requests.add(req);
        Future<String> f = threadPool.submit(new Callable<String>() {
            @Override
            public String call() throws Exception {
                // Same as the implementation of DXAPI.systemWhoami, except allows us to hold on
                // to the DXHTTPRequest object being used.
                WhoamiResponse response = DXJSON.safeTreeToValue(req.request("/system/whoami",
                        mapper.valueToTree(new WhoamiRequest()), RetryStrategy.SAFE_TO_RETRY),
                        WhoamiResponse.class);
                return response.id;
            }
        });
        futures.add(f);
    }
    threadPool.shutdown();
    threadPool.awaitTermination(1000, TimeUnit.SECONDS);
}