mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
blockingGet test
This commit is contained in:
@@ -18,10 +18,12 @@ package org.jetbrains.concurrency
|
||||
import com.intellij.util.containers.ContainerUtil
|
||||
import com.intellij.util.lang.CompoundRuntimeException
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.Assertions.assertThatThrownBy
|
||||
import org.junit.Test
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import java.util.concurrent.Executors
|
||||
import java.util.concurrent.TimeUnit
|
||||
import java.util.concurrent.TimeoutException
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
|
||||
class AsyncPromiseTest {
|
||||
@@ -60,6 +62,28 @@ class AsyncPromiseTest {
|
||||
assertThat(count.get()).isEqualTo((numThreads / 2) + 1)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blockingGet() {
|
||||
val promise = AsyncPromise<String>()
|
||||
assertConcurrent(
|
||||
{ assertThat(promise.blockingGet(100)).isEqualTo("test") },
|
||||
{
|
||||
Thread.sleep(80)
|
||||
promise.setResult("test")
|
||||
})
|
||||
}
|
||||
|
||||
@Test
|
||||
fun blockingGet2() {
|
||||
val promise = AsyncPromise<String>()
|
||||
assertConcurrent(
|
||||
{ assertThatThrownBy { promise.blockingGet(50) }.isInstanceOf(TimeoutException::class.java) },
|
||||
{
|
||||
Thread.sleep(80)
|
||||
promise.setResult("test")
|
||||
})
|
||||
}
|
||||
|
||||
fun doHandlerTest(reject: Boolean) {
|
||||
val promise = AsyncPromise<String>()
|
||||
val count = AtomicInteger()
|
||||
|
||||
@@ -22,18 +22,21 @@ import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.jetbrains.concurrency.Promises.rejectedPromise;
|
||||
import static org.jetbrains.concurrency.Promises.resolvedPromise;
|
||||
|
||||
public interface Promise<T> {
|
||||
/**
|
||||
* @deprecated Use Promises.resolvedPromise()
|
||||
*/
|
||||
@Deprecated
|
||||
Promise<Void> DONE = Promises.resolvedPromise();
|
||||
Promise<Void> DONE = resolvedPromise();
|
||||
|
||||
/**
|
||||
* @deprecated Use Promises.rejectedPromise()
|
||||
*/
|
||||
@Deprecated
|
||||
Promise<Void> REJECTED = Promises.rejectedPromise();
|
||||
Promise<Void> REJECTED = rejectedPromise();
|
||||
|
||||
enum State {
|
||||
PENDING, FULFILLED, REJECTED
|
||||
@@ -41,13 +44,7 @@ public interface Promise<T> {
|
||||
|
||||
@NotNull
|
||||
static <T> Promise<T> resolve(T result) {
|
||||
if (result == null) {
|
||||
//noinspection unchecked
|
||||
return (Promise<T>)DONE;
|
||||
}
|
||||
else {
|
||||
return new DonePromise<>(result);
|
||||
}
|
||||
return result == null ? resolvedPromise() : new DonePromise<>(result);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -73,5 +70,9 @@ public interface Promise<T> {
|
||||
@Nullable
|
||||
T blockingGet(int timeout, @NotNull TimeUnit timeUnit);
|
||||
|
||||
default T blockingGet(int timeout) {
|
||||
return blockingGet(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
|
||||
void notify(@NotNull AsyncPromise<? super T> child);
|
||||
}
|
||||
Reference in New Issue
Block a user