root / branches / Mobile_Compatible_Hito_1 / libFMap_mobile_shp_driver / src-test / org / gvsig / data / datastores / vectorial / file / shp / PerformanceTest.java @ 22037
History | View | Annotate | Download (6.62 KB)
1 |
package org.gvsig.data.datastores.vectorial.file.shp; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.Date; |
5 |
|
6 |
import junit.framework.TestCase; |
7 |
|
8 |
import org.apache.log4j.FileAppender; |
9 |
import org.apache.log4j.Level; |
10 |
import org.apache.log4j.Logger; |
11 |
import org.apache.log4j.PatternLayout; |
12 |
import org.gvsig.compatible.StringUtil; |
13 |
import org.gvsig.data.datastores.vectorial.file.shp_inst.InstSHPStore; |
14 |
import org.gvsig.data.datastores.vectorial.file.shp_jni.JNISHPStore; |
15 |
import org.gvsig.data.datastores.vectorial.file.shp_mem.MemSHPStore; |
16 |
import org.gvsig.data.datastores.vectorial.file.shp_util.Utils; |
17 |
|
18 |
import es.prodevelop.gvsig.mobile.fmap.driver.vect.shp.ShpReader; |
19 |
|
20 |
//import es.prodevelop.gvsig.mobile.fmap.layer.newmodel.FPerformanceTestVectorLayer;
|
21 |
//import es.prodevelop.gvsig.mobile.fmap.util.ResourceReader;
|
22 |
//import es.prodevelop.gvsig.mobile.fmap.util.Utils;
|
23 |
//import es.prodevelop.gvsig.mobile.fmap.util.string.StringUtilities;
|
24 |
|
25 |
/**
|
26 |
* This class tests the performance of three SHP drivers implemented for gvSIG Mobile.
|
27 |
* These drivers are compatible with the new data access model (june 2008)
|
28 |
* and will share a lot of code with gvsig Desktop.
|
29 |
*
|
30 |
* The right testdata folder is needed.
|
31 |
*
|
32 |
*
|
33 |
* @author jldominguez
|
34 |
*
|
35 |
*/
|
36 |
public class PerformanceTest extends TestCase { |
37 |
|
38 |
private static Logger logger; |
39 |
public static String SD_FOLDER = "Tarjeta SD"; |
40 |
|
41 |
private static String resourceDir = ""; |
42 |
|
43 |
static {
|
44 |
String base = System.getProperty("java.class.path"); |
45 |
int ind = base.indexOf(File.pathSeparator); |
46 |
if (ind != -1) base = base.substring(0, ind); |
47 |
ind = base.lastIndexOf(File.separator);
|
48 |
base = base.substring(0, ind);
|
49 |
//logger.debug("Base directory: " + base);
|
50 |
ind = base.lastIndexOf(File.separator);
|
51 |
resourceDir = base.substring(0, ind) + File.separator + "resources"; |
52 |
} |
53 |
|
54 |
/**
|
55 |
* Number of sample executions
|
56 |
*/
|
57 |
public static final int REPEAT_TIMES = 5; |
58 |
|
59 |
public static final String[] SIZE_TEST_BASE_FILE_NAMES = { |
60 |
"point_", "polygon_" }; |
61 |
|
62 |
public static final int[] SIZE_TEST_FILE_SIZES = { |
63 |
10,
|
64 |
200,
|
65 |
1000,
|
66 |
8000,
|
67 |
40000,
|
68 |
200000 };
|
69 |
|
70 |
public static final int[] SIZE_TEST_FILE_SIZES_JNI = { |
71 |
10,
|
72 |
200,
|
73 |
1000,
|
74 |
8000,
|
75 |
40000 };
|
76 |
|
77 |
public static final int[] SIZE_TEST_FILE_SIZES_MEM = { |
78 |
10,
|
79 |
200,
|
80 |
1000,
|
81 |
8000 };
|
82 |
public static final String[] FEATURE_SIZE_TEST_FEATURE_TYPES = { |
83 |
"few", "medium", "many" }; |
84 |
public static final String FEATURE_SIZE_TEST_BASE_FILE_NAME = "VerticesPerFeature.shp"; |
85 |
|
86 |
public PerformanceTest() {
|
87 |
ShpReader.touch(); |
88 |
initLogger(); |
89 |
} |
90 |
|
91 |
public static void main(String[] args) { |
92 |
junit.textui.TestRunner.run(PerformanceTest.class); |
93 |
} |
94 |
|
95 |
protected void setUp() throws Exception { |
96 |
super.setUp();
|
97 |
} |
98 |
|
99 |
public void testInitialize() { |
100 |
|
101 |
new SHPStore();
|
102 |
doit(SHPStore.DATASTORE_NAME); |
103 |
|
104 |
new MemSHPStore();
|
105 |
doit(MemSHPStore.DATASTORE_NAME); |
106 |
|
107 |
new JNISHPStore();
|
108 |
doit(JNISHPStore.DATASTORE_NAME); |
109 |
|
110 |
new InstSHPStore();
|
111 |
doit(InstSHPStore.DATASTORE_NAME); |
112 |
|
113 |
logger.debug("FIN.");
|
114 |
} |
115 |
|
116 |
private void doit(String storename) { |
117 |
File shpFile = null; |
118 |
|
119 |
int[] sizes = SIZE_TEST_FILE_SIZES; |
120 |
if (storename.compareTo(JNISHPStore.DATASTORE_NAME) == 0) { |
121 |
sizes = SIZE_TEST_FILE_SIZES_JNI; |
122 |
} else {
|
123 |
if (storename.compareTo(InstSHPStore.DATASTORE_NAME) == 0) { |
124 |
sizes = SIZE_TEST_FILE_SIZES_MEM; |
125 |
} else {
|
126 |
if (storename.compareTo(MemSHPStore.DATASTORE_NAME) == 0) { |
127 |
sizes = SIZE_TEST_FILE_SIZES_MEM; |
128 |
} |
129 |
} |
130 |
} |
131 |
|
132 |
// ---------- size test
|
133 |
for (int i=0; i<sizes.length; i++) { |
134 |
int size = sizes[i];
|
135 |
for (int j=0; j<SIZE_TEST_BASE_FILE_NAMES.length; j++) { |
136 |
String base_name = SIZE_TEST_BASE_FILE_NAMES[j];
|
137 |
String filename = base_name + size + ".shp"; |
138 |
|
139 |
if (Utils.USING_PDA) {
|
140 |
shpFile = getPdaTestFile(SD_FOLDER, "testdata", filename);
|
141 |
} else {
|
142 |
shpFile = getResourceFile("testdata", filename);
|
143 |
} |
144 |
|
145 |
performance(shpFile, storename); |
146 |
} |
147 |
} |
148 |
|
149 |
// ---------- feature size test
|
150 |
for (int i=0; i<FEATURE_SIZE_TEST_FEATURE_TYPES.length; i++) { |
151 |
String feat_type = FEATURE_SIZE_TEST_FEATURE_TYPES[i];
|
152 |
String filename = feat_type + FEATURE_SIZE_TEST_BASE_FILE_NAME;
|
153 |
if (Utils.USING_PDA) {
|
154 |
shpFile = getPdaTestFile(SD_FOLDER, "testdata", filename);
|
155 |
} else {
|
156 |
shpFile = getResourceFile("testdata", filename);
|
157 |
} |
158 |
performance(shpFile, storename); |
159 |
} |
160 |
} |
161 |
|
162 |
private void initLogger() { |
163 |
|
164 |
Date now = new Date(System.currentTimeMillis()); |
165 |
String nowstr = now.toString();
|
166 |
|
167 |
nowstr = StringUtil.replaceAllString(nowstr, " ", "_"); |
168 |
nowstr = StringUtil.replaceAllString(nowstr, ":", "_") + ".txt"; |
169 |
|
170 |
|
171 |
String outlogpath = ""; |
172 |
|
173 |
if (Utils.USING_PDA) {
|
174 |
outlogpath = getPdaTestFile(SD_FOLDER, "testdata", "performance_test_" + nowstr).getAbsolutePath(); |
175 |
} else {
|
176 |
outlogpath = getResourceFile("testdata", "performance_test_" + nowstr).getAbsolutePath(); |
177 |
} |
178 |
|
179 |
System.out.println("Log file: " + outlogpath); |
180 |
|
181 |
try {
|
182 |
PatternLayout l = new PatternLayout("%5p [%t] - %m%n"); |
183 |
FileAppender fa = new FileAppender(l, outlogpath, false); |
184 |
// ConsoleAppender ca = new ConsoleAppender(l);
|
185 |
Logger.getRootLogger().setLevel(Level.DEBUG); |
186 |
Logger.getRootLogger().addAppender(fa);
|
187 |
// Logger.getRootLogger().addAppender(ca);
|
188 |
} catch (Exception ex) { |
189 |
System.err.println("Error while initializing log4j: " + ex.getMessage()); |
190 |
} |
191 |
|
192 |
logger = Logger.getLogger(PerformanceTest.class);
|
193 |
|
194 |
} |
195 |
|
196 |
private void performance(File file, String st_name) { |
197 |
|
198 |
if (!file.exists()) return; |
199 |
PerformanceMeasure lyr = null;
|
200 |
try {
|
201 |
lyr = new PerformanceMeasure(file, logger, st_name);
|
202 |
for (int i=0; i<REPEAT_TIMES; i++) { |
203 |
// just to see the progress bar
|
204 |
assertTrue(true);
|
205 |
lyr.drawStore(); |
206 |
} |
207 |
} catch (Exception e) { |
208 |
logger.debug("PERFORMANCE_TEST LAYER " + file.getName() + " STORE " + st_name + " ERROR " + e.getMessage()); |
209 |
} |
210 |
|
211 |
if (lyr != null) lyr.clean(); |
212 |
System.gc();
|
213 |
lyr = null;
|
214 |
System.gc();
|
215 |
} |
216 |
|
217 |
|
218 |
private boolean acceptablySimilar(double expec, double area, double tol) { |
219 |
double diff = Math.abs(expec - area); |
220 |
return ((diff / Math.abs((expec + area) / 2)) < tol); |
221 |
} |
222 |
|
223 |
/**
|
224 |
* Gets a file from the resource folder
|
225 |
* @param dir
|
226 |
* @param file_name
|
227 |
* @return the file object
|
228 |
*/
|
229 |
public static File getResourceFile(String dir, String file_name) { |
230 |
String filePath = resourceDir + File.separator + dir + File.separator + file_name; |
231 |
File resp = new File(filePath); |
232 |
return resp;
|
233 |
} |
234 |
|
235 |
/**
|
236 |
* Gets a file from the pda sd card folder
|
237 |
* @param dir
|
238 |
* @param file_name
|
239 |
* @return the file object
|
240 |
*/
|
241 |
public static File getPdaTestFile(String sdfolder, String dir, String file_name) { |
242 |
String filePath = File.separator + sdfolder + File.separator + dir + File.separator + file_name; |
243 |
File resp = new File(filePath); |
244 |
return resp;
|
245 |
} |
246 |
|
247 |
} |