@Test
    public void testAsyncFetch() throws InterruptedException, ExecutionException, TimeoutException {
        LocalAsyncSession session = access.createAsyncSession(new AsyncParameters());
        List<DocumentId> ids = new ArrayList<>();
        ids.add(new DocumentId("id:music:music::1"));
        ids.add(new DocumentId("id:music:music::2"));
        ids.add(new DocumentId("id:music:music::3"));
        for (DocumentId id : ids)
            session.put(new Document(access.getDocumentTypeManager().getDocumentType("music"), id));

        // Let all async operations wait for a signal from the test thread before sending their responses, and let test
        // thread wait for all responses to be delivered afterwards.
        Phaser phaser = new Phaser(1);
        access.setPhaser(phaser);

        long startTime = System.currentTimeMillis();
        int timeoutMillis = 1000;
        Set<Long> outstandingRequests = new HashSet<>();
        for (DocumentId id : ids) {
            Result result = session.get(id);
            if ( ! result.isSuccess())
                throw new IllegalStateException("Failed requesting document " + id + ": " + result.error().toString());
            outstandingRequests.add(result.getRequestId());
        }

        // Wait for responses in separate thread.
        Future<?> futureWithAssertions = Executors.newSingleThreadExecutor().submit(() -> {
            try {
                List<Document> documents = new ArrayList<>();
                while ( ! outstandingRequests.isEmpty()) {
                    int timeSinceStart = (int) (System.currentTimeMillis() - startTime);
                    Response response = session.getNext(timeoutMillis - timeSinceStart);
                    if (response == null)
                        throw new RuntimeException("Timed out waiting for documents"); // or return what you have
                    if ( ! outstandingRequests.contains(response.getRequestId())) continue; // Stale: Ignore

                    if (response.isSuccess())
                        documents.add(((DocumentResponse) response).getDocument());
                    outstandingRequests.remove(response.getRequestId());
                }
                assertEquals(3, documents.size());
                for (Document document : documents)
                    assertNotNull(document);
            }
            catch (InterruptedException e) {
                throw new IllegalArgumentException("Interrupted while waiting for responses");
            }
        });

        // All operations, and receiver, now waiting for this thread to arrive.
        assertEquals(4, phaser.getRegisteredParties());
        assertEquals(0, phaser.getPhase());
        phaser.arriveAndAwaitAdvance();
        assertEquals(1, phaser.getPhase());
        phaser.awaitAdvance(phaser.arriveAndDeregister());

        futureWithAssertions.get(1000, TimeUnit.MILLISECONDS);
    }
Runs the superclass tests on this implementation

@author bratseth
documentapi/src/test/java/com/yahoo/documentapi/local/LocalDocumentApiTestCase.java