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 @ 40435
History | View | Annotate | Download (2.23 KB)
1 | 40435 | jjdelcerro | package org.gvsig.fmap.dal.resource.spi; |
---|---|---|---|
2 | |||
3 | import junit.framework.TestCase; |
||
4 | |||
5 | import org.easymock.MockControl; |
||
6 | import org.gvsig.fmap.dal.resource.Resource; |
||
7 | import org.gvsig.fmap.dal.resource.ResourceAction; |
||
8 | import org.gvsig.fmap.dal.resource.ResourceParameters; |
||
9 | |||
10 | public class TestAbstractResourcePerformance extends TestCase { |
||
11 | private MockControl paramsControl;
|
||
12 | private ResourceParameters params;
|
||
13 | private AbstractResource resource;
|
||
14 | private MockControl paramsControl2;
|
||
15 | private ResourceParameters params2;
|
||
16 | private AbstractNonBlockingResource nonBlockingResource;
|
||
17 | |||
18 | protected void setUp() throws Exception { |
||
19 | super.setUp();
|
||
20 | paramsControl = MockControl.createNiceControl(ResourceParameters.class); |
||
21 | params = (ResourceParameters) paramsControl.getMock(); |
||
22 | resource = new TestResource(params);
|
||
23 | paramsControl2 = |
||
24 | MockControl.createNiceControl(ResourceParameters.class); |
||
25 | params2 = (ResourceParameters) paramsControl2.getMock(); |
||
26 | nonBlockingResource = new TestNonBlockingResource(params2);
|
||
27 | } |
||
28 | |||
29 | /**
|
||
30 | * Test method for
|
||
31 | * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
||
32 | * .
|
||
33 | */
|
||
34 | public void testExecuteBlockingPerformance() throws Exception { |
||
35 | executePerformance(new ResourceAction() {
|
||
36 | public Object run() throws Exception { |
||
37 | return null; |
||
38 | } |
||
39 | }, resource); |
||
40 | } |
||
41 | |||
42 | /**
|
||
43 | * Test method for
|
||
44 | * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
||
45 | * .
|
||
46 | */
|
||
47 | public void testExecuteNonBlockingPerformance() throws Exception { |
||
48 | executePerformance(new ResourceAction() {
|
||
49 | public Object run() throws Exception { |
||
50 | return null; |
||
51 | } |
||
52 | }, nonBlockingResource); |
||
53 | } |
||
54 | |||
55 | /**
|
||
56 | * Test method for
|
||
57 | * {@link org.gvsig.fmap.dal.resource.spi.AbstractResource#execute(java.lang.Runnable)}
|
||
58 | * .
|
||
59 | */
|
||
60 | public void executePerformance(ResourceAction action, Resource resource) |
||
61 | throws Exception { |
||
62 | |||
63 | final int executions = 100000; |
||
64 | long time1 = System.currentTimeMillis(); |
||
65 | for (int i = 0; i < executions; i++) { |
||
66 | resource.execute(action); |
||
67 | } |
||
68 | long time2 = System.currentTimeMillis(); |
||
69 | |||
70 | System.out.print(resource.getName());
|
||
71 | System.out.print(": total time: " + (time2 - time1) + " ms."); |
||
72 | System.out.println(" - time per execution: " |
||
73 | + ((float) (time2 - time1) / (float) executions) + " ms."); |
||
74 | } |
||
75 | } |