01: // $Id: ChannelTest.java,v 1.2 2006/01/11 15:02:34 belaban Exp $
02:
03: package org.jgroups.tests;
04:
05: import junit.framework.Test;
06: import junit.framework.TestCase;
07: import junit.framework.TestSuite;
08: import org.jgroups.*;
09:
10: /**
11: * Tests various methods in JChannel
12: * @author Bela Ban
13: * @version $Id: ChannelTest.java,v 1.2 2006/01/11 15:02:34 belaban Exp $
14: */
15: public class ChannelTest extends TestCase {
16: JChannel ch;
17:
18: private static final String GROUP = "DiscardTestGroup";
19:
20: public ChannelTest(String name) {
21: super (name);
22: }
23:
24: protected void setUp() throws Exception {
25: super .setUp();
26: ch = new JChannel();
27: ch.connect(GROUP);
28: }
29:
30: protected void tearDown() throws Exception {
31: super .tearDown();
32: ch.close();
33: }
34:
35: public void testFirstView() throws Exception {
36: Object obj = ch.receive(5000);
37: if (!(obj instanceof View)) {
38: fail("first object returned needs to be a View (was " + obj
39: + ")");
40: } else {
41: System.out.println("view is " + obj);
42: }
43: }
44:
45: public void testReceiveTimeout() throws ChannelException,
46: TimeoutException {
47: ch.receive(1000); // this one works, because we're expecting a View
48:
49: // .. but this one doesn't (no msg available) - needs to throw a TimeoutException
50: try {
51: ch.receive(2000);
52: } catch (ChannelNotConnectedException e) {
53: fail("channel should be connected");
54: } catch (ChannelClosedException e) {
55: fail("channel should not be closed");
56: } catch (TimeoutException e) {
57: System.out
58: .println("caught a TimeoutException - this is the expected behavior");
59: }
60: }
61:
62: public void testNullMessage() throws ChannelClosedException,
63: ChannelNotConnectedException {
64: try {
65: ch.send(null);
66: fail("null message should throw an exception - we should not get here");
67: } catch (NullPointerException e) {
68: System.out
69: .println("caught NullPointerException - this is expected");
70: }
71: }
72:
73: public static Test suite() {
74: TestSuite s = new TestSuite(ChannelTest.class);
75: return s;
76: }
77:
78: public static void main(String[] args) {
79: junit.textui.TestRunner.run(suite());
80: }
81:
82: }
|