/* * Copyright (C) 2008 Digital Sundhed (SDSD) * * All source code and information supplied as part of chronos * is copyright to its contributers. * * The source code has been released under a dual license - meaning you can * use either licensed version of the library with your code. * * It is released under the Common Public License 1.0, a copy of which can * be found at the link below. * http://www.opensource.org/licenses/cpl.php * * It is released under the LGPL (GNU Lesser General Public License), either * version 2.1 of the License, or (at your option) any later version. A copy * of which can be found at the link below. * http://www.gnu.org/copyleft/lesser.html */ package org.codehaus.mojo.chronos.jmeter; import java.util.Properties; import org.codehaus.mojo.chronos.responsetime.ResponsetimeSample; /** * This class represents info from a jmeter logentry, in a jtl2.0 format. * * @author ksr@lakeside.dk */ public class Jtl20Sample implements ResponsetimeSample { private static final long serialVersionUID = -804458217898447540L; private static final String JUNIT_SAMPLER = "org.apache.jmeter.protocol.java.sampler.JUnitSampler"; private final int responsetime; private final long timestamp; private final boolean success; private final String threadId; /** * @param attributes */ public Jtl20Sample(Properties attributes) { responsetime = Integer.parseInt(attributes.getProperty("time")); timestamp = Long.parseLong(attributes.getProperty("timeStamp")); success = "true".equals(attributes.getProperty("success")); threadId = attributes.getProperty("threadName").intern(); } /** * This will normally contain the name of this sample, as defined in JMeter.<br/> * If the report is generated by JMeter2.1, the name will be derived * from an embedded property instead * * @return the name of this sample */ public static String getSampleName(Properties attributes, String embeddedPropertyValue) { // it seems like when generated from Jmeter 2.1, the label will always // contain the String // 'org.apache.jmeter.protocol.java.sampler.JUnitSampler' String label = attributes.getProperty("label"); if(JUNIT_SAMPLER.equals(label) && !"".equals(embeddedPropertyValue)) { return embeddedPropertyValue; } else { return label; } } /** * @see ResponsetimeSample#getResponsetime() * @return Returns the responsetime. */ public final int getResponsetime() { return responsetime; } /** * @see ResponsetimeSample#getTimestamp() * @return Returns the timestamp. */ public final long getTimestamp() { return timestamp; } /** * @see ResponsetimeSample#isSuccess() * @return Returns the success. */ public final boolean isSuccess() { return success; } /** * @see ResponsetimeSample#getThreadId() * @return Returns the threadgroupId. */ public final String getThreadId() { return threadId; } }