Search in sources :

Example 1 with GridNioFutureImpl

use of org.apache.ignite.internal.util.nio.GridNioFutureImpl in project ignite by apache.

the class GridNioFutureSelfTest method testListenSyncNotify.

/**
     * @throws Exception If failed.
     */
public void testListenSyncNotify() throws Exception {
    GridNioFutureImpl<String> fut = new GridNioFutureImpl<>(null);
    int lsnrCnt = 10;
    final CountDownLatch latch = new CountDownLatch(lsnrCnt);
    final Thread runThread = Thread.currentThread();
    final AtomicReference<Exception> err = new AtomicReference<>();
    for (int i = 0; i < lsnrCnt; i++) {
        fut.listen(new CI1<IgniteInternalFuture<String>>() {

            @Override
            public void apply(IgniteInternalFuture<String> t) {
                if (Thread.currentThread() != runThread)
                    err.compareAndSet(null, new Exception("Wrong notification thread: " + Thread.currentThread()));
                latch.countDown();
            }
        });
    }
    fut.onDone();
    assertEquals(0, latch.getCount());
    if (err.get() != null)
        throw err.get();
    final AtomicBoolean called = new AtomicBoolean();
    err.set(null);
    fut.listen(new CI1<IgniteInternalFuture<String>>() {

        @Override
        public void apply(IgniteInternalFuture<String> t) {
            if (Thread.currentThread() != runThread)
                err.compareAndSet(null, new Exception("Wrong notification thread: " + Thread.currentThread()));
            called.set(true);
        }
    });
    assertTrue(called.get());
    if (err.get() != null)
        throw err.get();
}
Also used : AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) GridNioFutureImpl(org.apache.ignite.internal.util.nio.GridNioFutureImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 2 with GridNioFutureImpl

use of org.apache.ignite.internal.util.nio.GridNioFutureImpl in project ignite by apache.

the class GridNioFutureSelfTest method testOnDone.

/**
     * @throws Exception If failed.
     */
public void testOnDone() throws Exception {
    GridNioFutureImpl<String> fut = new GridNioFutureImpl<>(null);
    fut.onDone();
    assertNull(fut.get());
    fut = new GridNioFutureImpl<>(null);
    fut.onDone("test");
    assertEquals("test", fut.get());
    fut = new GridNioFutureImpl<>(null);
    fut.onDone(new IgniteCheckedException("TestMessage"));
    final GridNioFutureImpl<String> callFut1 = fut;
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return callFut1.get();
        }
    }, IgniteCheckedException.class, "TestMessage");
    fut = new GridNioFutureImpl<>(null);
    fut.onDone("test", new IgniteCheckedException("TestMessage"));
    final GridNioFuture<String> callFut2 = fut;
    GridTestUtils.assertThrows(log, new Callable<Object>() {

        @Override
        public Object call() throws Exception {
            return callFut2.get();
        }
    }, IgniteCheckedException.class, "TestMessage");
    fut = new GridNioFutureImpl<>(null);
    fut.onDone("test");
    fut.onCancelled();
    assertEquals("test", fut.get());
}
Also used : IgniteCheckedException(org.apache.ignite.IgniteCheckedException) GridNioFutureImpl(org.apache.ignite.internal.util.nio.GridNioFutureImpl) IgniteCheckedException(org.apache.ignite.IgniteCheckedException) IgniteFutureCancelledCheckedException(org.apache.ignite.internal.IgniteFutureCancelledCheckedException) IgniteFutureTimeoutCheckedException(org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)

Aggregations

IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 IgniteFutureCancelledCheckedException (org.apache.ignite.internal.IgniteFutureCancelledCheckedException)2 IgniteFutureTimeoutCheckedException (org.apache.ignite.internal.IgniteFutureTimeoutCheckedException)2 GridNioFutureImpl (org.apache.ignite.internal.util.nio.GridNioFutureImpl)2 CountDownLatch (java.util.concurrent.CountDownLatch)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)1