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