Source Code Cross Referenced for SuspendTest.java in  » Apache-Harmony-Java-SE » org-package » org » apache » harmony » jpda » tests » jdwp » ThreadReference » 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.ThreadReference 
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
021:         * @version $Revision: 1.6 $
022:         */
023:
024:        /**
025:         * Created on 15.02.2005
026:         */package org.apache.harmony.jpda.tests.jdwp.ThreadReference;
027:
028:        import org.apache.harmony.jpda.tests.framework.jdwp.exceptions.*;
029:        import org.apache.harmony.jpda.tests.framework.jdwp.CommandPacket;
030:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPCommands;
031:        import org.apache.harmony.jpda.tests.framework.jdwp.JDWPConstants;
032:        import org.apache.harmony.jpda.tests.framework.jdwp.ReplyPacket;
033:        import org.apache.harmony.jpda.tests.jdwp.share.JDWPSyncTestCase;
034:        import org.apache.harmony.jpda.tests.share.JPDADebuggeeSynchronizer;
035:
036:        /**
037:         * JDWP Unit test for ThreadReference.Suspend command.
038:         */
039:        public class SuspendTest extends JDWPSyncTestCase {
040:
041:            static final int testStatusPassed = 0;
042:            static final int testStatusFailed = -1;
043:
044:            protected String getDebuggeeClassName() {
045:                return "org.apache.harmony.jpda.tests.jdwp.ThreadReference.SuspendDebuggee";
046:            }
047:
048:            /**
049:             * This testcase exercises ThreadReference.Suspend command.
050:             * <BR>At first the test starts SuspendDebuggee which starts and runs some tested threads.
051:             * <BR>After the tested threads starts, the test for every tested thread does:
052:             * <BR>&nbsp;&nbsp; - suspends thread by ThreadReference.Suspend command;
053:             * <BR>&nbsp;&nbsp; - performs the ThreadReference.Status command for tested thread;
054:             * <BR>It is expected that for every tested thread returned suspend 
055:             * status is SUSPEND_STATUS_SUSPENDED status;
056:             */
057:            public void testSuspend001() {
058:                logWriter.println("==> testSuspend001: START...");
059:                String debuggeeMessage = synchronizer.receiveMessage();
060:                int testedThreadsNumber = 0;
061:                try {
062:                    testedThreadsNumber = Integer.valueOf(debuggeeMessage)
063:                            .intValue();
064:                } catch (NumberFormatException exception) {
065:                    logWriter
066:                            .println("## FAILURE: Exception while getting number of started threads from debuggee = "
067:                                    + exception);
068:                    printErrorAndFail("Can NOT get number of started threads from debuggee! ");
069:                }
070:                if (testedThreadsNumber == 0) {
071:                    logWriter
072:                            .println("==>  There are no started threads in debuggee to test!");
073:                    return;
074:                }
075:                logWriter
076:                        .println("==>  Number of started threads in debuggee to test = "
077:                                + testedThreadsNumber);
078:                String[] testedThreadsNames = new String[testedThreadsNumber];
079:                long[] testedThreadsIDs = new long[testedThreadsNumber];
080:                for (int i = 0; i < testedThreadsNumber; i++) {
081:                    testedThreadsNames[i] = SuspendDebuggee.THREAD_NAME_PATTERN
082:                            + i;
083:                    testedThreadsIDs[i] = 0;
084:                }
085:
086:                // getting ID of the tested thread
087:                ReplyPacket allThreadIDReply = null;
088:                try {
089:                    allThreadIDReply = debuggeeWrapper.vmMirror
090:                            .getAllThreadID();
091:                } catch (ReplyErrorCodeException exception) {
092:                    logWriter
093:                            .println("## FAILURE: Exception in vmMirror.getAllThreadID() = "
094:                                    + exception);
095:                    printErrorAndFail("Can NOT get all ThreadID in debuggee! ");
096:                }
097:                int threads = allThreadIDReply.getNextValueAsInt();
098:                logWriter.println("==>  Number of all threads in debuggee = "
099:                        + threads);
100:                boolean suspendCommandFailed = false;
101:                boolean statusCommandFailed = false;
102:                boolean suspendStatusFailed = false;
103:                boolean resumeThreadFailed = false;
104:
105:                for (int i = 0; i < threads; i++) {
106:                    long threadID = allThreadIDReply.getNextValueAsThreadID();
107:                    String threadName = null;
108:                    try {
109:                        threadName = debuggeeWrapper.vmMirror
110:                                .getThreadName(threadID);
111:                    } catch (ReplyErrorCodeException exception) {
112:                        logWriter
113:                                .println("==> WARNING: Can NOT get thread name for threadID = "
114:                                        + threadID);
115:                        continue;
116:                    }
117:                    int k = 0;
118:                    for (; k < testedThreadsNumber; k++) {
119:                        if (threadName.equals(testedThreadsNames[k])) {
120:                            testedThreadsIDs[k] = threadID;
121:                            break;
122:                        }
123:                    }
124:                    if (k == testedThreadsNumber) {
125:                        // it is not thread to test
126:                        continue;
127:                    }
128:
129:                    logWriter.println("\n==> Check for Thread: threadID = "
130:                            + threadID + "; threadName = " + threadName);
131:
132:                    // suspending the thread
133:                    logWriter
134:                            .println("==> Send ThreadReference.Suspend command...");
135:                    CommandPacket packet = new CommandPacket(
136:                            JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
137:                            JDWPCommands.ThreadReferenceCommandSet.SuspendCommand);
138:                    packet.setNextValueAsThreadID(threadID);
139:                    ReplyPacket reply = debuggeeWrapper.vmMirror
140:                            .performCommand(packet);
141:                    if (!checkReplyPacketWithoutFail(reply,
142:                            "ThreadReference.Suspend command")) {
143:                        suspendCommandFailed = true;
144:                        continue;
145:                    }
146:
147:                    logWriter
148:                            .println("==> Send ThreadReference.Status command...");
149:                    packet = new CommandPacket(
150:                            JDWPCommands.ThreadReferenceCommandSet.CommandSetID,
151:                            JDWPCommands.ThreadReferenceCommandSet.StatusCommand);
152:                    packet.setNextValueAsReferenceTypeID(threadID);
153:                    reply = debuggeeWrapper.vmMirror.performCommand(packet);
154:                    if (!checkReplyPacketWithoutFail(reply,
155:                            "ThreadReference.Status command")) {
156:                        statusCommandFailed = true;
157:                        continue;
158:                    }
159:
160:                    int threadStatus = reply.getNextValueAsInt();
161:                    int suspendStatus = reply.getNextValueAsInt();
162:
163:                    logWriter.println("==> threadStatus = " + threadStatus
164:                            + "("
165:                            + JDWPConstants.ThreadStatus.getName(threadStatus)
166:                            + ")");
167:                    logWriter.println("==> suspendStatus = "
168:                            + suspendStatus
169:                            + "("
170:                            + JDWPConstants.SuspendStatus
171:                                    .getName(suspendStatus) + ")");
172:                    if (suspendStatus != JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED) {
173:                        logWriter
174:                                .println("## FAILURE: Unexpected suspendStatus for thread = "
175:                                        + threadName);
176:                        logWriter
177:                                .println("##          Expected suspendStatus  = "
178:                                        + JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED
179:                                        + "("
180:                                        + JDWPConstants.SuspendStatus
181:                                                .getName(JDWPConstants.SuspendStatus.SUSPEND_STATUS_SUSPENDED)
182:                                        + ")");
183:                        suspendStatusFailed = true;
184:                        continue;
185:                    }
186:
187:                    // resuming the thread
188:                    int resumeErr = debuggeeWrapper.vmMirror.resumeThread(
189:                            threadID).getErrorCode();
190:                    if (resumeErr != JDWPConstants.Error.NONE) {
191:                        logWriter
192:                                .println("## FAILURE: Can NOT resume thread = "
193:                                        + threadName);
194:                        logWriter
195:                                .println("##          Received ERROR while resume thread = "
196:                                        + resumeErr
197:                                        + "("
198:                                        + JDWPConstants.Error
199:                                                .getName(resumeErr) + ")");
200:                        resumeThreadFailed = true;
201:                    }
202:                }
203:
204:                synchronizer
205:                        .sendMessage(JPDADebuggeeSynchronizer.SGNL_CONTINUE);
206:                String errorMessage = "";
207:                if (suspendCommandFailed) {
208:                    errorMessage = "## Error found out while ThreadReference.Suspend command performing!\n";
209:                }
210:                if (statusCommandFailed) {
211:                    errorMessage = errorMessage
212:                            + "## Error found out while ThreadReference.Status command performing!\n";
213:                }
214:                if (suspendStatusFailed) {
215:                    errorMessage = errorMessage
216:                            + "## Unexpected suspendStatus found out!\n";
217:                }
218:                if (resumeThreadFailed) {
219:                    errorMessage = errorMessage
220:                            + "## Error found out while resuming thread!\n";
221:                }
222:
223:                boolean testedThreadNotFound = false;
224:                for (int i = 0; i < testedThreadsNumber; i++) {
225:                    if (testedThreadsIDs[i] == 0) {
226:                        logWriter
227:                                .println("## FAILURE: Tested thread is not found out among debuggee threads!");
228:                        logWriter.println("##          Thread name = "
229:                                + testedThreadsNames[i]);
230:                        testedThreadNotFound = true;
231:                    }
232:                }
233:
234:                if (testedThreadNotFound) {
235:                    errorMessage = errorMessage
236:                            + "## Some of tested threads are not found!\n";
237:                }
238:
239:                if (!errorMessage.equals("")) {
240:                    printErrorAndFail("\ntestSuspend001 FAILED:\n"
241:                            + errorMessage);
242:                }
243:                logWriter.println("\n==> testSuspend001 - OK!");
244:            }
245:
246:            public static void main(String[] args) {
247:                junit.textui.TestRunner.run(SuspendTest.class);
248:            }
249:        }
ww___w___.___j__a_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.