use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class AtomicPutAllChangingTopologyTest method testPutAllOnChangingTopology.
/**
* @throws Exception If failed.
*/
public void testPutAllOnChangingTopology() throws Exception {
List<IgniteInternalFuture> futs = new LinkedList<>();
for (int i = 1; i < NODES_CNT; i++) futs.add(startNodeAsync(i));
futs.add(startSeedNodeAsync());
boolean failed = false;
for (IgniteInternalFuture fut : futs) {
try {
fut.get();
} catch (Throwable th) {
log.error("Check failed.", th);
failed = true;
}
}
if (failed)
throw new RuntimeException("Test Failed.");
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class MarshallerCacheJobRunNodeRestartTest method testJobRun.
/**
* @throws Exception If failed.
*/
public void testJobRun() throws Exception {
for (int i = 0; i < 5; i++) {
U.resolveWorkDirectory(U.defaultWorkDirectory(), "marshaller", true);
log.info("Iteration: " + i);
final int NODES = 3;
startGridsMultiThreaded(NODES);
client = true;
startGrid(NODES);
client = false;
final IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
for (int i = 0; i < 3; i++) {
startGrid(NODES + 1);
U.sleep(1000);
stopGrid(NODES + 1);
}
return null;
}
});
GridTestUtils.runMultiThreaded(new IgniteInClosure<Integer>() {
@Override
public void apply(Integer integer) {
Ignite ignite = ignite(integer % 4);
while (!fut.isDone()) {
for (int i = 0; i < 10; i++) ignite.compute().broadcast(job(i));
}
}
}, (NODES + 1) * 5, "test");
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridCacheDhtPreloadPutGetSelfTest method performTest.
/**
* @throws Exception If test fails.
*/
private void performTest() throws Exception {
try {
final CountDownLatch writeLatch = new CountDownLatch(1);
final CountDownLatch readLatch = new CountDownLatch(1);
final AtomicBoolean done = new AtomicBoolean();
IgniteInternalFuture fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
Ignite g2 = startGrid(2);
for (int i = 0; i < ITER_CNT; i++) {
info("Iteration # " + i);
IgniteCache<Integer, Integer> cache = g2.cache(DEFAULT_CACHE_NAME);
for (int j = 0; j < KEY_CNT; j++) {
Integer val = cache.get(j);
if (j % FREQUENCY == 0)
info("Read entry: " + j + " -> " + val);
if (done.get())
assert val != null && val == j;
}
writeLatch.countDown();
readLatch.await();
}
return null;
}
}, 1, "reader");
IgniteInternalFuture fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
try {
writeLatch.await(10, TimeUnit.SECONDS);
Ignite g1 = startGrid(1);
IgniteCache<Integer, Integer> cache = g1.cache(DEFAULT_CACHE_NAME);
for (int j = 0; j < KEY_CNT; j++) {
cache.put(j, j);
if (j % FREQUENCY == 0)
info("Stored value in cache: " + j);
}
done.set(true);
for (int j = 0; j < KEY_CNT; j++) {
Integer val = internalCache(cache).get(j);
assert val != null;
if (j % FREQUENCY == 0)
info("Read entry: " + j + " -> " + val);
assert val != null && val == j;
}
if (backups > 0)
stopGrid(1);
} finally {
readLatch.countDown();
}
return null;
}
}, 1, "writer");
fut1.get();
fut2.get();
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridCachePartitionedTopologyChangeSelfTest method testExplicitLocks.
/**
* @throws Exception If failed.
*/
public void testExplicitLocks() throws Exception {
try {
startGridsMultiThreaded(2);
IgniteKernal[] nodes = new IgniteKernal[] { (IgniteKernal) grid(0), (IgniteKernal) grid(1) };
Collection<IgniteInternalFuture> futs = new ArrayList<>();
final CountDownLatch startLatch = new CountDownLatch(1);
for (final IgniteKernal node : nodes) {
List<Integer> parts = partitions(node, PARTITION_PRIMARY);
Map<Integer, Integer> keyMap = keysFor(node, parts);
for (final Integer key : keyMap.values()) {
futs.add(multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
Lock lock = node.cache(DEFAULT_CACHE_NAME).lock(key);
lock.lock();
try {
info(">>> Acquired explicit lock for key: " + key);
startLatch.await();
info(">>> Acquiring explicit lock for key: " + key * 10);
Lock lock10 = node.cache(DEFAULT_CACHE_NAME).lock(key * 10);
lock10.lock();
try {
info(">>> Releasing locks [key1=" + key + ", key2=" + key * 10 + ']');
} finally {
lock10.unlock();
}
} finally {
lock.unlock();
}
} catch (CacheException e) {
info(">>> Failed to perform lock [key=" + key + ", e=" + e + ']');
} catch (InterruptedException ignored) {
info(">>> Interrupted while waiting for start latch.");
Thread.currentThread().interrupt();
}
}
}, 1));
}
}
IgniteInternalFuture<?> startFut = multithreadedAsync(new Runnable() {
@Override
public void run() {
try {
startGrid(2);
info(">>> Started grid2.");
} catch (Exception e) {
info(">>> Failed to start grid: " + e);
}
}
}, 1);
U.sleep(5000);
assertFalse(startFut.isDone());
info(">>> Waiting for all locks to be released.");
startLatch.countDown();
for (IgniteInternalFuture fut : futs) fut.get(1000);
startFut.get();
} finally {
stopAllGrids();
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class HadoopChildProcessRunner method notifyTaskFinished.
/**
* @param taskInfo Finished task info.
* @param status Task status.
*/
private void notifyTaskFinished(final HadoopTaskInfo taskInfo, final HadoopTaskStatus status, boolean flush) {
final HadoopTaskState state = status.state();
final Throwable err = status.failCause();
if (!flush) {
try {
if (log.isDebugEnabled())
log.debug("Sending notification to parent node [taskInfo=" + taskInfo + ", state=" + state + ", err=" + err + ']');
comm.sendMessage(nodeDesc, new HadoopTaskFinishedMessage(taskInfo, status));
} catch (IgniteCheckedException e) {
log.error("Failed to send message to parent node (will terminate child process).", e);
shutdown();
terminate();
}
} else {
if (log.isDebugEnabled())
log.debug("Flushing shuffle messages before sending last task completion notification [taskInfo=" + taskInfo + ", state=" + state + ", err=" + err + ']');
final long start = U.currentTimeMillis();
try {
shuffleJob.flush().listen(new CI1<IgniteInternalFuture<?>>() {
@Override
public void apply(IgniteInternalFuture<?> f) {
long end = U.currentTimeMillis();
if (log.isDebugEnabled())
log.debug("Finished flushing shuffle messages [taskInfo=" + taskInfo + ", flushTime=" + (end - start) + ']');
try {
// Check for errors on shuffle.
f.get();
notifyTaskFinished(taskInfo, status, false);
} catch (IgniteCheckedException e) {
log.error("Failed to flush shuffle messages (will fail the task) [taskInfo=" + taskInfo + ", state=" + state + ", err=" + err + ']', e);
notifyTaskFinished(taskInfo, new HadoopTaskStatus(HadoopTaskState.FAILED, e), false);
}
}
});
} catch (IgniteCheckedException e) {
log.error("Failed to flush shuffle messages (will fail the task) [taskInfo=" + taskInfo + ", state=" + state + ", err=" + err + ']', e);
notifyTaskFinished(taskInfo, new HadoopTaskStatus(HadoopTaskState.FAILED, e), false);
}
}
}
Aggregations