2
* JBoss, Home of Professional Open Source
3
* Copyright 2006, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
package org.jboss.test.remoting.multihome;
25
import java.io.ByteArrayInputStream;
27
import javax.xml.parsers.DocumentBuilderFactory;
29
import junit.framework.TestCase;
31
import org.jboss.logging.Logger;
32
import org.jboss.remoting.transport.Connector;
33
import org.w3c.dom.Document;
36
* Unit tests for JBREM-983.
38
* @author <a href="mailto:ron.sigal@jboss.com">Ron Sigal</a>
39
* @version $Revision: 3873 $
41
* Copyright (c) Jun 13, 2006
44
public class XmlMultihomeConfigTestCase extends TestCase
46
protected static Logger log = Logger.getLogger(XmlMultihomeConfigTestCase.class);
47
protected static boolean firstTime = true;
50
protected String getTransport()
61
public void testXmlConfigOneHome() throws Throwable
63
Connector connector = new Connector();
65
// Create and set xml configuration document.
66
StringBuffer buf = new StringBuffer();
67
buf.append("<?xml version=\"1.0\"?>\n");
68
buf.append("<config>");
69
buf.append(" <invoker transport=\"socket\">");
70
buf.append(" <attribute name=\"homes\">");
71
buf.append(" <home>host2:2222</home>");
72
buf.append(" </attribute>");
73
buf.append(" <attribute name=\"path\">a/b</attribute>");
74
buf.append(" <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
75
buf.append(" </invoker>");
76
buf.append("</config>");
77
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
78
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
79
connector.setConfiguration(xml.getDocumentElement());
82
String createdURI = connector.getInvokerLocator();
83
log.info("created InvokerLocator: " + createdURI);
84
String expectedURI = "socket://multihome/a/b/?";
85
expectedURI += "homes=host2:2222&";
86
expectedURI += "timeout=1000";
87
log.info("expected InvokerLocator: " + expectedURI);
88
assertEquals(expectedURI, createdURI);
90
log.info(getName() + " PASSES");
94
public void testXmlConfigThreeHomes() throws Throwable
96
Connector connector = new Connector();
98
// Create and set xml configuration document.
99
StringBuffer buf = new StringBuffer();
100
buf.append("<?xml version=\"1.0\"?>\n");
101
buf.append("<config>");
102
buf.append(" <invoker transport=\"socket\">");
103
buf.append(" <attribute name=\"homes\">");
104
buf.append(" <home>host2:2222</home>");
105
buf.append(" <home>host3:3333</home>");
106
buf.append(" <home>host4:4444</home>");
107
buf.append(" </attribute>");
108
buf.append(" <attribute name=\"path\">a/b</attribute>");
109
buf.append(" <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
110
buf.append(" </invoker>");
111
buf.append("</config>");
112
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
113
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
114
connector.setConfiguration(xml.getDocumentElement());
117
String createdURI = connector.getInvokerLocator();
118
log.info("created InvokerLocator: " + createdURI);
119
String expectedURI = "socket://multihome/a/b/?";
120
expectedURI += "homes=host2:2222!host3:3333!host4:4444&";
121
expectedURI += "timeout=1000";
122
log.info("expected InvokerLocator: " + expectedURI);
123
assertEquals(expectedURI, createdURI);
125
log.info(getName() + " PASSES");
129
public void testXmlConfigWithConnectHomes() throws Throwable
131
Connector connector = new Connector();
133
// Create and set xml configuration document.
134
StringBuffer buf = new StringBuffer();
135
buf.append("<?xml version=\"1.0\"?>\n");
136
buf.append("<config>");
137
buf.append(" <invoker transport=\"socket\">");
138
buf.append(" <attribute name=\"homes\">");
139
buf.append(" <home>host2:2222</home>");
140
buf.append(" <home>host3:3333</home>");
141
buf.append(" </attribute>");
142
buf.append(" <attribute name=\"connecthomes\">");
143
buf.append(" <connecthome>host4:4444</connecthome>");
144
buf.append(" <connecthome>host5:5555</connecthome>");
145
buf.append(" </attribute>");
146
buf.append(" <attribute name=\"path\">a/b</attribute>");
147
buf.append(" <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
148
buf.append(" </invoker>");
149
buf.append("</config>");
150
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
151
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
152
connector.setConfiguration(xml.getDocumentElement());
155
String createdURI = connector.getInvokerLocator();
156
log.info("created InvokerLocator: " + createdURI);
157
String expectedURI = "socket://multihome/a/b/?";
158
expectedURI += "connecthomes=host4:4444!host5:5555&";
159
expectedURI += "homes=host2:2222!host3:3333&";
160
expectedURI += "timeout=1000";
161
log.info("expected InvokerLocator: " + expectedURI);
162
assertEquals(expectedURI, createdURI);
164
log.info(getName() + " PASSES");
168
public void testXmlConfigWithServerBindPort() throws Throwable
170
Connector connector = new Connector();
172
// Create and set xml configuration document.
173
StringBuffer buf = new StringBuffer();
174
buf.append("<?xml version=\"1.0\"?>\n");
175
buf.append("<config>");
176
buf.append(" <invoker transport=\"socket\">");
177
buf.append(" <attribute name=\"serverBindAddress\">host1</attribute>");
178
buf.append(" <attribute name=\"serverBindPort\">1111</attribute>");
179
buf.append(" <attribute name=\"homes\">");
180
buf.append(" <home>host2:2222</home>");
181
buf.append(" <home>host3</home>");
182
buf.append(" </attribute>");
183
buf.append(" <attribute name=\"connecthomes\">");
184
buf.append(" <connecthome>host4</connecthome>");
185
buf.append(" <connecthome>host5:5555</connecthome>");
186
buf.append(" </attribute>");
187
buf.append(" <attribute name=\"path\">a/b</attribute>");
188
buf.append(" <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
189
buf.append(" </invoker>");
190
buf.append("</config>");
191
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
192
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
193
connector.setConfiguration(xml.getDocumentElement());
196
String createdURI = connector.getInvokerLocator();
197
log.info("created InvokerLocator: " + createdURI);
198
String expectedURI = "socket://multihome:1111/a/b/?";
199
expectedURI += "connecthomes=host4:1111!host5:5555&";
200
expectedURI += "homes=host2:2222!host3:1111&";
201
expectedURI += "timeout=1000";
202
log.info("expected InvokerLocator: " + expectedURI);
203
assertEquals(expectedURI, createdURI);
205
log.info(getName() + " PASSES");
209
public void testXmlConfigWithClientConnectPort() throws Throwable
211
Connector connector = new Connector();
213
// Create and set xml configuration document.
214
StringBuffer buf = new StringBuffer();
215
buf.append("<?xml version=\"1.0\"?>\n");
216
buf.append("<config>");
217
buf.append(" <invoker transport=\"socket\">");
218
buf.append(" <attribute name=\"serverBindAddress\">host1</attribute>");
219
buf.append(" <attribute name=\"serverBindPort\">1111</attribute>");
220
buf.append(" <attribute name=\"clientConnectAddress\">host2</attribute>");
221
buf.append(" <attribute name=\"clientConnectPort\">2222</attribute>");
222
buf.append(" <attribute name=\"homes\">");
223
buf.append(" <home>host3:3333</home>");
224
buf.append(" <home>host4</home>");
225
buf.append(" </attribute>");
226
buf.append(" <attribute name=\"connecthomes\">");
227
buf.append(" <connecthome>host5</connecthome>");
228
buf.append(" <connecthome>host6:6666</connecthome>");
229
buf.append(" </attribute>");
230
buf.append(" <attribute name=\"path\">a/b</attribute>");
231
buf.append(" <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
232
buf.append(" </invoker>");
233
buf.append("</config>");
234
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
235
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
236
connector.setConfiguration(xml.getDocumentElement());
239
String createdURI = connector.getInvokerLocator();
240
log.info("created InvokerLocator: " + createdURI);
241
String expectedURI = "socket://multihome:2222/a/b/?";
242
expectedURI += "connecthomes=host5:2222!host6:6666&";
243
expectedURI += "homes=host3:3333!host4:2222&";
244
expectedURI += "timeout=1000";
245
log.info("expected InvokerLocator: " + expectedURI);
246
assertEquals(expectedURI, createdURI);
248
log.info(getName() + " PASSES");
252
public void testXmlConfigWithConnectHomesAndNoHomes() throws Throwable
254
Connector connector = new Connector();
256
// Create and set xml configuration document.
257
StringBuffer buf = new StringBuffer();
258
buf.append("<?xml version=\"1.0\"?>\n");
259
buf.append("<config>");
260
buf.append(" <invoker transport=\"socket\">");
261
buf.append(" <attribute name=\"connecthomes\">");
262
buf.append(" <connecthome>host5</connecthome>");
263
buf.append(" <connecthome>host6:6666</connecthome>");
264
buf.append(" </attribute>");
265
buf.append(" <attribute name=\"path\">a/b</attribute>");
266
buf.append(" <attribute name=\"timeout\" isParam=\"true\">1000</attribute>");
267
buf.append(" </invoker>");
268
buf.append("</config>");
269
ByteArrayInputStream bais = new ByteArrayInputStream(buf.toString().getBytes());
270
Document xml = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(bais);
271
connector.setConfiguration(xml.getDocumentElement());
275
log.info("================= EXCEPTION EXPECTED ================");
277
fail("Should have gotten IllegalStateException");
279
catch (IllegalStateException e)
281
String msg = "Error configuring invoker for connector. Can not continue without invoker.";
282
assertEquals("unexpected message", msg, e.getMessage());
283
log.info("got expected IllegalStateException");
284
log.info("======================================================");
287
log.info(getName() + " PASSES");
b'\\ No newline at end of file'