@Override
    public <T extends Response> CompletableFuture<T> sendAsync(
            Request request, Class<T> responseType) {

        CompletableFuture<T> result = new CompletableFuture<>();
        long requestId = request.getId();
        requestForId.put(requestId, new WebSocketRequest<>(result, responseType));
        try {
            sendRequest(request, requestId);
        } catch (IOException e) {
            closeRequest(requestId, e);
        }

        return result;
    }
@Test
    public void testCancelRequestAfterTimeout() {
        when(executorService.schedule(
                        any(Runnable.class),
                        eq(WebSocketService.REQUEST_TIMEOUT),
                        eq(TimeUnit.SECONDS)))
                .then(
                        invocation -> {
                            Runnable runnable = invocation.getArgument(0, Runnable.class);
                            runnable.run();
                            return null;
                        });

        CompletableFuture<Web3ClientVersion> reply =
                service.sendAsync(request, Web3ClientVersion.class);

        assertTrue(reply.isDone());
        assertThrows(ExecutionException.class, () -> reply.get());
    }