Search in sources :

Example 16 with Source

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()));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 17 with Source

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);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 18 with Source

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));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) NullFilterImpl(org.geotools.filter.NullFilterImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 19 with Source

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;
}
Also used : ActiveSearch(org.codice.ddf.resourcemanagement.query.plugin.ActiveSearch) Source(ddf.catalog.source.Source) Date(java.util.Date)

Example 20 with Source

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;
    }
}
Also used : ServiceUnavailableException(org.osgi.service.blueprint.container.ServiceUnavailableException) Source(ddf.catalog.source.Source) FederatedSource(ddf.catalog.source.FederatedSource) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) ServiceUnavailableException(org.osgi.service.blueprint.container.ServiceUnavailableException)

Aggregations

Source (ddf.catalog.source.Source)46 Test (org.junit.Test)24 QueryRequest (ddf.catalog.operation.QueryRequest)22 ArrayList (java.util.ArrayList)16 FederatedSource (ddf.catalog.source.FederatedSource)15 QueryResponse (ddf.catalog.operation.QueryResponse)14 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)11 Result (ddf.catalog.data.Result)10 CatalogProvider (ddf.catalog.source.CatalogProvider)10 ContentType (ddf.catalog.data.ContentType)9 Query (ddf.catalog.operation.Query)9 SourceResponse (ddf.catalog.operation.SourceResponse)9 CachedSource (ddf.catalog.util.impl.CachedSource)8 SourcePoller (ddf.catalog.util.impl.SourcePoller)8 ByteSource (com.google.common.io.ByteSource)7 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)7 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)7 SourceDescriptor (ddf.catalog.source.SourceDescriptor)6 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)6 HashMap (java.util.HashMap)6