use of org.apache.ignite.lang.IgniteFuture in project ignite by apache.
the class CacheRebalancingSelfTest method testRebalanceFuture.
/**
* @throws Exception If failed.
*/
public void testRebalanceFuture() throws Exception {
IgniteEx ig0 = startGrid(0);
startGrid(1);
IgniteCache<Object, Object> cache = ig0.cache(DEFAULT_CACHE_NAME);
IgniteFuture fut1 = cache.rebalance();
fut1.get();
startGrid(2);
IgniteFuture fut2 = cache.rebalance();
assert internalFuture(fut2) != internalFuture(fut1);
fut2.get();
}
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 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 DataStreamerImplSelfTest method testAllOperationFinishedBeforeFutureCompletion.
/**
* @throws Exception If failed.
*/
public void testAllOperationFinishedBeforeFutureCompletion() throws Exception {
cnt = 0;
Ignite ignite = startGrids(MAX_CACHE_COUNT);
final IgniteCache cache = ignite.cache(DEFAULT_CACHE_NAME);
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<Throwable> ex = new AtomicReference<>();
Collection<Map.Entry> entries = new ArrayList<>(100);
for (int i = 0; i < 100; i++) entries.add(new IgniteBiTuple<>(i, "" + i));
IgniteDataStreamer ldr = ignite.dataStreamer(DEFAULT_CACHE_NAME);
ldr.addData(entries).listen(new IgniteInClosure<IgniteFuture<?>>() {
@Override
public void apply(IgniteFuture<?> future) {
try {
future.get();
for (int i = 0; i < 100; i++) assertEquals("" + i, cache.get(i));
} catch (Throwable e) {
ex.set(e);
}
latch.countDown();
}
});
ldr.tryFlush();
assertTrue(latch.await(5, TimeUnit.SECONDS));
Throwable e = ex.get();
if (e != null) {
if (e instanceof Error)
throw (Error) e;
if (e instanceof RuntimeException)
throw (RuntimeException) e;
throw new RuntimeException(e);
}
}
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);
}
}
Aggregations