1 11 package org.eclipse.test.internal.performance.tests; 12 13 import java.sql.SQLException ; 14 import java.util.ArrayList ; 15 import java.util.Date ; 16 import java.util.HashSet ; 17 import java.util.List ; 18 import java.util.Set ; 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 CONFIG= "c"; private static final String BUILD= "b"; 40 private static final String SCENARIO_NAME_0= "bar.testScenario0"; private static final String SCENARIO_NAME_1= "bar.testScenario1"; private static final String SCENARIO_NAME_2= "bar.testScenario2"; private static final String SCENARIO_NAME_3= "foo.testScenario3"; private static final String SCENARIO_NAME_4= "foo.testScenario4"; private static final String SHORT_NAME_2= "ShortName2"; private static final String SHORT_NAME_3= "ShortName3"; private static final String SHORT_NAME_4= "ShortName4"; 49 private static final String DBLOC= "testDBs"; private static String DBNAME; 52 private static final String DBUSER= "testUser"; private static final String DBPASSWD= "testPassword"; 55 56 protected void setUp() throws Exception { 57 super.setUp(); 58 59 DBNAME= "testDB_" + new Date ().getTime(); 62 System.setProperty("eclipse.perf.dbloc", DBLOC + ";dbname=" + DBNAME + ";dbuser=" + DBUSER + ";dbpasswd=" + DBPASSWD); System.setProperty("eclipse.perf.config", CONFIG+"=test;"+BUILD+"=b0001;jvm=sun142"); System.setProperty("eclipse.perf.assertAgainst", BUILD+"=base"); } 66 67 protected void tearDown() throws Exception { 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()); assertEquals("|"+BUILD+"=base||"+CONFIG+"=test||jvm=sun142|", PerformanceTestPlugin.getAssertAgainst().toExactMatchString()); } 80 81 public void testAssertPerformance() throws SQLException { 82 83 Performance perf= Performance.getDefault(); 84 85 System.setProperty("eclipse.perf.config", CONFIG+"=test;"+BUILD+"=ref"); 88 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 build= "001"; System.setProperty("eclipse.perf.config", CONFIG+"=test;"+BUILD+"="+build); System.setProperty("eclipse.perf.assertAgainst", BUILD+"=ref"); 104 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 Variations v= new Variations(); 123 v.put(CONFIG, "%"); 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 [] failureMessages= s.getFailureMessages(); 129 if (failureMessages.length == 1) { 130 String 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")) 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 180 Variations v= new Variations(); 181 v.put(CONFIG, "test"); v.put(BUILD, "b0001"); v.put("jvm", "sun142"); 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 Set dims= new HashSet (); 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 List buildNames= new ArrayList (); 212 Variations v2= new Variations(); 213 v2.put(CONFIG, "%"); v2.put(BUILD, "b%"); DB.queryDistinctValues(buildNames, BUILD, v2, "%"); assertEquals(1, buildNames.size()); 217 assertEquals("b0001", buildNames.get(0)); 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.%"); 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 |