1 4 package com.tctest; 5 6 import EDU.oswego.cs.dl.util.concurrent.CyclicBarrier; 7 8 import com.tc.object.ObjectID; 9 import com.tc.object.TCObject; 10 import com.tc.object.bytecode.Manageable; 11 import com.tc.object.config.ConfigVisitor; 12 import com.tc.object.config.DSOClientConfigHelper; 13 import com.tc.object.config.TransparencyClassSpec; 14 import com.tc.object.dna.api.DNAWriter; 15 import com.tc.object.dna.api.PhysicalAction; 16 import com.tc.simulator.app.ApplicationConfig; 17 import com.tc.simulator.listener.ListenerProvider; 18 import com.tc.util.Assert; 19 import com.tctest.runner.AbstractTransparentApp; 20 21 import java.io.File ; 22 import java.util.ArrayList ; 23 import java.util.Iterator ; 24 import java.util.List ; 25 26 public class FileSharingTestApp extends AbstractTransparentApp { 27 private final static String UNIX_STYLE_MOCK_FILE_NAME = "\\home\\test\\file1"; 28 29 private final CyclicBarrier barrier; 30 private File fileRoot; 31 32 public FileSharingTestApp(String appId, ApplicationConfig cfg, ListenerProvider listenerProvider) { 33 super(appId, cfg, listenerProvider); 34 barrier = new CyclicBarrier(getParticipantCount()); 35 } 36 37 public void run() { 38 try { 39 int index = barrier.barrier(); 40 41 basicTest(index); 42 fileDehydrateTest(index); 43 } catch (Throwable t) { 44 notifyError(t); 45 } 46 } 47 48 52 private void basicTest(int index) throws Exception { 53 if (index == 0) { 54 fileRoot = new File (UNIX_STYLE_MOCK_FILE_NAME); 55 } 56 57 barrier.barrier(); 58 59 if (index != 0) { 60 Assert.assertEquals(UNIX_STYLE_MOCK_FILE_NAME, fileRoot.getPath()); 61 } 62 63 barrier.barrier(); 64 } 65 66 69 private void fileDehydrateTest(int index) throws Exception { 70 if (index == 0) { 71 Manageable managed = (Manageable)fileRoot; 72 TCObject tcObject = managed.__tc_managed(); 73 MockDNAWriter dnaWriter = new MockDNAWriter(); 74 tcObject.dehydrate(dnaWriter); 75 76 List dna = dnaWriter.getDNA(); 77 boolean separatorFound = false; 78 for (Iterator i=dna.iterator(); i.hasNext(); ) { 79 PhysicalAction action = (PhysicalAction)i.next(); 80 Assert.assertTrue(action.isTruePhysical()); 81 if ("File.fileSeparator".equals(action.getFieldName())) { 82 separatorFound = true; 83 } 84 } 85 Assert.assertTrue(separatorFound); 86 } 87 } 88 89 public static void visitL1DSOConfig(ConfigVisitor visitor, DSOClientConfigHelper config) { 90 TransparencyClassSpec spec = config.getOrCreateSpec(CyclicBarrier.class.getName()); 91 config.addWriteAutolock("* " + CyclicBarrier.class.getName() + "*.*(..)"); 92 93 String testClass = FileSharingTestApp.class.getName(); 94 spec = config.getOrCreateSpec(testClass); 95 96 config.addIncludePattern(testClass + "$*"); 97 98 String methodExpression = "* " + testClass + "*.*(..)"; 99 config.addWriteAutolock(methodExpression); 100 101 spec.addRoot("fileRoot", "fileRoot"); 102 spec.addRoot("barrier", "barrier"); 103 } 104 105 private static class MockDNAWriter implements DNAWriter { 106 107 public List dna = new ArrayList (); 108 109 public MockDNAWriter() { 110 } 112 113 public void addLogicalAction(int method, Object [] parameters) { 114 } 116 117 public void addPhysicalAction(String fieldName, Object value) { 118 addPhysicalAction(fieldName, value, true); 120 } 121 122 public void finalizeDNA() { 123 } 125 126 public void addArrayElementAction(int index, Object value) { 127 } 129 130 public void addEntireArray(Object value) { 131 } 133 134 public void addLiteralValue(Object value) { 135 } 137 138 public void setParentObjectID(ObjectID id) { 139 } 141 142 public void setArrayLength(int length) { 143 } 145 146 public void addPhysicalAction(String fieldName, Object value, boolean canBeReference) { 147 dna.add(new PhysicalAction(fieldName, value, canBeReference)); 148 } 149 150 public List getDNA() { 151 return dna; 152 } 153 154 public void addClassLoaderAction(String classLoaderFieldName, Object value) { 155 157 } 158 159 public void addSubArrayAction(int start, Object array, int length) { 160 } 162 } 163 164 } 165 | Popular Tags |