Search in sources :

Example 6 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridMultipleVersionsDeploymentSelfTest method testMultipleVersionsP2PDeploy.

/**
     * @throws Exception If test failed.
     */
@SuppressWarnings("unchecked")
public void testMultipleVersionsP2PDeploy() throws Exception {
    try {
        Ignite g1 = startGrid(1);
        Ignite g2 = startGrid(2);
        final CountDownLatch latch = new CountDownLatch(2);
        g2.events().localListen(new IgnitePredicate<Event>() {

            @Override
            public boolean apply(Event evt) {
                info("Received event: " + evt);
                latch.countDown();
                return true;
            }
        }, EVT_TASK_UNDEPLOYED);
        ClassLoader ldr1 = new GridTestClassLoader(Collections.singletonMap("testResource", "1"), getClass().getClassLoader(), EXCLUDE_CLASSES);
        ClassLoader ldr2 = new GridTestClassLoader(Collections.singletonMap("testResource", "2"), getClass().getClassLoader(), EXCLUDE_CLASSES);
        Class<? extends ComputeTask<?, ?>> taskCls1 = (Class<? extends ComputeTask<?, ?>>) ldr1.loadClass(GridDeploymentTestTask.class.getName());
        Class<? extends ComputeTask<?, ?>> taskCls2 = (Class<? extends ComputeTask<?, ?>>) ldr2.loadClass(GridDeploymentTestTask.class.getName());
        g1.compute().localDeployTask(taskCls1, ldr1);
        // Task will wait for the signal.
        ComputeTaskFuture fut1 = executeAsync(g1.compute(), "GridDeploymentTestTask", null);
        assert checkDeployed(g1, "GridDeploymentTestTask");
        // We should wait here when to be sure that job has been started.
        // Since we loader task/job classes with different class loaders we cannot
        // use any kind of mutex because of the illegal state exception.
        // We have to use timer here. DO NOT CHANGE 2 seconds here.
        Thread.sleep(2000);
        // Deploy new one - this should move first task to the obsolete list.
        g1.compute().localDeployTask(taskCls2, ldr2);
        // Task will wait for the signal.
        ComputeTaskFuture fut2 = executeAsync(g1.compute(), "GridDeploymentTestTask", null);
        boolean deployed = checkDeployed(g1, "GridDeploymentTestTask");
        Object res1 = fut1.get();
        Object res2 = fut2.get();
        g1.compute().undeployTask("GridDeploymentTestTask");
        // New one should be deployed.
        assert deployed;
        // Wait for the execution.
        assert res1.equals(1);
        assert res2.equals(2);
        stopGrid(1);
        assert latch.await(3000, MILLISECONDS);
        assert !checkDeployed(g2, "GridDeploymentTestTask");
    } finally {
        stopGrid(2);
        stopGrid(1);
    }
}
Also used : ComputeTask(org.apache.ignite.compute.ComputeTask) CountDownLatch(java.util.concurrent.CountDownLatch) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) Event(org.apache.ignite.events.Event) GridTestClassLoader(org.apache.ignite.testframework.GridTestClassLoader) Ignite(org.apache.ignite.Ignite)

Example 7 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridStealingLoadTest method testStealingLoad.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
public void testStealingLoad() throws Exception {
    final Ignite ignite = grid(0);
    assert ignite != null;
    assert !ignite.cluster().forRemotes().nodes().isEmpty() : "Test requires at least 2 nodes.";
    final UUID stealingNodeId = ignite.cluster().forRemotes().nodes().iterator().next().id();
    info("Set stealing node id to: " + stealingNodeId);
    ignite.compute().localDeployTask(GridStealingLoadTestTask.class, GridStealingLoadTestTask.class.getClassLoader());
    final long end = 2 * 60 * 1000 + System.currentTimeMillis();
    info("Test timeout: " + getTestTimeout() + " ms.");
    info("Thread count: " + getThreadCount());
    final GridLoadTestStatistics stats = new GridLoadTestStatistics();
    final AtomicBoolean failed = new AtomicBoolean(false);
    final AtomicInteger stolen = new AtomicInteger(0);
    GridTestUtils.runMultiThreaded(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            try {
                while (end - System.currentTimeMillis() > 0) {
                    long start = System.currentTimeMillis();
                    // Pass stealing node id.
                    ComputeTaskFuture<?> fut = ignite.compute().withTimeout(20000).execute(GridStealingLoadTestTask.class.getName(), stealingNodeId);
                    stolen.addAndGet((Integer) fut.get());
                    long taskCnt = stats.onTaskCompleted(fut, 1, System.currentTimeMillis() - start);
                    if (taskCnt % 500 == 0)
                        info("Stats [stats=" + stats.toString() + ", stolen=" + stolen + ']');
                }
            } catch (Throwable e) {
                error("Load test failed.", e);
                failed.set(true);
            }
        }
    }, getThreadCount(), "grid-load-test-thread");
    info("Final test statistics: " + stats);
    if (failed.get())
        fail();
    assert stolen.get() != 0 : "No jobs were stolen by stealing node.";
    info("Stolen jobs: " + stolen.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID)

Example 8 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridMultiSplitsRedeployLoadTest method testLoad.

/**
     * Load test grid.
     *
     * @throws Exception If task execution failed.
     */
public void testLoad() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    deployTask(ignite);
    final long end = getTestDurationInMinutes() * 60 * 1000 + System.currentTimeMillis();
    // Warm up.
    ignite.compute().withTimeout(10000).execute(TASK_TYPE_ID, 3);
    info("Load test will be executed for '" + getTestDurationInMinutes() + "' mins.");
    info("Thread count: " + getThreadCount());
    final GridLoadTestStatistics stats = new GridLoadTestStatistics();
    GridTestUtils.runMultiThreaded(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            while (end - System.currentTimeMillis() > 0) {
                int levels = 3;
                int exp = factorial(levels);
                long start = System.currentTimeMillis();
                try {
                    ComputeTaskFuture<Integer> fut = ignite.compute().withTimeout(10000).execute(TASK_TYPE_ID, levels);
                    int res = fut.get();
                    if (res != exp)
                        fail("Received wrong result [expected=" + exp + ", actual=" + res + ']');
                    long taskCnt = stats.onTaskCompleted(fut, exp, System.currentTimeMillis() - start);
                    if (taskCnt % 100 == 0) {
                        try {
                            deployTask(ignite);
                        } catch (Exception e) {
                            error("Failed to deploy grid task.", e);
                            fail();
                        }
                    }
                    if (taskCnt % 500 == 0)
                        info(stats.toString());
                } catch (IgniteException e) {
                    error("Failed to execute grid task.", e);
                    fail();
                }
            }
        }
    }, getThreadCount(), "grid-notaop-load-test");
    info("Final test statistics: " + stats);
}
Also used : IgniteException(org.apache.ignite.IgniteException) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite) IgniteException(org.apache.ignite.IgniteException)

Example 9 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridSingleSplitsNewNodesAbstractLoadTest method testLoad.

/**
     * Load test grid.
     *
     * @throws Exception If task execution failed.
     */
public void testLoad() throws Exception {
    final Ignite ignite = startGrid(getTestIgniteInstanceName());
    try {
        final long end = getTestDurationInMinutes() * 60 * 1000 + System.currentTimeMillis();
        // Warm up.
        ignite.compute().execute(GridSingleSplitNewNodesTestTask.class.getName(), 3);
        info("Load test will be executed for '" + getTestDurationInMinutes() + "' mins.");
        info("Thread count: " + getThreadCount());
        final GridLoadTestStatistics stats = new GridLoadTestStatistics();
        final AtomicInteger gridIdx = new AtomicInteger(0);
        for (int i = 0; i < getNodeCount(); i++) {
            new Thread(new Runnable() {

                /** {@inheritDoc} */
                @SuppressWarnings("BusyWait")
                @Override
                public void run() {
                    try {
                        while (end - System.currentTimeMillis() > 0 && !Thread.currentThread().isInterrupted()) {
                            int idx = gridIdx.incrementAndGet();
                            startGrid(idx);
                            Thread.sleep(grid(idx).configuration().getMetricsUpdateFrequency() * 3);
                            stopGrid(idx);
                            Thread.sleep(grid(idx).configuration().getMetricsUpdateFrequency() * 3);
                        }
                    } catch (Throwable e) {
                        error("Failed to start new node.", e);
                        fail();
                    }
                }
            }, "grid-notaop-nodes-load-test").start();
        }
        GridTestUtils.runMultiThreaded(new Runnable() {

            /** {@inheritDoc} */
            @Override
            public void run() {
                while (end - System.currentTimeMillis() > 0 && !Thread.currentThread().isInterrupted()) {
                    long start = System.currentTimeMillis();
                    try {
                        int levels = 3;
                        ComputeTaskFuture<Integer> fut = ignite.compute().executeAsync(new GridSingleSplitNewNodesTestTask(), levels);
                        int res = fut.get();
                        if (res != levels)
                            fail("Received wrong result [expected=" + levels + ", actual=" + res + ']');
                        long taskCnt = stats.onTaskCompleted(fut, levels, System.currentTimeMillis() - start);
                        if (taskCnt % 500 == 0)
                            info(stats.toString());
                    } catch (Throwable e) {
                        error("Failed to execute grid task.", e);
                        fail();
                    }
                }
            }
        }, getThreadCount(), "grid-notaop-load-test");
        info("Final test statistics: " + stats);
    } finally {
        G.stop(getTestIgniteInstanceName(), false);
    }
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite)

Example 10 with ComputeTaskFuture

use of org.apache.ignite.compute.ComputeTaskFuture in project ignite by apache.

the class GridSessionLoadTest method testSessionLoad.

/**
     * @throws Exception If failed.
     */
@SuppressWarnings("unchecked")
public void testSessionLoad() throws Exception {
    final Ignite ignite = G.ignite(getTestIgniteInstanceName());
    assert ignite != null;
    ignite.compute().localDeployTask(GridSessionLoadTestTask.class, GridSessionLoadTestTask.class.getClassLoader());
    final long end = getTestDurationInMinutes() * 60 * 1000 + System.currentTimeMillis();
    info("Load test will be executed for '" + getTestDurationInMinutes() + "' mins.");
    info("Thread count: " + getThreadCount());
    final GridLoadTestStatistics stats = new GridLoadTestStatistics();
    final AtomicBoolean failed = new AtomicBoolean(false);
    GridTestUtils.runMultiThreaded(new Runnable() {

        /** {@inheritDoc} */
        @Override
        public void run() {
            try {
                while (end - System.currentTimeMillis() > 0) {
                    long start = System.currentTimeMillis();
                    ComputeTaskFuture<?> fut = ignite.compute().withTimeout(10000).execute(GridSessionLoadTestTask.class.getName(), ignite.cluster().nodes().size());
                    Object res = fut.get();
                    assert (Boolean) res;
                    long taskCnt = stats.onTaskCompleted(fut, 1, System.currentTimeMillis() - start);
                    if (taskCnt % 500 == 0)
                        info(stats.toString());
                }
            } catch (Throwable e) {
                error("Load test failed.", e);
                failed.set(true);
            }
        }
    }, getThreadCount(), "grid-load-test-thread");
    info("Final test statistics: " + stats);
    if (failed.get())
        fail();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ComputeTaskFuture(org.apache.ignite.compute.ComputeTaskFuture) GridLoadTestStatistics(org.apache.ignite.loadtest.GridLoadTestStatistics) Ignite(org.apache.ignite.Ignite)

Aggregations

Ignite (org.apache.ignite.Ignite)17 ComputeTaskFuture (org.apache.ignite.compute.ComputeTaskFuture)17 IgniteException (org.apache.ignite.IgniteException)9 GridLoadTestStatistics (org.apache.ignite.loadtest.GridLoadTestStatistics)7 CountDownLatch (java.util.concurrent.CountDownLatch)5 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 ArrayList (java.util.ArrayList)4 UUID (java.util.UUID)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteCompute (org.apache.ignite.IgniteCompute)2 ComputeTask (org.apache.ignite.compute.ComputeTask)2 IgniteFuture (org.apache.ignite.lang.IgniteFuture)2 GridTestClassLoader (org.apache.ignite.testframework.GridTestClassLoader)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Random (java.util.Random)1 ClusterNode (org.apache.ignite.cluster.ClusterNode)1