use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridEventConsumeSelfTest method testResources.
/**
* @throws Exception If failed.
*/
public void testResources() throws Exception {
final Collection<UUID> nodeIds = new HashSet<>();
final AtomicInteger cnt = new AtomicInteger();
final CountDownLatch latch = new CountDownLatch(GRID_CNT);
UUID consumeId = grid(0).events().remoteListen(new P2<UUID, Event>() {
@IgniteInstanceResource
private Ignite grid;
@Override
public boolean apply(UUID nodeId, Event evt) {
info("Event from " + nodeId + " [" + evt.shortDisplay() + ']');
assertEquals(EVT_JOB_STARTED, evt.type());
assertNotNull(grid);
nodeIds.add(nodeId);
cnt.incrementAndGet();
latch.countDown();
return true;
}
}, new P1<Event>() {
@IgniteInstanceResource
private Ignite grid;
@Override
public boolean apply(Event evt) {
assertNotNull(grid);
return true;
}
}, EVT_JOB_STARTED);
try {
assertNotNull(consumeId);
grid(0).compute().broadcast(F.noop());
assert latch.await(2, SECONDS);
assertEquals(GRID_CNT, nodeIds.size());
assertEquals(GRID_CNT, cnt.get());
} finally {
grid(0).events().stopRemoteListen(consumeId);
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridBinaryAffinityKeySelfTest method testAffinityRun.
/**
* @throws Exception If failed.
*/
public void testAffinityRun() throws Exception {
Affinity<Object> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1000; i++) {
nodeId.set(null);
grid(0).compute().affinityRun(DEFAULT_CACHE_NAME, new TestObject(i), new IgniteRunnable() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public void run() {
nodeId.set(ignite.configuration().getNodeId());
}
});
assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
grid(0).compute().affinityRun(DEFAULT_CACHE_NAME, new AffinityKey(0, i), new IgniteRunnable() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public void run() {
nodeId.set(ignite.configuration().getNodeId());
}
});
assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridBinaryAffinityKeySelfTest method testAffinityCall.
/**
* @throws Exception If failed.
*/
public void testAffinityCall() throws Exception {
Affinity<Object> aff = grid(0).affinity(DEFAULT_CACHE_NAME);
for (int i = 0; i < 1000; i++) {
nodeId.set(null);
grid(0).compute().affinityCall(DEFAULT_CACHE_NAME, new TestObject(i), new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public Object call() {
nodeId.set(ignite.configuration().getNodeId());
return null;
}
});
assertEquals(aff.mapKeyToNode(i).id(), nodeId.get());
}
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class IgniteExecutorServiceTest method testExecute.
/**
* @throws Exception Thrown in case of test failure.
*/
public void testExecute() throws Exception {
Ignite ignite = G.ignite(getTestIgniteInstanceName());
ExecutorService srvc = createExecutorService(ignite);
srvc.execute(new Runnable() {
@IgniteInstanceResource
private Ignite ignite;
@Override
public void run() {
System.out.println("Test message.");
assert this.ignite != null;
}
});
srvc.execute(new TestRunnable());
srvc.shutdown();
}
use of org.apache.ignite.resources.IgniteInstanceResource in project ignite by apache.
the class GridClusterStateProcessor method sendComputeCheckGlobalState.
/**
* Check cluster state.
*
* @return Cluster state, {@code True} if cluster active, {@code False} if inactive.
*/
private boolean sendComputeCheckGlobalState() {
AffinityTopologyVersion topVer = ctx.discovery().topologyVersionEx();
if (log.isInfoEnabled()) {
log.info("Sending check cluster state request from node [id=" + ctx.localNodeId() + ", topVer=" + topVer + ", client=" + ctx.clientNode() + ", daemon" + ctx.isDaemon() + "]");
}
IgniteCompute comp = ((ClusterGroupAdapter) ctx.cluster().get().forServers()).compute();
return comp.call(new IgniteCallable<Boolean>() {
@IgniteInstanceResource
private Ignite ig;
@Override
public Boolean call() throws Exception {
return ig.active();
}
});
}
Aggregations