Source Code Cross Referenced for DSOVerifierTest.java in  » Net » Terracotta » com » tcverify » 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 » Net » Terracotta » com.tcverify 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003:         * notice. All rights reserved.
004:         */
005:        package com.tcverify;
006:
007:        import org.apache.commons.io.output.TeeOutputStream;
008:        import org.apache.commons.lang.ArrayUtils;
009:
010:        import com.tc.config.schema.builder.InstrumentedClassConfigBuilder;
011:        import com.tc.config.schema.builder.LockConfigBuilder;
012:        import com.tc.config.schema.builder.RootConfigBuilder;
013:        import com.tc.config.schema.setup.FatalIllegalConfigurationChangeHandler;
014:        import com.tc.config.schema.setup.StandardTVSConfigurationSetupManagerFactory;
015:        import com.tc.config.schema.setup.TVSConfigurationSetupManagerFactory;
016:        import com.tc.config.schema.test.InstrumentedClassConfigBuilderImpl;
017:        import com.tc.config.schema.test.L2ConfigBuilder;
018:        import com.tc.config.schema.test.LockConfigBuilderImpl;
019:        import com.tc.config.schema.test.RootConfigBuilderImpl;
020:        import com.tc.config.schema.test.TerracottaConfigBuilder;
021:        import com.tc.process.LinkedJavaProcess;
022:        import com.tc.process.StreamCopier;
023:        import com.tc.server.TCServerImpl;
024:        import com.tc.test.TCTestCase;
025:        import com.tc.test.TestConfigObject;
026:        import com.tc.util.PortChooser;
027:
028:        import java.io.BufferedReader;
029:        import java.io.ByteArrayOutputStream;
030:        import java.io.File;
031:        import java.io.FileOutputStream;
032:        import java.io.FileWriter;
033:        import java.io.IOException;
034:        import java.io.StringReader;
035:        import java.util.ArrayList;
036:        import java.util.Collection;
037:        import java.util.Collections;
038:        import java.util.List;
039:
040:        /**
041:         * A quick/shallow test that uses the DSOVerifier client program
042:         */
043:        public class DSOVerifierTest extends TCTestCase {
044:
045:            TCServerImpl server;
046:
047:            public static void main(String[] args) throws Exception {
048:                DSOVerifierTest t = new DSOVerifierTest();
049:                t.setUp();
050:                t.test();
051:                t.tearDown();
052:            }
053:
054:            public DSOVerifierTest() {
055:                // disableAllUntil("2007-09-11");
056:            }
057:
058:            protected void setUp() throws Exception {
059:                super .setUp();
060:
061:                File configFile = writeConfigFile();
062:
063:                StandardTVSConfigurationSetupManagerFactory config;
064:                config = new StandardTVSConfigurationSetupManagerFactory(
065:                        new String[] {
066:                                StandardTVSConfigurationSetupManagerFactory.CONFIG_SPEC_ARGUMENT_WORD,
067:                                configFile.getAbsolutePath() }, true,
068:                        new FatalIllegalConfigurationChangeHandler());
069:
070:                server = new TCServerImpl(config
071:                        .createL2TVSConfigurationSetupManager(null));
072:                server.start();
073:            }
074:
075:            protected void tearDown() throws Exception {
076:                if (server != null) {
077:                    server.stop();
078:                }
079:                super .tearDown();
080:            }
081:
082:            private boolean verifyOutput(String output, String desiredPrefix)
083:                    throws IOException {
084:                BufferedReader reader = new BufferedReader(new StringReader(
085:                        output));
086:
087:                String line;
088:                while ((line = reader.readLine()) != null) {
089:                    if (line.startsWith(desiredPrefix)) {
090:                        return true;
091:                    }
092:                }
093:
094:                return false;
095:            }
096:
097:            public void test() throws Exception {
098:                LinkedJavaProcess p1 = new LinkedJavaProcess(getMainClass(),
099:                        new String[] { "1", "2" });
100:                p1.setJavaArguments(getJvmArgs());
101:
102:                LinkedJavaProcess p2 = new LinkedJavaProcess(getMainClass(),
103:                        new String[] { "2", "1" });
104:                p2.setJavaArguments(getJvmArgs());
105:
106:                p1.start();
107:                p2.start();
108:
109:                p1.getOutputStream().close();
110:                p2.getOutputStream().close();
111:
112:                FileOutputStream p1o = new FileOutputStream(
113:                        getTempFile("p1out.log"));
114:                FileOutputStream p1e = new FileOutputStream(
115:                        getTempFile("p1err.log"));
116:                FileOutputStream p2o = new FileOutputStream(
117:                        getTempFile("p2out.log"));
118:                FileOutputStream p2e = new FileOutputStream(
119:                        getTempFile("p2err.log"));
120:
121:                ByteArrayOutputStream p1oBytes = new ByteArrayOutputStream();
122:                ByteArrayOutputStream p1eBytes = new ByteArrayOutputStream();
123:                ByteArrayOutputStream p2oBytes = new ByteArrayOutputStream();
124:                ByteArrayOutputStream p2eBytes = new ByteArrayOutputStream();
125:
126:                StreamCopier p1StdOut = new StreamCopier(p1.getInputStream(),
127:                        new TeeOutputStream(p1oBytes, p1o));
128:                StreamCopier p1StdErr = new StreamCopier(p1.getErrorStream(),
129:                        new TeeOutputStream(p1eBytes, p1e));
130:                StreamCopier p2StdOut = new StreamCopier(p2.getInputStream(),
131:                        new TeeOutputStream(p2oBytes, p2o));
132:                StreamCopier p2StdErr = new StreamCopier(p2.getErrorStream(),
133:                        new TeeOutputStream(p2eBytes, p2e));
134:                p1StdOut.start();
135:                p1StdErr.start();
136:                p2StdOut.start();
137:                p2StdErr.start();
138:
139:                p1.waitFor();
140:                p2.waitFor();
141:
142:                p1StdOut.join();
143:                p1StdErr.join();
144:                p2StdOut.join();
145:                p2StdErr.join();
146:
147:                String p1Out = new String(p1oBytes.toByteArray());
148:                String p1Err = new String(p1eBytes.toByteArray());
149:                String p2Out = new String(p2oBytes.toByteArray());
150:                String p2Err = new String(p2eBytes.toByteArray());
151:
152:                String compound = "Process 1 output:\n\n" + p1Out
153:                        + "\n\nProcess 1 error:\n\n" + p1Err
154:                        + "\n\nProcess 2 output:\n\n" + p2Out
155:                        + "\n\nProcess 2 error:\n\n" + p2Err + "\n\n";
156:
157:                String output = "L2-DSO-OK:";
158:                if (!verifyOutput(p1Out, output)) {
159:                    fail(compound);
160:                }
161:
162:                if (!verifyOutput(p2Out, output)) {
163:                    fail(compound);
164:                }
165:            }
166:
167:            protected String getMainClass() {
168:                return DSOVerifier.class.getName();
169:            }
170:
171:            protected String[] getJvmArgs() {
172:                String bootclasspath = "-Xbootclasspath/p:"
173:                        + TestConfigObject.getInstance().normalBootJar();
174:
175:                List<String> args = new ArrayList<String>();
176:                args.add(bootclasspath);
177:                args
178:                        .add("-D"
179:                                + TVSConfigurationSetupManagerFactory.CONFIG_FILE_PROPERTY_NAME
180:                                + "=localhost:" + server.getDSOListenPort());
181:
182:                args.addAll(getExtraJvmArgs());
183:
184:                String[] rv = args.toArray(new String[args.size()]);
185:                System.out.println("JVM args: " + ArrayUtils.toString(rv));
186:                return rv;
187:            }
188:
189:            protected Collection<String> getExtraJvmArgs() {
190:                return Collections.EMPTY_LIST;
191:            }
192:
193:            protected boolean isSynchronousWrite() {
194:                return false;
195:            }
196:
197:            private File writeConfigFile() throws IOException {
198:                TerracottaConfigBuilder config = TerracottaConfigBuilder
199:                        .newMinimalInstance();
200:
201:                PortChooser portChooser = new PortChooser();
202:                L2ConfigBuilder l2Builder = L2ConfigBuilder
203:                        .newMinimalInstance();
204:                l2Builder.setDSOPort(portChooser.chooseRandomPort());
205:                l2Builder.setJMXPort(portChooser.chooseRandomPort());
206:                l2Builder.setName("localhost");
207:
208:                config.getServers().setL2s(new L2ConfigBuilder[] { l2Builder });
209:
210:                InstrumentedClassConfigBuilder instrumentedClass = new InstrumentedClassConfigBuilderImpl();
211:                instrumentedClass.setClassExpression("com.tcverify..*");
212:                config
213:                        .getApplication()
214:                        .getDSO()
215:                        .setInstrumentedClasses(
216:                                new InstrumentedClassConfigBuilder[] { instrumentedClass });
217:
218:                LockConfigBuilder lock1 = new LockConfigBuilderImpl(
219:                        LockConfigBuilder.TAG_NAMED_LOCK);
220:                lock1
221:                        .setMethodExpression("java.lang.Object com.tcverify.DSOVerifier.getValue(int)");
222:                lock1.setLockName("verifierMap");
223:                if (isSynchronousWrite()) {
224:                    lock1
225:                            .setLockLevel(LockConfigBuilder.LEVEL_SYNCHRONOUS_WRITE);
226:                } else {
227:                    lock1.setLockLevel(LockConfigBuilder.LEVEL_WRITE);
228:                }
229:
230:                LockConfigBuilder lock2 = new LockConfigBuilderImpl(
231:                        LockConfigBuilder.TAG_NAMED_LOCK);
232:                lock2
233:                        .setMethodExpression("void com.tcverify.DSOVerifier.setValue(int)");
234:                lock2.setLockName("verifierMap");
235:                if (isSynchronousWrite()) {
236:                    lock2
237:                            .setLockLevel(LockConfigBuilder.LEVEL_SYNCHRONOUS_WRITE);
238:                } else {
239:                    lock2.setLockLevel(LockConfigBuilder.LEVEL_WRITE);
240:                }
241:
242:                config.getApplication().getDSO().setLocks(
243:                        new LockConfigBuilder[] { lock1, lock2 });
244:
245:                RootConfigBuilder root = new RootConfigBuilderImpl();
246:                root.setFieldName("com.tcverify.DSOVerifier.verifierMap");
247:                root.setRootName("verifierMap");
248:
249:                config.getApplication().getDSO().setRoots(
250:                        new RootConfigBuilder[] { root });
251:
252:                File configDir = this .getTempDirectory();
253:                File configFile = new File(configDir, "dso-verifier-config.xml");
254:                FileWriter cfgOut = new FileWriter(configFile);
255:                cfgOut.write(config.toString());
256:                cfgOut.flush();
257:                cfgOut.close();
258:                return configFile;
259:            }
260:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.