use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteLockAbstractSelfTest method checkLock.
/**
* @throws Exception Exception.
*/
private void checkLock(final boolean fair) throws Exception {
// Check only 'false' cases here. Successful lock is tested over the grid.
final IgniteLock lock = createReentrantLock("acquire", false, fair);
lock.lock();
IgniteInternalFuture fut = GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
assertNotNull(lock);
assert !lock.tryLock();
assert !lock.tryLock(10, MICROSECONDS);
return null;
}
});
fut.get();
lock.unlock();
removeReentrantLock("acquire", fair);
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteSemaphoreAbstractSelfTest method checkSemaphore.
/**
* @throws Exception If failed.
*/
private void checkSemaphore() throws Exception {
// Test API.
checkAcquire();
checkRelease();
checkFailoverSafe();
// Test main functionality.
final IgniteSemaphore semaphore1 = grid(0).semaphore("semaphore", -2, true, true);
assertEquals(-2, semaphore1.availablePermits());
IgniteFuture<Object> fut = grid(0).compute().callAsync(new IgniteCallable<Object>() {
@IgniteInstanceResource
private Ignite ignite;
@LoggerResource
private IgniteLogger log;
@Nullable
@Override
public Object call() throws Exception {
// Test semaphore in multiple threads on each node.
IgniteInternalFuture<?> fut = GridTestUtils.runMultiThreadedAsync(new Callable<Object>() {
@Nullable
@Override
public Object call() throws Exception {
IgniteSemaphore semaphore = ignite.semaphore("semaphore", -2, true, true);
assert semaphore != null && semaphore.availablePermits() == -2;
log.info("Thread is going to wait on semaphore: " + Thread.currentThread().getName() + ", node = " + ignite.cluster().localNode() + ", sem = " + semaphore);
assert semaphore.tryAcquire(1, 1, MINUTES);
log.info("Thread is again runnable: " + Thread.currentThread().getName() + ", node = " + ignite.cluster().localNode() + ", sem = " + semaphore);
semaphore.release();
return null;
}
}, 5, "test-thread");
fut.get();
return null;
}
});
Thread.sleep(3000);
semaphore1.release(2);
assert semaphore1.availablePermits() == 0;
semaphore1.release(1);
// Ensure there are no hangs.
fut.get();
// Test operations on removed semaphore.
semaphore1.close();
checkRemovedSemaphore(semaphore1);
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteSemaphoreAbstractSelfTest method testSemaphoreMultinode1.
/**
* @throws Exception If failed.
*/
public void testSemaphoreMultinode1() throws Exception {
if (gridCount() == 1)
return;
IgniteSemaphore semaphore = grid(0).semaphore("s1", 0, true, true);
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
for (int i = 0; i < gridCount(); i++) {
final Ignite ignite = grid(i);
futs.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteSemaphore semaphore = ignite.semaphore("s1", 0, true, false);
assertNotNull(semaphore);
boolean wait = semaphore.tryAcquire(30_000, MILLISECONDS);
assertTrue(wait);
return null;
}
}));
}
for (int i = 0; i < 10; i++) semaphore.release();
for (IgniteInternalFuture<?> fut : futs) fut.get(30_000);
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class IgniteCountDownLatchAbstractSelfTest method testLatchMultinode1.
/**
* @throws Exception If failed.
*/
public void testLatchMultinode1() throws Exception {
if (gridCount() == 1)
return;
IgniteCountDownLatch latch = grid(0).countDownLatch("l1", 10, true, true);
List<IgniteInternalFuture<?>> futs = new ArrayList<>();
final AtomicBoolean countedDown = new AtomicBoolean();
for (int i = 0; i < gridCount(); i++) {
final Ignite ignite = grid(i);
futs.add(GridTestUtils.runAsync(new Callable<Void>() {
@Override
public Void call() throws Exception {
IgniteCountDownLatch latch = ignite.countDownLatch("l1", 10, true, false);
assertNotNull(latch);
boolean wait = latch.await(30_000);
assertTrue(countedDown.get());
assertEquals(0, latch.count());
assertTrue(wait);
return null;
}
}));
}
for (int i = 0; i < 10; i++) {
if (i == 9)
countedDown.set(true);
latch.countDown();
}
for (IgniteInternalFuture<?> fut : futs) fut.get(30_000);
}
use of org.apache.ignite.internal.IgniteInternalFuture in project ignite by apache.
the class TxDeadlockDetectionNoHangsTest method checkDetectionFutures.
/**
*/
private void checkDetectionFutures() {
for (int i = 0; i < NODES_CNT; i++) {
Ignite ignite = ignite(i);
IgniteTxManager txMgr = ((IgniteKernal) ignite).context().cache().context().tm();
Collection<IgniteInternalFuture<?>> futs = txMgr.deadlockDetectionFutures();
assertTrue(futs.isEmpty());
}
}
Aggregations