svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.impl / src / test / java / org / gvsig / fmap / dal / resource / spi / TestAbstractResourcePerformance.java @ 40559
History | View | Annotate | Download (3.17 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.fmap.dal.resource.spi; |
25 |
|
26 |
import junit.framework.TestCase; |
27 |
|
28 |
import org.easymock.MockControl; |
29 |
import org.gvsig.fmap.dal.resource.Resource; |
30 |
import org.gvsig.fmap.dal.resource.ResourceAction; |
31 |
import org.gvsig.fmap.dal.resource.ResourceParameters; |
32 |
|
33 |
public class TestAbstractResourcePerformance extends TestCase { |
34 |
private MockControl paramsControl;
|
35 |
private ResourceParameters params;
|
36 |
private AbstractResource resource;
|
37 |
private MockControl paramsControl2;
|
38 |
private ResourceParameters params2;
|
39 |
private AbstractNonBlockingResource nonBlockingResource;
|
40 |
|
41 |
protected void setUp() throws Exception { |
42 |
super.setUp();
|
43 |
paramsControl = MockControl.createNiceControl(ResourceParameters.class); |
44 |
params = (ResourceParameters) paramsControl.getMock(); |
45 |
resource = new TestResource(params);
|
46 |
paramsControl2 = |
47 |
MockControl.createNiceControl(ResourceParameters.class); |
48 |
params2 = (ResourceParameters) paramsControl2.getMock(); |
49 |
nonBlockingResource = new TestNonBlockingResource(params2);
|
50 |
} |
51 |
|
52 |
/**
|
53 |
* Test method for
|
54 |
* {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
55 |
* .
|
56 |
*/
|
57 |
public void testExecuteBlockingPerformance() throws Exception { |
58 |
executePerformance(new ResourceAction() {
|
59 |
public Object run() throws Exception { |
60 |
return null; |
61 |
} |
62 |
}, resource); |
63 |
} |
64 |
|
65 |
/**
|
66 |
* Test method for
|
67 |
* {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
68 |
* .
|
69 |
*/
|
70 |
public void testExecuteNonBlockingPerformance() throws Exception { |
71 |
executePerformance(new ResourceAction() {
|
72 |
public Object run() throws Exception { |
73 |
return null; |
74 |
} |
75 |
}, nonBlockingResource); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Test method for
|
80 |
* {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
81 |
* .
|
82 |
*/
|
83 |
public void executePerformance(ResourceAction action, Resource resource) |
84 |
throws Exception { |
85 |
|
86 |
final int executions = 100000; |
87 |
long time1 = System.currentTimeMillis(); |
88 |
for (int i = 0; i < executions; i++) { |
89 |
resource.execute(action); |
90 |
} |
91 |
long time2 = System.currentTimeMillis(); |
92 |
|
93 |
System.out.print(resource.getName());
|
94 |
System.out.print(": total time: " + (time2 - time1) + " ms."); |
95 |
System.out.println(" - time per execution: " |
96 |
+ ((float) (time2 - time1) / (float) executions) + " ms."); |
97 |
} |
98 |
} |