use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class GridMultipleJobsSelfTest method runTest.
/**
* @param jobsNum Number of jobs.
* @param threadNum Number of threads.
* @param jobCls Job class.
* @throws Exception If failed.
*/
private void runTest(final int jobsNum, int threadNum, final Class<? extends IgniteCallable<Boolean>> jobCls) throws Exception {
final Ignite ignite1 = grid(1);
final CountDownLatch latch = new CountDownLatch(jobsNum);
final AtomicInteger jobsCnt = new AtomicInteger();
final AtomicInteger resCnt = new AtomicInteger();
GridTestUtils.runMultiThreaded(new CAX() {
@Override
public void applyx() throws IgniteCheckedException {
while (true) {
int cnt = jobsCnt.incrementAndGet();
if (cnt > jobsNum)
break;
IgniteCallable<Boolean> job;
try {
job = jobCls.newInstance();
} catch (Exception e) {
throw new IgniteCheckedException("Could not instantiate a job.", e);
}
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();
} finally {
latch.countDown();
long cnt = resCnt.incrementAndGet();
if (cnt % LOG_MOD == 0)
X.println("Results count: " + cnt);
}
}
});
}
}
}, threadNum, "TEST-THREAD");
latch.await();
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class DataStreamerImplSelfTest method testNoDataNodesOnFlush.
/**
* Test logging on {@code DataStreamer.addData()} method when cache have no data nodes
*
* @throws Exception If fail.
*/
public void testNoDataNodesOnFlush() throws Exception {
boolean failed = false;
cnt = 0;
noNodesFilter = true;
try {
Ignite ignite = startGrid(1);
IgniteFuture fut = null;
try (IgniteDataStreamer<Integer, String> streamer = ignite.dataStreamer(DEFAULT_CACHE_NAME)) {
fut = streamer.addData(1, "1");
streamer.flush();
} catch (IllegalStateException ignored) {
try {
fut.get();
fail("DataStreamer ignores failed streaming.");
} catch (CacheServerNotFoundException ignored2) {
// No-op.
}
failed = true;
}
} finally {
noNodesFilter = false;
assertTrue(failed);
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class DataStreamProcessorSelfTest method checkLoaderMultithreaded.
/**
* Tests loader in multithreaded environment with various count of grids started.
*
* @param nodesCntNoCache How many nodes should be started without cache.
* @param nodesCntCache How many nodes should be started with cache.
* @throws Exception If failed.
*/
protected void checkLoaderMultithreaded(int nodesCntNoCache, int nodesCntCache) throws Exception {
try {
// Start all required nodes.
int idx = 1;
useCache = true;
for (int i = 0; i < nodesCntCache; i++) startGrid(idx++);
useCache = false;
for (int i = 0; i < nodesCntNoCache; i++) startGrid(idx++);
Ignite g1 = grid(idx - 1);
// Get and configure loader.
final IgniteDataStreamer<Integer, Integer> ldr = g1.dataStreamer(DEFAULT_CACHE_NAME);
ldr.receiver(DataStreamerCacheUpdaters.<Integer, Integer>individual());
ldr.perNodeBufferSize(2);
// Define count of puts.
final AtomicInteger idxGen = new AtomicInteger();
final AtomicBoolean done = new AtomicBoolean();
try {
final int totalPutCnt = 50000;
IgniteInternalFuture<?> fut1 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
Collection<IgniteFuture<?>> futs = new ArrayList<>();
while (!done.get()) {
int idx = idxGen.getAndIncrement();
if (idx >= totalPutCnt) {
info(">>> Stopping producer thread since maximum count of puts reached.");
break;
}
futs.add(ldr.addData(idx, idx));
}
ldr.flush();
for (IgniteFuture<?> fut : futs) fut.get();
return null;
}
}, 5, "producer");
IgniteInternalFuture<?> fut2 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
while (!done.get()) {
ldr.flush();
U.sleep(100);
}
return null;
}
}, 1, "flusher");
// Define index of node being restarted.
final int restartNodeIdx = nodesCntCache + nodesCntNoCache + 1;
IgniteInternalFuture<?> fut3 = multithreadedAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
try {
for (int i = 0; i < 5; i++) {
Ignite g = startGrid(restartNodeIdx);
UUID id = g.cluster().localNode().id();
info(">>>>>>> Started node: " + id);
U.sleep(1000);
stopGrid(getTestIgniteInstanceName(restartNodeIdx), true);
info(">>>>>>> Stopped node: " + id);
}
} finally {
done.set(true);
info("Start stop thread finished.");
}
return null;
}
}, 1, "start-stop-thread");
fut1.get();
fut2.get();
fut3.get();
} finally {
ldr.close(false);
}
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class SchemaExchangeSelfTest method testServerRestartWithNewTypes.
/**
* Test client reconnect after server restart accompanied by schema change.
*
* @throws Exception If failed.
*/
public void testServerRestartWithNewTypes() throws Exception {
IgniteEx node1 = start(1, KeyClass.class, ValueClass.class);
assertTypes(node1, ValueClass.class);
IgniteEx node2 = startClientNoCache(2);
assertTypes(node2);
node2.cache(CACHE_NAME);
assertTypes(node2, ValueClass.class);
stopGrid(1);
assertTrue(GridTestUtils.waitForCondition(new GridAbsPredicate() {
@Override
public boolean apply() {
return grid(2).context().clientDisconnected();
}
}, 10_000L));
IgniteFuture reconnFut = null;
try {
node2.cache(CACHE_NAME);
fail();
} catch (IgniteClientDisconnectedException e) {
reconnFut = e.reconnectFuture();
}
node1 = start(1, KeyClass.class, ValueClass.class, KeyClass2.class, ValueClass2.class);
assertTypes(node1, ValueClass.class, ValueClass2.class);
reconnFut.get();
assertTypes(node2);
node2.cache(CACHE_NAME);
assertTypes(node2, ValueClass.class, ValueClass2.class);
}
use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class CacheAsyncOperationsFailoverAbstractTest method startAsyncOperations.
/**
* @param ops Number of operations.
* @param cache Cache.
* @return Futures.
* @throws Exception If failed.
*/
private List<IgniteFuture<?>> startAsyncOperations(final int ops, final IgniteCache<TestKey, TestValue> cache) throws Exception {
final List<IgniteFuture<?>> futs = Collections.synchronizedList(new ArrayList<IgniteFuture<?>>(ops));
final AtomicInteger left = new AtomicInteger(ops);
GridTestUtils.runMultiThreaded(new Callable<Object>() {
@Override
public Object call() throws Exception {
List<IgniteFuture<?>> futs0 = new ArrayList<>();
ThreadLocalRandom rnd = ThreadLocalRandom.current();
while (left.getAndDecrement() > 0) {
TreeMap<TestKey, TestValue> map = new TreeMap<>();
int keys = 50;
for (int k = 0; k < keys; k++) map.put(new TestKey(rnd.nextInt(10_000)), new TestValue(k));
IgniteFuture<?> fut = cache.putAllAsync(map);
assertNotNull(fut);
futs0.add(fut);
}
futs.addAll(futs0);
return null;
}
}, 10, "put-thread");
assertEquals(ops, futs.size());
return futs;
}
Aggregations