use of org.apache.ignite.IgniteCompute 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.IgniteCompute in project ignite by apache.
the class IgniteClientReconnectFailoverTest method testReconnectComputeApi.
/**
* @throws Exception If failed.
*/
public void testReconnectComputeApi() throws Exception {
final Ignite client = grid(serverCount());
final IgniteCompute comp = client.compute();
reconnectFailover(new Callable<Void>() {
@Override
public Void call() throws Exception {
comp.call(new DummyClosure());
comp.broadcast(new DummyClosure());
return null;
}
});
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class GridMultithreadedJobStealingSelfTest method testJoinedNodeCanStealJobs.
/**
* Test newly joined node can steal jobs.
*
* @throws Exception If test failed.
*/
public void testJoinedNodeCanStealJobs() throws Exception {
final AtomicReference<Exception> fail = new AtomicReference<>(null);
final AtomicInteger stolen = new AtomicInteger(0);
final AtomicInteger noneStolen = new AtomicInteger(0);
final ConcurrentHashSet nodes = new ConcurrentHashSet();
int threadsNum = 10;
final int jobsPerTask = 4;
jobExecutedLatch = new CountDownLatch(threadsNum);
final IgniteInternalFuture<Long> future = GridTestUtils.runMultiThreadedAsync(new Runnable() {
/**
*/
@Override
public void run() {
try {
final IgniteCompute compute = ignite.compute().withAsync();
compute.execute(new JobStealingTask(jobsPerTask), null);
JobStealingResult res = (JobStealingResult) compute.future().get();
info("Task result: " + res);
stolen.addAndGet(res.stolen);
noneStolen.addAndGet(res.nonStolen);
nodes.addAll(res.nodes);
} catch (IgniteException e) {
log.error("Failed to execute task.", e);
fail.getAndSet(e);
}
}
}, threadsNum, "JobStealingThread");
// Wait for first job begin execution.
jobExecutedLatch.await();
startGrid(2);
for (Ignite g : G.allGrids()) info("Metrics [nodeId=" + g.cluster().localNode().id() + ", metrics=" + g.cluster().localNode().metrics() + ']');
future.get();
assertNull("Test failed with exception: ", fail.get());
// Total jobs number is threadsNum * 3
assertEquals("Incorrect processed jobs number", threadsNum * jobsPerTask, stolen.get() + noneStolen.get());
assertFalse("No jobs were stolen.", stolen.get() == 0);
for (Ignite g : G.allGrids()) assertTrue("Node get no jobs.", nodes.contains(g.name()));
assertTrue("Stats [stolen=" + stolen + ", noneStolen=" + noneStolen + ']', Math.abs(stolen.get() - 2 * noneStolen.get()) <= 6);
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class TaskNodeRestartTest method testTaskNodeRestart.
/**
* @throws Exception If failed.
*/
public void testTaskNodeRestart() throws Exception {
final AtomicBoolean finished = new AtomicBoolean();
final AtomicInteger stopIdx = new AtomicInteger();
IgniteInternalFuture<?> restartFut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
int idx = stopIdx.getAndIncrement();
int node = NODES + idx;
while (!finished.get()) {
log.info("Start node: " + node);
startGrid(node);
U.sleep(300);
log.info("Stop node: " + node);
stopGrid(node);
}
return null;
}
}, 2, "stop-thread");
IgniteInternalFuture<?> fut = null;
try {
final long stopTime = System.currentTimeMillis() + 60_000;
final AtomicInteger idx = new AtomicInteger();
fut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
int node = idx.getAndIncrement() % NODES;
Ignite ignite = ignite(node);
log.info("Start thread: " + ignite.name());
IgniteCompute compute = ignite.compute();
while (U.currentTimeMillis() < stopTime) {
try {
compute.broadcast(new TestCallable());
compute.call(new TestCallable());
compute.execute(new TestTask1(), null);
compute.execute(new TestTask2(), null);
} catch (IgniteException e) {
log.info("Error: " + e);
}
}
return null;
}
}, 20, "test-thread");
fut.get(90_000);
finished.set(true);
restartFut.get();
} finally {
finished.set(true);
if (fut != null)
fut.cancel();
restartFut.get(5000);
}
}
use of org.apache.ignite.IgniteCompute in project ignite by apache.
the class IgniteComputeTopologyExceptionTest method testCorrectException.
/**
* @throws Exception If failed.
*/
public void testCorrectException() throws Exception {
Ignite ignite = ignite(0);
IgniteCompute comp = ignite.compute(ignite.cluster().forRemotes()).withNoFailover();
stopGrid(1);
try {
comp.call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
fail("Should not be called.");
return null;
}
});
fail();
} catch (ClusterTopologyException e) {
log.info("Expected exception: " + e);
}
}
Aggregations