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());
});
}
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);
}
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();
});
}
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);
}
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());
}
Aggregations