use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class IgniteClientReconnectDiscoveryStateTest method testReconnect.
/**
* @throws Exception If failed.
*/
public void testReconnect() throws Exception {
final Ignite client = ignite(serverCount());
assertTrue(client.cluster().localNode().isClient());
long topVer = 4;
IgniteCluster cluster = client.cluster();
cluster.nodeLocalMap().put("locMapKey", 10);
Map<Integer, Integer> nodeCnt = new HashMap<>();
nodeCnt.put(1, 1);
nodeCnt.put(2, 2);
nodeCnt.put(3, 3);
nodeCnt.put(4, 4);
for (Map.Entry<Integer, Integer> e : nodeCnt.entrySet()) {
Collection<ClusterNode> nodes = cluster.topology(e.getKey());
assertNotNull("No nodes for topology: " + e.getKey(), nodes);
assertEquals((int) e.getValue(), nodes.size());
}
ClusterNode locNode = cluster.localNode();
assertEquals(topVer, locNode.order());
TestTcpDiscoverySpi srvSpi = spi(clientRouter(client));
final CountDownLatch reconnectLatch = new CountDownLatch(1);
client.events().localListen(new IgnitePredicate<Event>() {
@Override
public boolean apply(Event evt) {
if (evt.type() == EVT_CLIENT_NODE_DISCONNECTED) {
info("Disconnected: " + evt);
IgniteFuture<?> fut = client.cluster().clientReconnectFuture();
assertNotNull(fut);
assertFalse(fut.isDone());
} else if (evt.type() == EVT_CLIENT_NODE_RECONNECTED) {
info("Reconnected: " + evt);
reconnectLatch.countDown();
}
return true;
}
}, EVT_CLIENT_NODE_DISCONNECTED, EVT_CLIENT_NODE_RECONNECTED);
srvSpi.failNode(client.cluster().localNode().id(), null);
waitReconnectEvent(reconnectLatch);
// Client failed and rejoined.
topVer += 2;
locNode = cluster.localNode();
assertEquals(topVer, locNode.order());
assertEquals(topVer, cluster.topologyVersion());
nodeCnt.put(5, 3);
nodeCnt.put(6, 4);
for (Map.Entry<Integer, Integer> e : nodeCnt.entrySet()) {
Collection<ClusterNode> nodes = cluster.topology(e.getKey());
assertNotNull("No nodes for topology: " + e.getKey(), nodes);
assertEquals((int) e.getValue(), nodes.size());
}
assertEquals(10, cluster.nodeLocalMap().get("locMapKey"));
}
use of org.apache.ignite.lang.IgniteFuture 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.IgniteFuture in project ignite by apache.
the class CacheFutureExceptionSelfTest method testGet.
/**
* @param nearCache If {@code true} creates near cache on client.
* @param cpyOnRead Cache copy on read flag.
* @throws Exception If failed.
*/
private void testGet(boolean nearCache, boolean cpyOnRead) throws Exception {
fail = false;
Ignite srv = grid(0);
Ignite client = grid(1);
final String cacheName = nearCache ? ("NEAR-CACHE-" + cpyOnRead) : ("CACHE-" + cpyOnRead);
CacheConfiguration<Object, Object> ccfg = new CacheConfiguration<>(DEFAULT_CACHE_NAME);
ccfg.setCopyOnRead(cpyOnRead);
ccfg.setName(cacheName);
IgniteCache<Object, Object> cache = srv.createCache(ccfg);
cache.put("key", new NotSerializableClass());
IgniteCache<Object, Object> clientCache = nearCache ? client.createNearCache(cacheName, new NearCacheConfiguration<>()) : client.cache(cacheName);
fail = true;
final CountDownLatch futLatch = new CountDownLatch(1);
clientCache.getAsync("key").listen(new IgniteInClosure<IgniteFuture<Object>>() {
@Override
public void apply(IgniteFuture<Object> fut) {
assertTrue(fut.isDone());
try {
fut.get();
fail();
} catch (CacheException e) {
log.info("Expected error: " + e);
futLatch.countDown();
}
}
});
assertTrue(futLatch.await(5, SECONDS));
srv.destroyCache(cache.getName());
}
use of org.apache.ignite.lang.IgniteFuture 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());
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class IgniteComputeJobOneThreadTest method testNoTimeout.
/**
* @throws Exception If failed.
*/
public void testNoTimeout() throws Exception {
Ignite ignite = ignite(0);
IgniteFuture fut = null;
for (int i = 0; i < 10000; i++) {
fut = ignite.compute().runAsync(new IgniteRunnable() {
@Override
public void run() {
}
});
}
fut.get();
assertTrue(true);
}
Aggregations