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

TestRing

public class TestRing extends com.sun.midp.i3test.TestCase
Tests sending messages around a ring of three isolates.

Fields Summary
Constructors Summary
Methods Summary
public voidrunTests()
Runs all tests.

        declare("testRing");
        testRing();
    
voidtestRing()

        Isolate zero = Isolate.currentIsolate();
        Isolate one = new Isolate("com.sun.midp.links.Echo", null);
        Isolate two = new Isolate("com.sun.midp.links.Echo", null);

        one.start();
        two.start();

        Link link01 = Link.newLink(zero, one);
        Link link12 = Link.newLink(one, two);
        Link link20 = Link.newLink(two, zero);

        LinkPortal.setLinks(one, new Link[] { link01, link12 });
        LinkPortal.setLinks(two, new Link[] { link12, link20 });

        String ss = "Mr. Watson, come here. I want you!";
        link01.send(LinkMessage.newStringMessage(ss));
        LinkMessage lm = link20.receive();

        assertTrue("contains string", lm.containsString());
        String rs = lm.extractString();
        assertNotSame("strings not same", ss, rs);
        assertEquals("strings equal", ss, rs);

        LinkPortal.setLinks(one, null);
        LinkPortal.setLinks(two, null);
        one.exit(0);
        two.exit(0);
        one.waitForExit();
        two.waitForExit();