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);
}
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();
}
}
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;
}
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);
}
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);
}
}
Aggregations