Package be.pw999.jape.models

Examples of be.pw999.jape.models.Result


                                }
                                totalDuration += (System.currentTimeMillis() - start);
                            }

                            log.trace("Test finished (" + test.getClass().getSimpleName() + "#" + method.getName() + ")");
                            addResult(new Result(test.getClass(), method, totalDuration), test.getClass().getAnnotation(TestSuite.class));

                            if (ReflectionUtils.getAnnotation(DirtiesObject.class, method) != null) {
                                log.trace("DirtiesObject annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ": reinitializing");
                                test.init();
                            }
                        } catch (InvocationTargetException e) {
                            log.error("Failed to invoke testmethod " + test.getClass().getSimpleName() + "#" + method.getName() + ": " + e.getMessage(), e);
                            addResult(new Result(test.getClass(), method, Long.MIN_VALUE), test.getClass().getAnnotation(TestSuite.class));
                        }
                    } else {
                        if (method.getName().startsWith("test")) {
                            log.warn("Method " + method.getName() + " skipped");
                        } else {
View Full Code Here


                log.error("ClassNotFoundException on test " + clazz.getSimpleName() + ": " + e.getMessage(), e);
            }
        }
        ExcelExporter e = new ExcelExporter();
        try {
            Result r = new Result(ITest.class, Object.class.getMethod("wait"), Long.MIN_VALUE);
        } catch (NoSuchMethodException z) {
            ;
        }
    }
View Full Code Here


                int l = entry.getValue().size();
                Collections.sort(entry.getValue(), new ResultFullTestIdComparator());
                for (int i = 0; i < l; ++i) {
                    Result result = entry.getValue().get(i);
                    double testId = TestUtils.getTestId(result.getDeclaringClass(), result.getDeclaredMethod());
                    String description = ReflectionUtils.getAnnotation(Test.class, result.getDeclaredMethod()).description();
                    double time = result.getDuration();
                    Row resultRow = sheet.createRow(i + 1);
                    resultRow.createCell(0).setCellValue(testId);
                    resultRow.createCell(1).setCellValue(result.getDeclaringClass().getSimpleName());
                    resultRow.createCell(2).setCellValue(description);
                    resultRow.createCell(3).setCellValue(time);
                }
                sheet.autoSizeColumn(0);
                sheet.autoSizeColumn(1);
                sheet.autoSizeColumn(2);
                sheet.autoSizeColumn(3);
            }


            //Comparable export
            for (Map.Entry<String, List<Result>> entry : results.entrySet()) {
                Sheet sheet = getOrCreateSheet(entry.getKey() + "(group)", wb);
                log.info("Creating sheet " + sheet.getSheetName());

                int l = entry.getValue().size();
                Collections.sort(entry.getValue(), new ResultFullTestIdComparator());

                //Find all test descriptions and class names
                Set<String> testDescriptions = new TreeSet<String>();
                Set<String> classNames = new TreeSet<String>();
                Map<String, Double> minVal = new HashMap<String, Double>();
                for (int i = 0; i < l; ++i) {
                    String desc = ReflectionUtils.getAnnotation(Test.class, entry.getValue().get(i).getDeclaredMethod()).description();
                    testDescriptions.add(desc);
                    classNames.add(entry.getValue().get(i).getDeclaringClass().getSimpleName());

                    if (minVal.containsKey(desc) && (minVal.get(desc) > entry.getValue().get(i).getDuration())) {
                        minVal.put(desc, entry.getValue().get(i).getDuration());
                    } else if (!minVal.containsKey(desc)) {
                        minVal.put(desc, entry.getValue().get(i).getDuration());
                    }
                }

                //Generate a row/col mapping
                Map<String, Integer> rowMapping = new TreeMap<String, Integer>();
                Map<String, Integer> colMapping = new TreeMap<String, Integer>();

                int z = 1;
                for (String s : testDescriptions) {
                    rowMapping.put(s, z++);
                }
                z = 1;
                for (String s : classNames) {
                    colMapping.put(s, z++);
                }

                //Init cells and stuff
                for (Integer i : rowMapping.values()) {
                    Row row = sheet.createRow(i);
                    for (int j : colMapping.values()) {
                        row.createCell(j);
                    }
                }

                //Create headers
                Row header = sheet.createRow(0);
                for (String s : colMapping.keySet()) {
                    header.createCell(colMapping.get(s)).setCellValue(s);
                }

                for (String s : rowMapping.keySet()) {
                    Row row = sheet.getRow(rowMapping.get(s));
                    row.createCell(0).setCellValue(s);
                }

                //CellStyle style = wb.createCellStyle();
                //DataFormat format = wb.createDataFormat();
                //style.setDataFormat(format.getFormat("0.00%"));
                //Write results
                for (int i = 0; i < l; ++i) {
                    Result result = entry.getValue().get(i);
                    String desc = ReflectionUtils.getAnnotation(Test.class, entry.getValue().get(i).getDeclaredMethod()).description();
                    Row row = sheet.getRow(rowMapping.get(desc));
                    Cell cell = row.getCell(colMapping.get(result.getDeclaringClass().getSimpleName()));
                    cell.setCellValue(result.getDuration());
                    //cell.setCellStyle(style);
                }

                sheet.autoSizeColumn(0);
                for (Integer i : colMapping.values()) {
View Full Code Here

                header.createCell(2).setCellValue("Test Description");
                header.createCell(3).setCellValue("Test Time (ms)");


                int l = entry.getValue().size();
                Collections.sort(entry.getValue(), new ResultFullTestIdComparator());
                for (int i = 0; i < l; ++i) {
                    Result result = entry.getValue().get(i);
                    double testId = TestUtils.getTestId(result.getDeclaringClass(), result.getDeclaredMethod());
                    String description = ReflectionUtils.getAnnotation(Test.class, result.getDeclaredMethod()).description();
                    double time = result.getDuration();
                    Row resultRow = sheet.createRow(i + 1);
                    resultRow.createCell(0).setCellValue(testId);
                    resultRow.createCell(1).setCellValue(result.getDeclaringClass().getSimpleName());
                    resultRow.createCell(2).setCellValue(description);
                    resultRow.createCell(3).setCellValue(time);
                }
                sheet.autoSizeColumn(0);
                sheet.autoSizeColumn(1);
                sheet.autoSizeColumn(2);
                sheet.autoSizeColumn(3);
            }


            //Comparable export
            for (Map.Entry<String, List<Result>> entry : results.entrySet()) {
                Sheet sheet = getOrCreateSheet(entry.getKey() + "(group)", wb);
                log.info("Creating sheet " + sheet.getSheetName());

                int l = entry.getValue().size();
                Collections.sort(entry.getValue(), new ResultFullTestIdComparator());

                //Find all test descriptions and class names
                Set<String> testDescriptions = new TreeSet<String>();
                Set<String> classNames = new TreeSet<String>();
                Map<String, Double> minVal = new HashMap<String, Double>();
View Full Code Here

        //The actual tests
        for (Class<? extends ITest> clazz : classes) {
            log.info("Starting test class " + clazz.getSimpleName());
            try {
                ITest test = (ITest) (this.getClass().getClassLoader().loadClass(clazz.getName())).newInstance();
                log.trace("Initializing test class for first time (" + test.getClass().getSimpleName() + ")");
                test.init();

                //Each test-method inside a test-class
                Method[] methods = test.getClass().getMethods();
                for (Method method : methods) {
                    if (ReflectionUtils.getAnnotation(Test.class, method) != null) {
                        try {
                            int repeats = 1;
                            int size = Settings.TEST_LOOPS;
                            int leftOvers = 0;
                            long totalDuration = 0L;
                            boolean noGC = false;
                            if (ReflectionUtils.getAnnotation(NotInfinite.class, method) != null) {
                                size = ReflectionUtils.getAnnotation(NotInfinite.class, method).invocations();
                                repeats = Settings.TEST_LOOPS / size;
                                leftOvers = Settings.TEST_LOOPS % size;
                                noGC = ReflectionUtils.getAnnotation(NotInfinite.class, method).noGC();
                                log.trace("NotInfinite annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ". {size=" + size + ",repeats=" + repeats + ",leftOvers=" + leftOvers + "}");
                            }
                            long start;
                            for (int i = 0; i < repeats; ++i) {
                                start = System.currentTimeMillis();
                                for (int j = 0; j < size; ++j) {
                                    method.invoke(test);
                                }
                                totalDuration += (System.currentTimeMillis() - start);
                                test.init();
                                if (!noGC) {
                                    GCManager.gc();
                                }
                            }
                            if (leftOvers != 0) {   //TODO: remove repeats
                                start = System.currentTimeMillis();
                                for (int j = 0; j < leftOvers; ++j) {
                                    method.invoke(test);
                                }
                                totalDuration += (System.currentTimeMillis() - start);
                            }

                            log.trace("Test finished (" + test.getClass().getSimpleName() + "#" + method.getName() + ")");
                            addResult(new Result(test.getClass(), method, totalDuration), test.getClass().getAnnotation(TestSuite.class));

                            if (ReflectionUtils.getAnnotation(DirtiesObject.class, method) != null) {
                                log.trace("DirtiesObject annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ": reinitializing");
                                test.init();
                            }
                        } catch (InvocationTargetException e) {
                            log.error("Failed to invoke testmethod " + test.getClass().getSimpleName() + "#" + method.getName() + ": " + e.getMessage(), e);
                            addResult(new Result(test.getClass(), method, Long.MIN_VALUE), test.getClass().getAnnotation(TestSuite.class));
                        }
                    } else {
                        if (method.getName().startsWith("test")) {
                            log.warn("Method " + method.getName() + " skipped");
                        } else {
                            log.trace("Method " + method.getName() + " skipped");
                        }
                    }
                }

                //Test-class finished, clear resources and go to next test-class
                log.trace("Test finished");
                test.destroy();
                test = null;
                GCManager.forceGC();
            } catch (InitializationException e) {
                log.error("Failed to initialize test " + clazz.getSimpleName() + ": " + e.getMessage(), e);
            } catch (InstantiationException e) {
View Full Code Here

        int k = -1;
        //The actual tests
        for (Class<? extends ITest> clazz : classes) {
            log.info("Pre-Loading test class " + clazz.getSimpleName() + " iteration " + k);
            try {
                ITest test = (ITest) (this.getClass().getClassLoader().loadClass(clazz.getName())).newInstance();
                log.trace("Initializing test class for first time (" + test.getClass().getSimpleName() + ")");
                test.init();

                //Each test-method inside a test-class
                Method[] methods = test.getClass().getMethods();
                for (Method method : methods) {
                    if (ReflectionUtils.getAnnotation(Test.class, method) != null) {
                        try {
                            int repeats = 100;
                            int size = 10;
                            int leftOvers = 0;
                            long totalDuration = 0L;
                            boolean noGC = false;
                            if (ReflectionUtils.getAnnotation(NotInfinite.class, method) != null) {
                                size = 10;
                                repeats = 100;
                                leftOvers = 0;
                                noGC = ReflectionUtils.getAnnotation(NotInfinite.class, method).noGC();
                                log.trace("NotInfinite annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ". {size=" + size + ",repeats=" + repeats + ",leftOvers=" + leftOvers + "}");
                            }
                            long start;
                            for (int i = 0; i < repeats; ++i) {
                                start = System.currentTimeMillis();
                                for (int j = 0; j < size; ++j) {
                                    method.invoke(test);
                                }
                                totalDuration += (System.currentTimeMillis() - start);
                                test.init();
                                if (!noGC) {
                                    GCManager.gc();
                                }
                            }
                            if (leftOvers != 0) {   //TODO: remove repeats
                                start = System.currentTimeMillis();
                                for (int j = 0; j < leftOvers; ++j) {
                                    method.invoke(test);
                                }
                                totalDuration += (System.currentTimeMillis() - start);
                            }

                            log.trace("Test finished (" + test.getClass().getSimpleName() + "#" + method.getName() + ")");

                            if (ReflectionUtils.getAnnotation(DirtiesObject.class, method) != null) {
                                log.trace("DirtiesObject annotation found on " + test.getClass().getSimpleName() + "#" + method.getName() + ": reinitializing");
                                test.init();
                            }
                        } catch (InvocationTargetException e) {
                            log.error("Failed to invoke testmethod " + test.getClass().getSimpleName() + "#" + method.getName() + ": " + e.getMessage(), e);
                        }
                    }
                }

                //Test-class finished, clear resources and go to next test-class
                log.trace("Test finished");
                test.destroy();
                test = null;
                GCManager.forceGC();
            } catch (InitializationException e) {
                log.error("Failed to initialize test " + clazz.getSimpleName() + ": " + e.getMessage(), e);
            } catch (InstantiationException e) {
View Full Code Here

TOP

Related Classes of be.pw999.jape.models.Result

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.