From 4bdc5cefe73505e53debf062c3c260c5a831e8b4 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 20 Nov 2018 16:09:18 +0100 Subject: [PATCH] move AsyncPromiseTest2 to correct package --- .../concurrency/AsyncPromiseTest2.kt | 168 +++++++++--------- 1 file changed, 83 insertions(+), 85 deletions(-) rename platform/platform-tests/testSrc/{com/intellij/util => org/jetbrains}/concurrency/AsyncPromiseTest2.kt (96%) diff --git a/platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt b/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest2.kt similarity index 96% rename from platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt rename to platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest2.kt index a88e7bba0c39..7d5d985dd161 100644 --- a/platform/platform-tests/testSrc/com/intellij/util/concurrency/AsyncPromiseTest2.kt +++ b/platform/platform-tests/testSrc/org/jetbrains/concurrency/AsyncPromiseTest2.kt @@ -1,10 +1,8 @@ // Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. -package com.intellij.util.concurrency +package org.jetbrains.concurrency import com.intellij.testFramework.assertions.Assertions.assertThat import com.intellij.util.TimeoutUtil.sleep -import org.jetbrains.concurrency.AsyncPromise -import org.jetbrains.concurrency.InternalPromiseUtil import org.junit.Test import java.awt.EventQueue.invokeLater import java.awt.EventQueue.isDispatchThread @@ -12,88 +10,6 @@ import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutionException import java.util.concurrent.TimeUnit -private const val PRINT = false - -private class CheckedException : Exception() - -private fun isMessageError(exception: Exception): Boolean { - return exception is InternalPromiseUtil.MessageError -} - -private fun log(message: String) { - @Suppress("ConstantConditionIf") - if (PRINT) { - println(message) - } -} - -private fun promise(state: AsyncPromiseTest2.State, `when`: When): AsyncPromise { - assert(!isDispatchThread()) - - val latch = CountDownLatch(1) - val promise = AsyncPromise() - val task = { - try { - sleep(10) - when (state) { - AsyncPromiseTest2.State.RESOLVE -> { - log("resolve promise") - promise.setResult("resolved") - } - AsyncPromiseTest2.State.REJECT -> { - log("reject promise") - promise.setError("rejected") - } - AsyncPromiseTest2.State.ERROR -> { - log("notify promise about error to preserve a cause") - promise.onError { /* add empty error handler to ensure that promise will not call LOG.error */ } - promise.setError(CheckedException()) - } - } - latch.countDown() - } - catch (throwable: Throwable) { - log("unexpected error that breaks current task") - throwable.printStackTrace() - } - } - - when (`when`) { - When.NOW -> { - log("resolve promise immediately") - task() - } - When.AFTER -> { - log("resolve promise on another thread") - invokeLater(task) - } - When.BEFORE -> { - log("resolve promise on another thread before handler is set") - invokeLater(task) - sleep(50) - } - } - - log("add processing handlers") - promise.onProcessed { log("promise is processed") } - try { - log("wait for task completion") - latch.await(100, TimeUnit.MILLISECONDS) - if (0L == latch.count) { - return promise - } - - throw AssertionError("task is not completed") - } - catch (exception: InterruptedException) { - throw AssertionError("task is interrupted", exception) - } -} - -private enum class When { - NOW, AFTER, BEFORE -} - class AsyncPromiseTest2 { internal enum class State { RESOLVE, REJECT, ERROR @@ -182,3 +98,85 @@ class AsyncPromiseTest2 { } } } + +private const val PRINT = false + +private class CheckedException : Exception() + +private fun isMessageError(exception: Exception): Boolean { + return exception is InternalPromiseUtil.MessageError +} + +private fun log(message: String) { + @Suppress("ConstantConditionIf") + if (PRINT) { + println(message) + } +} + +private fun promise(state: AsyncPromiseTest2.State, `when`: When): AsyncPromise { + assert(!isDispatchThread()) + + val latch = CountDownLatch(1) + val promise = AsyncPromise() + val task = { + try { + sleep(10) + when (state) { + AsyncPromiseTest2.State.RESOLVE -> { + log("resolve promise") + promise.setResult("resolved") + } + AsyncPromiseTest2.State.REJECT -> { + log("reject promise") + promise.setError("rejected") + } + AsyncPromiseTest2.State.ERROR -> { + log("notify promise about error to preserve a cause") + promise.onError { /* add empty error handler to ensure that promise will not call LOG.error */ } + promise.setError(CheckedException()) + } + } + latch.countDown() + } + catch (throwable: Throwable) { + log("unexpected error that breaks current task") + throwable.printStackTrace() + } + } + + when (`when`) { + When.NOW -> { + log("resolve promise immediately") + task() + } + When.AFTER -> { + log("resolve promise on another thread") + invokeLater(task) + } + When.BEFORE -> { + log("resolve promise on another thread before handler is set") + invokeLater(task) + sleep(50) + } + } + + log("add processing handlers") + promise.onProcessed { log("promise is processed") } + try { + log("wait for task completion") + latch.await(100, TimeUnit.MILLISECONDS) + if (0L == latch.count) { + return promise + } + + throw AssertionError("task is not completed") + } + catch (exception: InterruptedException) { + throw AssertionError("task is interrupted", exception) + } +} + +private enum class When { + NOW, AFTER, BEFORE +} \ No newline at end of file