use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridTaskExecutionContextSelfTest method testWithNoFailoverClosure.
/**
* @throws Exception If failed.
*/
@Test
public void testWithNoFailoverClosure() throws Exception {
final IgniteRunnable r = new GridAbsClosureX() {
@Override
public void applyx() {
CNT.incrementAndGet();
throw new ComputeExecutionRejectedException("Expected error.");
}
};
final Ignite g = grid(0);
GridTestUtils.assertThrows(log, new Callable<Object>() {
@Override
public Object call() throws Exception {
g.compute().withNoFailover().run(r);
return null;
}
}, ComputeExecutionRejectedException.class, "Expected error.");
assertEquals(1, CNT.get());
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class IgniteMarshallerCacheSeparateDirectoryTest method run.
/**
*/
private void run(boolean ccfgOnClient, boolean ccfgOnServer, boolean indexedTypes, AccessMode putMode, AccessMode getMode) throws Exception {
this.ccfgOnClient = ccfgOnClient;
this.ccfgOnServer = ccfgOnServer;
this.indexedTypes = indexedTypes;
Ignite server = startGrid(SERVER);
Ignite client = startGrid(CLIENT);
if (putMode == AccessMode.CLOSURE) {
client.compute().run(new IgniteRunnable() {
@Override
public void run() {
Ignition.ignite(SERVER).cache(DEFAULT_CACHE_NAME).put(KEY, new TestClass());
}
});
} else
(putMode == AccessMode.SERVER ? server : client).cache(DEFAULT_CACHE_NAME).put(KEY, new TestClass());
Object val;
if (getMode == AccessMode.CLOSURE) {
val = client.compute().call(new IgniteCallable<Object>() {
@Override
public Object call() throws Exception {
return Ignition.ignite(SERVER).cache(DEFAULT_CACHE_NAME).get(KEY);
}
});
} else
val = (putMode == AccessMode.SERVER ? server : client).cache(DEFAULT_CACHE_NAME).get(KEY);
assertNotNull(val);
assertTrue(val.toString().contains("TestClass"));
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class IgniteCacheReadThroughStoreCallTest method checkLoadCount.
/**
* @param ccfg Cache configuration.
* @throws Exception If failed.
*/
private void checkLoadCount(CacheConfiguration<Object, Object> ccfg) throws Exception {
storeMap.clear();
Ignite ignite0 = ignite(0);
ignite0.createCache(ccfg);
try {
int key = 0;
for (Ignite node : G.allGrids()) {
log.info("Test for node: " + node.name());
final IgniteCache<Object, Object> cache = node.cache(ccfg.getName());
for (int i = 0; i < 50; i++) {
final int k = key++;
checkReadThrough(cache, new IgniteRunnable() {
@Override
public void run() {
cache.invoke(k, new TestEntryProcessor());
}
}, null, null, 1);
}
for (int i = 0; i < 50; i++) {
final int k = key++;
checkReadThrough(cache, new IgniteRunnable() {
@Override
public void run() {
cache.put(k, k);
}
}, null, null, 0);
}
if (ccfg.getAtomicityMode() == TRANSACTIONAL) {
for (TransactionConcurrency concurrency : TransactionConcurrency.values()) {
for (TransactionIsolation isolation : values()) {
log.info("Test tx [concurrency=" + concurrency + ", isolation=" + isolation + ']');
for (int i = 0; i < 50; i++) {
final int k = key++;
checkReadThrough(cache, new IgniteRunnable() {
@Override
public void run() {
cache.invoke(k, new TestEntryProcessor());
}
}, concurrency, isolation, 2);
}
}
}
}
}
ignite0.cache(ccfg.getName()).removeAll();
} finally {
ignite0.destroyCache(ccfg.getName());
}
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class TcpCommunicationSpiDropNodesTest method testTwoNodesEachOther.
/**
* Servers shouldn't fail each other if IGNITE_ENABLE_FORCIBLE_NODE_KILL=true.
* @throws Exception If failed.
*/
@Test
public void testTwoNodesEachOther() throws Exception {
pred = new IgniteBiPredicate<ClusterNode, ClusterNode>() {
@Override
public boolean apply(ClusterNode locNode, ClusterNode rmtNode) {
return block && (locNode.order() == 2 || locNode.order() == 4) && (rmtNode.order() == 2 || rmtNode.order() == 4);
}
};
startGrids(NODES_CNT);
AtomicInteger evts = new AtomicInteger();
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
evts.incrementAndGet();
return true;
}
}, EVT_NODE_FAILED);
// Wait for write timeout and closing idle connections.
U.sleep(1000);
block = true;
final CyclicBarrier barrier = new CyclicBarrier(2);
IgniteInternalFuture<Void> fut1 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
grid(1).compute().withNoFailover().broadcast(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
return null;
}
});
IgniteInternalFuture<Void> fut2 = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
barrier.await();
grid(3).compute().withNoFailover().broadcast(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
return null;
}
});
try {
fut1.get();
fail("Should fail with SpiException");
} catch (IgniteCheckedException e) {
assertTrue(e.getCause().getCause() instanceof IgniteSpiException);
}
try {
fut2.get();
fail("Should fail with SpiException");
} catch (IgniteCheckedException e) {
assertTrue(e.getCause().getCause() instanceof IgniteSpiException);
}
assertEquals(NODES_CNT, grid(0).cluster().nodes().size());
assertEquals(0, evts.get());
for (int j = 0; j < NODES_CNT; j++) {
IgniteEx ignite;
try {
ignite = grid(j);
log.info("Checking topology for grid(" + j + "): " + ignite.cluster().nodes());
assertEquals(NODES_CNT, ignite.cluster().nodes().size());
} catch (Exception e) {
log.info("Checking topology for grid(" + j + "): no grid in topology.");
}
}
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class TcpCommunicationSpiDropNodesTest method testOneNode.
/**
* Server node shouldn't be failed by other server node if IGNITE_ENABLE_FORCIBLE_NODE_KILL=true.
*
* @throws Exception If failed.
*/
@Test
public void testOneNode() throws Exception {
pred = new IgniteBiPredicate<ClusterNode, ClusterNode>() {
@Override
public boolean apply(ClusterNode locNode, ClusterNode rmtNode) {
return block && rmtNode.order() == 3;
}
};
startGrids(NODES_CNT);
AtomicInteger evts = new AtomicInteger();
grid(0).events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
evts.incrementAndGet();
return true;
}
}, EVT_NODE_FAILED);
// Wait for write timeout and closing idle connections.
U.sleep(1000);
block = true;
try {
grid(0).compute().broadcast(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
fail("Should have exception here.");
} catch (IgniteException e) {
assertTrue(e.getCause() instanceof IgniteSpiException);
}
block = false;
assertEquals(NODES_CNT, grid(0).cluster().nodes().size());
assertEquals(0, evts.get());
}
Aggregations