FileDocCategorySizeDatePackage
ThreadsTest.javaAPI DocAndroid 1.5 API9933Wed May 06 22:41:04 BST 2009tests.api.org.apache.harmony.kernel.dalvik

ThreadsTest

public class ThreadsTest extends TestCase
Tests for the park() functionality of {@link Unsafe}.

Fields Summary
private static Unsafe
UNSAFE
private static RuntimeException
INITIALIZEFAILED
Constructors Summary
Methods Summary
protected voidsetUp()

        if (INITIALIZEFAILED != null) {
            throw INITIALIZEFAILED;
        }
    
public voidtest_parkFor_1()
Test the case where the park times out.

        Parker parker = new Parker(false, 500);
        Thread parkerThread = new Thread(parker);
        Thread waiterThread =
            new Thread(new WaitAndUnpark(1000, parkerThread));

        parkerThread.start();
        waiterThread.start();
        parker.assertDurationIsInRange(500);
    
public voidtest_parkFor_2()
Test the case where the unpark happens before the timeout.

        Parker parker = new Parker(false, 1000);
        Thread parkerThread = new Thread(parker);
        Thread waiterThread =
            new Thread(new WaitAndUnpark(300, parkerThread));

        parkerThread.start();
        waiterThread.start();
        parker.assertDurationIsInRange(300);
    
public voidtest_parkFor_3()
Test the case where the thread is preemptively unparked.

        Parker parker = new Parker(false, 1000);
        Thread parkerThread = new Thread(parker);

        UNSAFE.unpark(parkerThread);
        parkerThread.start();
        parker.assertDurationIsInRange(0);
    
public voidtest_parkUntil_1()
Test the case where the park times out.

        Parker parker = new Parker(true, 500);
        Thread parkerThread = new Thread(parker);
        Thread waiterThread =
            new Thread(new WaitAndUnpark(1000, parkerThread));

        parkerThread.start();
        waiterThread.start();
        parker.assertDurationIsInRange(500);
    
public voidtest_parkUntil_2()
Test the case where the unpark happens before the timeout.

        Parker parker = new Parker(true, 1000);
        Thread parkerThread = new Thread(parker);
        Thread waiterThread =
            new Thread(new WaitAndUnpark(300, parkerThread));

        parkerThread.start();
        waiterThread.start();
        parker.assertDurationIsInRange(300);
    
public voidtest_parkUntil_3()
Test the case where the thread is preemptively unparked.

        Parker parker = new Parker(true, 1000);
        Thread parkerThread = new Thread(parker);

        UNSAFE.unpark(parkerThread);
        parkerThread.start();
        parker.assertDurationIsInRange(0);