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