Source Code Cross Referenced for FileSharingTestApp.java in  » Net » Terracotta » com » tctest » 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.tctest 
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.tctest;
006:
007:        import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier;
008:
009:        import com.tc.object.ObjectID;
010:        import com.tc.object.TCObject;
011:        import com.tc.object.bytecode.Manageable;
012:        import com.tc.object.config.ConfigVisitor;
013:        import com.tc.object.config.DSOClientConfigHelper;
014:        import com.tc.object.config.TransparencyClassSpec;
015:        import com.tc.object.dna.api.DNAWriter;
016:        import com.tc.object.dna.api.PhysicalAction;
017:        import com.tc.simulator.app.ApplicationConfig;
018:        import com.tc.simulator.listener.ListenerProvider;
019:        import com.tc.util.Assert;
020:        import com.tctest.runner.AbstractTransparentApp;
021:
022:        import java.io.File;
023:        import java.lang.reflect.Field;
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:        import java.util.List;
027:
028:        public class FileSharingTestApp extends AbstractTransparentApp {
029:            private final static String MOCK_FILE_NAME = "/home/teck/.bashrc";
030:
031:            private final CyclicBarrier barrier;
032:            private File fileRoot;
033:
034:            public FileSharingTestApp(String appId, ApplicationConfig cfg,
035:                    ListenerProvider listenerProvider) {
036:                super (appId, cfg, listenerProvider);
037:                barrier = new CyclicBarrier(getParticipantCount());
038:            }
039:
040:            public void run() {
041:                try {
042:                    int index = barrier.barrier();
043:
044:                    basicTest(index);
045:                    fileDehydrateTest(index);
046:
047:                    mutateFileTest(index);
048:
049:                } catch (Throwable t) {
050:                    notifyError(t);
051:                }
052:            }
053:
054:            private void mutateFileTest(int index) throws Exception {
055:                File root = fileRoot; // ensure the root is faulted, so that the mutation will be broadcast
056:
057:                barrier.barrier();
058:
059:                if (index == 0) {
060:                    synchronized (root) {
061:                        Field field = File.class.getDeclaredField("path");
062:                        field.setAccessible(true);
063:                        field.set(root, "timmy");
064:                    }
065:                }
066:
067:                barrier.barrier();
068:
069:                synchronized (root) {
070:                    Assert.assertEquals("timmy", root.getPath());
071:                }
072:            }
073:
074:            private void basicTest(int index) throws Exception {
075:                if (index == 0) {
076:                    fileRoot = new File(MOCK_FILE_NAME);
077:                }
078:
079:                barrier.barrier();
080:
081:                if (index != 0) {
082:                    Assert.assertEquals(new File(MOCK_FILE_NAME).getPath(),
083:                            fileRoot.getPath());
084:                }
085:
086:                barrier.barrier();
087:            }
088:
089:            /**
090:             * This test makes sure that the file separator is contained in the dna via dehydration.
091:             */
092:            private void fileDehydrateTest(int index) throws Exception {
093:                if (index == 0) {
094:                    Manageable managed = (Manageable) fileRoot;
095:                    TCObject tcObject = managed.__tc_managed();
096:                    MockDNAWriter dnaWriter = new MockDNAWriter();
097:                    tcObject.setIsNew();
098:                    tcObject.dehydrateIfNew(dnaWriter);
099:
100:                    List dna = dnaWriter.getDNA();
101:
102:                    Assert.assertEquals(2, dna.size());
103:
104:                    boolean separatorFound = false;
105:                    for (Iterator i = dna.iterator(); i.hasNext();) {
106:                        PhysicalAction action = (PhysicalAction) i.next();
107:                        Assert.assertTrue(action.isTruePhysical());
108:                        if ("java.io.File._tcFileSeparator".equals(action
109:                                .getFieldName())) {
110:                            separatorFound = true;
111:                        }
112:                    }
113:                    Assert.assertTrue(separatorFound);
114:                }
115:            }
116:
117:            public static void visitL1DSOConfig(ConfigVisitor visitor,
118:                    DSOClientConfigHelper config) {
119:                TransparencyClassSpec spec = config
120:                        .getOrCreateSpec(CyclicBarrier.class.getName());
121:                config.addWriteAutolock("* " + CyclicBarrier.class.getName()
122:                        + "*.*(..)");
123:
124:                String testClass = FileSharingTestApp.class.getName();
125:                spec = config.getOrCreateSpec(testClass);
126:
127:                config.addIncludePattern(testClass + "$*");
128:
129:                String methodExpression = "* " + testClass + "*.*(..)";
130:                config.addWriteAutolock(methodExpression);
131:
132:                spec.addRoot("fileRoot", "fileRoot");
133:                spec.addRoot("barrier", "barrier");
134:            }
135:
136:            private static class MockDNAWriter implements  DNAWriter {
137:
138:                public List dna = new ArrayList();
139:
140:                public MockDNAWriter() {
141:                    //
142:                }
143:
144:                public void addLogicalAction(int method, Object[] parameters) {
145:                    //
146:                }
147:
148:                public void addPhysicalAction(String fieldName, Object value) {
149:                    // dna.add(new PhysicalAction(fieldName, value));
150:                    addPhysicalAction(fieldName, value, true);
151:                }
152:
153:                public void finalizeDNA(boolean isDeltaDNA) {
154:                    //
155:                }
156:
157:                public void addArrayElementAction(int index, Object value) {
158:                    //
159:                }
160:
161:                public void addEntireArray(Object value) {
162:                    //
163:                }
164:
165:                public void addLiteralValue(Object value) {
166:                    //
167:                }
168:
169:                public void setParentObjectID(ObjectID id) {
170:                    //
171:                }
172:
173:                public void setArrayLength(int length) {
174:                    //
175:                }
176:
177:                public void addPhysicalAction(String fieldName, Object value,
178:                        boolean canBeReference) {
179:                    dna
180:                            .add(new PhysicalAction(fieldName, value,
181:                                    canBeReference));
182:                }
183:
184:                public List getDNA() {
185:                    return dna;
186:                }
187:
188:                public void addClassLoaderAction(String classLoaderFieldName,
189:                        Object value) {
190:                    //
191:
192:                }
193:
194:                public void addSubArrayAction(int start, Object array,
195:                        int length) {
196:                    //
197:                }
198:            }
199:
200:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.