use of org.apache.geode.cache.lucene.internal.repository.RepositoryManager in project geode by apache.
the class LuceneIndexRecoveryHAIntegrationTest method recoverRepoInANewNode.
/**
* On rebalance, new repository manager will be created. It will try to read fileAndChunkRegion
* and construct index. This test simulates the same.
*/
// @Test
public void recoverRepoInANewNode() throws BucketNotFoundException, IOException, InterruptedException {
LuceneServiceImpl service = (LuceneServiceImpl) LuceneServiceProvider.get(cache);
service.createIndexFactory().setFields(indexedFields).create("index1", "/userRegion");
PartitionAttributes<String, String> attrs = new PartitionAttributesFactory().setTotalNumBuckets(1).create();
RegionFactory<String, String> regionfactory = cache.createRegionFactory(RegionShortcut.PARTITION);
regionfactory.setPartitionAttributes(attrs);
PartitionedRegion userRegion = (PartitionedRegion) regionfactory.create("userRegion");
LuceneIndexForPartitionedRegion index = (LuceneIndexForPartitionedRegion) service.getIndex("index1", "/userRegion");
// put an entry to create the bucket
userRegion.put("rebalance", "test");
service.waitUntilFlushed("index1", "userRegion", 30000, TimeUnit.MILLISECONDS);
RepositoryManager manager = new PartitionedRepositoryManager((LuceneIndexImpl) index, mapper);
IndexRepository repo = manager.getRepository(userRegion, 0, null);
assertNotNull(repo);
repo.create("rebalance", "test");
repo.commit();
// close the region to simulate bucket movement. New node will create repo using data persisted
// by old region
// ((PartitionedRegion)index.fileAndChunkRegion).close();
// ((PartitionedRegion)index.chunkRegion).close();
userRegion.close();
userRegion = (PartitionedRegion) regionfactory.create("userRegion");
userRegion.put("rebalance", "test");
manager = new PartitionedRepositoryManager((LuceneIndexImpl) index, mapper);
IndexRepository newRepo = manager.getRepository(userRegion, 0, null);
Assert.assertNotEquals(newRepo, repo);
}
use of org.apache.geode.cache.lucene.internal.repository.RepositoryManager in project geode by apache.
the class LuceneEventListenerJUnitTest method shouldThrowAndCaptureIOException.
@Test
public void shouldThrowAndCaptureIOException() throws BucketNotFoundException {
RepositoryManager manager = Mockito.mock(RepositoryManager.class);
Mockito.when(manager.getRepository(any(), any(), any())).thenThrow(IOException.class);
AtomicReference<Throwable> lastException = new AtomicReference<>();
LuceneEventListener.setExceptionObserver(lastException::set);
LuceneEventListener listener = new LuceneEventListener(manager);
AsyncEvent event = Mockito.mock(AsyncEvent.class);
try {
listener.processEvents(Arrays.asList(new AsyncEvent[] { event }));
fail("should have thrown an exception");
} catch (InternalGemFireError expected) {
assertEquals(expected, lastException.get());
}
}
Aggregations