1 | package felix.test; |
2 | |
3 | import static org.junit.Assert.*; |
4 | |
5 | import java.util.ArrayList; |
6 | import java.util.HashMap; |
7 | import java.util.HashSet; |
8 | |
9 | |
10 | import org.junit.BeforeClass; |
11 | import org.junit.Test; |
12 | |
13 | import tuffy.util.Timer; |
14 | import tuffy.util.UIMan; |
15 | import felix.compiler.StaticAnalyzer; |
16 | import felix.dstruct.ConcurrentOperatorsBucket; |
17 | import felix.dstruct.ExecutionPlan; |
18 | import felix.dstruct.StatOperator; |
19 | import felix.executor.Executor; |
20 | import felix.main.Felix; |
21 | import felix.optimizer.Scheduler; |
22 | import felix.parser.FelixCommandOptions; |
23 | import felix.util.FelixConfig; |
24 | import felix.util.FelixUIMan; |
25 | |
26 | |
27 | /** |
28 | * Test the scheduler: 1) cost-based optimizer; 2) planner of the |
29 | * operator order. |
30 | * @author Ce Zhang |
31 | * |
32 | */ |
33 | public class SchedulerTest extends Felix{ |
34 | |
35 | public static ArrayList<Double> planCosts = new ArrayList<Double>(); |
36 | public static String exeTime = ""; |
37 | |
38 | /** |
39 | * Test the planner for operator order: One operator A should run before |
40 | * operator B if A provide information to B or A has a larger precedence. |
41 | */ |
42 | @Test |
43 | public final void testSillyPlanner() { |
44 | try{ |
45 | String[] args = {"-e", "test/felix/compiler_test_evidence.db", "-i", "test/felix/compiler_test_prog.mln", |
46 | "-o", "test/testOutput.txt", "-queryFile", "test/felix/compiler_test_query.db"}; |
47 | FelixConfig.overrideID(); |
48 | FelixCommandOptions options = FelixUIMan.parseCommand(args); |
49 | |
50 | |
51 | Timer.start("Felix-Timer"); |
52 | this.options = options; |
53 | resetACoupleAuxDataStructures(); |
54 | |
55 | fq = this.parseFelixQuery(); |
56 | |
57 | sa = new StaticAnalyzer(this.fq, options); |
58 | sa.parse(); |
59 | |
60 | Scheduler sc = new Scheduler(this, this.fq, options); |
61 | ExecutionPlan ep = sc.schedule(); |
62 | |
63 | for(int i = 0; i < ep.operators.size(); i++){ |
64 | for(int j = 0; j < ep.operators.size(); j ++){ |
65 | |
66 | if( i >= j ){ |
67 | continue; |
68 | } |
69 | |
70 | ConcurrentOperatorsBucket oup = ep.operators.get(j); |
71 | ConcurrentOperatorsBucket odown = ep.operators.get(i); |
72 | |
73 | if(i < j){ |
74 | if(sc.getOperatorBucketGraph().getDownStreamOperator(oup).contains(odown) && |
75 | sc.getOperatorBucketGraph().getDownStreamOperator(odown).contains(oup)){ |
76 | assertTrue(oup.getPrecedence() >= odown.getPrecedence()); |
77 | }else if(sc.getOperatorBucketGraph().getDownStreamOperator(oup).contains(odown)){ |
78 | assertTrue(true); |
79 | }else if(sc.getOperatorBucketGraph().getDownStreamOperator(odown).contains(oup)){ |
80 | assertTrue(false); |
81 | }else{ |
82 | assertTrue(true); |
83 | } |
84 | } |
85 | |
86 | } |
87 | } |
88 | |
89 | }catch(Exception e){ |
90 | e.printStackTrace(); |
91 | } |
92 | } |
93 | |
94 | /** |
95 | * Test the cost-based optimizer on a sampled Enron dataset. |
96 | */ |
97 | @Test |
98 | public final void testDecomposition(){ |
99 | |
100 | try{ |
101 | /* |
102 | double minCost = Double.MAX_VALUE; |
103 | double nTime = -1; |
104 | |
105 | int numberOfIters = 10; |
106 | String tobprint = ""; |
107 | double sum = 0; |
108 | for(int i=0;i<numberOfIters;i++){ |
109 | sum = 0; |
110 | Config.pickRandom = true; |
111 | String[] args = {"-e", "test/mobius/enron.evid.db.5k", "-i", "test/mobius/enron.prog.mln--", |
112 | "-o", "test/testOutput.txt", "-queryFile", "test/mobius/query.db", "-mcsatSamples", "0"}; |
113 | |
114 | CommandOptions opt = UIMan.parseCommand(args); |
115 | Config.explainMode = opt.explainMode; |
116 | planCosts.clear(); |
117 | |
118 | new Mobius().run(opt); |
119 | |
120 | String time = exeTime; |
121 | for(Double d : planCosts){ |
122 | sum += d; |
123 | } |
124 | Config.pickRandom = false; |
125 | |
126 | tobprint += "\nEstimated Cost : " + sum + "\t|\t Execution Time: " + time + "\n"; |
127 | tobprint += planCosts.toString() + "\n"; |
128 | System.err.println(tobprint); |
129 | |
130 | //Manually check whether output is reasonable |
131 | |
132 | } |
133 | */ |
134 | |
135 | }catch(Exception e){ |
136 | e.printStackTrace(); |
137 | assertTrue(false); |
138 | } |
139 | |
140 | } |
141 | |
142 | } |
143 | |
144 | |
145 | |
146 | |
147 | |
148 | |