001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.test.aop.nonjunit;
023:
024: //import java.rmi.*;
025:
026: import javax.naming.InitialContext;
027:
028: import org.jboss.test.JBossTestCase;
029: import junit.framework.Test;
030: import java.net.InetAddress;
031: import javax.management.ObjectName;
032: import org.jboss.jmx.adaptor.rmi.RMIAdaptor;
033: import java.util.Properties;
034: import javax.naming.Context;
035: import javax.naming.InitialContext;
036: import java.util.List;
037:
038: /**
039: * Sample client for the jboss container.
040: *
041: * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
042: * @version $Id: ClusterCacheTester.java 57211 2006-09-26 12:39:46Z dimitris@jboss.org $
043: */
044:
045: public class ClusterCacheTester {
046: static RMIAdaptor server1;
047: static RMIAdaptor server2;
048:
049: public static void main(String args[]) throws Exception {
050: String serverName = InetAddress.getLocalHost().getHostName();
051: String connectorName = "jmx:" + serverName + ":rmi";
052: RMIAdaptor server1 = (RMIAdaptor) new InitialContext()
053: .lookup(connectorName);
054:
055: Properties p = new Properties();
056: p.put(Context.INITIAL_CONTEXT_FACTORY,
057: "org.jnp.interfaces.NamingContextFactory");
058: p.put(Context.URL_PKG_PREFIXES,
059: "jboss.naming:org.jnp.interfaces");
060: p.put(Context.PROVIDER_URL, System.getProperty(
061: "jbosstest.server.host", "localhost")
062: + ":11099");
063: RMIAdaptor server2 = (RMIAdaptor) new InitialContext(p)
064: .lookup(connectorName);
065: ObjectName testerName = new ObjectName(
066: "jboss.aop:name=CacheTester");
067:
068: int baseAge = 32;
069:
070: for (int j = 0; j < 5; j++) {
071: {
072: // Just to be absolutely sure that server1 and server2 are different VMs
073: Object[] params = {};
074: String[] sig = {};
075: System.out.println("vmid server1: "
076: + server1.invoke(testerName, "getVMID", params,
077: sig));
078: System.out.println("vmid server2: "
079: + server2.invoke(testerName, "getVMID", params,
080: sig));
081:
082: }
083: {
084: Object[] params = { "Bill" };
085: String[] sig = { "java.lang.String" };
086: Integer age1 = (Integer) server1.invoke(testerName,
087: "getAge", params, sig);
088: System.out.println("server1 age: " + age1);
089:
090: Integer age2 = (Integer) server2.invoke(testerName,
091: "getAge", params, sig);
092: System.out.println("server2 age: " + age2);
093: }
094: {
095: System.out.println("set age to " + ++baseAge
096: + " on server1");
097: Object[] params = { "Bill", new Integer(baseAge) };
098: String[] sig = { "java.lang.String", "int" };
099: server1.invoke(testerName, "setAge", params, sig);
100: }
101: {
102: System.out.println("check age");
103: Object[] params = { "Bill" };
104: String[] sig = { "java.lang.String" };
105: Integer age1 = (Integer) server1.invoke(testerName,
106: "getAge", params, sig);
107: System.out.println("server1 age: " + age1);
108:
109: Integer age2 = (Integer) server2.invoke(testerName,
110: "getAge", params, sig);
111: System.out.println("server2 age: " + age2);
112: }
113: {
114: Object[] params = { "Bill" };
115: String[] sig = { "java.lang.String" };
116: List hobbies = (List) server1.invoke(testerName,
117: "getHobbies", params, sig);
118: System.out.println("server1 hobbies: ");
119: for (int i = 0; i < hobbies.size(); i++) {
120: System.out.println(" " + hobbies.get(i));
121: }
122:
123: hobbies = (List) server2.invoke(testerName,
124: "getHobbies", params, sig);
125: System.out.println("server2 hobbies: ");
126: for (int i = 0; i < hobbies.size(); i++) {
127: System.out.println(" " + hobbies.get(i));
128: }
129: }
130: {
131: System.out.println("addHobby fishing");
132: Object[] params = { "Bill", "fishing" };
133: String[] sig = { "java.lang.String", "java.lang.String" };
134: server1.invoke(testerName, "addHobby", params, sig);
135: }
136: {
137: Object[] params = { "Bill" };
138: String[] sig = { "java.lang.String" };
139: List hobbies = (List) server1.invoke(testerName,
140: "getHobbies", params, sig);
141: System.out.println("server1 hobbies: ");
142: for (int i = 0; i < hobbies.size(); i++) {
143: System.out.println(" " + hobbies.get(i));
144: }
145:
146: hobbies = (List) server2.invoke(testerName,
147: "getHobbies", params, sig);
148: System.out.println("server2 hobbies: ");
149: for (int i = 0; i < hobbies.size(); i++) {
150: System.out.println(" " + hobbies.get(i));
151: }
152: }
153: {
154: Object[] params = { "Bill" };
155: String[] sig = { "java.lang.String" };
156: String city1 = (String) server1.invoke(testerName,
157: "getCity", params, sig);
158: System.out.println("server1 city: " + city1);
159:
160: String city2 = (String) server2.invoke(testerName,
161: "getCity", params, sig);
162: System.out.println("server2 city: " + city2);
163: }
164: {
165: System.out.println("set city to Atlanta");
166: Object[] params = { "Bill", "Atlanta" + baseAge };
167: String[] sig = { "java.lang.String", "java.lang.String" };
168: server1.invoke(testerName, "setCity", params, sig);
169: }
170: {
171: Object[] params = { "Bill" };
172: String[] sig = { "java.lang.String" };
173: String city1 = (String) server1.invoke(testerName,
174: "getCity", params, sig);
175: System.out.println("server1 city: " + city1);
176:
177: String city2 = (String) server2.invoke(testerName,
178: "getCity", params, sig);
179: System.out.println("server2 city: " + city2);
180: }
181: }
182: }
183: }
|