1 | /** |
2 | * |
3 | */ |
4 | package de.uka.ipd.sdq.tcfmoop.tests; |
5 | |
6 | import static org.junit.Assert.*; |
7 | |
8 | import org.junit.Before; |
9 | import org.junit.Test; |
10 | |
11 | import de.uka.ipd.sdq.tcfmoop.config.ElapsedTimeConfig; |
12 | import de.uka.ipd.sdq.tcfmoop.config.ElapsedTimeConfig.TimeType; |
13 | import de.uka.ipd.sdq.tcfmoop.terminationcriteria.ElapsedTimeCriterion; |
14 | |
15 | /** |
16 | * @author Atanas Dimitrov |
17 | * |
18 | */ |
19 | public class ElapsedTimeCriterionTest { |
20 | ElapsedTimeConfig etconfUser; |
21 | ElapsedTimeCriterion etcritUser; |
22 | ElapsedTimeConfig etconfCPUFalse; |
23 | ElapsedTimeCriterion etcritCPUFalse; |
24 | ElapsedTimeConfig etconfCPUTrue; |
25 | ElapsedTimeCriterion etcritCPUTrue; |
26 | |
27 | /** |
28 | * @throws java.lang.Exception |
29 | */ |
30 | @Before |
31 | public void setUp() throws Exception { |
32 | //User Time |
33 | etconfUser = new ElapsedTimeConfig(); |
34 | etconfUser.setExecutionInterval(1000*60*60); |
35 | etconfUser.setTimeType(TimeType.USER_TIME); |
36 | if(!etconfUser.validateConfiguration()){ |
37 | throw new Exception(); |
38 | } |
39 | etcritUser = new ElapsedTimeCriterion(etconfUser, null, null); |
40 | |
41 | //CPU False |
42 | etconfCPUFalse = new ElapsedTimeConfig(); |
43 | etconfCPUFalse.setExecutionInterval(1000*60*60); |
44 | etconfCPUFalse.setTimeType(TimeType.CPU_TIME); |
45 | if(!etconfCPUFalse.validateConfiguration()){ |
46 | throw new Exception(); |
47 | } |
48 | etcritCPUFalse = new ElapsedTimeCriterion(etconfCPUFalse, null, null); |
49 | |
50 | //CPU True |
51 | etconfCPUTrue = new ElapsedTimeConfig(); |
52 | etconfCPUTrue.setExecutionInterval(10); |
53 | etconfCPUTrue.setTimeType(TimeType.CPU_TIME); |
54 | if(!etconfCPUTrue.validateConfiguration()){ |
55 | throw new Exception(); |
56 | } |
57 | etcritCPUTrue = new ElapsedTimeCriterion(etconfCPUTrue, null, null); |
58 | } |
59 | |
60 | /** |
61 | * Test method for {@link de.uka.ipd.sdq.tcfmoop.terminationcriteria.AbstractTerminationCriterion#getEvaluationResult()}. |
62 | */ |
63 | @Test |
64 | public void testUserTime() { |
65 | etcritUser.evaluate(251, System.currentTimeMillis()); |
66 | assertFalse(etcritUser.getEvaluationResult()); |
67 | etcritUser.evaluate(251, System.currentTimeMillis() + (1000*60*60*2)); |
68 | assertTrue(etcritUser.getEvaluationResult()); |
69 | } |
70 | |
71 | /** |
72 | * Test method for {@link de.uka.ipd.sdq.tcfmoop.terminationcriteria.AbstractTerminationCriterion#getEvaluationResult()}. |
73 | */ |
74 | @Test |
75 | public void testCPUTime() { |
76 | etcritUser.evaluate(251, System.currentTimeMillis()); |
77 | assertFalse(etcritUser.getEvaluationResult()); |
78 | etcritUser.evaluate(251, System.currentTimeMillis() + (1000*60*60*2)); |
79 | assertTrue(etcritUser.getEvaluationResult()); |
80 | } |
81 | |
82 | } |