private void doCompareResults( PerformanceSuiteResult oldResult, PerformanceSuiteResult newResult, String testMethod) throws PerformanceException { for (String className : oldResult.getResults().keySet()) { PerformanceClassResult oldClassResult = oldResult.getResult(className); if (oldClassResult.getMethodResult(testMethod) != null) { oldClassResult .getMethodResult(testMethod) .compareResults( newResult.getResult(className).getMethodResult(testMethod), oldClassResult.getPerformanceSpecs().resultsThreshold()); } } }
/** * Verify that the test ended within specified time * * @param event, the test * @throws PerformanceException if the test did not end within the specified time */ private void verifyPerformance(Test event) throws PerformanceException { TestResult result = testResultInst.get(); if (result != null) { // check if we have set a threshold Performance performance = null; Annotation[] annotations = event.getTestMethod().getDeclaredAnnotations(); for (Annotation a : annotations) if (a.annotationType().getName().equals(Performance.class.getCanonicalName())) performance = (Performance) a; double maxTime = -1; if (performance != null) { // System.out.println("For test: "+event.toString()+", it took: // "+(result.getEnd()-result.getStart())); if (performance.time() > 0 && performance.time() < (result.getEnd() - result.getStart())) { result.setStatus(TestResult.Status.FAILED); result.setThrowable( new PerformanceException( "The test didnt finish within the specified time: " + performance.time() + "ms, it took " + (result.getEnd() - result.getStart()) + "ms.")); } maxTime = performance.time(); } // fetch suiteResult, get the correct classResult and append the test to that // classResult. PerformanceSuiteResult suiteResult = suiteResultInst.get(); if (suiteResult != null) { suiteResult .getResult(event.getTestClass().getName()) .addMethodResult( new PerformanceMethodResult( maxTime, result.getEnd() - result.getStart(), event.getTestMethod())); } } }
/** * 1. make sure folder exists, if not create folder 2. generate file name 3. save file * * @param suiteResult that should be saved */ private void storePerformanceSuiteResult(PerformanceSuiteResult suiteResult) { String filename = suiteResult.getName() + "-" + fileFormat.format(new Date()) + ".ser"; File currentPath = getArqPerfFolder(); boolean fileStatus = true; if (!currentPath.isDirectory()) fileStatus = currentPath.mkdirs(); if (fileStatus) { try { FileOutputStream fos = new FileOutputStream(currentPath.getPath() + File.separator + filename); ObjectOutputStream out = new ObjectOutputStream(fos); out.writeObject(suiteResult); out.close(); } catch (IOException ex) { System.err.println("Storing test results failed."); ex.printStackTrace(); } } }