01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26:
27: package com.sun.midp.links;
28:
29: import com.sun.cldc.isolate.Isolate;
30: import com.sun.cldc.isolate.IsolateStartupException;
31: import com.sun.midp.i3test.TestCase;
32: import java.io.IOException;
33:
34: /**
35: * Tests sending messages around a ring of three isolates.
36: */
37: public class TestRing extends TestCase {
38:
39: void testRing() throws IOException, IsolateStartupException {
40: Isolate zero = Isolate.currentIsolate();
41: Isolate one = new Isolate("com.sun.midp.links.Echo", null);
42: Isolate two = new Isolate("com.sun.midp.links.Echo", null);
43:
44: one.start();
45: two.start();
46:
47: Link link01 = Link.newLink(zero, one);
48: Link link12 = Link.newLink(one, two);
49: Link link20 = Link.newLink(two, zero);
50:
51: LinkPortal.setLinks(one, new Link[] { link01, link12 });
52: LinkPortal.setLinks(two, new Link[] { link12, link20 });
53:
54: String ss = "Mr. Watson, come here. I want you!";
55: link01.send(LinkMessage.newStringMessage(ss));
56: LinkMessage lm = link20.receive();
57:
58: assertTrue("contains string", lm.containsString());
59: String rs = lm.extractString();
60: assertNotSame("strings not same", ss, rs);
61: assertEquals("strings equal", ss, rs);
62:
63: LinkPortal.setLinks(one, null);
64: LinkPortal.setLinks(two, null);
65: one.exit(0);
66: two.exit(0);
67: one.waitForExit();
68: two.waitForExit();
69: }
70:
71: /**
72: * Runs all tests.
73: */
74: public void runTests() throws IOException, IsolateStartupException {
75: declare("testRing");
76: testRing();
77: }
78: }
|