Search in sources :

Example 11 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl 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 12 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class MetacardsMigratable method export.

/**
     * Exports all the metacards currently stored in the catalog framework.
     * <p>
     * {@inheritDoc}
     */
@Override
@NotNull
public MigrationMetadata export(@NotNull Path exportPath) throws MigrationException {
    config.setExportPath(exportPath.resolve(this.getId()));
    fileWriter.createExportDirectory(config.getExportPath());
    Collection<MigrationWarning> warnings = new ArrayList<>();
    Map<String, Serializable> props = createMapWithNativeQueryMode();
    Filter dumpFilter = filterBuilder.attribute(Metacard.ANY_TEXT).is().like().text("*");
    QueryImpl exportQuery = new QueryImpl(dumpFilter);
    exportQuery.setPageSize(config.getExportQueryPageSize());
    exportQuery.setRequestsTotalResultsCount(false);
    QueryRequest exportQueryRequest = new QueryRequestImpl(exportQuery, props);
    try {
        executeQueryLoop(exportQuery, exportQueryRequest);
    } catch (Exception e) {
        LOGGER.info("Internal error occurred when exporting catalog: {}", e);
        throw new ExportMigrationException(DEFAULT_FAILURE_MESSAGE);
    } finally {
        cleanup();
    }
    return new MigrationMetadata(warnings);
}
Also used : MigrationWarning(org.codice.ddf.migration.MigrationWarning) Serializable(java.io.Serializable) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) MigrationMetadata(org.codice.ddf.migration.MigrationMetadata) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) MigrationException(org.codice.ddf.migration.MigrationException) ExportMigrationException(org.codice.ddf.migration.ExportMigrationException) FederationException(ddf.catalog.federation.FederationException) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) NotNull(javax.validation.constraints.NotNull)

Example 13 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class CatalogMetricsTest method catalogExceptionMetric.

@Test
public void catalogExceptionMetric() throws Exception {
    QueryResponse response = new QueryResponseImpl(new QueryRequestImpl(new QueryImpl(idFilter)));
    Set<ProcessingDetails> details = response.getProcessingDetails();
    details.addAll(new HashSet<ProcessingDetails>() {

        {
            add(new ProcessingDetailsImpl("source1", new UnsupportedQueryException()));
            add(new ProcessingDetailsImpl("source2", new SourceUnavailableException()));
            add(new ProcessingDetailsImpl("source3", new FederationException()));
            add(new ProcessingDetailsImpl("source4", new Exception()));
        }
    });
    underTest.process(response);
    assertThat(underTest.exceptions.getCount(), is(4L));
    assertThat(underTest.unsupportedQueryExceptions.getCount(), is(1L));
    assertThat(underTest.sourceUnavailableExceptions.getCount(), is(1L));
    assertThat(underTest.federationExceptions.getCount(), is(1L));
}
Also used : ProcessingDetails(ddf.catalog.operation.ProcessingDetails) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryResponse(ddf.catalog.operation.QueryResponse) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) ProcessingDetailsImpl(ddf.catalog.operation.impl.ProcessingDetailsImpl) SourceUnavailableException(ddf.catalog.source.SourceUnavailableException) UnsupportedQueryException(ddf.catalog.source.UnsupportedQueryException) FederationException(ddf.catalog.federation.FederationException) Test(org.junit.Test)

Example 14 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class CatalogMetricsTest method catalogTemporalQueryMetric.

@Test
public void catalogTemporalQueryMetric() throws Exception {
    Filter temporalFilter = filterBuilder.attribute(Metacard.ANY_DATE).before().date(new Date());
    QueryRequest query = new QueryRequestImpl(new QueryImpl(temporalFilter));
    underTest.process(query);
    assertThat(underTest.temporalQueries.getCount(), is(1L));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Date(java.util.Date) Test(org.junit.Test)

Example 15 with QueryImpl

use of ddf.catalog.operation.impl.QueryImpl in project ddf by codice.

the class CatalogMetricsTest method catalogQueryMetric.

@Test
public void catalogQueryMetric() throws Exception {
    QueryRequest query = new QueryRequestImpl(new QueryImpl(idFilter));
    underTest.process(query);
    assertThat(underTest.queries.getCount(), is(1L));
    assertThat(underTest.comparisonQueries.getCount(), is(1L));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Aggregations

QueryImpl (ddf.catalog.operation.impl.QueryImpl)232 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)186 Test (org.junit.Test)149 Filter (org.opengis.filter.Filter)117 SourceResponse (ddf.catalog.operation.SourceResponse)95 QueryRequest (ddf.catalog.operation.QueryRequest)66 Metacard (ddf.catalog.data.Metacard)61 ArrayList (java.util.ArrayList)50 Result (ddf.catalog.data.Result)49 Matchers.containsString (org.hamcrest.Matchers.containsString)30 Query (ddf.catalog.operation.Query)29 QueryResponse (ddf.catalog.operation.QueryResponse)28 SortByImpl (ddf.catalog.filter.impl.SortByImpl)27 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)25 SortBy (org.opengis.filter.sort.SortBy)25 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)24 Serializable (java.io.Serializable)23 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)22 HashMap (java.util.HashMap)20 Matchers.anyString (org.mockito.Matchers.anyString)20