01: package org.jgroups.blocks;
02:
03: import junit.framework.Test;
04: import junit.framework.TestCase;
05: import junit.framework.TestSuite;
06: import org.jgroups.*;
07: import org.jgroups.util.Util;
08:
09: /**
10: * @author Bela Ban
11: * @version $Id: PullPushShunTest.java,v 1.3 2005/10/31 10:56:31 belaban Exp $
12: */
13: public class PullPushShunTest extends TestCase implements
14: MessageListener, MembershipListener, ChannelListener {
15: private JChannel channel;
16: PullPushAdapter adapter;
17:
18: public static Test suite() {
19: return new TestSuite(PullPushShunTest.class);
20: }
21:
22: public static void main(String[] args) {
23: junit.textui.TestRunner.run(suite());
24: }
25:
26: protected void setUp() throws Exception {
27: super .setUp();
28: }
29:
30: protected void tearDown() throws Exception {
31: super .tearDown();
32: }
33:
34: public void testShunningandReconnect() throws Exception {
35: Address old_local_addr, new_local_addr;
36: channel = new JChannel();
37: channel.setOpt(Channel.AUTO_RECONNECT, Boolean.TRUE);
38: channel.addChannelListener(this );
39: channel.connect("PullPushTestShun");
40: adapter = new PullPushAdapter(channel, this , this );
41: assertEquals(1, channel.getView().getMembers().size());
42: old_local_addr = channel.getLocalAddress();
43: assertNotNull(old_local_addr);
44:
45: Util.sleep(1000);
46: System.out.println("shunning channel");
47: shun();
48: Util.sleep(5000);
49: new_local_addr = channel.getLocalAddress();
50: assertNotNull(new_local_addr);
51: assertFalse(old_local_addr.equals(new_local_addr));
52: channel.close();
53: }
54:
55: private void shun() {
56: channel.up(new Event(Event.EXIT));
57: }
58:
59: public void receive(Message msg) {
60: System.out.println("-- received " + msg);
61: }
62:
63: public byte[] getState() {
64: return new byte[0];
65: }
66:
67: public void setState(byte[] state) {
68: }
69:
70: public void viewAccepted(View new_view) {
71: System.out.println("-- view: " + new_view);
72: }
73:
74: public void suspect(Address suspected_mbr) {
75: }
76:
77: public void block() {
78: }
79:
80: public void channelConnected(Channel channel) {
81: System.out.println("-- channelConnected()");
82: }
83:
84: public void channelDisconnected(Channel channel) {
85: System.out.println("-- channelDisconnected()");
86: }
87:
88: public void channelClosed(Channel channel) {
89: System.out.println("-- channelClosed()");
90: }
91:
92: public void channelShunned() {
93: System.out.println("-- channelShunned()");
94: }
95:
96: public void channelReconnected(Address addr) {
97: System.out.println("-- channelReconnected(" + addr + ")");
98: }
99: }
|