Source Code Cross Referenced for ThreadReferenceTest.java in  » IDE-Eclipse » jdt » org » eclipse » debug » jdi » tests » 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 » IDE Eclipse » jdt » org.eclipse.debug.jdi.tests 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*******************************************************************************
002:         * Copyright (c) 2000, 2005 IBM Corporation and others.
003:         * All rights reserved. This program and the accompanying materials
004:         * are made available under the terms of the Eclipse Public License v1.0
005:         * which accompanies this distribution, and is available at
006:         * http://www.eclipse.org/legal/epl-v10.html
007:         * 
008:         * Contributors:
009:         *     IBM Corporation - initial API and implementation
010:         *******************************************************************************/package org.eclipse.debug.jdi.tests;
011:
012:        import java.util.List;
013:
014:        import com.sun.jdi.ClassNotLoadedException;
015:        import com.sun.jdi.ClassType;
016:        import com.sun.jdi.IncompatibleThreadStateException;
017:        import com.sun.jdi.InvalidTypeException;
018:        import com.sun.jdi.InvocationException;
019:        import com.sun.jdi.Method;
020:        import com.sun.jdi.ObjectReference;
021:        import com.sun.jdi.StackFrame;
022:        import com.sun.jdi.ThreadReference;
023:        import com.sun.jdi.event.ThreadStartEvent;
024:
025:        /**
026:         * Tests for JDI com.sun.jdi.ThreadReference
027:         * and JDWP Thread command set.
028:         */
029:        public class ThreadReferenceTest extends AbstractJDITest {
030:
031:            private ThreadReference fThread;
032:
033:            /**
034:             * Creates a new test .
035:             */
036:            public ThreadReferenceTest() {
037:                super ();
038:            }
039:
040:            /**
041:             * Init the fields that are used by this test only.
042:             */
043:            public void localSetUp() {
044:                // Get thread
045:                fThread = getThread();
046:            }
047:
048:            /**
049:             * Run all tests and output to standard output.
050:             * @param args
051:             */
052:            public static void main(java.lang.String[] args) {
053:                new ThreadReferenceTest().runSuite(args);
054:            }
055:
056:            /**
057:             * Gets the name of the test case.
058:             * @see junit.framework.TestCase#getName()
059:             */
060:            public String getName() {
061:                return "com.sun.jdi.ThreadReference";
062:            }
063:
064:            /**
065:             * Test JDI currentContendedMonitor().
066:             */
067:            public void testJDICurrentContendedMonitor() {
068:                if (fVM.canGetCurrentContendedMonitor()) {
069:                    try {
070:                        assertTrue("1",
071:                                fThread.currentContendedMonitor() == null);
072:                    } catch (IncompatibleThreadStateException e) {
073:                        assertTrue("2", false);
074:                    }
075:                }
076:            }
077:
078:            /**
079:             * Test JDI frame(int).
080:             */
081:            public void testJDIFrame() {
082:                try {
083:                    StackFrame frame = fThread.frame(0);
084:                    assertTrue("1", fThread.frames().contains(frame));
085:                } catch (IncompatibleThreadStateException e) {
086:                    assertTrue("2", false);
087:                }
088:            }
089:
090:            /**
091:             * Test JDI frameCount.
092:             */
093:            public void testJDIFrameCount() {
094:                try {
095:                    int count = fThread.frameCount();
096:                    assertTrue("1", count <= 4);
097:                } catch (IncompatibleThreadStateException e) {
098:                    assertTrue("2", false);
099:                }
100:            }
101:
102:            /**
103:             * Test JDI frames() and JDWP 'Thread - Get frames'.
104:             */
105:            public void testJDIFrames() {
106:                List frames = null;
107:                try {
108:                    frames = fThread.frames();
109:                } catch (IncompatibleThreadStateException e) {
110:                    assertTrue("1", false);
111:                }
112:                assertTrue("2", frames.size() > 0);
113:            }
114:
115:            /**
116:             * Test JDI interrupt()().
117:             */
118:            public void testJDIInterrupt() {
119:                assertEquals("1", 1, fThread.suspendCount());
120:                fThread.interrupt();
121:                assertEquals("2", 1, fThread.suspendCount());
122:            }
123:
124:            /**
125:             * Test JDI isAtBreakpoint().
126:             */
127:            public void testJDIIsAtBreakpoint() {
128:                assertTrue("1", !fThread.isAtBreakpoint());
129:            }
130:
131:            /**
132:             * Test JDI isSuspended().
133:             */
134:            public void testJDIIsSuspended() {
135:                assertTrue("1", fThread.isSuspended());
136:            }
137:
138:            /**
139:             * Test JDI name() and JDWP 'Thread - Get name'.
140:             */
141:            public void testJDIName() {
142:                assertEquals("1", "Test Thread", fThread.name());
143:            }
144:
145:            /**
146:             * Test JDI ownedMonitors().
147:             */
148:            public void testJDIOwnedMonitors() {
149:                if (fVM.canGetOwnedMonitorInfo()) {
150:                    waitUntilReady();
151:                    try {
152:                        assertEquals("1", 1, fThread.ownedMonitors().size());
153:                    } catch (IncompatibleThreadStateException e) {
154:                        assertTrue("2", false);
155:                    }
156:                }
157:            }
158:
159:            /**
160:             * Test JDI status() and JDWP 'Thread - Get status'.
161:             */
162:            public void testJDIStatus() {
163:                int status = fThread.status();
164:                assertTrue(
165:                        "1",
166:                        ((status == ThreadReference.THREAD_STATUS_RUNNING)
167:                                || (status == ThreadReference.THREAD_STATUS_SLEEPING) || (status == ThreadReference.THREAD_STATUS_WAIT)));
168:            }
169:
170:            /**
171:             * Test JDI stop(ObjectReference).
172:             */
173:            public void testJDIStop() {
174:                // Make sure the entire VM is not suspended before we start a new thread
175:                // (otherwise this new thread will start suspended and we will never get the
176:                // ThreadStart event)
177:                fVM.resume();
178:
179:                // Trigger a thread start event to get a new thread
180:                ThreadStartEvent event = (ThreadStartEvent) triggerAndWait(fVM
181:                        .eventRequestManager().createThreadStartRequest(),
182:                        "ThreadStartEvent", false);
183:                ThreadReference thread = event.thread();
184:
185:                // Create a java.lang.Throwable instance in 
186:                java.util.List classes = fVM
187:                        .classesByName("java.lang.Throwable");
188:                assertTrue("1", classes.size() != 0);
189:                ClassType threadDeathClass = (ClassType) classes.get(0);
190:                Method constructor = threadDeathClass.concreteMethodByName(
191:                        "<init>", "()V");
192:                ObjectReference threadDeath = null;
193:                try {
194:                    threadDeath = threadDeathClass.newInstance(thread,
195:                            constructor, new java.util.LinkedList(),
196:                            ClassType.INVOKE_SINGLE_THREADED);
197:                    threadDeath.disableCollection();
198:                    // This object is going to be used for the lifetime of the VM.
199:                } catch (ClassNotLoadedException e) {
200:                    assertTrue("2", false);
201:                } catch (InvalidTypeException e) {
202:                    assertTrue("3", false);
203:                } catch (InvocationException e) {
204:                    assertTrue("4", false);
205:                } catch (IncompatibleThreadStateException e) {
206:                    assertTrue("5", false);
207:                }
208:
209:                // Stop the thread
210:                try {
211:                    thread.stop(threadDeath);
212:                } catch (InvalidTypeException e) {
213:                    assertTrue("6", false);
214:                }
215:
216:                waitUntilReady();
217:
218:            }
219:
220:            /**
221:             * Test JDI suspend() and resume() 
222:             * and JDWP 'Thread - Suspend' and 'Thread - Resume'.
223:             */
224:            public void testJDISuspendResume() {
225:                assertEquals("1", 1, fThread.suspendCount());
226:                fThread.resume();
227:                assertTrue("2", !fThread.isSuspended());
228:                fThread.suspend();
229:                assertTrue("3", fThread.isSuspended());
230:
231:                waitUntilReady();
232:            }
233:
234:            /**
235:             * Test JDI threadGroup() and JDWP 'Thread - Get threadGroup'.
236:             */
237:            public void testJDIThreadGroup() {
238:                assertNotNull("1", fThread.threadGroup());
239:            }
240:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.