001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: * The Original Software is NetBeans. The Initial Developer of the Original
026: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
027: * Microsystems, Inc. All Rights Reserved.
028: *
029: * If you wish your version of this file to be governed by only the CDDL
030: * or only the GPL Version 2, indicate your decision by adding
031: * "[Contributor] elects to include this software in this distribution
032: * under the [CDDL or GPL Version 2] license." If you do not indicate a
033: * single choice of license, a recipient has the option to distribute
034: * your version of this file under either the CDDL, the GPL Version 2 or
035: * to extend the choice of license to its licensees as provided above.
036: * However, if you add GPL Version 2 code and therefore, elected the GPL
037: * Version 2 license, then the option applies only if the new code is
038: * made subject to such option by the copyright holder.
039: */
040:
041: package org.netbeans.lib.profiler.tests.jfluid.wireio;
042:
043: import org.netbeans.lib.profiler.global.CommonConstants;
044: import org.netbeans.lib.profiler.server.system.Timers;
045: import org.netbeans.lib.profiler.wireprotocol.*;
046: import java.net.Socket;
047:
048: /**
049: *
050: * @author ehucka
051: */
052: public class BasicTest extends CommonWireIOTestCase {
053: //~ Constructors -------------------------------------------------------------------------------------------------------------
054:
055: /** Creates a new instance of BasicTest */
056: public BasicTest(String name) {
057: super (name);
058: }
059:
060: //~ Methods ------------------------------------------------------------------------------------------------------------------
061:
062: public void testComplexCommands() {
063: LoggingThread t = new LoggingThread();
064: t.start();
065:
066: try {
067: while (!t.isPrepared()) {
068: Thread.sleep(1000);
069: }
070:
071: Socket clientSocket = new Socket("localhost", PORT);
072: WireIO wireIO = createWireIOClient(clientSocket);
073:
074: Command cmd;
075: cmd = new AsyncMessageCommand(true, "async message text");
076: log("sending command " + cmd);
077: wireIO.sendComplexCommand(cmd);
078:
079: cmd = new ClassLoadedCommand("java.lang.String",
080: new int[3], new byte[0], true);
081: log("sending command " + cmd);
082: wireIO.sendComplexCommand(cmd);
083:
084: cmd = new RootClassLoadedCommand(
085: new String[] { "java.lang.String" }, new int[1],
086: new byte[1][0], 1, new int[1], "file name");
087: log("sending command " + cmd);
088: wireIO.sendComplexCommand(cmd);
089:
090: cmd = new SetUnchangeableInstrParamsCommand(true, false, 0,
091: 1024);
092: log("sending command " + cmd);
093: wireIO.sendComplexCommand(cmd);
094:
095: cmd = new MethodInvokedFirstTimeCommand(0);
096: log("sending command " + cmd);
097: wireIO.sendComplexCommand(cmd);
098:
099: cmd = new GetMethodNamesForJMethodIdsCommand(
100: new int[] { 1 });
101: log("sending command " + cmd);
102: wireIO.sendComplexCommand(cmd);
103:
104: cmd = new MethodLoadedCommand("java.lang.String", 7,
105: "toString()", "");
106: log("sending command " + cmd);
107: wireIO.sendComplexCommand(cmd);
108:
109: cmd = new EventBufferDumpedCommand(1024);
110: log("sending command " + cmd);
111: wireIO.sendComplexCommand(cmd);
112:
113: cmd = new SetChangeableInstrParamsCommand(32, 10, 5, 10,
114: true, true, true);
115: log("sending command " + cmd);
116: wireIO.sendComplexCommand(cmd);
117:
118: cmd = new InitiateInstrumentationCommand(
119: CommonConstants.CPU_INSTR_FULL, "java.lang.String",
120: false);
121: log("sending command " + cmd);
122: wireIO.sendComplexCommand(cmd);
123:
124: cmd = new InstrumentMethodGroupCommand(
125: CommonConstants.CPU_INSTR_FULL,
126: new String[] { "java.lang.String" }, new int[1],
127: new byte[1][0], new boolean[1], 0);
128: log("sending command " + cmd);
129: wireIO.sendComplexCommand(cmd);
130:
131: cmd = new GetDefiningClassLoaderCommand("java.lang.String",
132: 1);
133: log("sending command " + cmd);
134: wireIO.sendComplexCommand(cmd);
135:
136: clientSocket.close();
137: log("wait for thread");
138:
139: long tm = 0;
140:
141: while ((tm < 20000) && t.isRunning()) {
142: Thread.sleep(1000);
143: tm += 1000;
144: }
145:
146: t.setRunning(false);
147: log("finished.");
148: } catch (Exception ex) {
149: ex.printStackTrace();
150: assertTrue(ex.getMessage(), false);
151: }
152: }
153:
154: public void testComplexResponse() {
155: LoggingThread t = new LoggingThread();
156: t.start();
157:
158: try {
159: while (!t.isPrepared()) {
160: Thread.sleep(1000);
161: }
162:
163: Socket clientSocket = new Socket("localhost", PORT);
164: WireIO wireIO = createWireIOClient(clientSocket);
165:
166: Response resp;
167: resp = new CodeRegionCPUResultsResponse(new long[] { 10L,
168: 20L, 30L });
169: log("send response " + resp);
170: wireIO.sendComplexResponse(resp);
171:
172: resp = new ThreadLivenessStatusResponse("status".getBytes());
173: log("send response " + resp);
174: wireIO.sendComplexResponse(resp);
175:
176: // Testing VMProperties against a golden file may fail because of different environemtn; ommiting this response
177: // resp = new VMPropertiesResponse(
178: // System.getProperty("java.version"), // NOI18N
179: // System.getProperty("java.class.path"), // NOI18N
180: // System.getProperty("java.ext.dirs"), // NOI18N
181: // System.getProperty("sun.boot.class.path"), // NOI18N
182: // System.getProperty("user.dir"), // NOI18N
183: // "-cp",
184: // "Run",
185: // System.getProperty("os.name"), // NOI18N
186: // Runtime.getRuntime().maxMemory(),
187: // System.currentTimeMillis(),
188: // Timers.getCurrentTimeInCounts(),
189: // 10
190: // ); // NOI18N
191: //
192: //// resp=new VMPropertiesResponse("1.5.0_04", "rt.jar", "/tmp" , "agentpath", ".", "-cp", "Run", "linux", 128, 10);
193: // log("send response "+resp);
194: // wireIO.sendComplexResponse(resp);
195: resp = new DumpResultsResponse(true, 200508181215L);
196: log("send response " + resp);
197: wireIO.sendComplexResponse(resp);
198:
199: resp = new InstrumentMethodGroupResponse(
200: new String[] { "java.lang.String" }, new int[1],
201: new byte[1][0], new boolean[1], 0);
202: log("send response " + resp);
203: wireIO.sendComplexResponse(resp);
204:
205: resp = new MethodNamesResponse(new byte[0], new int[0]);
206: log("send response " + resp);
207: wireIO.sendComplexResponse(resp);
208:
209: resp = new DefiningLoaderResponse(1);
210: log("send response " + resp);
211: wireIO.sendComplexResponse(resp);
212:
213: resp = new CalibrationDataResponse(new double[] { 12.4 },
214: new double[] { 10.4 }, new double[] { 13.54 },
215: new long[] { 3, 10 });
216: log("send response " + resp);
217: wireIO.sendComplexResponse(resp);
218:
219: resp = new InternalStatsResponse();
220: log("send response " + resp);
221: wireIO.sendComplexResponse(resp);
222:
223: resp = new ObjectAllocationResultsResponse(
224: new int[] { 20 }, 1);
225: log("send response " + resp);
226: wireIO.sendComplexResponse(resp);
227:
228: resp = new MonitoredNumbersResponse(new long[] { 20L });
229: log("send response " + resp);
230: wireIO.sendComplexResponse(resp);
231:
232: clientSocket.close();
233: log("wait for thread");
234:
235: long tm = 0;
236:
237: while ((tm < 20000) && t.isRunning()) {
238: Thread.sleep(1000);
239: tm += 1000;
240: }
241:
242: t.setRunning(false);
243: } catch (Exception ex) {
244: ex.printStackTrace();
245: assertTrue(ex.getMessage(), false);
246: }
247: }
248:
249: public void testSimpleCommands() {
250: LoggingThread t = new LoggingThread();
251: t.start();
252:
253: try {
254: while (!t.isPrepared()) {
255: Thread.sleep(1000);
256: }
257:
258: Socket clientSocket = new Socket("localhost", PORT);
259: WireIO wireIO = createWireIOClient(clientSocket);
260:
261: for (int cmd = 1; cmd < 40; cmd++) {
262: wireIO.sendSimpleCommand(cmd);
263: log("send command " + cmd);
264: }
265:
266: clientSocket.close();
267: log("wait for thread");
268:
269: long tm = 0;
270:
271: while ((tm < 20000) && t.isRunning()) {
272: Thread.sleep(1000);
273: tm += 1000;
274: }
275:
276: t.setRunning(false);
277: log("finished.");
278: } catch (Exception ex) {
279: ex.printStackTrace();
280: assertTrue(ex.getMessage(), false);
281: }
282: }
283:
284: public void testSimpleResponse() {
285: LoggingThread t = new LoggingThread();
286: t.start();
287:
288: try {
289: while (!t.isPrepared()) {
290: Thread.sleep(1000);
291: }
292:
293: Socket clientSocket = new Socket("localhost", PORT);
294: WireIO wireIO = createWireIOClient(clientSocket);
295:
296: wireIO.sendSimpleResponse(true, "Error message.");
297: log("response send");
298: clientSocket.close();
299: log("wait for thread");
300:
301: long tm = 0;
302:
303: while ((tm < 20000) && t.isRunning()) {
304: Thread.sleep(1000);
305: tm += 1000;
306: }
307:
308: t.setRunning(false);
309: } catch (Exception ex) {
310: ex.printStackTrace();
311: assertTrue(ex.getMessage(), false);
312: }
313: }
314:
315: public void testUnknownSimpleCommand() {
316: LoggingThread t = new LoggingThread();
317: t.start();
318:
319: try {
320: while (!t.isPrepared()) {
321: Thread.sleep(1000);
322: }
323:
324: Socket clientSocket = new Socket("localhost", PORT);
325: WireIO wireIO = createWireIOClient(clientSocket);
326:
327: int cmd = 0;
328: wireIO.sendSimpleCommand(cmd);
329: log("send command " + cmd);
330: clientSocket.close();
331: log("wait for thread");
332:
333: long tm = 0;
334:
335: while ((tm < 20000) && t.isRunning()) {
336: Thread.sleep(1000);
337: tm += 1000;
338: }
339:
340: t.setRunning(false);
341: } catch (Exception ex) {
342: ex.printStackTrace();
343: assertTrue(ex.getMessage(), false);
344: }
345: }
346: }
|