Search in sources :

Example 6 with RepositoryManager

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);
}
Also used : IndexRepository(org.apache.geode.cache.lucene.internal.repository.IndexRepository) PartitionedRegion(org.apache.geode.internal.cache.PartitionedRegion) RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager)

Example 7 with RepositoryManager

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());
    }
}
Also used : RepositoryManager(org.apache.geode.cache.lucene.internal.repository.RepositoryManager) AtomicReference(java.util.concurrent.atomic.AtomicReference) AsyncEvent(org.apache.geode.cache.asyncqueue.AsyncEvent) InternalGemFireError(org.apache.geode.InternalGemFireError) UnitTest(org.apache.geode.test.junit.categories.UnitTest) Test(org.junit.Test)

Aggregations

RepositoryManager (org.apache.geode.cache.lucene.internal.repository.RepositoryManager)7 IndexRepository (org.apache.geode.cache.lucene.internal.repository.IndexRepository)5 Region (org.apache.geode.cache.Region)3 AsyncEvent (org.apache.geode.cache.asyncqueue.AsyncEvent)3 RegionFunctionContext (org.apache.geode.cache.execute.RegionFunctionContext)3 BucketNotFoundException (org.apache.geode.internal.cache.BucketNotFoundException)3 UnitTest (org.apache.geode.test.junit.categories.UnitTest)3 Test (org.junit.Test)3 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 InternalLuceneIndex (org.apache.geode.cache.lucene.internal.InternalLuceneIndex)2 FileSystem (org.apache.geode.cache.lucene.internal.filesystem.FileSystem)2 IndexWriter (org.apache.lucene.index.IndexWriter)2 File (java.io.File)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 InternalGemFireError (org.apache.geode.InternalGemFireError)1 CacheClosedException (org.apache.geode.cache.CacheClosedException)1 FunctionException (org.apache.geode.cache.execute.FunctionException)1 ResultSender (org.apache.geode.cache.execute.ResultSender)1 LuceneIndexNotFoundException (org.apache.geode.cache.lucene.LuceneIndexNotFoundException)1