FileDocCategorySizeDatePackage
TestKill.javaAPI DocphoneME MR2 API (J2ME)3997Wed May 02 18:00:02 BST 2007com.sun.midp.links

TestKill

public class TestKill extends com.sun.midp.i3test.TestCase
Tests proper link state after an isolate is killed.

Fields Summary
com.sun.cldc.isolate.Isolate
us
com.sun.cldc.isolate.Isolate
them
Link
to
Link
from
Constructors Summary
Methods Summary
voidcheckClosedLinks()

        boolean thrown = false;

        try {
            to.send(LinkMessage.newStringMessage("Hello, world!"));
        } catch (ClosedLinkException cle) {
            thrown = true;
        }
        assertTrue("send should throw CLE", thrown);

        thrown = false;
        try {
            LinkMessage msg = from.receive();
        } catch (ClosedLinkException cle) {
            thrown = true;
        }
        assertTrue("receive should throw CLE", thrown);
    
public voidrunTests()
Runs all tests.


        declare("testKillReceive");
        setUp();
        testKillReceive();
        tearDown();

        declare("testKillSend");
        setUp();
        testKillSend();
        tearDown();

        declare("testStrandMessage");
        setUp();
        testStrandMessage();
        tearDown();
    
voidsetUp()

        us = Isolate.currentIsolate();
        them = new Isolate("com.sun.midp.links.Echo", null);
        them.start();
        to = Link.newLink(us, them);
        from = Link.newLink(them, us);
        LinkPortal.setLinks(them, new Link[] { to, from });
    
voidtearDown()

        us = them = null;
        to = from = null;
    
voidtestKillReceive()

        Receiver receiver = new Receiver(from);
        assertFalse("receiver blocked", receiver.done);

        them.exit(0);
        them.waitForExit();
        receiver.await();

        assertTrue("receiver got IIOE",
            receiver.exception instanceof InterruptedIOException);
        checkClosedLinks();
    
voidtestKillSend()

        to.send(LinkMessage.newStringMessage("one"));
        Sender sender = new Sender(to, LinkMessage.newStringMessage("two"));
        assertFalse("sender blocked", sender.done);

        them.exit(0);
        them.waitForExit();
        sender.await();

        assertTrue("sender got IIOE",
            sender.exception instanceof InterruptedIOException);
        checkClosedLinks();
    
voidtestStrandMessage()
Tests have the sender strand a message in a link.

        byte[] data = new byte[20];
        to.send(LinkMessage.newDataMessage(data));

        // wait until echo is blocked sending reply back to us
        Utils.sleep(100);

        them.exit(0);
        them.waitForExit();
        checkClosedLinks();