Search in sources :

Example 46 with IgniteRunnable

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

the class IgniteComputeJobOneThreadTest method testNoTimeout.

/**
 * @throws Exception If failed.
 */
@Test
public void testNoTimeout() throws Exception {
    Ignite ignite = ignite(0);
    IgniteFuture fut = null;
    for (int i = 0; i < 10000; i++) {
        fut = ignite.compute().runAsync(new IgniteRunnable() {

            @Override
            public void run() {
            }
        });
    }
    fut.get();
    assertTrue(true);
}
Also used : IgniteFuture(org.apache.ignite.lang.IgniteFuture) Ignite(org.apache.ignite.Ignite) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 47 with IgniteRunnable

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

the class GridMarshallerAbstractTest method testCompute.

/**
 * @throws Exception If failed.
 */
@Test
public void testCompute() throws Exception {
    IgniteConfiguration cfg = optimize(getConfiguration("g1"));
    try (Ignite g1 = G.start(cfg)) {
        IgniteCompute compute = compute(grid().cluster().forNode(g1.cluster().localNode()));
        compute.run(new IgniteRunnable() {

            @Override
            public void run() {
            // No-op.
            }
        });
        GridMarshallerTestBean inBean = newTestBean(compute);
        byte[] buf = marshal(inBean);
        GridMarshallerTestBean outBean = unmarshal(buf);
        assert inBean.getObjectField() != null;
        assert outBean.getObjectField() != null;
        assert inBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
        assert outBean.getObjectField().getClass().equals(IgniteComputeImpl.class);
        assert inBean != outBean;
        assert inBean.equals(outBean);
        ClusterGroup inPrj = compute.clusterGroup();
        ClusterGroup outPrj = ((IgniteCompute) outBean.getObjectField()).clusterGroup();
        assert inPrj.getClass().equals(outPrj.getClass());
        assert F.eqNotOrdered(inPrj.nodes(), outPrj.nodes());
        outBean.checkNullResources();
    }
}
Also used : IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) ClusterGroup(org.apache.ignite.cluster.ClusterGroup) Ignite(org.apache.ignite.Ignite) IgniteCompute(org.apache.ignite.IgniteCompute) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 48 with IgniteRunnable

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

the class WalEnableDisableWithRestartsTest method startNodeWithMaintenance.

/**
 */
private Ignite startNodeWithMaintenance(String consistentId) throws Exception {
    Ignite node;
    try {
        node = Ignition.start(igniteCfg(false, consistentId));
    } catch (Exception ex) {
        if (!X.hasCause(ex, "Cache groups with potentially corrupted partition files", IgniteException.class))
            throw ex;
        node = Ignition.start(igniteCfg(false, consistentId));
        node.compute().run(new IgniteRunnable() {

            /**
             */
            @IgniteInstanceResource
            private Ignite ignite;

            /**
             */
            @Override
            public void run() {
                MaintenanceRegistry mntcRegistry = ((IgniteEx) ignite).context().maintenanceRegistry();
                List<MaintenanceAction<?>> actions = mntcRegistry.actionsForMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
                actions.stream().filter(a -> a.name().equals(CleanCacheStoresMaintenanceAction.ACTION_NAME)).findFirst().get().execute();
                mntcRegistry.unregisterMaintenanceTask(CORRUPTED_DATA_FILES_MNTC_TASK_NAME);
            }
        });
        node.close();
        node = Ignition.start(igniteCfg(false, consistentId));
    }
    return node;
}
Also used : CacheAtomicityMode(org.apache.ignite.cache.CacheAtomicityMode) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) IgniteException(org.apache.ignite.IgniteException) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteEx(org.apache.ignite.internal.IgniteEx) Test(org.junit.Test) Ignite(org.apache.ignite.Ignite) List(java.util.List) IgniteConfiguration(org.apache.ignite.configuration.IgniteConfiguration) Ignition(org.apache.ignite.Ignition) CacheConfiguration(org.apache.ignite.configuration.CacheConfiguration) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) X(org.apache.ignite.internal.util.typedef.X) After(org.junit.After) DataStorageConfiguration(org.apache.ignite.configuration.DataStorageConfiguration) LinkedList(java.util.LinkedList) DataRegionConfiguration(org.apache.ignite.configuration.DataRegionConfiguration) CacheMode(org.apache.ignite.cache.CacheMode) CORRUPTED_DATA_FILES_MNTC_TASK_NAME(org.apache.ignite.internal.processors.cache.persistence.file.FilePageStoreManager.CORRUPTED_DATA_FILES_MNTC_TASK_NAME) MaintenanceAction(org.apache.ignite.maintenance.MaintenanceAction) CleanCacheStoresMaintenanceAction(org.apache.ignite.internal.processors.cache.persistence.CleanCacheStoresMaintenanceAction) Ignite(org.apache.ignite.Ignite) MaintenanceRegistry(org.apache.ignite.maintenance.MaintenanceRegistry) IgniteException(org.apache.ignite.IgniteException) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable)

Example 49 with IgniteRunnable

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

the class IgniteComputeCustomExecutorSelfTest method testAllComputeApiByCustomExecutor.

/**
 * @throws Exception If fails.
 */
@Test
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) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 50 with IgniteRunnable

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

the class InboundConnectionHandler method onMessage.

/**
 * {@inheritDoc}
 */
@Override
public void onMessage(final GridNioSession ses, Message msg) {
    Span span = MTC.span();
    span.addLog(() -> "Communication received");
    span.addTag(SpanTags.MESSAGE, () -> traceName(msg));
    ConnectionKey connKey = ses.meta(CONN_IDX_META);
    if (connKey == null) {
        assert ses.accepted() : ses;
        if (!connectGate.tryEnter()) {
            if (log.isDebugEnabled())
                log.debug("Close incoming connection, failed to enter gateway.");
            ses.send(new RecoveryLastReceivedMessage(NODE_STOPPING)).listen(fut -> ses.close());
            return;
        }
        try {
            onFirstMessage(ses, msg);
        } finally {
            connectGate.leave();
        }
    } else {
        if (isChannelConnIdx(connKey.connectionIndex())) {
            if (ses.meta(CHANNEL_FUT_META) == null)
                nioSrvWrapper.onChannelCreate((GridSelectorNioSessionImpl) ses, connKey, msg);
            else {
                GridFutureAdapter<Channel> fut = ses.meta(CHANNEL_FUT_META);
                GridSelectorNioSessionImpl ses0 = (GridSelectorNioSessionImpl) ses;
                ses0.closeSocketOnSessionClose(false);
                ses0.close().listen(f -> {
                    if (f.error() != null) {
                        fut.onDone(f.error());
                        return;
                    }
                    fut.onDone(ses0.key().channel());
                });
            }
            return;
        }
        Object consistentId = ses.meta(CONSISTENT_ID_META);
        assert consistentId != null;
        if (msg instanceof RecoveryLastReceivedMessage) {
            metricsLsnr.onMessageReceived(msg, consistentId);
            GridNioRecoveryDescriptor recovery = ses.outRecoveryDescriptor();
            if (recovery != null) {
                RecoveryLastReceivedMessage msg0 = (RecoveryLastReceivedMessage) msg;
                if (log.isDebugEnabled()) {
                    log.debug("Received recovery acknowledgement [rmtNode=" + connKey.nodeId() + ", connIdx=" + connKey.connectionIndex() + ", rcvCnt=" + msg0.received() + ']');
                }
                recovery.ackReceived(msg0.received());
            }
            return;
        } else {
            GridNioRecoveryDescriptor recovery = ses.inRecoveryDescriptor();
            if (recovery != null) {
                long rcvCnt = recovery.onReceived();
                if (rcvCnt % cfg.ackSendThreshold() == 0) {
                    if (log.isDebugEnabled()) {
                        log.debug("Send recovery acknowledgement [rmtNode=" + connKey.nodeId() + ", connIdx=" + connKey.connectionIndex() + ", rcvCnt=" + rcvCnt + ']');
                    }
                    ses.systemMessage(new RecoveryLastReceivedMessage(rcvCnt));
                    recovery.lastAcknowledged(rcvCnt);
                }
            } else if (connKey.dummy()) {
                assert msg instanceof NodeIdMessage : msg;
                TcpCommunicationNodeConnectionCheckFuture fut = ses.meta(SES_FUT_META);
                assert fut != null : msg;
                fut.onConnected(U.bytesToUuid(((NodeIdMessage) msg).nodeIdBytes(), 0));
                nioSrvWrapper.nio().closeFromWorkerThread(ses);
                return;
            }
        }
        metricsLsnr.onMessageReceived(msg, consistentId);
        IgniteRunnable c;
        if (cfg.messageQueueLimit() > 0) {
            GridNioMessageTracker tracker = ses.meta(TRACKER_META);
            if (tracker == null) {
                GridNioMessageTracker old = ses.addMeta(TRACKER_META, tracker = new GridNioMessageTracker(ses, cfg.messageQueueLimit()));
                assert old == null;
            }
            tracker.onMessageReceived();
            c = tracker;
        } else
            c = NOOP;
        lsnr.onMessage(connKey.nodeId(), msg, c);
    }
}
Also used : RecoveryLastReceivedMessage(org.apache.ignite.spi.communication.tcp.messages.RecoveryLastReceivedMessage) Channel(java.nio.channels.Channel) Span(org.apache.ignite.internal.processors.tracing.Span) GridNioMessageTracker(org.apache.ignite.internal.util.nio.GridNioMessageTracker) IgniteRunnable(org.apache.ignite.lang.IgniteRunnable) NodeIdMessage(org.apache.ignite.spi.communication.tcp.messages.NodeIdMessage) GridNioRecoveryDescriptor(org.apache.ignite.internal.util.nio.GridNioRecoveryDescriptor) GridSelectorNioSessionImpl(org.apache.ignite.internal.util.nio.GridSelectorNioSessionImpl)

Aggregations

IgniteRunnable (org.apache.ignite.lang.IgniteRunnable)57 Test (org.junit.Test)30 Ignite (org.apache.ignite.Ignite)25 IgniteException (org.apache.ignite.IgniteException)19 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)19 IgniteEx (org.apache.ignite.internal.IgniteEx)13 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)12 IgniteInstanceResource (org.apache.ignite.resources.IgniteInstanceResource)11 UUID (java.util.UUID)10 ArrayList (java.util.ArrayList)6 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)6 ClusterNode (org.apache.ignite.cluster.ClusterNode)6 IgniteFuture (org.apache.ignite.lang.IgniteFuture)6 IOException (java.io.IOException)5 IgniteConfiguration (org.apache.ignite.configuration.IgniteConfiguration)5 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)5 List (java.util.List)4 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)4 Channel (java.nio.channels.Channel)3 Collection (java.util.Collection)3