All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.codehaus.mojo.chronos.xml.GroupedResponseTimeSamples Maven / Gradle / Ivy

Go to download

This plugin enables you to track and the executiontimes of a selection of Your unittests (JUnit or TestNG). One usage is to regard some of your automatic testcases as performancetests, tracking their executiontimes. Another usage is simply to monitor Your automatic tests to discover reasons for slow build times.

The newest version!
/*
 * The MIT License
 *
 * Original work sponsored and donated by National Board of e-Health (NSI), Denmark (http://www.nsi.dk)
 * Further enhancement before move to Codehaus sponsored and donated by Lakeside A/S (http://www.lakeside.dk)
 *
 * Copyright (c) to all contributors
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
 * of the Software, and to permit persons to whom the Software is furnished to do
 * so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 *
 * $HeadURL: https://svn.codehaus.org/mojo/tags/chronos-1.0/chronos-jmeter-maven-plugin/src/main/java/org/codehaus/mojo/chronos/check/CheckMojo.java $
 * $Id: CheckMojo.java 14893 2011-10-24 12:08:52Z soelvpil $
 */
package org.codehaus.mojo.chronos.xml;

import org.apache.commons.math.stat.descriptive.rank.Min;
import org.jdom2.Comment;
import org.jdom2.Document;
import org.jdom2.Element;
import org.jdom2.output.Format;
import org.jdom2.output.XMLOutputter;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Wrapper class used for creating an Chronos xml data file.
 * 
 * @author [email protected]
 */
public class GroupedResponseTimeSamples {

	private List groups = new ArrayList();

	public GroupedResponseTimeSamples() {
		// Do nothing
	}

	public void addGroup(ResponseTimeSampleGroup group) {
		groups.add(group);
	}

	public void dumpResults(File parentDirectory) throws IOException {
        File outputFile = new File( parentDirectory, "perf-chronostiming.xml" );
        Element root = new Element("groupedresponsetimesamples");
        int index = 0;
        int succeeded = 0;
        Min testStart = new Min( );
		for (ResponseTimeSampleGroup group : groups) {
			Element child = group.toXML();
			child.setAttribute("index", Integer.toString( ++index ));
			root.addContent(child);
            succeeded += group.getSucceeded();
            testStart.increment( group.getTestStart() );
		}
        root.setAttribute("succeeded", Integer.toString(succeeded));
        root.setAttribute( "starttime", Long.toString( (long) testStart.getResult() ) );
        root.setAttribute( "dateformat", "yyyy.MM.dd 'at' HH:mm:ss" );
        Document doc = new Document(root);
		doc.addContent(new Comment("File generated by \"Chronos timing\""));
        XMLOutputter outputter = new XMLOutputter( Format.getPrettyFormat());
        outputter.output(doc, new FileOutputStream( outputFile ));
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy