use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class ReadWriteLockMultiThreadedTest method testReadLockAcquire.
/**
* @throws Exception If failed.
*/
@SuppressWarnings({ "LockAcquiredButNotSafelyReleased" })
public void testReadLockAcquire() throws Exception {
final ReadWriteLock lock = new ReentrantReadWriteLock();
lock.writeLock().lock();
X.println("Write lock acquired: " + lock);
IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
X.println("Attempting to acquire read lock: " + lock);
lock.readLock().lock();
try {
X.println("Read lock acquired: " + lock);
return null;
} finally {
lock.readLock().unlock();
}
}
}, 1, "read-lock");
Thread.sleep(2000);
X.println(">>> Dump threads now! <<<");
Thread.sleep(15 * 1000);
X.println("Write lock released.");
lock.writeLock().unlock();
fut.get();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class GridSharedFsCheckpointSpiMultiThreadedSelfTest method testSpi.
/**
* @throws Exception If failed.
*/
public void testSpi() throws Exception {
final AtomicInteger writeFinished = new AtomicInteger();
final AtomicBoolean fail = new AtomicBoolean();
IgniteInternalFuture fut1 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
try {
byte[] state = createTestArray((byte) 1);
for (int i = 0; i < ITER_CNT; i++) getSpi().saveCheckpoint(CHECK_POINT_KEY, state, 0, true);
return null;
} finally {
writeFinished.incrementAndGet();
}
}
}, THREAD_CNT, "writer-1");
IgniteInternalFuture fut2 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
try {
byte[] state = createTestArray((byte) 2);
for (int i = 0; i < ITER_CNT; i++) getSpi().saveCheckpoint(CHECK_POINT_KEY, state, 0, true);
return null;
} finally {
writeFinished.incrementAndGet();
}
}
}, THREAD_CNT, "writer-2");
IgniteInternalFuture fut3 = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
while (writeFinished.get() < THREAD_CNT * 2) {
try {
byte[] state = getSpi().loadCheckpoint(CHECK_POINT_KEY);
if (state == null)
continue;
assert state.length == ARRAY_SIZE;
boolean has1 = false;
boolean has2 = false;
for (int j = 0; j < ARRAY_SIZE; j++) {
switch(state[j]) {
case 1:
has1 = true;
assert !has2;
break;
case 2:
has2 = true;
assert !has1;
break;
default:
assert false : "Unexpected value in state: " + state[j];
}
}
info(">>>>>>> Checkpoint is fine.");
} catch (Throwable e) {
error("Failed to load checkpoint: " + e.getMessage());
fail.set(true);
}
}
return null;
}
}, 1, "reader");
fut1.get();
fut2.get();
fut3.get();
assert !fail.get();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheTopologyCommandHandlerTest method topologyCommandOnDynamicCacheCreateDestroy.
/**
* @param node Ignite node.
* @param req Rest request.
* @throws Exception If failed.
*/
private void topologyCommandOnDynamicCacheCreateDestroy(final Ignite node, GridRestTopologyRequest req) throws Exception {
GridTopologyCommandHandler hnd = new GridTopologyCommandHandler(((IgniteKernal) node).context());
final AtomicReference<Exception> ex = new AtomicReference<>();
final long deadline = System.currentTimeMillis() + 5000;
final AtomicInteger cntr = new AtomicInteger();
IgniteInternalFuture fut = GridTestUtils.runMultiThreadedAsync(new Runnable() {
@Override
public void run() {
int startIdx = cntr.getAndAdd(4);
int idx = 0;
boolean start = true;
while (System.currentTimeMillis() < deadline) {
try {
if (start)
node.createCache("cache" + (startIdx + idx));
else
node.destroyCache("cache" + (startIdx + idx));
if ((idx = (idx + 1) % 4) == 0)
start = !start;
} catch (Exception e) {
if (ex.get() != null || !ex.compareAndSet(null, e))
ex.get().addSuppressed(e);
break;
}
}
}
}, 4, "cache-start-destroy");
while (!fut.isDone()) hnd.handleAsync(req).get();
if (ex.get() != null)
throw ex.get();
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteCacheNodeJoinAbstractTest method testScanQuery.
/**
* @throws Exception If failed.
*/
public void testScanQuery() throws Exception {
final IgniteCache<Integer, Integer> cache = jcache(0);
for (int i = 0; i < 5; i++) {
log.info("Iteration: " + i);
final IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
startGrid(1);
return null;
}
});
final AtomicBoolean stop = new AtomicBoolean();
GridTestUtils.runMultiThreaded(new Callable<Void>() {
@Override
public Void call() throws Exception {
ScanQuery qry = new ScanQuery();
while (!stop.get() && !fut.isDone()) cache.query(qry).getAll();
return null;
}
}, 10, "test-qry");
try {
fut.get(60_000);
} finally {
stop.set(true);
}
stopGrid(1);
}
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class CacheExchangeMergeTest method testDelayExchangeMessages.
/**
* @throws Exception If failed.
*/
public void testDelayExchangeMessages() throws Exception {
testDelaySpi = true;
System.setProperty(IgniteSystemProperties.IGNITE_EXCHANGE_MERGE_DELAY, "2000");
try {
final int srvs = 6;
final int clients = 3;
startGridsMultiThreaded(srvs);
for (int i = 0; i < clients; i++) {
client.set(true);
startGrid(srvs + i);
}
final int initNodes = srvs + clients;
final AtomicInteger stopIdx = new AtomicInteger();
IgniteInternalFuture stopFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
Thread.sleep(ThreadLocalRandom.current().nextLong(500) + 1);
stopGrid(stopIdx.incrementAndGet());
return null;
}
}, 3, "stop-srv");
final AtomicInteger startIdx = new AtomicInteger(initNodes);
IgniteInternalFuture startFut = GridTestUtils.runMultiThreadedAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
ThreadLocalRandom rnd = ThreadLocalRandom.current();
int nodeIdx = startIdx.incrementAndGet();
if (rnd.nextInt(3) == 0) {
log.info("Start client: " + nodeIdx);
client.set(true);
} else
log.info("Start server: " + nodeIdx);
startGrid(nodeIdx);
if (rnd.nextBoolean()) {
log.info("Stop started node: " + nodeIdx);
stopGrid(nodeIdx);
}
return null;
}
}, 5, "start-node");
stopFut.get();
startFut.get();
checkCaches();
} finally {
System.clearProperty(IgniteSystemProperties.IGNITE_EXCHANGE_MERGE_DELAY);
}
}
Aggregations