use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class GridCacheSetAbstractSelfTest method testAffinityRun.
/**
* @throws Exception If failed.
*/
public void testAffinityRun() throws Exception {
final CollectionConfiguration colCfg = collectionConfiguration();
colCfg.setCollocated(false);
colCfg.setCacheMode(CacheMode.PARTITIONED);
try (final IgniteSet<Integer> set1 = grid(0).set("Set1", colCfg)) {
GridTestUtils.assertThrows(log, new Callable<Void>() {
@Override
public Void call() throws Exception {
set1.affinityRun(new IgniteRunnable() {
@Override
public void run() {
// No-op.
}
});
return null;
}
}, IgniteException.class, "Failed to execute affinityRun() for non-collocated set: " + set1.name() + ". This operation is supported only for collocated sets.");
}
colCfg.setCollocated(true);
try (final IgniteSet<Integer> set2 = grid(0).set("Set2", colCfg)) {
set2.add(100);
set2.affinityRun(new IgniteRunnable() {
@IgniteInstanceResource
private IgniteEx ignite;
@Override
public void run() {
assertTrue(ignite.cachex("datastructures_0").affinity().isPrimaryOrBackup(ignite.cluster().localNode(), "Set2"));
assertEquals(100, set2.iterator().next().intValue());
}
});
}
}
use of org.apache.ignite.lang.IgniteRunnable in project ignite by apache.
the class CacheConcurrentReadThroughTest method testConcurrentReadThrough.
/**
* @throws Exception If failed.
*/
public void testConcurrentReadThrough() throws Exception {
startGrid(0);
client = true;
Ignite client = startGrid(1);
assertTrue(client.configuration().isClientMode());
for (int iter = 0; iter < 10; iter++) {
CacheConfiguration ccfg = new CacheConfiguration(DEFAULT_CACHE_NAME);
final String cacheName = "test-" + iter;
ccfg.setName(cacheName);
ccfg.setReadThrough(true);
ccfg.setCacheStoreFactory(new TestStoreFactory());
ccfg.setStatisticsEnabled(true);
client.createCache(ccfg);
final Integer key = 1;
TestCacheStore.loadCnt.set(0);
Collection<IgniteFuture<?>> futs = new ArrayList<>();
for (int i = 0; i < SYS_THREADS * 3; i++) {
futs.add(client.compute().runAsync(new IgniteRunnable() {
@IgniteInstanceResource
private transient Ignite ignite;
@Override
public void run() {
assertFalse(ignite.configuration().isClientMode());
Object v = ignite.<Integer, Integer>cache(cacheName).get(key);
if (v == null)
throw new IgniteException("Failed to get value");
}
}));
}
for (IgniteFuture<?> fut : futs) fut.get();
int loadCnt = TestCacheStore.loadCnt.get();
long misses = ignite(1).cache(cacheName).metrics().getCacheMisses();
log.info("Iteration [iter=" + iter + ", loadCnt=" + loadCnt + ", misses=" + misses + ']');
assertTrue("Unexpected loadCnt: " + loadCnt, loadCnt > 0 && loadCnt <= SYS_THREADS);
assertTrue("Unexpected misses: " + misses, misses > 0 && misses <= SYS_THREADS);
client.destroyCache(cacheName);
}
}
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 GridTaskExecutionContextSelfTest method testWithNoFailoverClosure.
/**
* @throws Exception If failed.
*/
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 GridFactorySelfTest method testCurrentIgnite.
/**
* @throws Exception If failed.
*/
public void testCurrentIgnite() throws Exception {
final String LEFT = "LEFT";
final String RIGHT = "RIGHT";
try {
Ignite iLEFT = startGrid(LEFT);
Ignite iRIGHT = startGrid(RIGHT);
waitForDiscovery(iLEFT, iRIGHT);
iLEFT.compute(iLEFT.cluster().forRemotes()).run(new IgniteRunnable() {
@Override
public void run() {
assert Ignition.localIgnite().name().equals(RIGHT);
}
});
iRIGHT.compute(iRIGHT.cluster().forRemotes()).run(new IgniteRunnable() {
@Override
public void run() {
assert Ignition.localIgnite().name().equals(LEFT);
}
});
} finally {
stopAllGrids();
}
}
Aggregations