use of org.apache.geode.cache.lucene.internal.repository.IndexRepository in project geode by apache.
the class RawIndexRepositoryFactory method computeIndexRepository.
@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
final IndexRepository repo;
if (oldRepository != null) {
oldRepository.cleanup();
}
LuceneRawIndex indexForRaw = (LuceneRawIndex) index;
BucketRegion dataBucket = getMatchingBucket(userRegion, bucketId);
Directory dir = null;
if (indexForRaw.withPersistence()) {
String bucketLocation = LuceneServiceImpl.getUniqueIndexName(index.getName(), index.getRegionPath() + "_" + bucketId);
File location = new File(index.getName(), bucketLocation);
if (!location.exists()) {
location.mkdirs();
}
dir = new NIOFSDirectory(location.toPath());
} else {
dir = new RAMDirectory();
}
IndexWriterConfig config = new IndexWriterConfig(indexForRaw.getAnalyzer());
IndexWriter writer = new IndexWriter(dir, config);
return new IndexRepositoryImpl(null, writer, serializer, indexForRaw.getIndexStats(), dataBucket, null, "");
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepository in project geode by apache.
the class LuceneQueryFunctionJUnitTest method createMocksAndCommonObjects.
@Before
public void createMocksAndCommonObjects() throws Exception {
mockContext = mock(InternalRegionFunctionContext.class);
mockResultSender = mock(ResultSender.class);
mockRegion = mock(Region.class);
mockRepoManager = mock(RepositoryManager.class);
mockRepository1 = mock(IndexRepository.class, "repo1");
mockRepository2 = mock(IndexRepository.class, "repo2");
mockCollector = mock(IndexResultCollector.class);
mockStats = mock(LuceneIndexStats.class);
repos = new ArrayList<IndexRepository>();
repos.add(mockRepository1);
repos.add(mockRepository2);
mockIndex = mock(LuceneIndexImpl.class);
mockService = mock(InternalLuceneService.class);
mockCache = mock(InternalCache.class);
Analyzer analyzer = new StandardAnalyzer();
Mockito.doReturn(analyzer).when(mockIndex).getAnalyzer();
queryProvider = new StringQueryProvider("gemfire:lucene", DEFAULT_FIELD);
searchArgs = new LuceneFunctionContext<IndexResultCollector>(queryProvider, "indexName");
when(mockRegion.getCache()).thenReturn(mockCache);
when(mockRegion.getFullPath()).thenReturn(regionPath);
when(mockCache.getService(any())).thenReturn(mockService);
when(mockService.getIndex(eq("indexName"), eq(regionPath))).thenReturn(mockIndex);
when(mockIndex.getRepositoryManager()).thenReturn(mockRepoManager);
when(mockIndex.getFieldNames()).thenReturn(new String[] { "gemfire" });
when(mockIndex.getIndexStats()).thenReturn(mockStats);
query = queryProvider.getQuery(mockIndex);
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepository in project geode by apache.
the class DumpDirectoryFilesJUnitTest method createMocks.
@Before
public void createMocks() throws BucketNotFoundException {
GemFireCacheImpl cache = Fakes.cache();
context = mock(RegionFunctionContext.class);
ResultSender sender = mock(ResultSender.class);
Region region = mock(Region.class);
InternalLuceneService service = mock(InternalLuceneService.class);
InternalLuceneIndex index = mock(InternalLuceneIndex.class);
RepositoryManager repoManager = mock(RepositoryManager.class);
IndexRepository repo = mock(IndexRepository.class);
IndexWriter writer = mock(IndexWriter.class);
RegionDirectory directory = mock(RegionDirectory.class);
fileSystem = mock(FileSystem.class);
Region bucket = mock(Region.class);
when(bucket.getFullPath()).thenReturn(bucketName);
when(context.getArguments()).thenReturn(new String[] { directoryName, indexName });
when(context.getResultSender()).thenReturn(sender);
when(context.getDataSet()).thenReturn(region);
when(region.getCache()).thenReturn(cache);
when(cache.getService(any())).thenReturn(service);
when(repoManager.getRepositories(eq(context))).thenReturn(Collections.singleton(repo));
when(index.getRepositoryManager()).thenReturn(repoManager);
when(index.getName()).thenReturn(indexName);
when(service.getIndex(eq(indexName), any())).thenReturn(index);
when(directory.getFileSystem()).thenReturn(fileSystem);
when(writer.getDirectory()).thenReturn(directory);
when(repo.getWriter()).thenReturn(writer);
when(repo.getRegion()).thenReturn(bucket);
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepository in project geode by apache.
the class LuceneEventListenerJUnitTest method testProcessBatch.
@Test
public void testProcessBatch() throws Exception {
RepositoryManager manager = Mockito.mock(RepositoryManager.class);
IndexRepository repo1 = Mockito.mock(IndexRepository.class);
IndexRepository repo2 = Mockito.mock(IndexRepository.class);
Region region1 = Mockito.mock(Region.class);
Region region2 = Mockito.mock(Region.class);
Object callback1 = new Object();
Mockito.when(manager.getRepository(eq(region1), any(), eq(callback1))).thenReturn(repo1);
Mockito.when(manager.getRepository(eq(region2), any(), eq(null))).thenReturn(repo2);
LuceneEventListener listener = new LuceneEventListener(manager);
List<AsyncEvent> events = new ArrayList<AsyncEvent>();
int numEntries = 100;
for (int i = 0; i < numEntries; i++) {
AsyncEvent event = Mockito.mock(AsyncEvent.class);
Region region = i % 2 == 0 ? region1 : region2;
Object callback = i % 2 == 0 ? callback1 : null;
Mockito.when(event.getRegion()).thenReturn(region);
Mockito.when(event.getKey()).thenReturn(i);
Mockito.when(event.getCallbackArgument()).thenReturn(callback);
switch(i % 4) {
case 0:
case 1:
final EntrySnapshot entry = mock(EntrySnapshot.class);
when(entry.getRawValue(true)).thenReturn(i);
when(region.getEntry(eq(i))).thenReturn(entry);
break;
case 2:
case 3:
// Do nothing, get value will return a destroy
break;
}
events.add(event);
}
listener.processEvents(events);
verify(repo1, atLeast(numEntries / 4)).delete(any());
verify(repo1, atLeast(numEntries / 4)).update(any(), any());
verify(repo2, atLeast(numEntries / 4)).delete(any());
verify(repo2, atLeast(numEntries / 4)).update(any(), any());
verify(repo1, times(1)).commit();
verify(repo2, times(1)).commit();
}
use of org.apache.geode.cache.lucene.internal.repository.IndexRepository in project geode by apache.
the class IndexRepositorySpy method computeIndexRepository.
@Override
public IndexRepository computeIndexRepository(final Integer bucketId, LuceneSerializer serializer, LuceneIndexImpl index, PartitionedRegion userRegion, IndexRepository oldRepository) throws IOException {
LuceneIndexForPartitionedRegion indexForPR = (LuceneIndexForPartitionedRegion) index;
final IndexRepository indexRepo = super.computeIndexRepository(bucketId, serializer, index, userRegion, oldRepository);
if (indexRepo == null) {
return null;
}
if (mockingDetails(indexRepo).isSpy()) {
return indexRepo;
}
final IndexRepository spy = Mockito.spy(indexRepo);
Answer invokeBeforeWrite = invocation -> {
beforeWrite.accept(invocation.getArgumentAt(0, Object.class));
return invocation.callRealMethod();
};
doAnswer(invokeBeforeWrite).when(spy).update(any(), any());
doAnswer(invokeBeforeWrite).when(spy).create(any(), any());
doAnswer(invokeBeforeWrite).when(spy).delete(any());
return spy;
}
Aggregations