Search in sources :

Example 11 with IgniteCallable

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

the class GridTaskExecutionSelfTest method testJobIdCollision.

/**
 * Test for https://issues.apache.org/jira/browse/IGNITE-1384
 *
 * @throws Exception If failed.
 */
public void testJobIdCollision() throws Exception {
    fail("Test refactoring is needed: https://issues.apache.org/jira/browse/IGNITE-4706");
    long locId = IgniteUuid.lastLocalId();
    ArrayList<IgniteFuture<Object>> futs = new ArrayList<>(2016);
    IgniteCompute compute = grid(1).compute(grid(1).cluster().forNodeId(grid(3).localNode().id()));
    for (int i = 0; i < 1000; i++) {
        futs.add(compute.callAsync(new IgniteCallable<Object>() {

            @JobContextResource
            ComputeJobContext ctx;

            boolean held;

            @Override
            public Object call() throws Exception {
                if (!held) {
                    ctx.holdcc(1000);
                    held = true;
                }
                return null;
            }
        }));
    }
    info("Finished first loop.");
    AtomicLong idx = U.field(IgniteUuid.class, "cntGen");
    idx.set(locId);
    IgniteCompute compute1 = grid(2).compute(grid(2).cluster().forNodeId(grid(3).localNode().id()));
    for (int i = 0; i < 100; i++) {
        futs.add(compute1.callAsync(new IgniteCallable<Object>() {

            @JobContextResource
            ComputeJobContext ctx;

            boolean held;

            @Override
            public Object call() throws Exception {
                if (!held) {
                    ctx.holdcc(1000);
                    held = true;
                }
                return null;
            }
        }));
    }
    for (IgniteFuture<Object> fut : futs) fut.get();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) ComputeJobContext(org.apache.ignite.compute.ComputeJobContext) IgniteCallable(org.apache.ignite.lang.IgniteCallable) ArrayList(java.util.ArrayList) IgniteFuture(org.apache.ignite.lang.IgniteFuture) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 12 with IgniteCallable

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

the class IgniteClientReconnectApiExceptionTest method igniteOperationsTest.

/**
 * @throws Exception If failed.
 */
@SuppressWarnings("unchecked")
public void igniteOperationsTest() throws Exception {
    clientMode = true;
    final Ignite client = startGrid(serverCount());
    final IgniteCache<Object, Object> dfltCache = client.cache(DEFAULT_CACHE_NAME);
    final CountDownLatch recvLatch = new CountDownLatch(1);
    assertNotNull(dfltCache);
    doTestIgniteOperationOnDisconnect(client, Arrays.asList(// Check compute.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.compute();
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.compute();
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            IgniteCompute comp = (IgniteCompute) o;
            Collection<UUID> uuids = comp.broadcast(new IgniteCallable<UUID>() {

                @IgniteInstanceResource
                private Ignite ignite;

                @Override
                public UUID call() throws Exception {
                    return ignite.cluster().localNode().id();
                }
            });
            assertFalse(uuids.isEmpty());
            for (UUID uuid : uuids) assertNotNull(uuid);
            return true;
        }
    }), // Check ping node.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.cluster().pingNode(new UUID(0, 0));
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.cluster().pingNode(new UUID(0, 0));
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            Boolean pingNode = (Boolean) o;
            assertFalse(pingNode);
            return true;
        }
    }), // Check register remote listener.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.events().remoteListen(null, new IgnitePredicate<Event>() {

                    @Override
                    public boolean apply(Event event) {
                        return true;
                    }
                });
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.events().remoteListen(null, new IgnitePredicate<Event>() {

                @Override
                public boolean apply(Event event) {
                    return true;
                }
            });
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            UUID remoteId = (UUID) o;
            assertNotNull(remoteId);
            client.events().stopRemoteListen(remoteId);
            return true;
        }
    }), // Check message operation.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() {

                    @Override
                    public boolean apply(UUID uuid, Object o) {
                        if (o.equals("Test message."))
                            recvLatch.countDown();
                        return true;
                    }
                });
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.message().remoteListen(null, new IgniteBiPredicate<UUID, Object>() {

                @Override
                public boolean apply(UUID uuid, Object o) {
                    if (o.equals("Test message."))
                        recvLatch.countDown();
                    return true;
                }
            });
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            IgniteMessaging msg = client.message();
            msg.send(null, "Test message.");
            try {
                assertTrue(recvLatch.await(2, SECONDS));
            } catch (InterruptedException ignored) {
                fail("Message wasn't received.");
            }
            return true;
        }
    }), // Check executor.
    new T2<Callable, C1<Object, Boolean>>(new Callable() {

        @Override
        public Object call() throws Exception {
            boolean failed = false;
            try {
                client.executorService().submit(new Callable<Integer>() {

                    @Override
                    public Integer call() throws Exception {
                        return 42;
                    }
                });
            } catch (IgniteClientDisconnectedException e) {
                failed = true;
                checkAndWait(e);
            }
            assertTrue(failed);
            return client.executorService().submit(new Callable<Integer>() {

                @Override
                public Integer call() throws Exception {
                    return 42;
                }
            });
        }
    }, new C1<Object, Boolean>() {

        @Override
        public Boolean apply(Object o) {
            assertNotNull(o);
            Future<Integer> fut = (Future<Integer>) o;
            try {
                assertEquals(42, (int) fut.get());
            } catch (Exception ignored) {
                fail("Failed submit task.");
            }
            return true;
        }
    })));
    clientMode = false;
}
Also used : IgniteBiPredicate(org.apache.ignite.lang.IgniteBiPredicate) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgnitePredicate(org.apache.ignite.lang.IgnitePredicate) CountDownLatch(java.util.concurrent.CountDownLatch) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) EntryProcessorException(javax.cache.processor.EntryProcessorException) CacheException(javax.cache.CacheException) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) IgniteMessaging(org.apache.ignite.IgniteMessaging) IgniteCallable(org.apache.ignite.lang.IgniteCallable) Collection(java.util.Collection) Event(org.apache.ignite.events.Event) Future(java.util.concurrent.Future) Ignite(org.apache.ignite.Ignite) UUID(java.util.UUID) T2(org.apache.ignite.internal.util.typedef.T2) IgniteCompute(org.apache.ignite.IgniteCompute)

Example 13 with IgniteCallable

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

the class IgniteClientReconnectComputeTest method testReconnectBroadcastInProgress.

/**
 * @throws Exception If failed.
 */
public void testReconnectBroadcastInProgress() throws Exception {
    final Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = clientRouter(client);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    commSpi.blockMessage(GridJobExecuteResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                client.compute().broadcast(new IgniteCallable<Object>() {

                    @Override
                    public Object call() throws Exception {
                        return 42;
                    }
                });
            } catch (IgniteClientDisconnectedException e) {
                checkAndWait(e);
                return true;
            }
            return false;
        }
    });
    // Check that client waiting operation.
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return fut.get(200);
        }
    }, IgniteFutureTimeoutCheckedException.class, null);
    assertNotDone(fut);
    commSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
}
Also used : IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 14 with IgniteCallable

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

the class IgniteClientReconnectComputeTest method testReconnectAffinityCallInProgress.

/**
 * @throws Exception If failed.
 */
public void testReconnectAffinityCallInProgress() throws Exception {
    final Ignite client = grid(serverCount());
    assertTrue(client.cluster().localNode().isClient());
    Ignite srv = clientRouter(client);
    IgniteCache<Integer, Integer> cache = client.getOrCreateCache("test-cache");
    for (int i = 0; i < 100; i++) cache.put(i, i);
    BlockTcpCommunicationSpi commSpi = commSpi(srv);
    commSpi.blockMessage(GridJobExecuteResponse.class);
    final IgniteInternalFuture<Object> fut = GridTestUtils.runAsync(new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            try {
                client.compute().affinityCall("test-cache", 40, new IgniteCallable<Object>() {

                    @Override
                    public Integer call() throws Exception {
                        return 42;
                    }
                });
            } catch (IgniteClientDisconnectedException e) {
                checkAndWait(e);
                return true;
            }
            return false;
        }
    });
    // Check that client waiting operation.
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return fut.get(200);
        }
    }, IgniteFutureTimeoutCheckedException.class, null);
    assertNotDone(fut);
    commSpi.unblockMessage();
    reconnectClientNode(client, srv, null);
    assertTrue((Boolean) fut.get(2, TimeUnit.SECONDS));
}
Also used : IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException) Ignite(org.apache.ignite.Ignite) IgniteClientDisconnectedException(org.apache.ignite.IgniteClientDisconnectedException)

Example 15 with IgniteCallable

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

the class GridJobServicesAddNodeTest method testServiceDescriptorsJob.

/**
 * @throws Exception If test failed.
 */
public void testServiceDescriptorsJob() throws Exception {
    final int tasks = 5000;
    final int threads = 10;
    final Ignite ignite1 = grid(1);
    final CountDownLatch latch = new CountDownLatch(tasks);
    final AtomicInteger jobsCnt = new AtomicInteger();
    final AtomicInteger resCnt = new AtomicInteger();
    ignite1.services().deployClusterSingleton("jobsSvc", new DummyService());
    GridTestUtils.runMultiThreadedAsync(new CAX() {

        @Override
        public void applyx() throws IgniteCheckedException {
            while (true) {
                int cnt = jobsCnt.incrementAndGet();
                if (cnt > 5000)
                    break;
                IgniteCallable<Boolean> job;
                job = new ServiceDescriptorsJob();
                IgniteFuture<Boolean> fut = ignite1.compute().callAsync(job);
                if (cnt % LOG_MOD == 0)
                    X.println("Submitted jobs: " + cnt);
                fut.listen(new CIX1<IgniteFuture<Boolean>>() {

                    @Override
                    public void applyx(IgniteFuture<Boolean> f) {
                        try {
                            assert f.get();
                            long cnt = resCnt.incrementAndGet();
                            if (cnt % LOG_MOD == 0)
                                X.println("Results count: " + cnt);
                        } finally {
                            latch.countDown();
                        }
                    }
                });
                IgniteUtils.sleep(5);
            }
        }
    }, threads, "TEST-THREAD");
    int additionalNodesStarted = 0;
    while (!latch.await(threads, TimeUnit.MILLISECONDS)) {
        if (additionalNodesStarted++ <= MAX_ADD_NODES) {
            startGrid(2 + additionalNodesStarted);
        }
    }
    assertEquals("Jobs cnt != Results cnt", jobsCnt.get() - threads, resCnt.get());
}
Also used : CIX1(org.apache.ignite.internal.util.typedef.CIX1) DummyService(org.apache.ignite.internal.processors.service.DummyService) IgniteFuture(org.apache.ignite.lang.IgniteFuture) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) IgniteCallable(org.apache.ignite.lang.IgniteCallable) Ignite(org.apache.ignite.Ignite) CAX(org.apache.ignite.internal.util.typedef.CAX)

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