Search in sources :

Example 6 with LuceneService

use of org.apache.geode.cache.lucene.LuceneService 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 7 with LuceneService

use of org.apache.geode.cache.lucene.LuceneService 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 8 with LuceneService

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

the class LuceneIndexCommandsDUnitTest method createIndex.

private void createIndex(final VM vm1) {
    vm1.invoke(() -> {
        LuceneService luceneService = LuceneServiceProvider.get(getCache());
        Map<String, Analyzer> fieldAnalyzers = new HashMap();
        fieldAnalyzers.put("field1", new StandardAnalyzer());
        fieldAnalyzers.put("field2", new KeywordAnalyzer());
        fieldAnalyzers.put("field3", null);
        luceneService.createIndexFactory().setFields(fieldAnalyzers).create(INDEX_NAME, REGION_NAME);
        createRegion();
    });
}
Also used : KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) HashMap(java.util.HashMap) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) KeywordAnalyzer(org.apache.lucene.analysis.core.KeywordAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) LuceneService(org.apache.geode.cache.lucene.LuceneService)

Example 9 with LuceneService

use of org.apache.geode.cache.lucene.LuceneService 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 LuceneService

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

the class LuceneIndexXmlGeneratorIntegrationJUnitTest method generateWithFields.

/**
   * Test of generating and reading cache configuration back in.
   */
@Test
public void generateWithFields() {
    cache = new CacheFactory().set(MCAST_PORT, "0").create();
    LuceneService service = LuceneServiceProvider.get(cache);
    service.createIndexFactory().setFields("a", "b", "c").create("index", "region");
    cache.createRegionFactory(RegionShortcut.PARTITION).create("region");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    PrintWriter pw = new PrintWriter(baos);
    CacheXmlGenerator.generate(cache, pw, true, false, false);
    pw.flush();
    cache.close();
    cache = new CacheFactory().set(MCAST_PORT, "0").create();
    byte[] bytes = baos.toByteArray();
    ByteArrayInputStream in = new ByteArrayInputStream(bytes);
    System.out.println("---FILE---");
    System.out.println(new String(bytes, Charset.defaultCharset()));
    cache.loadCacheXml(new ByteArrayInputStream(bytes));
    LuceneService service2 = LuceneServiceProvider.get(cache);
    assertTrue(service != service2);
    LuceneIndex index = service2.getIndex("index", "region");
    assertNotNull(index);
    assertArrayEquals(new String[] { "a", "b", "c" }, index.getFieldNames());
}
Also used : LuceneIndex(org.apache.geode.cache.lucene.LuceneIndex) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CacheFactory(org.apache.geode.cache.CacheFactory) LuceneService(org.apache.geode.cache.lucene.LuceneService) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) IntegrationTest(org.apache.geode.test.junit.categories.IntegrationTest)

Aggregations

LuceneService (org.apache.geode.cache.lucene.LuceneService)23 LuceneIndex (org.apache.geode.cache.lucene.LuceneIndex)10 Test (org.junit.Test)10 DistributedTest (org.apache.geode.test.junit.categories.DistributedTest)6 Analyzer (org.apache.lucene.analysis.Analyzer)6 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)6 Cache (org.apache.geode.cache.Cache)5 KeywordAnalyzer (org.apache.lucene.analysis.core.KeywordAnalyzer)5 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)4 VM (org.apache.geode.test.dunit.VM)4 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)4 LuceneIndexImpl (org.apache.geode.cache.lucene.internal.LuceneIndexImpl)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 CacheFactory (org.apache.geode.cache.CacheFactory)2 Region (org.apache.geode.cache.Region)2 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)2 LuceneServiceImpl (org.apache.geode.cache.lucene.internal.LuceneServiceImpl)2 CliFunctionResult (org.apache.geode.management.internal.cli.functions.CliFunctionResult)2 MemberVM (org.apache.geode.test.dunit.rules.MemberVM)2