⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 testrunneractionsimultaneousrunblockingtest.java

📁 sourcode about java basic
💻 JAVA
字号:
package jsunit.java.tests_server.net.jsunit.action;

import junit.framework.TestCase;

public class TestRunnerActionSimultaneousRunBlockingTest extends TestCase {
    private BlockingTestRunner runner;
    private TestRunnerAction action1;
    private TestRunnerAction action2;

    protected void setUp() throws Exception {
        super.setUp();
        runner = new BlockingTestRunner();
        action1 = new TestRunnerAction();
        action1.setBrowserTestRunner(runner);
        action2 = new TestRunnerAction();
        action2.setBrowserTestRunner(runner);
    }

    public void testSimultaneousRequestsAreQueued() throws Exception {
        Executor executor1 = new Executor(action1);
        executor1.start();
        waitTillRunnerIsBlocked(runner);
        Executor executor2 = new Executor(action2);
        executor2.start();
        runner.blocked = false;
        waitTillExecutorIsDead(executor1);
        waitTillRunnerIsBlocked(runner);
        runner.blocked = false;
        waitTillExecutorIsDead(executor2);
    }

    private void waitTillExecutorIsDead(Executor executor) throws InterruptedException {
        while (executor.isAlive())
            Thread.sleep(10);
    }

    private void waitTillRunnerIsBlocked(BlockingTestRunner runner) throws InterruptedException {
        while (!runner.blocked) {
            Thread.sleep(10);
        }
    }

    class Executor extends Thread {

        private TestRunnerAction action;

        public Executor(TestRunnerAction action) {
            this.action = action;

        }

        public void run() {
            try {
                action.execute();
            } catch (Exception e) {
                fail();
            }
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -