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