1 19 package org.openide.filesystems; 20 21 import java.io.IOException ; 22 import java.io.File ; 23 import java.util.Enumeration ; 24 import java.util.List ; 25 import java.util.ArrayList ; 26 import java.util.Random ; 27 import java.util.Map ; 28 29 import org.netbeans.performance.Benchmark; 30 import org.openide.filesystems.*; 31 32 37 public abstract class FSTest extends ReadOnlyFSTest { 38 39 public static final String ATTRIBUTES_NO_KEY = "ATTRIBUTES_NO"; 40 41 42 protected int attrsCount; 43 44 45 public FSTest(String name) { 46 super(name); 47 } 48 49 50 public FSTest(String name, Object [] args) { 51 super(name, args); 52 } 53 54 55 protected void setUp() throws Exception { 56 super.setUp(); 57 if (shouldDefAttrNo()) { 58 attrsCount = getIntValue(ATTRIBUTES_NO_KEY); 59 } 60 postSetup(); 61 } 62 63 64 protected void postSetup() throws Exception { 65 if (getName().startsWith("testGetAttributes")) { 67 testSetOneAttributeSeq(1); 68 } 69 } 70 71 72 protected void tearDownFileObjects(FileObject[] fos) throws Exception { 73 if (getName().startsWith("testGetAttributes")) { 75 unsetOneAttributeSeq(); 76 } 77 } 78 79 80 protected Map createDefaultMap() { 81 Map map = super.createDefaultMap(); 82 if (shouldDefAttrNo()) { 83 map.put(ATTRIBUTES_NO_KEY, new Integer (2)); 84 } 85 if (getName().startsWith("testSet")) { 86 narrow(map); 87 } 88 return map; 89 } 90 91 92 private boolean shouldDefAttrNo() { 93 return getName().startsWith("testSetMany"); 94 } 95 96 97 protected Map [] createArguments() { 98 if (shouldDefAttrNo()) { 99 Map [] ret = new Map [2]; 100 ret[0] = createDefaultMap(); 101 102 ret[1] = createDefaultMap(); 103 ret[1].put(ATTRIBUTES_NO_KEY, new Integer (5)); 104 return ret; 105 } else { 106 return super.createArguments(); 107 } 108 } 109 110 111 private static final void narrow(Map map) { 112 Integer in = (Integer ) map.get(FILE_NO_KEY); 113 int ival = Math.max(in.intValue() / 10, 10); 114 map.put(FILE_NO_KEY, new Integer (ival)); 115 } 116 117 120 123 private void testSetOneAttributeSeq(int xiterations) throws IOException { 124 FileObject[] files = this.files; 125 String [][] pairs = this.pairs; 126 127 for (int it = 0; it < xiterations; it++) { 128 for (int i = 0; i < files.length; i++) { 129 files[i].setAttribute(pairs[i][0], pairs[i][1]); 130 } 131 } 132 } 133 134 135 private void unsetOneAttributeSeq() throws IOException { 136 FileObject[] files = this.files; 137 String [][] pairs = this.pairs; 138 139 for (int i = 0; i < files.length; i++) { 140 files[i].setAttribute(pairs[i][0], null); 141 } 142 } 143 144 147 public void testSetOneAttributeSeq() throws IOException { 148 testSetOneAttributeSeq(iterations); 149 } 150 151 154 public void testSetManyAttributesSeq() throws IOException { 155 FileObject[] files = this.files; 156 String [][] pairs = this.pairs; 157 int iterations = this.iterations; 158 159 for (int it = 0; it < iterations; it++) { 160 for (int i = 0; i < files.length; i++) { 161 for (int j = 0; (j < pairs.length) && (j < attrsCount); j++) { 162 files[i].setAttribute(pairs[j][0], pairs[j][1]); 163 } 164 } 165 } 166 } 167 168 171 public void testSetOneAttributeRnd() throws IOException { 172 FileObject[] files = this.files; 173 String [][] pairs = this.pairs; 174 int iterations = this.iterations; 175 int perm[] = this.perm; 176 177 for (int it = 0; it < iterations; it++) { 178 for (int i = 0; i < files.length; i++) { 179 files[perm[i]].setAttribute(pairs[i][0], pairs[i][1]); 180 } 181 } 182 } 183 184 187 public void testSetManyAttributesRnd() throws IOException { 188 FileObject[] files = this.files; 189 String [][] pairs = this.pairs; 190 int iterations = this.iterations; 191 int perm[] = this.perm; 192 193 for (int it = 0; it < iterations; it++) { 194 for (int i = 0; i < files.length; i++) { 195 for (int j = 0; (j < pairs.length) && (j < attrsCount); j++) { 196 files[perm[i]].setAttribute(pairs[j][0], pairs[j][1]); 197 } 198 } 199 } 200 } 201 } 202 | Popular Tags |