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();
}
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());
}
Aggregations