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);
}
}
Aggregations