use of org.apache.geode.internal.cache.BucketRegion 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.internal.cache.BucketRegion in project geode by apache.
the class PartitionedRepositoryManagerJUnitTest method setUpMockBucket.
protected BucketRegion setUpMockBucket(int id) throws BucketNotFoundException {
BucketRegion mockBucket = Mockito.mock(BucketRegion.class);
BucketRegion fileAndChunkBucket = Mockito.mock(BucketRegion.class);
// Allowing the fileAndChunkBucket to behave like a map so that the IndexWriter operations don't
// fail
Fakes.addMapBehavior(fileAndChunkBucket);
when(fileAndChunkBucket.getFullPath()).thenReturn("File" + id);
when(mockBucket.getId()).thenReturn(id);
when(userRegion.getBucketRegion(eq(id), eq(null))).thenReturn(mockBucket);
when(userDataStore.getLocalBucketById(eq(id))).thenReturn(mockBucket);
when(userRegion.getBucketRegion(eq(id + 113), eq(null))).thenReturn(mockBucket);
when(userDataStore.getLocalBucketById(eq(id + 113))).thenReturn(mockBucket);
when(fileDataStore.getLocalBucketById(eq(id))).thenReturn(fileAndChunkBucket);
fileAndChunkBuckets.put(id, fileAndChunkBucket);
dataBuckets.put(id, mockBucket);
BucketAdvisor mockBucketAdvisor = Mockito.mock(BucketAdvisor.class);
when(fileAndChunkBucket.getBucketAdvisor()).thenReturn(mockBucketAdvisor);
when(mockBucketAdvisor.isPrimary()).thenReturn(true);
return mockBucket;
}
use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.
the class IndexRepositoryImplJUnitTest method setUp.
@Before
public void setUp() throws IOException {
ConcurrentHashMap fileAndChunkRegion = new ConcurrentHashMap();
fileSystemStats = mock(FileSystemStats.class);
RegionDirectory dir = new RegionDirectory(fileAndChunkRegion, fileSystemStats);
IndexWriterConfig config = new IndexWriterConfig(analyzer);
writer = new IndexWriter(dir, config);
String[] indexedFields = new String[] { "s", "i", "l", "d", "f", "s2", "missing" };
mapper = new HeterogeneousLuceneSerializer(indexedFields);
region = Mockito.mock(Region.class);
userRegion = Mockito.mock(BucketRegion.class);
BucketAdvisor bucketAdvisor = Mockito.mock(BucketAdvisor.class);
Mockito.when(bucketAdvisor.isPrimary()).thenReturn(true);
Mockito.when(((BucketRegion) userRegion).getBucketAdvisor()).thenReturn(bucketAdvisor);
Mockito.when(((BucketRegion) userRegion).getBucketAdvisor().isPrimary()).thenReturn(true);
stats = Mockito.mock(LuceneIndexStats.class);
Mockito.when(userRegion.isDestroyed()).thenReturn(false);
repo = new IndexRepositoryImpl(region, writer, mapper, stats, userRegion, mock(DistributedLockService.class), "lockName");
}
use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.
the class WANTestBase method addCacheListenerOnBucketRegion.
private void addCacheListenerOnBucketRegion(String regionName, int numBuckets) {
PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
for (int i = 0; i < numBuckets; i++) {
BucketRegion br = region.getBucketRegion(i);
AttributesMutator mutator = br.getAttributesMutator();
listener1 = new QueueListener();
mutator.addCacheListener(listener1);
}
}
use of org.apache.geode.internal.cache.BucketRegion in project geode by apache.
the class WANTestBase method checkBR.
public static HashMap checkBR(String regionName, int numBuckets) {
PartitionedRegion region = (PartitionedRegion) cache.getRegion(regionName);
HashMap listenerAttrs = new HashMap();
for (int i = 0; i < numBuckets; i++) {
BucketRegion br = region.getBucketRegion(i);
QueueListener listener = (QueueListener) br.getCacheListener();
listenerAttrs.put("Create" + i, listener.createList);
listenerAttrs.put("Update" + i, listener.updateList);
listenerAttrs.put("Destroy" + i, listener.destroyList);
}
return listenerAttrs;
}
Aggregations