KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > test > internal > performance > tests > DBTests


1 /*******************************************************************************
2  * Copyright (c) 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.test.internal.performance.tests;
12
13 import java.sql.SQLException JavaDoc;
14 import java.util.ArrayList JavaDoc;
15 import java.util.Date JavaDoc;
16 import java.util.HashSet JavaDoc;
17 import java.util.List JavaDoc;
18 import java.util.Set JavaDoc;
19
20 import org.eclipse.test.internal.performance.InternalDimensions;
21 import org.eclipse.test.internal.performance.PerformanceTestPlugin;
22 import org.eclipse.test.internal.performance.data.DataPoint;
23 import org.eclipse.test.internal.performance.data.Dim;
24 import org.eclipse.test.internal.performance.data.Scalar;
25 import org.eclipse.test.internal.performance.db.DB;
26 import org.eclipse.test.internal.performance.db.Scenario;
27 import org.eclipse.test.internal.performance.db.SummaryEntry;
28 import org.eclipse.test.internal.performance.db.Variations;
29 import org.eclipse.test.performance.Dimension;
30 import org.eclipse.test.performance.Performance;
31
32 import junit.framework.AssertionFailedError;
33 import junit.framework.TestCase;
34
35 public class DBTests extends TestCase {
36     
37     private static final String JavaDoc CONFIG= "c"; //$NON-NLS-1$
38
private static final String JavaDoc BUILD= "b"; //$NON-NLS-1$
39

40     private static final String JavaDoc SCENARIO_NAME_0= "bar.testScenario0"; //$NON-NLS-1$
41
private static final String JavaDoc SCENARIO_NAME_1= "bar.testScenario1"; //$NON-NLS-1$
42
private static final String JavaDoc SCENARIO_NAME_2= "bar.testScenario2"; //$NON-NLS-1$
43
private static final String JavaDoc SCENARIO_NAME_3= "foo.testScenario3"; //$NON-NLS-1$
44
private static final String JavaDoc SCENARIO_NAME_4= "foo.testScenario4"; //$NON-NLS-1$
45
private static final String JavaDoc SHORT_NAME_2= "ShortName2"; //$NON-NLS-1$
46
private static final String JavaDoc SHORT_NAME_3= "ShortName3"; //$NON-NLS-1$
47
private static final String JavaDoc SHORT_NAME_4= "ShortName4"; //$NON-NLS-1$
48

49     private static final String JavaDoc DBLOC= "testDBs"; //$NON-NLS-1$
50
//private static final String DBLOC= "net://localhost"; //$NON-NLS-1$
51
private static String JavaDoc DBNAME;
52     private static final String JavaDoc DBUSER= "testUser"; //$NON-NLS-1$
53
private static final String JavaDoc DBPASSWD= "testPassword"; //$NON-NLS-1$
54

55     
56     protected void setUp() throws Exception JavaDoc {
57         super.setUp();
58         
59         // generate a unique DB name
60
DBNAME= "testDB_" + new Date JavaDoc().getTime(); //$NON-NLS-1$
61

62         System.setProperty("eclipse.perf.dbloc", DBLOC + ";dbname=" + DBNAME + ";dbuser=" + DBUSER + ";dbpasswd=" + DBPASSWD); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
63
System.setProperty("eclipse.perf.config", CONFIG+"=test;"+BUILD+"=b0001;jvm=sun142"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
64
System.setProperty("eclipse.perf.assertAgainst", BUILD+"=base"); //$NON-NLS-1$ //$NON-NLS-2$
65
}
66
67     protected void tearDown() throws Exception JavaDoc {
68         super.tearDown();
69     }
70     
71     public void testPropertyGetters() {
72         assertEquals(DBLOC, PerformanceTestPlugin.getDBLocation());
73         assertEquals(DBNAME, PerformanceTestPlugin.getDBName());
74         assertEquals(DBUSER, PerformanceTestPlugin.getDBUser());
75         assertEquals(DBPASSWD, PerformanceTestPlugin.getDBPassword());
76         
77         assertEquals("|"+BUILD+"=b0001||"+CONFIG+"=test||jvm=sun142|", PerformanceTestPlugin.getVariations().toExactMatchString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
78
assertEquals("|"+BUILD+"=base||"+CONFIG+"=test||jvm=sun142|", PerformanceTestPlugin.getAssertAgainst().toExactMatchString()); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
79
}
80     
81     public void testAssertPerformance() throws SQLException JavaDoc {
82
83         Performance perf= Performance.getDefault();
84         
85         // set the variation for the reference data
86
System.setProperty("eclipse.perf.config", CONFIG+"=test;"+BUILD+"=ref"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
87

88         // store a reference value
89
TestPerformanceMeter pm1= new TestPerformanceMeter(SCENARIO_NAME_0);
90         pm1.addPair(InternalDimensions.CPU_TIME, 100, 1000);
91         pm1.addPair(InternalDimensions.WORKING_SET, 1000, 2000);
92
93         pm1.start();
94         pm1.stop();
95         pm1.commit();
96         pm1.dispose();
97         
98         String JavaDoc build= "001"; //$NON-NLS-1$
99
// set the variation for the this run
100
System.setProperty("eclipse.perf.config", CONFIG+"=test;"+BUILD+"="+build); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
101
// assert that this run's values are compared against reference data
102
System.setProperty("eclipse.perf.assertAgainst", BUILD+"=ref"); //$NON-NLS-1$ //$NON-NLS-2$
103

104         // store a reference value
105
TestPerformanceMeter pm2= new TestPerformanceMeter(SCENARIO_NAME_0);
106         pm2.addPair(InternalDimensions.CPU_TIME, 100, 1100);
107         pm2.addPair(InternalDimensions.WORKING_SET, 1000, 2000);
108         
109         pm2.start();
110         pm2.stop();
111         pm2.commit();
112         boolean failed= false;
113         try {
114             perf.assertPerformanceInRelativeBand(pm2, InternalDimensions.CPU_TIME, -5, +5);
115         } catch (AssertionFailedError e) {
116             failed= true;
117         }
118         pm2.dispose();
119         
120         if (!failed) {
121             // check in DB
122
Variations v= new Variations();
123             v.put(CONFIG, "%"); //$NON-NLS-1$
124
v.put(BUILD, build);
125             Scenario[] scenarios= DB.queryScenarios(v, SCENARIO_NAME_0, CONFIG, null);
126             if (scenarios != null && scenarios.length > 0) {
127                     Scenario s= scenarios[0];
128                     String JavaDoc[] failureMessages= s.getFailureMessages();
129                     if (failureMessages.length == 1) {
130                         String JavaDoc mesg= failureMessages[0];
131                         if (mesg != null && mesg.equals("Performance criteria not met when compared to '{b=ref, c=test}':\nCPU Time: 1 s is not within [95%, 105%] of 900 ms")) //$NON-NLS-1$
132
failed= true;
133                     }
134             }
135         }
136         assertTrue(failed);
137     }
138
139     public void testBasicDBFunctionality() {
140         
141         Performance perf= Performance.getDefault();
142         
143         TestPerformanceMeter pm1= new TestPerformanceMeter(SCENARIO_NAME_1);
144         pm1.addPair(InternalDimensions.CPU_TIME, 100, 1000);
145         pm1.addPair(InternalDimensions.WORKING_SET, 1000, 2000);
146         pm1.start();
147         pm1.stop();
148         pm1.commit();
149         pm1.dispose();
150         
151         TestPerformanceMeter pm2= new TestPerformanceMeter(SCENARIO_NAME_2);
152         pm2.addPair(InternalDimensions.CPU_TIME, 100, 1000);
153         pm2.addPair(InternalDimensions.WORKING_SET, 1000, 2000);
154         perf.tagAsGlobalSummary(pm2, SHORT_NAME_2, new Dimension[] { Dimension.CPU_TIME, Dimension.USED_JAVA_HEAP } );
155         pm2.start();
156         pm2.stop();
157         pm2.commit();
158         pm2.dispose();
159
160         TestPerformanceMeter pm3= new TestPerformanceMeter(SCENARIO_NAME_3);
161         pm3.addPair(InternalDimensions.CPU_TIME, 100, 1000);
162         pm3.addPair(InternalDimensions.WORKING_SET, 1000, 2000);
163         perf.tagAsGlobalSummary(pm3, SHORT_NAME_3, Dimension.CPU_TIME);
164         pm3.start();
165         pm3.stop();
166         pm3.commit();
167         pm3.dispose();
168
169         TestPerformanceMeter pm4= new TestPerformanceMeter(SCENARIO_NAME_4);
170         pm4.addPair(InternalDimensions.CPU_TIME, 100, 1000);
171         pm4.addPair(InternalDimensions.WORKING_SET, 1000, 2000);
172         perf.tagAsSummary(pm4, SHORT_NAME_4, Dimension.USED_JAVA_HEAP);
173         pm4.start();
174         pm4.stop();
175         pm4.commit();
176         pm4.dispose();
177
178         //
179

180         Variations v= new Variations();
181         v.put(CONFIG, "test"); //$NON-NLS-1$
182
v.put(BUILD, "b0001"); //$NON-NLS-1$
183
v.put("jvm", "sun142"); //$NON-NLS-1$ //$NON-NLS-2$
184
DataPoint[] points= DB.queryDataPoints(v, SCENARIO_NAME_1, null);
185         assertEquals(1, points.length);
186         
187         DataPoint dp= points[0];
188         Dim[] dimensions= dp.getDimensions();
189         assertEquals(2, dimensions.length);
190         
191         Scalar s1= dp.getScalar(InternalDimensions.CPU_TIME);
192         assertNotNull(s1);
193         assertEquals(900, s1.getMagnitude());
194
195         Scalar s2= dp.getScalar(InternalDimensions.WORKING_SET);
196         assertNotNull(s2);
197         assertEquals(1000, s2.getMagnitude());
198
199         //
200
Set JavaDoc dims= new HashSet JavaDoc();
201         dims.add(InternalDimensions.WORKING_SET);
202         points= DB.queryDataPoints(v, SCENARIO_NAME_1, dims);
203         assertEquals(1, points.length);
204         dimensions= points[0].getDimensions();
205         assertEquals(1, dimensions.length);
206         Scalar s= points[0].getScalar(InternalDimensions.WORKING_SET);
207         assertNotNull(s);
208         assertEquals(1000, s.getMagnitude());
209         
210         //
211
List JavaDoc buildNames= new ArrayList JavaDoc();
212         Variations v2= new Variations();
213         v2.put(CONFIG, "%"); //$NON-NLS-1$
214
v2.put(BUILD, "b%"); //$NON-NLS-1$
215
DB.queryDistinctValues(buildNames, BUILD, v2, "%"); //$NON-NLS-1$
216
assertEquals(1, buildNames.size());
217         assertEquals("b0001", buildNames.get(0)); //$NON-NLS-1$
218

219         SummaryEntry[] fps= DB.querySummaries(PerformanceTestPlugin.getVariations(), null);
220         assertEquals(3, fps.length);
221         
222         assertEquals(SCENARIO_NAME_2, fps[0].scenarioName);
223         assertEquals(SHORT_NAME_2, fps[0].shortName);
224         assertEquals(Dimension.USED_JAVA_HEAP, fps[0].dimension);
225
226         assertEquals(SCENARIO_NAME_2, fps[1].scenarioName);
227         assertEquals(SHORT_NAME_2, fps[1].shortName);
228         assertEquals(Dimension.CPU_TIME, fps[1].dimension);
229
230         assertEquals(SCENARIO_NAME_3, fps[2].scenarioName);
231         assertEquals(SHORT_NAME_3, fps[2].shortName);
232         assertEquals(Dimension.CPU_TIME, fps[2].dimension);
233         
234         
235         SummaryEntry[] fps2= DB.querySummaries(PerformanceTestPlugin.getVariations(), "foo.%"); //$NON-NLS-1$
236
assertEquals(2, fps2.length);
237         
238         assertEquals(SCENARIO_NAME_3, fps2[0].scenarioName);
239         assertEquals(SHORT_NAME_3, fps2[0].shortName);
240         assertEquals(Dimension.CPU_TIME, fps2[0].dimension);
241
242         assertEquals(SCENARIO_NAME_4, fps2[1].scenarioName);
243         assertEquals(SHORT_NAME_4, fps2[1].shortName);
244         assertEquals(Dimension.USED_JAVA_HEAP, fps2[1].dimension);
245     }
246     
247 }
248
Popular Tags