use of ddf.catalog.source.Source in project ddf by codice.
the class CachingFederationStrategyTest method testFederateQueryUpdateCacheBlocking.
@Test
public void testFederateQueryUpdateCacheBlocking() throws Exception {
properties.put(QUERY_MODE, INDEX_QUERY_MODE);
QueryRequest fedQueryRequest = new QueryRequestImpl(mockQuery, properties);
Source mockSource = mock(Source.class);
when(mockSource.query(any(QueryRequest.class))).thenReturn(mockResponse);
doNothing().when(cacheCommitPhaser).add(cacheArgs.capture());
QueryResponse federateResponse = strategy.federate(Arrays.asList(mockSource), fedQueryRequest);
assertThat(requestArgumentCaptor.getValue().getPropertyValue(QUERY_MODE), is(INDEX_QUERY_MODE));
verify(mockSource).query(any(QueryRequest.class));
verify(cache, times(0)).query(any(QueryRequest.class));
// CacheCommitPhaser.add() is called
verify(cacheCommitPhaser).add(cacheArgs.getValue());
verifyCacheUpdated();
assertThat(federateResponse.getRequest().getQuery(), is(requestArgumentCaptor.getValue().getQuery()));
}
use of ddf.catalog.source.Source in project ddf by codice.
the class CachingFederationStrategyTest method testValidCollectionWithNullSource.
@Test(expected = IllegalArgumentException.class)
public void testValidCollectionWithNullSource() throws Exception {
List<Source> sources = new ArrayList<>();
sources.add(null);
QueryRequest fedQueryRequest = mock(QueryRequest.class);
when(fedQueryRequest.getQuery()).thenReturn(mockQuery);
strategy.federate(sources, fedQueryRequest);
}
use of ddf.catalog.source.Source in project ddf by codice.
the class CachingFederationStrategyTest method testFederateDuplicateSources.
@Test
public void testFederateDuplicateSources() throws Exception {
Query mockQ = new QueryImpl(mock(NullFilterImpl.class), 2, 2, mock(SortBy.class), true, LONG_TIMEOUT);
QueryRequest fedQueryRequest = new QueryRequestImpl(mockQ, properties);
List<Source> sources = new ArrayList<>();
// Multiple sources needed for OffsetResultHandler to be used
for (int i = 0; i < 2; i++) {
Source mockSource = mock(Source.class);
when(mockSource.getId()).thenReturn("mock source");
sources.add(mockSource);
}
strategy.federate(sources, fedQueryRequest);
verify(sources.get(0), atLeastOnce()).query(any(QueryRequest.class));
verify(sources.get(1), times(0)).query(any(QueryRequest.class));
}
use of ddf.catalog.source.Source in project ddf by codice.
the class TestQueryMonitor method generateActiveSearch.
private ActiveSearch generateActiveSearch(String name, String uuid) {
Source source = mock(Source.class);
doReturn(SOURCE).when(source).getId();
Date date = new Date();
ActiveSearch activeSearch = mock(ActiveSearch.class);
doReturn(source).when(activeSearch).getSource();
doReturn(name).when(activeSearch).getClientInfo();
doReturn(CQL).when(activeSearch).getCQL();
doReturn(date).when(activeSearch).getStartTime();
doReturn(UUID.fromString(uuid)).when(activeSearch).getUniqueID();
return activeSearch;
}
use of ddf.catalog.source.Source in project ddf by codice.
the class SourceOperations method isSourceAvailable.
//
// Helper methods - check visibility
//
/**
* Checks that the specified source is valid and available.
*
* @param source the {@link Source} to check availability of
* @return true if the {@link Source} is available, false otherwise
*/
boolean isSourceAvailable(Source source) {
if (source == null) {
LOGGER.debug("source is null, therefore not available");
return false;
}
try {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Checking if source \"{}\" is available...", source.getId());
}
// source is considered available unless we have checked and seen otherwise
boolean available = true;
Source cachedSource = frameworkProperties.getSourcePoller().getCachedSource(source);
if (cachedSource != null) {
available = cachedSource.isAvailable();
}
if (!available) {
LOGGER.info("source \"{}\" is not available", source.getId());
}
return available;
} catch (ServiceUnavailableException e) {
LOGGER.info("Caught ServiceUnavaiableException", e);
return false;
} catch (Exception e) {
LOGGER.info("Caught Exception", e);
return false;
}
}
Aggregations