Search in sources :

Example 21 with IgniteCallable

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

the class GridClosureSerializationTest method testAttributesSerializationFailure.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings({ "ThrowableResultOfMethodCallIgnored", "Convert2Lambda" })
public void testAttributesSerializationFailure() throws Exception {
    final IgniteEx ignite0 = grid(0);
    final IgniteEx ignite1 = grid(1);
    GridTestUtils.assertThrows(null, new Callable<Object>() {

        @JobContextResource
        private ComputeJobContext jobCtx;

        @Override
        public Object call() throws Exception {
            ignite1.compute(ignite1.cluster().forNode(ignite0.localNode())).call(new IgniteCallable<Object>() {

                @Override
                public Object call() throws Exception {
                    jobCtx.setAttribute("test-attr", new BrokenAttribute());
                    return null;
                }
            });
            return null;
        }
    }, IgniteException.class, null);
}
Also used : ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteEx(org.apache.ignite.internal.IgniteEx) IgniteCallable(org.apache.ignite.lang.IgniteCallable) JobContextResource(org.apache.ignite.resources.JobContextResource) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) BinaryObjectException(org.apache.ignite.binary.BinaryObjectException)

Example 22 with IgniteCallable

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

the class IgniteComputeCustomExecutorSelfTest method testAllComputeApiByCustomExecutor.

/**
 * @throws Exception If fails.
 */
public void testAllComputeApiByCustomExecutor() throws Exception {
    IgniteCompute comp = grid(0).compute().withExecutor(EXEC_NAME0);
    comp.affinityRun(CACHE_NAME, primaryKey(grid(1).cache(CACHE_NAME)), new IgniteRunnable() {

        @Override
        public void run() {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
        }
    });
    comp.affinityCall(CACHE_NAME, 0, new IgniteCallable<Object>() {

        @Override
        public Object call() throws Exception {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    });
    comp.broadcast(new IgniteRunnable() {

        @Override
        public void run() {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
        }
    });
    comp.broadcast(new IgniteCallable<Object>() {

        @Override
        public Object call() throws Exception {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    });
    comp.broadcast(new IgniteClosure<Object, Object>() {

        @Override
        public Object apply(Object o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, 0);
    comp.apply(new IgniteClosure<Object, Object>() {

        @Override
        public Object apply(Object o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, 0);
    comp.apply(new IgniteClosure<Integer, Object>() {

        @Override
        public Object apply(Integer o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, Collections.singletonList(0));
    comp.apply(new IgniteClosure<Integer, Object>() {

        @Override
        public Object apply(Integer o) {
            assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            return null;
        }
    }, Collections.singletonList(0), new IgniteReducer<Object, Object>() {

        @Override
        public boolean collect(@Nullable Object o) {
            return true;
        }

        @Override
        public Object reduce() {
            return null;
        }
    });
    List<IgniteCallable<Object>> calls = new ArrayList<>();
    for (int i = 0; i < GRID_CNT * 2; ++i) {
        calls.add(new IgniteCallable<Object>() {

            @Override
            public Object call() throws Exception {
                assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
                return null;
            }
        });
    }
    comp.call(calls.get(0));
    comp.call(calls);
    comp.call(calls, new IgniteReducer<Object, Object>() {

        @Override
        public boolean collect(@Nullable Object o) {
            return true;
        }

        @Override
        public Object reduce() {
            return null;
        }
    });
    List<IgniteRunnable> runs = new ArrayList<>();
    for (int i = 0; i < GRID_CNT * 2; ++i) {
        runs.add(new IgniteRunnable() {

            @Override
            public void run() {
                assertTrue(Thread.currentThread().getName().contains(EXEC_NAME0));
            }
        });
    }
    comp.run(runs.get(0));
    comp.run(runs);
    comp.execute(TestTask.class, null);
}
Also used : ArrayList(java.util.ArrayList) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteException(org.apache.ignite.IgniteException) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 23 with IgniteCallable

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

the class IgniteLockAbstractSelfTest method checkReentrantLock.

/**
 * @throws Exception If failed.
 */
private void checkReentrantLock(final boolean fair) throws Exception {
    // Test API.
    checkLock(fair);
    checkFailoverSafe(fair);
    // Test main functionality.
    IgniteLock lock1 = grid(0).reentrantLock("lock", true, fair, true);
    assertFalse(lock1.isLocked());
    lock1.lock();
    IgniteFuture<Object> fut = grid(0).compute().callAsync(new IgniteCallable<Object>() {

        @IgniteInstanceResource
        private Ignite ignite;

        @LoggerResource
        private IgniteLogger log;

        @Nullable
        @Override
        public Object call() throws Exception {
            // Test reentrant lock in multiple threads on each node.
            IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {

                @Nullable
                @Override
                public Object call() throws Exception {
                    IgniteLock lock = ignite.reentrantLock("lock", true, fair, true);
                    assert lock != null;
                    log.info("Thread is going to wait on reentrant lock: " + Thread.currentThread().getName());
                    assert lock.tryLock(1, MINUTES);
                    log.info("Thread is again runnable: " + Thread.currentThread().getName());
                    lock.unlock();
                    return null;
                }
            }, 5, "test-thread");
            fut.get();
            return null;
        }
    });
    Thread.sleep(3000);
    assert lock1.isHeldByCurrentThread();
    assert lock1.getHoldCount() == 1;
    lock1.lock();
    assert lock1.isHeldByCurrentThread();
    assert lock1.getHoldCount() == 2;
    lock1.unlock();
    lock1.unlock();
    // Ensure there are no hangs.
    fut.get();
    // Test operations on removed lock.
    lock1.close();
    checkRemovedReentrantLock(lock1);
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) ExpectedException(org.junit.rules.ExpectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteLock(org.apache.ignite.IgniteLock) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with IgniteCallable

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

the class GridP2PLocalDeploymentSelfTest method testConcurrentDeploymentWithDelegatingClassloader.

/**
 * Tests concurrent deployment using delegating classloader for the task.
 */
public void testConcurrentDeploymentWithDelegatingClassloader() throws Exception {
    depMode = DeploymentMode.SHARED;
    // Force rmvQueue removal task to run very often.
    System.setProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL, "1");
    System.setProperty(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK, "true");
    try {
        final Ignite ignite = startGrid();
        final ClassLoader delegate = ignite.getClass().getClassLoader();
        final ClassLoader root = new DelegateClassLoader(null, delegate);
        final AtomicBoolean stop = new AtomicBoolean();
        IgniteInternalFuture<?> fut = multithreadedAsync(new Callable<Void>() {

            @Override
            public Void call() throws Exception {
                while (!stop.get()) {
                    final Class<?> clazz = root.loadClass("org.apache.ignite.p2p.GridP2PLocalDeploymentSelfTest$TestClosure");
                    ignite.compute().call((IgniteCallable) clazz.getDeclaredConstructor(ClassLoader.class).newInstance(root));
                }
                return null;
            }
        }, 1);
        ignite.scheduler().runLocal(new Runnable() {

            @Override
            public void run() {
                stop.set(true);
            }
        }, 10, TimeUnit.SECONDS);
        fut.get();
    } finally {
        stopAllGrids();
        System.clearProperty(IGNITE_CACHE_REMOVED_ENTRIES_TTL);
        System.clearProperty(IGNITE_DEPLOYMENT_ADDITIONAL_CHECK);
    }
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) IgniteCallable(org.apache.ignite.lang.IgniteCallable) URLClassLoader(java.net.URLClassLoader) Ignite(org.apache.ignite.Ignite) IgniteException(org.apache.ignite.IgniteException)

Aggregations

IgniteCallable (org.apache.ignite.lang.IgniteCallable)24 Ignite (org.apache.ignite.Ignite)15 IgniteException (org.apache.ignite.IgniteException)13 ArrayList (java.util.ArrayList)8 IOException (java.io.IOException)7 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)7 Collection (java.util.Collection)6 Callable (java.util.concurrent.Callable)6 IgniteEx (org.apache.ignite.internal.IgniteEx)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Nullable (org.jetbrains.annotations.Nullable)4 UUID (java.util.UUID)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 IgniteClientDisconnectedException (org.apache.ignite.IgniteClientDisconnectedException)3 IgniteCompute (org.apache.ignite.IgniteCompute)3 IgniteLogger (org.apache.ignite.IgniteLogger)3 BinaryObjectException (org.apache.ignite.binary.BinaryObjectException)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 IgniteFuture (org.apache.ignite.lang.IgniteFuture)3