Search in sources :

Example 1 with CompletionService

use of java.util.concurrent.CompletionService in project ddf by codice.

the class SortedQueryMonitorTest method setUp.

@Before
public void setUp() throws Exception {
    cachingFederationStrategy = mock(CachingFederationStrategy.class);
    completionService = mock(CompletionService.class);
    queryRequest = mock(QueryRequest.class);
    queryResponse = new QueryResponseImpl(queryRequest);
    query = mock(Query.class);
    // Enforce insertion order for testing purposes
    futures = new LinkedHashMap<>();
    for (int i = 0; i < 4; i++) {
        SourceResponse sourceResponseMock = null;
        Future futureMock = mock(Future.class);
        QueryRequest queryRequest = mock(QueryRequest.class);
        when(queryRequest.getSourceIds()).thenReturn(Collections.singleton("Source-" + i));
        switch(i) {
            case 1:
                sourceResponseMock = mock(SourceResponse.class);
                when(sourceResponseMock.getResults()).thenReturn(Lists.newArrayList(mock(Result.class), mock(Result.class), mock(Result.class)));
                when(sourceResponseMock.getHits()).thenReturn(3L);
                break;
            case 2:
                sourceResponseMock = mock(SourceResponse.class);
                when(sourceResponseMock.getResults()).thenReturn(Lists.newArrayList(mock(Result.class)));
                when(sourceResponseMock.getHits()).thenReturn(1L);
                break;
            case 3:
                sourceResponseMock = mock(SourceResponse.class);
                when(sourceResponseMock.getResults()).thenReturn(Lists.<Result>emptyList());
                when(sourceResponseMock.getHits()).thenReturn(0L);
                break;
        }
        when(futureMock.get()).thenReturn(sourceResponseMock);
        futures.put(futureMock, queryRequest);
    }
}
Also used : QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Query(ddf.catalog.operation.Query) SourceResponse(ddf.catalog.operation.SourceResponse) CompletionService(java.util.concurrent.CompletionService) Future(java.util.concurrent.Future) Before(org.junit.Before)

Aggregations

Query (ddf.catalog.operation.Query)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 SourceResponse (ddf.catalog.operation.SourceResponse)1 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)1 CompletionService (java.util.concurrent.CompletionService)1 Future (java.util.concurrent.Future)1 Before (org.junit.Before)1