Search in sources :

Example 1 with MockMetacard

use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.

the class SolrProviderRealTimeQueryTest method testRealTimeQueryMultipleIds.

@Test
public void testRealTimeQueryMultipleIds() throws Exception {
    final String metacardTitle1 = "testRealTimeQueryMultipleIds1";
    final String metacardTitle2 = "testRealTimeQueryMultipleIds2";
    deleteAll(provider);
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setTitle(metacardTitle1);
    MockMetacard metacard2 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setTitle(metacardTitle2);
    List<Metacard> metacards = new ArrayList<>(2);
    metacards.add(metacard1);
    metacards.add(metacard2);
    CreateResponse createResponse = create(metacards, provider);
    List<String> ids = createResponse.getCreatedMetacards().stream().map(m -> m.getId()).collect(Collectors.toList());
    // Real time queries only work when querying by ID, so a real time query by title only will
    // return
    // 0 results.
    queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle1), provider);
    queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle2), provider);
    Filter filter = getFilterBuilder().anyOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(ids.get(0)), getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(ids.get(1)));
    // When performing a real time query by ID, we get the results.
    queryAndVerifyCount(2, filter, provider);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTestUtil.deleteAll(ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) BeforeClass(org.junit.BeforeClass) SolrClient(org.codice.solr.client.solrj.SolrClient) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) LoggerFactory(org.slf4j.LoggerFactory) SolrProviderTestUtil.queryAndVerifyCount(ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount) ArrayList(java.util.ArrayList) BASIC_METACARD(ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Lists(com.google.common.collect.Lists) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SolrProviderTestUtil.create(ddf.catalog.source.solr.provider.SolrProviderTestUtil.create) ClassRule(org.junit.ClassRule) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) Awaitility.await(org.awaitility.Awaitility.await) QueryImpl(ddf.catalog.operation.impl.QueryImpl) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MetacardType(ddf.catalog.data.MetacardType) TimeUnit(java.util.concurrent.TimeUnit) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) List(java.util.List) Rule(org.junit.Rule) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Library(ddf.catalog.source.solr.provider.Library) Paths(java.nio.file.Paths) SolrCloudClientFactory(org.codice.solr.factory.impl.SolrCloudClientFactory) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) SolrProviderTestUtil.getFilterBuilder(ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) Metacard(ddf.catalog.data.Metacard) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 2 with MockMetacard

use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.

the class SolrProviderRealTimeQueryTest method testRealTimeQueryMultipleByIdAndTitle.

@Test
public void testRealTimeQueryMultipleByIdAndTitle() throws Exception {
    final String metacardTitle1 = "testRealTimeQueryMultipleIds1";
    final String metacardTitle2 = "testRealTimeQueryMultipleIds2";
    deleteAll(provider);
    MockMetacard metacard1 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setTitle(metacardTitle1);
    MockMetacard metacard2 = new MockMetacard(Library.getFlagstaffRecord());
    metacard1.setTitle(metacardTitle2);
    List<Metacard> metacards = new ArrayList<>(2);
    metacards.add(metacard1);
    metacards.add(metacard2);
    CreateResponse createResponse = create(metacards, provider);
    List<Metacard> createdMetacards = createResponse.getCreatedMetacards();
    // Real time queries only work when querying by ID, so a query by title only will
    // return 0 results.
    queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle1), provider);
    queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle2), provider);
    // this filter will look like ((id = <id0> AND title = <title0>) OR (id = <id1> AND title =
    // <title1>))
    Filter filter = getFilterBuilder().anyOf(getFilterBuilder().allOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(createdMetacards.get(0).getId()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(createdMetacards.get(0).getTitle())), getFilterBuilder().allOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(createdMetacards.get(1).getId()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(createdMetacards.get(1).getTitle())));
    // When performing a real time query by ID, we get the results.
    queryAndVerifyCount(2, filter, provider);
}
Also used : Metacard(ddf.catalog.data.Metacard) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) ArrayList(java.util.ArrayList) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 3 with MockMetacard

use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.

the class SolrProviderRealTimeQueryTest method testRealTimeQueryNotId.

@Test
public void testRealTimeQueryNotId() throws Exception {
    final String metacardTitle = "testRealTimeQueryNotId";
    deleteAll(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setTitle(metacardTitle);
    CreateResponse createResponse = create(metacard, provider);
    Optional<String> id = createResponse.getCreatedMetacards().stream().map(m -> m.getId()).findFirst();
    assertTrue("Metacard creation failed for metacard with title: " + metacardTitle, id.isPresent());
    // Verify the result is actually visible (searchable) in Solr using a real time query by ID.
    queryAndVerifyCount(1, getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id.get()), provider);
    Filter filter = getFilterBuilder().not(getFilterBuilder().attribute(Metacard.ID).equalTo().text(id.get()));
    // Verify a "not ID query" does not return the result.
    queryAndVerifyCount(0, filter, provider);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTestUtil.deleteAll(ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) BeforeClass(org.junit.BeforeClass) SolrClient(org.codice.solr.client.solrj.SolrClient) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) LoggerFactory(org.slf4j.LoggerFactory) SolrProviderTestUtil.queryAndVerifyCount(ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount) ArrayList(java.util.ArrayList) BASIC_METACARD(ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Lists(com.google.common.collect.Lists) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SolrProviderTestUtil.create(ddf.catalog.source.solr.provider.SolrProviderTestUtil.create) ClassRule(org.junit.ClassRule) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) Awaitility.await(org.awaitility.Awaitility.await) QueryImpl(ddf.catalog.operation.impl.QueryImpl) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MetacardType(ddf.catalog.data.MetacardType) TimeUnit(java.util.concurrent.TimeUnit) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) List(java.util.List) Rule(org.junit.Rule) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Library(ddf.catalog.source.solr.provider.Library) Paths(java.nio.file.Paths) SolrCloudClientFactory(org.codice.solr.factory.impl.SolrCloudClientFactory) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) SolrProviderTestUtil.getFilterBuilder(ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) Filter(org.opengis.filter.Filter) CreateResponse(ddf.catalog.operation.CreateResponse) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 4 with MockMetacard

use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.

the class SolrProviderRealTimeQueryTest method testRealTimeQueryByIdAndTitle.

@Test
public void testRealTimeQueryByIdAndTitle() throws Exception {
    final String metacardTitle = "testRealTimeQueryByIdAndTitle";
    deleteAll(provider);
    MockMetacard metacard = new MockMetacard(Library.getFlagstaffRecord());
    metacard.setTitle(metacardTitle);
    CreateResponse createResponse = create(metacard, provider);
    Optional<String> id = createResponse.getCreatedMetacards().stream().map(m -> m.getId()).findFirst();
    if (!id.isPresent()) {
        Assert.fail("Metacard creation failed for metacard with title: " + metacardTitle);
    }
    // Real time queries only work when querying by ID, so a real time query by title only will
    // return
    // 0 results.
    queryAndVerifyCount(0, getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle), provider);
    // When performing a real time query by ID and title, we get the result.
    queryAndVerifyCount(1, getFilterBuilder().allOf(getFilterBuilder().attribute(Metacard.ID).is().equalTo().text(id.get()), getFilterBuilder().attribute(Metacard.TITLE).is().equalTo().text(metacardTitle)), provider);
}
Also used : QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) SolrProviderTestUtil.deleteAll(ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) BeforeClass(org.junit.BeforeClass) SolrClient(org.codice.solr.client.solrj.SolrClient) MiniSolrCloudCluster(org.apache.solr.cloud.MiniSolrCloudCluster) LoggerFactory(org.slf4j.LoggerFactory) SolrProviderTestUtil.queryAndVerifyCount(ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount) ArrayList(java.util.ArrayList) BASIC_METACARD(ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Lists(com.google.common.collect.Lists) CreateResponse(ddf.catalog.operation.CreateResponse) Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) SolrProviderTestUtil.create(ddf.catalog.source.solr.provider.SolrProviderTestUtil.create) ClassRule(org.junit.ClassRule) JettyConfig(org.apache.solr.client.solrj.embedded.JettyConfig) Awaitility.await(org.awaitility.Awaitility.await) QueryImpl(ddf.catalog.operation.impl.QueryImpl) AfterClass(org.junit.AfterClass) Logger(org.slf4j.Logger) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MetacardType(ddf.catalog.data.MetacardType) TimeUnit(java.util.concurrent.TimeUnit) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) List(java.util.List) Rule(org.junit.Rule) TestCase.assertTrue(junit.framework.TestCase.assertTrue) Library(ddf.catalog.source.solr.provider.Library) Paths(java.nio.file.Paths) SolrCloudClientFactory(org.codice.solr.factory.impl.SolrCloudClientFactory) Optional(java.util.Optional) Filter(org.opengis.filter.Filter) SolrProviderTestUtil.getFilterBuilder(ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder) Assert(org.junit.Assert) TemporaryFolder(org.junit.rules.TemporaryFolder) CreateResponse(ddf.catalog.operation.CreateResponse) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Example 5 with MockMetacard

use of ddf.catalog.source.solr.provider.MockMetacard in project ddf by codice.

the class SolrProviderRealTimeQueryTest method testCommitNrt.

@Test
public void testCommitNrt() throws Exception {
    final String nrtTitle = "testCommitNrt";
    final String nonNrtTitle = "testCommitNonNrt";
    deleteAll(provider);
    MetacardType nrtMetacardType = new MetacardTypeImpl(COMMIT_NRT_TYPE, BASIC_METACARD.getAttributeDescriptors());
    MockMetacard nrtMetacard = new MockMetacard(Library.getFlagstaffRecord(), nrtMetacardType);
    nrtMetacard.setTitle(nrtTitle);
    MockMetacard nonNrtMetacard = new MockMetacard(Library.getFlagstaffRecord());
    nonNrtMetacard.setTitle(nonNrtTitle);
    create(Lists.newArrayList(nrtMetacard, nonNrtMetacard), provider);
    QueryRequest request = new QueryRequestImpl(new QueryImpl(getFilterBuilder().attribute(Metacard.TITLE).is().like().text("testCommit*Nrt")));
    await().pollInterval(100, TimeUnit.MILLISECONDS).atMost(30, TimeUnit.SECONDS).until(() -> provider.query(request).getResults().size() == 2);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) MetacardTypeImpl(ddf.catalog.data.impl.MetacardTypeImpl) MetacardType(ddf.catalog.data.MetacardType) MockMetacard(ddf.catalog.source.solr.provider.MockMetacard) Test(org.junit.Test)

Aggregations

MockMetacard (ddf.catalog.source.solr.provider.MockMetacard)8 Test (org.junit.Test)8 Metacard (ddf.catalog.data.Metacard)7 MetacardType (ddf.catalog.data.MetacardType)7 MetacardTypeImpl (ddf.catalog.data.impl.MetacardTypeImpl)7 CreateResponse (ddf.catalog.operation.CreateResponse)7 QueryRequest (ddf.catalog.operation.QueryRequest)7 QueryImpl (ddf.catalog.operation.impl.QueryImpl)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 ArrayList (java.util.ArrayList)7 Filter (org.opengis.filter.Filter)7 Lists (com.google.common.collect.Lists)6 BASIC_METACARD (ddf.catalog.data.impl.MetacardImpl.BASIC_METACARD)6 GeotoolsFilterAdapterImpl (ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl)6 Library (ddf.catalog.source.solr.provider.Library)6 SolrProviderTestUtil.create (ddf.catalog.source.solr.provider.SolrProviderTestUtil.create)6 SolrProviderTestUtil.deleteAll (ddf.catalog.source.solr.provider.SolrProviderTestUtil.deleteAll)6 SolrProviderTestUtil.getFilterBuilder (ddf.catalog.source.solr.provider.SolrProviderTestUtil.getFilterBuilder)6 SolrProviderTestUtil.queryAndVerifyCount (ddf.catalog.source.solr.provider.SolrProviderTestUtil.queryAndVerifyCount)6 Paths (java.nio.file.Paths)6