Search in sources :

Example 11 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl 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 MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.

the class PredicateTest method testGeospatialPredicateNullMetadata.

@Test
public void testGeospatialPredicateNullMetadata() throws IOException {
    String methodName = "testGeospatialPredicateNullMetadata()";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    String geometryWkt = "POLYGON ((40 34, 40 33, 44.5 33, 44.5 34, 40 34))";
    String operation = "overlaps";
    double distance = 0.0;
    GeospatialPredicate predicate = new GeospatialPredicate(geometryWkt, operation, distance);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setLocation("POINT (41 34)");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    // No Contextual map added to properties containing indexed metadata
    Event testEvent = new Event("topic", properties);
    assertTrue(predicate.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 13 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.

the class PredicateTest method testContentTypeEvaluationNullOperation.

@Test
public void testContentTypeEvaluationNullOperation() throws IOException {
    String methodName = "testContentTypeEvaluationNullOperation";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    ContentTypePredicate ctp = new ContentTypePredicate("type1", "version1");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, null);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    Event testEvent = new Event("topic", properties);
    assertTrue(ctp.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 14 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.

the class PredicateTest method testContentTypeEvaluation.

@Test
public void testContentTypeEvaluation() throws IOException {
    String methodName = "testContentTypeEvaluation";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    // test input that has type1:version1 matches
    // test input that has type1:version2 doesn't match
    // TODO: tests input that has type2:version1 doesn't match
    // TODO: test input that has type1:""
    // TODO: test input that has "":""
    // TODO: test input that has "":version1
    // TODO: test UNKNOWN for entire contentType String
    MetacardImpl metacard = new MetacardImpl();
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    ContentTypePredicate ctp = new ContentTypePredicate("type1", "version1");
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    Event testEvent = new Event("topic", properties);
    assertTrue(ctp.matches(testEvent));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version2");
    Event testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, ",version2");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, ",");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "UNKNOWN");
    testEvent1 = new Event("topic1", properties);
    assertFalse(ctp.matches(testEvent1));
    // TODO: test input type1:version1 matches
    // TODO: test input type1:someversion matches
    // TODO: test input type2:version1 doesn't match
    ContentTypePredicate ctp2 = new ContentTypePredicate("type1", null);
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,version1");
    Event testEvent2 = new Event("topic", properties);
    assertTrue(ctp2.matches(testEvent2));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type1,someversion");
    Event testEvent3 = new Event("topic", properties);
    assertTrue(ctp2.matches(testEvent3));
    properties.clear();
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_CONTENT_TYPE_KEY, "type2,someversion");
    Event testEvent4 = new Event("topic", properties);
    assertFalse(ctp2.matches(testEvent4));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : HashMap(java.util.HashMap) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 15 with MetacardImpl

use of ddf.catalog.data.impl.MetacardImpl in project ddf by codice.

the class PredicateTest method testContextualQuery.

@Test
public void testContextualQuery() throws Exception {
    String methodName = "testContextualQuery";
    LOGGER.debug("***************  START: {}  *****************", methodName);
    String searchPhrase = "serengeti event";
    MockQuery query = new MockQuery();
    query.addContextualFilter(searchPhrase, null);
    SubscriptionFilterVisitor visitor = new SubscriptionFilterVisitor();
    Predicate predicate = (Predicate) query.getFilter().accept(visitor, null);
    MetacardImpl metacard = new MetacardImpl();
    metacard.setId("ABC123");
    metacard.setMetadata(TestDataLibrary.getCatAndDogEntry());
    HashMap<String, Object> properties = new HashMap<>();
    properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    Map<String, Object> contextualMap = constructContextualMap(metacard);
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    // Above Pulled from PubSubProviderImpl
    Event testEvent = new Event("topic", properties);
    assertTrue(predicate.matches(testEvent));
    contextualMap.clear();
    properties.clear();
    metacard.setMetadata(TestDataLibrary.getDogEntry());
    Directory index1 = ContextualEvaluator.buildIndex(metacard.getMetadata());
    contextualMap.put("DEFAULT_INDEX", index1);
    contextualMap.put("METADATA", metacard.getMetadata());
    properties.put(PubSubConstants.HEADER_CONTEXTUAL_KEY, contextualMap);
    properties.put(PubSubConstants.HEADER_ID_KEY, metacard.getId());
    properties.put(PubSubConstants.HEADER_ENTRY_KEY, metacard);
    properties.put(PubSubConstants.HEADER_OPERATION_KEY, PubSubConstants.CREATE);
    testEvent = new Event("topic", properties);
    assertFalse(predicate.matches(testEvent));
    LOGGER.debug("***************  END: {}  *****************", methodName);
}
Also used : SubscriptionFilterVisitor(ddf.catalog.pubsub.internal.SubscriptionFilterVisitor) HashMap(java.util.HashMap) Event(org.osgi.service.event.Event) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) GeospatialPredicate(ddf.catalog.pubsub.predicate.GeospatialPredicate) ContentTypePredicate(ddf.catalog.pubsub.predicate.ContentTypePredicate) Predicate(ddf.catalog.pubsub.predicate.Predicate) Directory(org.apache.lucene.store.Directory) Test(org.junit.Test)

Aggregations

MetacardImpl (ddf.catalog.data.impl.MetacardImpl)384 Test (org.junit.Test)247 Metacard (ddf.catalog.data.Metacard)144 ArrayList (java.util.ArrayList)102 Result (ddf.catalog.data.Result)62 HashMap (java.util.HashMap)59 Date (java.util.Date)52 ResultImpl (ddf.catalog.data.impl.ResultImpl)51 AttributeImpl (ddf.catalog.data.impl.AttributeImpl)49 URI (java.net.URI)38 Matchers.anyString (org.mockito.Matchers.anyString)38 QueryRequest (ddf.catalog.operation.QueryRequest)36 QueryResponse (ddf.catalog.operation.QueryResponse)35 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)35 Serializable (java.io.Serializable)33 HashSet (java.util.HashSet)31 QueryImpl (ddf.catalog.operation.impl.QueryImpl)29 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)28 AttributeDescriptor (ddf.catalog.data.AttributeDescriptor)27 List (java.util.List)27