Search in sources :

Example 1 with VisorNodeDataCollectorTaskResult

use of org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskResult in project ignite by apache.

the class CacheGroupsMetricsRebalanceTest method testRebalanceProgressUnderLoad.

/**
 * @throws Exception If failed.
 */
@Test
public void testRebalanceProgressUnderLoad() throws Exception {
    Ignite ignite = startGrids(4);
    IgniteCache<Object, Object> cache1 = ignite.cache(CACHE1);
    Random r = new Random();
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 100_000; i++) {
                int next = r.nextInt();
                cache1.put(next, CACHE1 + "-" + next);
            }
        }
    });
    IgniteEx ig = startGrid(4);
    GridTestUtils.runAsync(new Runnable() {

        @Override
        public void run() {
            for (int i = 0; i < 100_000; i++) {
                int next = r.nextInt();
                cache1.put(next, CACHE1 + "-" + next);
            }
        }
    });
    CountDownLatch latch = new CountDownLatch(1);
    ig.events().localListen(new IgnitePredicate<Event>() {

        @Override
        public boolean apply(Event evt) {
            latch.countDown();
            return false;
        }
    }, EventType.EVT_CACHE_REBALANCE_STOPPED);
    latch.await();
    VisorNodeDataCollectorTaskArg taskArg = new VisorNodeDataCollectorTaskArg();
    taskArg.setCacheGroups(Collections.emptySet());
    VisorTaskArgument<VisorNodeDataCollectorTaskArg> arg = new VisorTaskArgument<>(Collections.singletonList(ignite.cluster().localNode().id()), taskArg, false);
    GridTestUtils.waitForCondition(new GridAbsPredicate() {

        @Override
        public boolean apply() {
            VisorNodeDataCollectorTaskResult res = ignite.compute().execute(VisorNodeDataCollectorTask.class, arg);
            CacheMetrics snapshot = ig.cache(CACHE1).metrics();
            return snapshot.getRebalancedKeys() > snapshot.getEstimatedRebalancingKeys() && Double.compare(res.getRebalance().get(ignite.cluster().localNode().id()), 1.0) == 0 && snapshot.getRebalancingPartitionsCount() == 0;
        }
    }, 5000);
}
Also used : CacheMetrics(org.apache.ignite.cache.CacheMetrics) GridAbsPredicate(org.apache.ignite.internal.util.lang.GridAbsPredicate) CountDownLatch(java.util.concurrent.CountDownLatch) Random(java.util.Random) VisorNodeDataCollectorTask(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTask) IgniteEx(org.apache.ignite.internal.IgniteEx) VisorNodeDataCollectorTaskResult(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskResult) Event(org.apache.ignite.events.Event) VisorTaskArgument(org.apache.ignite.internal.visor.VisorTaskArgument) Ignite(org.apache.ignite.Ignite) VisorNodeDataCollectorTaskArg(org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskArg) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Aggregations

Random (java.util.Random)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Ignite (org.apache.ignite.Ignite)1 CacheMetrics (org.apache.ignite.cache.CacheMetrics)1 Event (org.apache.ignite.events.Event)1 IgniteEx (org.apache.ignite.internal.IgniteEx)1 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)1 VisorTaskArgument (org.apache.ignite.internal.visor.VisorTaskArgument)1 VisorNodeDataCollectorTask (org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTask)1 VisorNodeDataCollectorTaskArg (org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskArg)1 VisorNodeDataCollectorTaskResult (org.apache.ignite.internal.visor.node.VisorNodeDataCollectorTaskResult)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1 Test (org.junit.Test)1