KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > ConfiguratorTest


1 package org.jgroups.tests;
2
3 import junit.framework.TestCase;
4 import org.jgroups.JChannel;
5 import org.jgroups.stack.Configurator;
6 import org.jgroups.stack.Protocol;
7 import org.jgroups.stack.ProtocolStack;
8
9 import java.util.List JavaDoc;
10 import java.util.Vector JavaDoc;
11
12 /**
13  * Tests ProtocolStack.insertProtocol() and removeProtocol()
14  * @author Bela Ban
15  * @version $Id: ConfiguratorTest.java,v 1.1 2007/07/04 07:29:33 belaban Exp $
16  */

17 public class ConfiguratorTest extends TestCase {
18     ProtocolStack stack;
19     static final String JavaDoc props="UDP(mcast_addr=225.1.2.3):PING:FD:pbcast.NAKACK:UNICAST:FC";
20     final String JavaDoc[] names={"FC", "UNICAST", "NAKACK", "FD", "PING", "UDP"};
21     final String JavaDoc[] below={"FC", "UNICAST", "TRACE", "NAKACK", "FD", "PING", "UDP"};
22     final String JavaDoc[] above={"FC", "TRACE", "UNICAST", "NAKACK", "FD", "PING", "UDP"};
23
24     public ConfiguratorTest(String JavaDoc name) {
25         super(name);
26     }
27
28     public void setUp() throws Exception JavaDoc {
29         super.setUp();
30
31         JChannel mock_channel=new JChannel() {
32
33         };
34
35         stack=new ProtocolStack(mock_channel, props);
36     }
37
38
39     public void tearDown() throws Exception JavaDoc {
40         super.tearDown();
41     }
42
43
44     public void testInsertion() throws Exception JavaDoc {
45         stack.setup();
46         List JavaDoc protocols=stack.getProtocols();
47         assertNotNull(protocols);
48         assertEquals(6, protocols.size());
49
50         for(int i=0; i < names.length; i++) {
51             String JavaDoc name=names[i];
52             Protocol p=(Protocol)protocols.get(i);
53             assertEquals(name, p.getName());
54         }
55
56         // insert below
57
Protocol new_prot=(Protocol)Class.forName("org.jgroups.protocols.TRACE").newInstance();
58         stack.insertProtocol(new_prot, ProtocolStack.BELOW, "UNICAST");
59         protocols=stack.getProtocols();
60         assertEquals(7, protocols.size());
61         for(int i=0; i < below.length; i++) {
62             String JavaDoc name=below[i];
63             Protocol p=(Protocol)protocols.get(i);
64             assertEquals(name, p.getName());
65         }
66
67         // remove
68
Protocol prot=stack.removeProtocol("TRACE");
69         assertNotNull(prot);
70         protocols=stack.getProtocols();
71         assertEquals(6, protocols.size());
72         for(int i=0; i < names.length; i++) {
73             String JavaDoc name=names[i];
74             Protocol p=(Protocol)protocols.get(i);
75             assertEquals(name, p.getName());
76         }
77
78         // insert above
79
new_prot=(Protocol)Class.forName("org.jgroups.protocols.TRACE").newInstance();
80         stack.insertProtocol(new_prot, ProtocolStack.ABOVE, "UNICAST");
81         protocols=stack.getProtocols();
82         assertEquals(7, protocols.size());
83         for(int i=0; i < above.length; i++) {
84             String JavaDoc name=above[i];
85             Protocol p=(Protocol)protocols.get(i);
86             assertEquals(name, p.getName());
87         }
88     }
89
90
91     public void testParsing() throws Exception JavaDoc {
92         String JavaDoc config="UDP(mcast_addr=ff18:eb72:479f::2:3;oob_thread_pool.max_threads=4;" +
93                 "oob_thread_pool.keep_alive_time=5000;max_bundle_size=64000;mcast_send_buf_size=640000;" +
94                 "oob_thread_pool.queue_max_size=10;mcast_recv_buf_size=25000000;" +
95                 "use_concurrent_stack=true;tos=8;mcast_port=45522;loopback=true;thread_pool.min_threads=2;" +
96                 "oob_thread_pool.rejection_policy=Run;thread_pool.max_threads=8;enable_diagnostics=true;" +
97                 "thread_naming_pattern=cl;ucast_send_buf_size=640000;ucast_recv_buf_size=20000000;" +
98                 "thread_pool.enabled=true;use_incoming_packet_handler=true;oob_thread_pool.enabled=true;ip_ttl=2;" +
99                 "enable_bundling=true;thread_pool.rejection_policy=Run;discard_incompatible_packets=true;" +
100                 "thread_pool.keep_alive_time=5000;thread_pool.queue_enabled=false;mcast_addr=228.10.10.15;" +
101                 "max_bundle_timeout=30;oob_thread_pool.queue_enabled=false;oob_thread_pool.min_threads=2;" +
102                 "thread_pool.queue_max_size=100):" +
103                 "PING(num_initial_members=3;timeout=2000):" +
104                 "MERGE2(min_interval=5000;max_interval=10000):" +
105                 "FD_SOCK:" +
106                 "FD(max_tries=3;timeout=2000):" +
107                 "VERIFY_SUSPECT(timeout=1500):" +
108                 "BARRIER:" +
109                 "pbcast.NAKACK(gc_lag=0;use_mcast_xmit=false;retransmit_timeout=300,600,1200,2400,4800;" +
110                 "discard_delivered_msgs=true;max_xmit_size=60000):" +
111                 "UNICAST(loopback=false;timeout=300,600,1200,2400,3600):" +
112                 "pbcast.STABLE(desired_avg_gossip=50000;max_bytes=1000000;stability_delay=1000):" +
113                 "VIEW_SYNC(avg_send_interval=60000):" +
114                 "pbcast.GMS(print_local_addr=true;view_bundling=true;join_timeout=3000;join_retry_timeout=2000;" +
115                 "shun=false):" +
116                 "FC(max_block_time=10000;max_credits=5000000;min_threshold=0.25):" +
117                 "FRAG2(frag_size=60000):" +
118                 "pbcast.STREAMING_STATE_TRANSFER(use_reading_thread=true)";
119         
120         Vector JavaDoc<Configurator.ProtocolConfiguration> ret=Configurator.parseConfigurations(config);
121         System.out.println("config:\n" + ret);
122         assertEquals(15, ret.size());
123
124         config="UDP(mcast_addr=ff18:eb72:479f::2:3;mcast_port=2453):pbcast.FD:FRAG(frag_size=2292):FD_SIMPLE(s=22;d=33):MERGE2(a=22)";
125         ret=Configurator.parseConfigurations(config);
126         System.out.println("config:\n" + ret);
127         assertEquals(5, ret.size());
128
129         config="com.mycomp.Class:B:pbcast.C:H(a=b;c=d;e=f)";
130         ret=Configurator.parseConfigurations(config);
131         System.out.println("config:\n" + ret);
132         assertEquals(4, ret.size());
133     }
134
135
136
137
138     public static void main(String JavaDoc[] args) {
139         String JavaDoc[] testCaseName={ConfiguratorTest.class.getName()};
140         junit.textui.TestRunner.main(testCaseName);
141     }
142
143 }
144
Popular Tags