Search in sources :

Example 31 with IgniteInternalFuture

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);
}
Also used : IgniteLock(org.apache.ignite.IgniteLock) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) IgniteInterruptedException(org.apache.ignite.IgniteInterruptedException) ExpectedException(org.junit.rules.ExpectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteException(org.apache.ignite.IgniteException) IOException(java.io.IOException)

Example 32 with IgniteInternalFuture

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);
}
Also used : LoggerResource(org.apache.ignite.resources.LoggerResource) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) ExpectedException(org.junit.rules.ExpectedException) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IOException(java.io.IOException) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable) IgniteInstanceResource(org.apache.ignite.resources.IgniteInstanceResource) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) Ignite(org.apache.ignite.Ignite) IgniteLogger(org.apache.ignite.IgniteLogger) Nullable(org.jetbrains.annotations.Nullable)

Example 33 with IgniteInternalFuture

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);
}
Also used : ArrayList(java.util.ArrayList) IgniteSemaphore(org.apache.ignite.IgniteSemaphore) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable)

Example 34 with IgniteInternalFuture

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);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) ArrayList(java.util.ArrayList) IgniteCountDownLatch(org.apache.ignite.IgniteCountDownLatch) Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) Callable(java.util.concurrent.Callable) IgniteCallable(org.apache.ignite.lang.IgniteCallable)

Example 35 with IgniteInternalFuture

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());
    }
}
Also used : Ignite(org.apache.ignite.Ignite) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture)

Aggregations

IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)245 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)114 Ignite (org.apache.ignite.Ignite)71 ArrayList (java.util.ArrayList)52 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)46 AffinityTopologyVersion (org.apache.ignite.internal.processors.affinity.AffinityTopologyVersion)46 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)43 IgniteException (org.apache.ignite.IgniteException)33 ClusterTopologyCheckedException (org.apache.ignite.internal.cluster.ClusterTopologyCheckedException)29 UUID (java.util.UUID)28 IgniteCache (org.apache.ignite.IgniteCache)28 ClusterNode (org.apache.ignite.cluster.ClusterNode)28 Callable (java.util.concurrent.Callable)27 HashMap (java.util.HashMap)25 Map (java.util.Map)25 CountDownLatch (java.util.concurrent.CountDownLatch)24 CacheConfiguration (org.apache.ignite.configuration.CacheConfiguration)19 CacheException (javax.cache.CacheException)16 GridFinishedFuture (org.apache.ignite.internal.util.future.GridFinishedFuture)16 GridFutureAdapter (org.apache.ignite.internal.util.future.GridFutureAdapter)16