Source Code Cross Referenced for ResumeTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » VirtualMachine » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » org package » org.apache.harmony.jpda.tests.jdwp.VirtualMachine 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         *  Unless required by applicable law or agreed to in writing, software
012:         *  distributed under the License is distributed on an "AS IS" BASIS,
013:         *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         *
015:         *  See the License for the specific language governing permissions and
016:         *  limitations under the License.
017:         */
018:
019:        /**
020:         * @author Vitaly A. Provodin, Anatoly F. Bondarenko
021:         * @version $Revision: 1.6 $
022:         */
023:
024:        /**
025:         * Created on 10.02.2005
026:         */package org.apache.harmony.jpda.tests.jdwp.VirtualMachine;
027:
028:        import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
029:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
030:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
031:        import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
032:        import org.apache.harmony.jpda.tests.framework.jdwp.exceptions.ReplyErrorCodeException;
033:        import org.apache.harmony.jpda.tests.jdwp.ThreadReference.ResumeDebuggee;
034:        import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
035:
036:        /**
037:         * JDWP Unit test for VirtualMachine.Resume command.
038:         */
039:        public class ResumeTest extends JDWPSyncTestCase {
040:
041:            static final String debuggeeSignature = "Lorg/apache/harmony/jpda/tests/jdwp/VirtualMachine/ResumeDebuggee;";
042:
043:            protected String getDebuggeeClassName() {
044:                return "org.apache.harmony.jpda.tests.jdwp.VirtualMachine.ResumeDebuggee";
045:            }
046:
047:            /**
048:             * This testcase exercises VirtualMachine.Resume command.
049:             * <BR>At first the test starts ResumeDebuggee which starts and runs some tested threads. 
050:             * <BR> Then the test performs VirtualMachine.Suspend command and checks with help of 
051:             * ThreadReference.Status command that all debuggee tested threads are suspended. 
052:             * <BR> Then the test performs VirtualMachine.Resume command and checks with help of 
053:             * ThreadReference.Status command that all debuggee tested threads are resumed. 
054:             */
055:            public void testResume001() {
056:                logWriter.println("==> testResume001: START...");
057:                String debuggeeMessage = synchronizer.receiveMessage();
058:                int testedThreadsNumber = 0;
059:                try {
060:                    testedThreadsNumber = Integer.valueOf(debuggeeMessage)
061:                            .intValue();
062:                } catch (NumberFormatException exception) {
063:                    logWriter
064:                            .println("## FAILURE: Exception while getting number of started threads from debuggee = "
065:                                    + exception);
066:                    setStaticIntField(debuggeeSignature,
067:                            ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
068:                    printErrorAndFail("\n## Can NOT get number of started threads from debuggee! ");
069:                }
070:                testedThreadsNumber++; // to add debuggee main thread
071:                logWriter
072:                        .println("==>  Number of threads in debuggee to test = "
073:                                + testedThreadsNumber);
074:                String[] testedThreadsNames = new String[testedThreadsNumber];
075:                long[] testedThreadsIDs = new long[testedThreadsNumber];
076:                String debuggeeMainThreadName = synchronizer.receiveMessage();
077:                for (int i = 0; i < testedThreadsNumber; i++) {
078:                    if (i < (testedThreadsNumber - 1)) {
079:                        testedThreadsNames[i] = ResumeDebuggee.THREAD_NAME_PATTERN
080:                                + i;
081:                    } else {
082:                        testedThreadsNames[i] = debuggeeMainThreadName;
083:                    }
084:                    testedThreadsIDs[i] = 0;
085:                }
086:
087:                // getting ID of the tested thread
088:                ReplyPacket allThreadIDReply = null;
089:                try {
090:                    allThreadIDReply = debuggeeWrapper.vmMirror
091:                            .getAllThreadID();
092:                } catch (ReplyErrorCodeException exception) {
093:                    logWriter
094:                            .println("## FAILURE: Exception in vmMirror.getAllThreadID() = "
095:                                    + exception);
096:                    setStaticIntField(debuggeeSignature,
097:                            ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
098:                    printErrorAndFail("\n## Can NOT get all ThreadID in debuggee! ");
099:                }
100:                int threads = allThreadIDReply.getNextValueAsInt();
101:                logWriter.println("==>  Number of all threads in debuggee = "
102:                        + threads);
103:                for (int i = 0; i < threads; i++) {
104:                    long threadID = allThreadIDReply.getNextValueAsThreadID();
105:                    String threadName = null;
106:                    try {
107:                        threadName = debuggeeWrapper.vmMirror
108:                                .getThreadName(threadID);
109:                    } catch (ReplyErrorCodeException exception) {
110:                        logWriter
111:                                .println("==> WARNING: Can NOT get thread name for threadID = "
112:                                        + threadID);
113:                        continue;
114:                    }
115:                    int k = 0;
116:                    for (; k < testedThreadsNumber; k++) {
117:                        if (threadName.equals(testedThreadsNames[k])) {
118:                            testedThreadsIDs[k] = threadID;
119:                            break;
120:                        }
121:                    }
122:                }
123:
124:                boolean testedThreadNotFound = false;
125:                for (int i = 0; i < testedThreadsNumber; i++) {
126:                    if (testedThreadsIDs[i] == 0) {
127:                        logWriter
128:                                .println("## FAILURE: Tested thread is not found out among debuggee threads!");
129:                        logWriter.println("##          Thread name = "
130:                                + testedThreadsNames[i]);
131:                        testedThreadNotFound = true;
132:                    }
133:                }
134:                if (testedThreadNotFound) {
135:                    setStaticIntField(debuggeeSignature,
136:                            ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
137:                    printErrorAndFail("\n## Some of tested threads are not found!");
138:                }
139:
140:                logWriter
141:                        .println("\n==> Send VirtualMachine.Suspend command...");
142:                CommandPacket packet = new CommandPacket(
143:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
144:                        JDWPCommands.VirtualMachineCommandSet.SuspendCommand);
145:                ReplyPacket reply = debuggeeWrapper.vmMirror
146:                        .performCommand(packet);
147:                int errorCode = reply.getErrorCode();
148:                if (errorCode != JDWPConstants.Error.NONE) {
149:                    setStaticIntField(debuggeeSignature,
150:                            ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
151:                    logWriter
152:                            .println("## FAILURE: VirtualMachine.Suspend command returns error = "
153:                                    + errorCode
154:                                    + "("
155:                                    + JDWPConstants.Error.getName(errorCode)
156:                                    + ")");
157:                    printErrorAndFail("\nVirtualMachine.Suspend command FAILED!");
158:                } else {
159:                    logWriter
160:                            .println("==> VirtualMachine.Suspend command - OK.");
161:                }
162:
163:                logWriter
164:                        .println("\n==> Check that all tested threads are suspended after VirtualMachine.Suspend command...");
165:
166:                boolean statusCommandFailed = false;
167:                boolean suspendStatusFailed = false;
168:                for (int i = 0; i < testedThreadsNumber; i++) {
169:                    logWriter.println("\n==> Check for Thread: threadID = "
170:                            + testedThreadsIDs[i] + "; threadName = "
171:                            + testedThreadsNames[i]);
172:
173:                    logWriter
174:                            .println("==> Send ThreadReference.Status command...");
175:                    packet = new CommandPacket(
176:                            JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
177:                            JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
178:                    packet.setNextValueAsReferenceTypeID(testedThreadsIDs[i]);
179:                    reply = debuggeeWrapper.vmMirror.performCommand(packet);
180:                    if (!checkReplyPacketWithoutFail(reply,
181:                            "ThreadReference.Status command")) {
182:                        statusCommandFailed = true;
183:                        continue;
184:                    }
185:
186:                    int threadStatus = reply.getNextValueAsInt();
187:                    int suspendStatus = reply.getNextValueAsInt();
188:
189:                    logWriter.println("==> threadStatus = " + threadStatus
190:                            + "("
191:                            + JDWPConstants.ThreadStatus.getName(threadStatus)
192:                            + ")");
193:                    logWriter.println("==> suspendStatus = "
194:                            + suspendStatus
195:                            + "("
196:                            + JDWPConstants.SuspendStatus
197:                                    .getName(suspendStatus) + ")");
198:                    if (suspendStatus != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
199:                        logWriter
200:                                .println("## FAILURE: Unexpected suspendStatus for checked thread!");
201:                        logWriter
202:                                .println("##          Expected suspendStatus  = "
203:                                        + JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED
204:                                        + "("
205:                                        + JDWPConstants.SuspendStatus
206:                                                .getName(JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED)
207:                                        + ")");
208:                        suspendStatusFailed = true;
209:                        continue;
210:                    }
211:                }
212:
213:                String errorMessage = "";
214:                if (statusCommandFailed) {
215:                    errorMessage = errorMessage
216:                            + "## Error found out while ThreadReference.Status command performing!\n";
217:                }
218:                if (suspendStatusFailed) {
219:                    errorMessage = errorMessage
220:                            + "## Unexpected suspendStatus found out!\n";
221:                }
222:
223:                logWriter
224:                        .println("\n==> Send VirtualMachine.Resume command...");
225:                packet = new CommandPacket(
226:                        JDWPCommands.VirtualMachineCommandSet.CommandSetID,
227:                        JDWPCommands.VirtualMachineCommandSet.ResumeCommand);
228:                reply = debuggeeWrapper.vmMirror.performCommand(packet);
229:                errorCode = reply.getErrorCode();
230:                if (errorCode != JDWPConstants.Error.NONE) {
231:                    setStaticIntField(debuggeeSignature,
232:                            ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
233:                    logWriter
234:                            .println("## FAILURE: VirtualMachine.Resume command returns error = "
235:                                    + errorCode
236:                                    + "("
237:                                    + JDWPConstants.Error.getName(errorCode)
238:                                    + ")");
239:                    printErrorAndFail("\nVirtualMachine.Resume command FAILED!");
240:                } else {
241:                    logWriter
242:                            .println("==> VirtualMachine.Resume command - OK.");
243:                }
244:
245:                if (!errorMessage.equals("")) {
246:                    setStaticIntField(debuggeeSignature,
247:                            ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
248:                    printErrorAndFail("\ntestResume001 FAILED:\n"
249:                            + errorMessage);
250:                }
251:
252:                logWriter
253:                        .println("\n==> Check that all tested threads are resumed after VirtualMachine.Resume command...");
254:
255:                for (int i = 0; i < testedThreadsNumber; i++) {
256:                    logWriter.println("\n==> Check for Thread: threadID = "
257:                            + testedThreadsIDs[i] + "; threadName = "
258:                            + testedThreadsNames[i]);
259:
260:                    logWriter
261:                            .println("==> Send ThreadReference.Status command...");
262:                    packet = new CommandPacket(
263:                            JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
264:                            JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
265:                    packet.setNextValueAsReferenceTypeID(testedThreadsIDs[i]);
266:                    reply = debuggeeWrapper.vmMirror.performCommand(packet);
267:                    if (!checkReplyPacketWithoutFail(reply,
268:                            "ThreadReference.Status command")) {
269:                        statusCommandFailed = true;
270:                        continue;
271:                    }
272:
273:                    int threadStatus = reply.getNextValueAsInt();
274:                    int suspendStatus = reply.getNextValueAsInt();
275:
276:                    logWriter.println("==> threadStatus = " + threadStatus
277:                            + "("
278:                            + JDWPConstants.ThreadStatus.getName(threadStatus)
279:                            + ")");
280:                    logWriter.println("==> suspendStatus = "
281:                            + suspendStatus
282:                            + "("
283:                            + JDWPConstants.SuspendStatus
284:                                    .getName(suspendStatus) + ")");
285:                    if (suspendStatus == JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
286:                        logWriter
287:                                .println("## FAILURE: Thread still is suspended after VirtualMachine.Resume commands!");
288:                        suspendStatusFailed = true;
289:                    }
290:                }
291:
292:                if (statusCommandFailed) {
293:                    errorMessage = errorMessage
294:                            + "## Error found out while ThreadReference.Status command performing!\n";
295:                }
296:                if (suspendStatusFailed) {
297:                    errorMessage = errorMessage
298:                            + "## Unexpected suspendStatus found out!\n";
299:                }
300:
301:                setStaticIntField(debuggeeSignature,
302:                        ResumeDebuggee.TO_FINISH_DEBUGGEE_FIELD_NAME, 99);
303:                if (!errorMessage.equals("")) {
304:                    printErrorAndFail("\ntestResume001 FAILED:\n"
305:                            + errorMessage);
306:                }
307:
308:                logWriter.println("\n==> testResume001 - OK!");
309:            }
310:
311:            public static void main(String[] args) {
312:                junit.textui.TestRunner.run(ResumeTest.class);
313:            }
314:        }
w_w_w.ja___v___a__2__s.__c__o__m__ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.