Search in sources :

Example 16 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class GridClosureProcessorSelfTest method testRunAsyncSingle.

/**
     * @throws Exception If failed.
     */
public void testRunAsyncSingle() throws Exception {
    IgniteRunnable job = new ClosureTestRunnable();
    IgniteFuture<?> fut = broadcast(0, job, null);
    assert fut.get() == null;
    assertEquals(NODES_CNT, execCntr.getAndSet(0));
    fut = broadcast(0, job, singleNodePredicate(0));
    assert fut.get() == null;
    assertEquals(1, execCntr.get());
    fut = runAsync(0, job, null);
    assert fut.get() == null : "Execution result must be null.";
    assert execCntr.get() == 1 : "Execution counter must be equal to 1, actual: " + execCntr.get();
}
Also used : IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 17 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class OptimizedMarshallerSelfTest method testTestMarshalling.

/**
     * @throws Exception If failed.
     */
public void testTestMarshalling() throws Exception {
    final String msg = "PASSED";
    byte[] buf = marshal(new IgniteRunnable() {

        @Override
        public void run() {
            c1.apply(msg);
            c2.apply(msg);
            c3.apply();
            c4.reduce();
            System.out.println("Test message: " + msg);
        }
    });
    Runnable r = unmarshal(buf);
    assertNotNull(r);
    r.run();
}
Also used : IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 18 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class GridComputeJobExecutionErrorToLogManualTest method testRuntimeException.

/**
     * @throws Exception If fails.
     */
public void testRuntimeException() throws Exception {
    Ignite ignite = grid(0);
    ignite.compute().runAsync(new IgniteRunnable() {

        @Override
        public void run() {
            try {
                Thread.sleep(500);
            } catch (InterruptedException ignored) {
            // No-op.
            }
        }
    }).listen(new IgniteInClosure<IgniteFuture<Void>>() {

        @Override
        public void apply(IgniteFuture<Void> future) {
            throw new RuntimeException();
        }
    });
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 19 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class GridTestMain method colocateJobs.

/**
     * @throws Exception If failed.
     */
private static void colocateJobs() throws Exception {
    X.println("Collocating jobs...");
    Ignite g = G.ignite();
    final IgniteCache<GridTestKey, Long> cache = g.cache("partitioned");
    final BlockingQueue<IgniteFuture> q = new ArrayBlockingQueue<>(400);
    long start = System.currentTimeMillis();
    // Collocate computations and data.
    for (long i = 0; i < GridTestConstants.ENTRY_COUNT; i++) {
        final long key = i;
        final IgniteFuture<?> f = g.compute().affinityRunAsync("partitioned", GridTestKey.affinityKey(key), new IgniteRunnable() {

            // This code will execute on remote nodes by collocating keys with cached data.
            @Override
            public void run() {
                Long val = cache.localPeek(new GridTestKey(key), CachePeekMode.ONHEAP);
                if (val == null || val != key)
                    throw new RuntimeException("Invalid value found [key=" + key + ", val=" + val + ']');
            }
        });
        q.put(f);
        f.listen(new CI1<IgniteFuture<?>>() {

            @Override
            public void apply(IgniteFuture<?> o) {
                q.poll();
            }
        });
        if (i % 10000 == 0)
            X.println("Executed jobs: " + i);
    }
    long end = System.currentTimeMillis();
    X.println("Executed " + GridTestConstants.ENTRY_COUNT + " computations in " + (end - start) + "ms.");
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) ArrayBlockingQueue(java.util.concurrent.ArrayBlockingQueue) Ignite(org.apache.ignite.Ignite)

Example 20 with IgniteRunnable

use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.

the class IgniteDynamicCacheStartStopConcurrentTest method testConcurrentStartStop.

/**
     * @throws Exception If failed.
     */
public void testConcurrentStartStop() throws Exception {
    awaitPartitionMapExchange();
    int minorVer = ignite(0).configuration().isLateAffinityAssignment() ? 1 : 0;
    checkTopologyVersion(new AffinityTopologyVersion(NODES, minorVer));
    for (int i = 0; i < 5; i++) {
        log.info("Iteration: " + i);
        GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {

            @Override
            public void apply(Integer idx) {
                Ignite ignite = ignite(idx);
                ignite.getOrCreateCache(new CacheConfiguration<>(DEFAULT_CACHE_NAME));
            }
        }, NODES, "cache-thread");
        minorVer++;
        checkTopologyVersion(new AffinityTopologyVersion(NODES, minorVer));
        ignite(0).compute().affinityRun(DEFAULT_CACHE_NAME, 1, new IgniteRunnable() {

            @Override
            public void run() {
            // No-op.
            }
        });
        GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {

            @Override
            public void apply(Integer idx) {
                Ignite ignite = ignite(idx);
                ignite.destroyCache(DEFAULT_CACHE_NAME);
            }
        }, NODES, "cache-thread");
        minorVer++;
        checkTopologyVersion(new AffinityTopologyVersion(NODES, minorVer));
    }
}
Also used : AffinityTopologyVersion(org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion) Ignite(org.apache.ignite.Ignite) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Aggregations

IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)45 Ignite (org.apache.ignite.Ignite)21 IgniteException (org.apache.ignite.IgniteException)11 IgniteEx (org.apache.ignite.internal.IgniteEx)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)7 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)7 ArrayList (java.util.ArrayList)6 IOException (java.io.IOException)5 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 ClusterNode (org.apache.ignite.cluster.ClusterNode)5 UUID (java.util.UUID)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 IgniteCompute (org.apache.ignite.IgniteCompute)4 TaskEvent (org.apache.ignite.events.TaskEvent)4 IgniteFuture (org.apache.ignite.lang.IgniteFuture)4 RejectedExecutionException (java.util.concurrent.RejectedExecutionException)3 Event (org.apache.ignite.events.Event)3 GridAbsPredicate (org.apache.ignite.internal.util.lang.GridAbsPredicate)3 Collection (java.util.Collection)2 RuntimeCamelException (org.apache.camel.RuntimeCamelException)2