Search in sources :

Example 1 with FrameworkProperties

use of ddf.catalog.impl.FrameworkProperties in project ddf by codice.

the class FederationStrategyTest method testQueryTimeout.

/**
     * Tests that the framework properly times out using the default federation strategy.
     */
@Test
public void testQueryTimeout() throws Exception {
    long queryDelay = 100;
    UuidGenerator uuidGenerator = mock(UuidGenerator.class);
    when(uuidGenerator.generateUuid()).thenReturn(UUID.randomUUID().toString());
    MockDelayProvider provider = new MockDelayProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<ContentType>(), true, new Date());
    provider.setQueryDelayMillis(queryDelay);
    // Mock register the provider in the container
    SourcePollerRunner runner = new SourcePollerRunner();
    SourcePoller poller = new SourcePoller(runner);
    runner.bind(provider);
    // Must have more than one thread or sleeps will block the monitor
    SortedFederationStrategy fedStrategy = new SortedFederationStrategy(executor, new ArrayList<>(), new ArrayList<>());
    FrameworkProperties props = new FrameworkProperties();
    props.setCatalogProviders(Collections.singletonList(provider));
    props.setFederationStrategy(fedStrategy);
    props.setSourcePoller(poller);
    props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    props.setFilterBuilder(new GeotoolsFilterBuilder());
    props.setDefaultAttributeValueRegistry(new DefaultAttributeValueRegistryImpl());
    OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
    MetacardFactory metacardFactory = new MetacardFactory(props.getMimeTypeToTransformerMapper(), uuidGenerator);
    OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(props, metacardFactory);
    Historian historian = new Historian();
    historian.setHistoryEnabled(false);
    SourceOperations sourceOperations = new SourceOperations(props);
    QueryOperations queryOperations = new QueryOperations(props, sourceOperations, opsSecurity, opsMetacard);
    OperationsStorageSupport opsStorage = new OperationsStorageSupport(sourceOperations, queryOperations);
    OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(props, sourceOperations);
    CreateOperations createOperations = new CreateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    UpdateOperations updateOperations = new UpdateOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard, opsCatStore, opsStorage);
    DeleteOperations deleteOperations = new DeleteOperations(props, queryOperations, sourceOperations, opsSecurity, opsMetacard);
    opsStorage.setHistorian(historian);
    updateOperations.setHistorian(historian);
    deleteOperations.setHistorian(historian);
    deleteOperations.setOpsCatStoreSupport(opsCatStore);
    CatalogFrameworkImpl framework = new CatalogFrameworkImpl(createOperations, updateOperations, deleteOperations, queryOperations, null, null, null);
    sourceOperations.bind(provider);
    List<Metacard> metacards = new ArrayList<Metacard>();
    MetacardImpl newCard = new MetacardImpl();
    newCard.setId(null);
    metacards.add(newCard);
    CreateResponse createResponse = null;
    try {
        try {
            createResponse = framework.create(new CreateRequestImpl(metacards, null));
        } catch (SourceUnavailableException e) {
            long timeout = System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(10);
            //this is a hack because the unit test is flaky and should be removed once a better test is possible
            while (System.currentTimeMillis() < timeout) {
                Thread.sleep(1000);
                try {
                    createResponse = framework.create(new CreateRequestImpl(metacards, null));
                    break;
                } catch (SourceUnavailableException e1) {
                //ignore
                }
            }
        }
        if (createResponse == null) {
            fail();
        }
    } catch (IngestException e) {
        fail();
    }
    assertEquals(createResponse.getCreatedMetacards().size(), provider.size());
    for (Metacard curCard : createResponse.getCreatedMetacards()) {
        assertNotNull(curCard.getId());
    }
    QueryImpl query = new QueryImpl(filterFactory.equals(filterFactory.property(Metacard.ID), filterFactory.literal(createResponse.getCreatedMetacards().get(0).getId())));
    query.setTimeoutMillis(SHORT_TIMEOUT);
    query.setSortBy(new FilterFactoryImpl().sort(Result.RELEVANCE, SortOrder.ASCENDING));
    QueryRequest fedQueryRequest = new QueryRequestImpl(query);
    try {
        QueryResponse response = framework.query(fedQueryRequest);
        assertEquals("Timeout should happen before results return", 0, response.getHits());
    } catch (UnsupportedQueryException e) {
        fail();
    } catch (FederationException e) {
        LOGGER.error("Unexpected federation exception during test", e);
        fail();
    }
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UuidGenerator(org.codice.ddf.platform.util.uuidgenerator.UuidGenerator) ContentType(ddf.catalog.data.ContentType) CreateResponse(ddf.catalog.operation.CreateResponse) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) ArrayList(java.util.ArrayList) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor) SourcePoller(ddf.catalog.util.impl.SourcePoller) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) QueryImpl(ddf.catalog.operation.impl.QueryImpl) OperationsStorageSupport(ddf.catalog.impl.operations.OperationsStorageSupport) SourcePollerRunner(ddf.catalog.util.impl.SourcePollerRunner) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) IngestException(ddf.catalog.source.IngestException) Historian(ddf.catalog.history.Historian) FrameworkProperties(ddf.catalog.impl.FrameworkProperties) DefaultAttributeValueRegistryImpl(ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl) MockDelayProvider(ddf.catalog.impl.MockDelayProvider) SourceOperations(ddf.catalog.impl.operations.SourceOperations) QueryRequest(ddf.catalog.operation.QueryRequest) FederationException(ddf.catalog.federation.FederationException) Date(java.util.Date) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) CatalogFrameworkImpl(ddf.catalog.impl.CatalogFrameworkImpl) Metacard(ddf.catalog.data.Metacard) QueryOperations(ddf.catalog.impl.operations.QueryOperations) UpdateOperations(ddf.catalog.impl.operations.UpdateOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) CreateRequestImpl(ddf.catalog.operation.impl.CreateRequestImpl) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) CreateOperations(ddf.catalog.impl.operations.CreateOperations) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 2 with FrameworkProperties

use of ddf.catalog.impl.FrameworkProperties in project ddf by codice.

the class ResourceOperationsOptionsTest method setUpFrameworkProperties.

private void setUpFrameworkProperties() {
    frameworkProperties = new FrameworkProperties();
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setPostResource(mockPostResourcePlugins);
    frameworkProperties.setFederationStrategy(mockFederationStrategy);
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPreResource(new ArrayList<>());
    frameworkProperties.setPostResource(new ArrayList<>());
    frameworkProperties.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(new MimeTypeMapperImpl(Collections.singletonList(mimeTypeResolver)));
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
}
Also used : FrameworkProperties(ddf.catalog.impl.FrameworkProperties) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor)

Example 3 with FrameworkProperties

use of ddf.catalog.impl.FrameworkProperties in project ddf by codice.

the class SourceOperationsTest method testGettingSourceActions.

@Test
public void testGettingSourceActions() throws SourceUnavailableException {
    Action action = mock(Action.class);
    FrameworkProperties frameworkProperties = mock(FrameworkProperties.class);
    CatalogProvider catalogProvider = mock(CatalogProvider.class);
    when(frameworkProperties.getCatalogProviders()).thenReturn(Collections.singletonList(catalogProvider));
    ActionRegistry actionRegistry = mock(ActionRegistry.class);
    when(actionRegistry.list(any(Source.class))).thenReturn(Collections.singletonList(action));
    final SourcePoller<SourceStatus> mockStatusSourcePoller = mock(SourcePoller.class);
    when(mockStatusSourcePoller.getCachedValueForSource(isA(Source.class))).thenReturn(Optional.empty());
    SourceOperations sourceOperations = new SourceOperations(frameworkProperties, actionRegistry, mockStatusSourcePoller, mock(SourcePoller.class));
    sourceOperations.bind((CatalogProvider) null);
    SourceInfoRequest sourceInfoRequest = mock(SourceInfoRequest.class);
    SourceInfoResponse sourceInfoResponse = sourceOperations.getSourceInfo(sourceInfoRequest, true);
    assertThat(sourceInfoResponse.getSourceInfo(), hasSize(1));
    SourceDescriptor sourceDescriptor = sourceInfoResponse.getSourceInfo().toArray(new SourceDescriptor[0])[0];
    assertThat(sourceDescriptor.getActions(), is(Collections.singletonList(action)));
}
Also used : FrameworkProperties(ddf.catalog.impl.FrameworkProperties) Action(ddf.action.Action) SourceDescriptor(ddf.catalog.source.SourceDescriptor) CatalogProvider(ddf.catalog.source.CatalogProvider) SourceStatus(org.codice.ddf.catalog.sourcepoller.SourceStatus) SourceInfoRequest(ddf.catalog.operation.SourceInfoRequest) ActionRegistry(ddf.action.ActionRegistry) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Source(ddf.catalog.source.Source) SourcePoller(org.codice.ddf.catalog.sourcepoller.SourcePoller) Test(org.junit.Test)

Example 4 with FrameworkProperties

use of ddf.catalog.impl.FrameworkProperties in project ddf by codice.

the class RemoteDeleteOperationsTest method setUpFrameworkProperties.

private void setUpFrameworkProperties() {
    frameworkProperties = new FrameworkProperties();
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
    frameworkProperties.setPostResource(mockPostResourcePlugins);
    frameworkProperties.setFederationStrategy(mockFederationStrategy);
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPreResource(new ArrayList<>());
    frameworkProperties.setPostResource(new ArrayList<>());
    frameworkProperties.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(new MimeTypeMapperImpl(Collections.singletonList(mimeTypeResolver)));
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
}
Also used : FrameworkProperties(ddf.catalog.impl.FrameworkProperties) CatalogProvider(ddf.catalog.source.CatalogProvider) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor)

Example 5 with FrameworkProperties

use of ddf.catalog.impl.FrameworkProperties in project ddf by codice.

the class ResourceOperationsTest method setUpFrameworkProperties.

private void setUpFrameworkProperties() {
    frameworkProperties = new FrameworkProperties();
    frameworkProperties.setAccessPlugins(new ArrayList<>());
    frameworkProperties.setPolicyPlugins(new ArrayList<>());
    frameworkProperties.setPostResource(mockPostResourcePlugins);
    frameworkProperties.setFederationStrategy(mockFederationStrategy);
    frameworkProperties.setFilterBuilder(new GeotoolsFilterBuilder());
    frameworkProperties.setPreIngest(new ArrayList<>());
    frameworkProperties.setPostIngest(postIngestPlugins);
    frameworkProperties.setPreQuery(new ArrayList<>());
    frameworkProperties.setPostQuery(new ArrayList<>());
    frameworkProperties.setPreResource(new ArrayList<>());
    frameworkProperties.setPostResource(new ArrayList<>());
    frameworkProperties.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
    frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
    frameworkProperties.setMimeTypeMapper(new MimeTypeMapperImpl(Collections.singletonList(mimeTypeResolver)));
    frameworkProperties.setMimeTypeToTransformerMapper(mimeTypeToTransformerMapper);
}
Also used : FrameworkProperties(ddf.catalog.impl.FrameworkProperties) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) MimeTypeMapperImpl(ddf.mime.mapper.MimeTypeMapperImpl) QueryResponsePostProcessor(ddf.catalog.impl.QueryResponsePostProcessor)

Aggregations

FrameworkProperties (ddf.catalog.impl.FrameworkProperties)5 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)4 QueryResponsePostProcessor (ddf.catalog.impl.QueryResponsePostProcessor)4 MimeTypeMapperImpl (ddf.mime.mapper.MimeTypeMapperImpl)3 CatalogProvider (ddf.catalog.source.CatalogProvider)2 Test (org.junit.Test)2 Action (ddf.action.Action)1 ActionRegistry (ddf.action.ActionRegistry)1 ContentType (ddf.catalog.data.ContentType)1 Metacard (ddf.catalog.data.Metacard)1 DefaultAttributeValueRegistryImpl (ddf.catalog.data.defaultvalues.DefaultAttributeValueRegistryImpl)1 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 FederationException (ddf.catalog.federation.FederationException)1 Historian (ddf.catalog.history.Historian)1 CatalogFrameworkImpl (ddf.catalog.impl.CatalogFrameworkImpl)1 MockDelayProvider (ddf.catalog.impl.MockDelayProvider)1 CreateOperations (ddf.catalog.impl.operations.CreateOperations)1 DeleteOperations (ddf.catalog.impl.operations.DeleteOperations)1 MetacardFactory (ddf.catalog.impl.operations.MetacardFactory)1 OperationsCatalogStoreSupport (ddf.catalog.impl.operations.OperationsCatalogStoreSupport)1