Search in sources :

Example 21 with Person

use of org.apache.ignite.client.Person in project ignite by apache.

the class DropIndexTest method testCorrectTaskExecute.

/**
 * Checking that the {@link DurableBackgroundCleanupIndexTreeTaskV2} will work correctly.
 *
 * @throws Exception If failed.
 */
@Test
public void testCorrectTaskExecute() throws Exception {
    IgniteEx n = startGrid(0);
    IgniteCache<Integer, Person> cache = n.cache(DEFAULT_CACHE_NAME);
    populate(cache, 100);
    String idxName = "IDX0";
    createIdx(cache, idxName);
    GridCacheContext<Integer, Person> cctx = cacheContext(cache);
    Index idx = index(n, cache, idxName);
    SortedIndexDefinition idxDef = indexDefinition(idx);
    InlineIndexTree[] trees = segments(idx);
    Map<Integer, RootPage> rootPages = toRootPages(trees);
    for (int i = 0; i < trees.length; i++) {
        InlineIndexTree tree = trees[i];
        assertEquals(new FullPageId(tree.getMetaPageId(), tree.groupId()), rootPages.get(i).pageId());
    }
    String oldTreeName = idxDef.treeName();
    String newTreeName = UUID.randomUUID().toString();
    int segments = idxDef.segments();
    assertFalse(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    DurableBackgroundCleanupIndexTreeTaskV2 task = new DurableBackgroundCleanupIndexTreeTaskV2(cctx.group().name(), cctx.name(), idxName, oldTreeName, newTreeName, segments, trees);
    assertTrue(task.name().startsWith(taskNamePrefix(cctx.name(), idxName)));
    assertTrue(getFieldValue(task, "needToRen"));
    GridFutureAdapter<Void> startFut = new GridFutureAdapter<>();
    GridFutureAdapter<Void> endFut = new GridFutureAdapter<>();
    idxTreeFactory = taskIndexTreeFactoryEx(startFut, endFut);
    IgniteInternalFuture<DurableBackgroundTaskResult<Long>> taskFut = task.executeAsync(n.context());
    startFut.get(getTestTimeout());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertFalse(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    endFut.onDone();
    DurableBackgroundTaskResult<Long> res = taskFut.get(getTestTimeout());
    assertTrue(res.completed());
    assertNull(res.error());
    assertTrue(res.result() >= 3);
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), oldTreeName, segments).isEmpty());
    assertTrue(findIndexRootPages(cctx.group(), cctx.name(), newTreeName, segments).isEmpty());
    assertFalse(getFieldValue(task, "needToRen"));
}
Also used : SortedIndexDefinition(org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition) InlineIndexTree(org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexTree) Index(org.apache.ignite.internal.cache.query.index.Index) DurableBackgroundTaskResult(org.apache.ignite.internal.processors.cache.persistence.metastorage.pendingtask.DurableBackgroundTaskResult) DurableBackgroundCleanupIndexTreeTaskV2(org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2) IgniteEx(org.apache.ignite.internal.IgniteEx) RootPage(org.apache.ignite.internal.processors.cache.persistence.RootPage) GridFutureAdapter(org.apache.ignite.internal.util.future.GridFutureAdapter) Person(org.apache.ignite.client.Person) FullPageId(org.apache.ignite.internal.pagemem.FullPageId) Test(org.junit.Test)

Aggregations

Person (org.apache.ignite.client.Person)21 IgniteEx (org.apache.ignite.internal.IgniteEx)12 Test (org.junit.Test)12 SortedIndexDefinition (org.apache.ignite.internal.cache.query.index.sorted.SortedIndexDefinition)7 RootPage (org.apache.ignite.internal.processors.cache.persistence.RootPage)5 HashMap (java.util.HashMap)3 IgniteClient (org.apache.ignite.client.IgniteClient)3 DurableBackgroundCleanupIndexTreeTaskV2 (org.apache.ignite.internal.cache.query.index.sorted.DurableBackgroundCleanupIndexTreeTaskV2)3 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 Index (org.apache.ignite.internal.cache.query.index.Index)2 FullPageId (org.apache.ignite.internal.pagemem.FullPageId)2 IndexRenameRootPageRecord (org.apache.ignite.internal.pagemem.wal.record.IndexRenameRootPageRecord)2 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1