Search in sources :

Example 6 with LuceneIndex

use of org.apache.geode.cache.lucene.LuceneIndex in project geode by apache.

the class LuceneClusterConfigurationDUnitTest method indexWithAnalyzerGetsCreatedUsingClusterConfiguration.

@Test
public void indexWithAnalyzerGetsCreatedUsingClusterConfiguration() throws Exception {
    startNodeUsingClusterConfiguration(1);
    // Connect Gfsh to locator.
    gfshConnector.connectAndVerify(locator);
    // Create lucene index.
    // createLuceneIndexUsingGfsh();
    createLuceneIndexWithAnalyzerUsingGfsh(false);
    createRegionUsingGfsh(REGION_NAME, RegionShortcut.PARTITION, null);
    // Start vm2. This should have lucene index created using cluster
    // configuration.
    MemberVM vm2 = startNodeUsingClusterConfiguration(2);
    vm2.invoke(() -> {
        LuceneService luceneService = LuceneServiceProvider.get(LocatorServerStartupRule.serverStarter.getCache());
        final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
        assertNotNull(index);
        String[] fields = new String[] { "field1", "field2", "field3" };
        validateIndexFields(fields, index);
        // Add this check back when we complete xml generation for analyzer.
        validateIndexFieldAnalyzer(fields, new String[] { "org.apache.lucene.analysis.standard.StandardAnalyzer", "org.apache.lucene.analysis.standard.StandardAnalyzer", "org.apache.lucene.analysis.standard.StandardAnalyzer" }, index);
    });
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) MemberVM(org.apache.geode.test.dunit.rules.MemberVM) LuceneService(org.apache.geode.cache.lucene.LuceneService) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 7 with LuceneIndex

use of org.apache.geode.cache.lucene.LuceneIndex in project geode by apache.

the class LuceneIndexCommandsDUnitTest method createIndexShouldCreateANewIndex.

@Test
public void createIndexShouldCreateANewIndex() throws Exception {
    final VM vm1 = Host.getHost(0).getVM(1);
    vm1.invoke(() -> {
        getCache();
    });
    CommandStringBuilder csb = new CommandStringBuilder(LuceneCliStrings.LUCENE_CREATE_INDEX);
    csb.addOption(LuceneCliStrings.LUCENE__INDEX_NAME, INDEX_NAME);
    csb.addOption(LuceneCliStrings.LUCENE__REGION_PATH, REGION_NAME);
    csb.addOption(LuceneCliStrings.LUCENE_CREATE_INDEX__FIELD, "field1,field2,field3");
    String resultAsString = executeCommandAndLogResult(csb);
    vm1.invoke(() -> {
        LuceneService luceneService = LuceneServiceProvider.get(getCache());
        createRegion();
        final LuceneIndex index = luceneService.getIndex(INDEX_NAME, REGION_NAME);
        assertArrayEquals(new String[] { "field1", "field2", "field3" }, index.getFieldNames());
    });
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) CommandStringBuilder(org.apache.geode.management.internal.cli.util.CommandStringBuilder) VM(org.apache.geode.test.dunit.VM) LuceneService(org.apache.geode.cache.lucene.LuceneService) Test(org.junit.Test) DistributedTest(org.apache.geode.test.junit.categories.DistributedTest)

Example 8 with LuceneIndex

use of org.apache.geode.cache.lucene.LuceneIndex in project geode by apache.

the class LuceneIndexRecoveryHAIntegrationTest method verifyIndexFinishFlushing.

private void verifyIndexFinishFlushing(String indexName, String regionName) throws InterruptedException {
    LuceneService service = LuceneServiceProvider.get(cache);
    LuceneIndex index = service.getIndex(indexName, regionName);
    boolean flushed = service.waitUntilFlushed(indexName, regionName, 60000, TimeUnit.MILLISECONDS);
    assertTrue(flushed);
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Example 9 with LuceneIndex

use of org.apache.geode.cache.lucene.LuceneIndex in project geode by apache.

the class LuceneTestUtilities method verifyIndexFinishFlushing.

public static void verifyIndexFinishFlushing(Cache cache, String indexName, String regionName) throws InterruptedException {
    LuceneService luceneService = LuceneServiceProvider.get(cache);
    LuceneIndex index = luceneService.getIndex(indexName, regionName);
    boolean flushed = luceneService.waitUntilFlushed(indexName, regionName, 60000, TimeUnit.MILLISECONDS);
    assertTrue(flushed);
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Example 10 with LuceneIndex

use of org.apache.geode.cache.lucene.LuceneIndex in project geode by apache.

the class LuceneIndexXmlGeneratorJUnitTest method generateWithFields.

/**
   * Test of generating and reading cache configuration back in.
   */
@Test
public void generateWithFields() throws Exception {
    LuceneIndex index = mock(LuceneIndex.class);
    when(index.getName()).thenReturn("index");
    String[] fields = new String[] { "field1", "field2" };
    when(index.getFieldNames()).thenReturn(fields);
    LuceneIndexXmlGenerator generator = new LuceneIndexXmlGenerator(index);
    CacheXmlGenerator cacheXmlGenerator = mock(CacheXmlGenerator.class);
    ContentHandler handler = mock(ContentHandler.class);
    when(cacheXmlGenerator.getContentHandler()).thenReturn(handler);
    generator.generate(cacheXmlGenerator);
    ArgumentCaptor<Attributes> captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler).startElement(eq(""), eq("index"), eq("lucene:index"), captor.capture());
    Attributes value = captor.getValue();
    assertEquals("index", value.getValue(LuceneXmlConstants.NAME));
    captor = ArgumentCaptor.forClass(Attributes.class);
    verify(handler, times(2)).startElement(eq(""), eq("field"), eq("lucene:field"), captor.capture());
    Set<String> foundFields = new HashSet<String>();
    for (Attributes fieldAttr : captor.getAllValues()) {
        foundFields.add(fieldAttr.getValue(LuceneXmlConstants.NAME));
    }
    HashSet<String> expected = new HashSet<String>(Arrays.asList(fields));
    assertEquals(expected, foundFields);
    verify(handler, times(2)).endElement(eq(""), eq("field"), eq("lucene:field"));
    verify(handler).endElement(eq(""), eq("index"), eq("lucene:index"));
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) CacheXmlGenerator(org.apache.geode.internal.cache.xmlcache.CacheXmlGenerator) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) HashSet(java.util.HashSet) Test(org.junit.Test) UnitTest(org.apache.geode.test.junit.categories.UnitTest)

Aggregations

LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)16 LuceneService (org.apache.geode.cache.lucene.LuceneService)10 Test (org.junit.Test)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)4 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)4 VM (org.apache.geode.test.dunit.VM)4 ArrayList (java.util.ArrayList)3 Cache (org.apache.geode.cache.Cache)3 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)3 LuceneIndexDetails (org.apache.geode.cache.lucene.internal.cli.LuceneIndexDetails)3 Analyzer (org.apache.lucene.analysis.Analyzer)3 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)3 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)3 HashSet (java.util.HashSet)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 LuceneIndexCreationProfile (org.apache.geode.cache.lucene.internal.LuceneIndexCreationProfile)2 MemberVM (org.apache.geode.test.dunit.rules.MemberVM)2 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)2 UnitTest (org.apache.geode.test.junit.categories.UnitTest)2