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"));
}
Aggregations