use of org.apache.jorphan.util.JMeterError in project jmeter-plugins by undera.
the class MergeResultsGuiTest method testActionPerformed_Merge.
@Test
public void testActionPerformed_Merge() throws Exception {
System.out.println("actionPerformed");
MergeResultsGui instance = new MergeResultsGui();
JTable grid = instance.getGrid();
ActionEvent actionMerge = new ActionEvent(new JButton(), 5, "merge");
ActionEvent actionAdd = new ActionEvent(new JButton(), 1, "add");
// create a file to test the merge action
BufferedWriter out;
String f1 = "test-merge-1.csv";
String f2 = "test-merge-2.csv";
String fRes = "test-merge-1-2.csv";
out = new BufferedWriter(new FileWriter(new File(DATA_DIR, f1)));
out.write("timeStamp;elapsed;label;responseCode;threadName;success;bytes;grpThreads;allThreads;Latency;Hostname");
out.write(CRLF);
out.write("2014-04-28 16:49:28.068;288478;P1_RECHERCHE;200;G3_G1_G2 Paliers 1-7;true;290687;28;28;1559;ITEM-63339");
out.write(CRLF);
out.close();
out = new BufferedWriter(new FileWriter(new File(DATA_DIR, f2)));
out.write("timeStamp;elapsed;label;responseCode;threadName;success;bytes;grpThreads;allThreads;Latency;Hostname");
out.write(CRLF);
out.write("2014-04-29 17:43:18.161;257065;P1_RECHERCHE;200;G3_G1_G2 Paliers 1-12;true;279542;20;20;908;ITEM-63339");
out.write(CRLF);
out.close();
instance.actionPerformed(actionAdd);
instance.actionPerformed(actionAdd);
grid.setValueAt(f1, 0, 0);
grid.setValueAt(f2, 1, 0);
instance.setFile(DATA_DIR + File.separator + fRes);
instance.updateUI();
instance.createTestElement();
try {
instance.actionPerformed(actionMerge);
File f = new File(DATA_DIR, f1);
f.delete();
f = new File(DATA_DIR, f2);
f.delete();
f = new File(DATA_DIR, fRes);
assertTrue(f.exists());
f.delete();
} catch (JMeterError e) {
// FIXME: this test is broken
e.printStackTrace(System.err);
}
}
use of org.apache.jorphan.util.JMeterError in project jmeter by apache.
the class CSVSaveService method makeResultFromDelimitedString.
/**
* Make a SampleResult given a set of tokens
*
* @param parts
* tokens parsed from the input
* @param saveConfig
* the save configuration (may be updated)
* @param lineNumber the line number (for error reporting)
* @return the sample result
*
* @throws JMeterError
*/
@SuppressWarnings("JdkObsolete")
private static SampleEvent makeResultFromDelimitedString(final String[] parts, // may be updated
final SampleSaveConfiguration saveConfig, final long lineNumber) {
SampleResult result = null;
// $NON-NLS-1$
String hostname = "";
long timeStamp = 0;
long elapsed = 0;
String text = null;
// Save the name for error reporting
String field = null;
int i = 0;
try {
if (saveConfig.saveTimestamp()) {
field = TIME_STAMP;
text = parts[i++];
if (saveConfig.printMilliseconds()) {
try {
// see if this works
timeStamp = Long.parseLong(text);
} catch (NumberFormatException e) {
// it did not, let's try some other formats
log.warn("Cannot parse timestamp: '{}', will try following formats {}", text, Arrays.asList(DATE_FORMAT_STRINGS));
boolean foundMatch = false;
for (String fmt : DATE_FORMAT_STRINGS) {
SimpleDateFormat dateFormat = new SimpleDateFormat(fmt);
dateFormat.setLenient(false);
try {
Date stamp = dateFormat.parse(text);
timeStamp = stamp.getTime();
log.warn("Setting date format to: {}", fmt);
saveConfig.setDateFormat(fmt);
foundMatch = true;
break;
} catch (ParseException pe) {
log.info("{} did not match {}, trying next date format", text, fmt);
}
}
if (!foundMatch) {
throw new ParseException("No date-time format found matching " + text, -1);
}
}
} else if (saveConfig.strictDateFormatter() != null) {
Date stamp = saveConfig.strictDateFormatter().parse(text);
timeStamp = stamp.getTime();
} else {
// can this happen?
final String msg = "Unknown timestamp format";
log.warn(msg);
throw new JMeterError(msg);
}
}
if (saveConfig.saveTime()) {
field = CSV_ELAPSED;
text = parts[i++];
elapsed = Long.parseLong(text);
}
if (saveConfig.saveSampleCount()) {
@SuppressWarnings("deprecation") StatisticalSampleResult sampleResult = new StatisticalSampleResult(timeStamp, elapsed);
result = sampleResult;
} else {
result = new SampleResult(timeStamp, elapsed);
}
if (saveConfig.saveLabel()) {
field = LABEL;
text = parts[i++];
result.setSampleLabel(text);
}
if (saveConfig.saveCode()) {
field = RESPONSE_CODE;
text = parts[i++];
result.setResponseCode(text);
}
if (saveConfig.saveMessage()) {
field = RESPONSE_MESSAGE;
text = parts[i++];
result.setResponseMessage(text);
}
if (saveConfig.saveThreadName()) {
field = THREAD_NAME;
text = parts[i++];
result.setThreadName(text);
}
if (saveConfig.saveDataType()) {
field = DATA_TYPE;
text = parts[i++];
result.setDataType(text);
}
if (saveConfig.saveSuccess()) {
field = SUCCESSFUL;
text = parts[i++];
result.setSuccessful(Boolean.valueOf(text));
}
if (saveConfig.saveAssertionResultsFailureMessage()) {
i++;
// TODO - should this be restored?
}
if (saveConfig.saveBytes()) {
field = CSV_BYTES;
text = parts[i++];
result.setBytes(Long.parseLong(text));
}
if (saveConfig.saveSentBytes()) {
field = CSV_SENT_BYTES;
text = parts[i++];
result.setSentBytes(Long.parseLong(text));
}
if (saveConfig.saveThreadCounts()) {
field = CSV_THREAD_COUNT1;
text = parts[i++];
result.setGroupThreads(Integer.parseInt(text));
field = CSV_THREAD_COUNT2;
text = parts[i++];
result.setAllThreads(Integer.parseInt(text));
}
if (saveConfig.saveUrl()) {
i++;
// TODO: should this be restored?
}
if (saveConfig.saveFileName()) {
field = CSV_FILENAME;
text = parts[i++];
result.setResultFileName(text);
}
if (saveConfig.saveLatency()) {
field = CSV_LATENCY;
text = parts[i++];
result.setLatency(Long.parseLong(text));
}
if (saveConfig.saveEncoding()) {
field = CSV_ENCODING;
text = parts[i++];
result.setEncodingAndType(text);
}
if (saveConfig.saveSampleCount()) {
field = CSV_SAMPLE_COUNT;
text = parts[i++];
result.setSampleCount(Integer.parseInt(text));
field = CSV_ERROR_COUNT;
text = parts[i++];
result.setErrorCount(Integer.parseInt(text));
}
if (saveConfig.saveHostname()) {
field = CSV_HOSTNAME;
hostname = parts[i++];
}
if (saveConfig.saveIdleTime()) {
field = CSV_IDLETIME;
text = parts[i++];
result.setIdleTime(Long.parseLong(text));
}
if (saveConfig.saveConnectTime()) {
field = CSV_CONNECT_TIME;
text = parts[i++];
result.setConnectTime(Long.parseLong(text));
}
if (i + saveConfig.getVarCount() < parts.length) {
log.warn("Line: {}. Found {} fields, expected {}. Extra fields have been ignored.", lineNumber, parts.length, i);
}
} catch (NumberFormatException | ParseException e) {
if (log.isWarnEnabled()) {
log.warn("Error parsing field '{}' at line {}. {}", field, lineNumber, e.toString());
}
throw new JMeterError(e);
} catch (ArrayIndexOutOfBoundsException e) {
log.warn("Insufficient columns to parse field '{}' at line {}", field, lineNumber);
throw new JMeterError(e);
}
return new SampleEvent(result, "", hostname);
}
use of org.apache.jorphan.util.JMeterError in project jmeter by apache.
the class ResultCollector method loadExistingFile.
/**
* Loads an existing sample data (JTL) file.
* This can be one of:
* <ul>
* <li>XStream format</li>
* <li>CSV format</li>
* </ul>
*/
public void loadExistingFile() {
final Visualizer visualizer = getVisualizer();
if (visualizer == null) {
// No point reading the file if there's no visualiser
return;
}
boolean parsedOK = false;
String filename = getFilename();
File file = new File(filename);
if (file.exists()) {
try (BufferedReader dataReader = Files.newBufferedReader(file.toPath())) {
// Get the first line, and see if it is XML
String line = dataReader.readLine();
dataReader.close();
if (line == null) {
log.warn("{} is empty", filename);
} else {
if (!line.startsWith("<?xml ")) {
// No, must be CSV //$NON-NLS-1$
CSVSaveService.processSamples(filename, visualizer, this);
parsedOK = true;
} else {
// We are processing XML
try (InputStream fis = Files.newInputStream(file.toPath());
BufferedInputStream bufferedInputStream = new BufferedInputStream(fis)) {
// Assume XStream
SaveService.loadTestResults(bufferedInputStream, new ResultCollectorHelper(this, visualizer));
parsedOK = true;
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Failed to load {} using XStream. Error was: {}", filename, e.toString());
}
}
}
}
} catch (IOException | JMeterError | RuntimeException e) {
log.warn("Problem reading JTL file: {}", file, e);
} finally {
if (!parsedOK) {
GuiPackage.showErrorMessage("Error loading results file - see log file", "Result file loader");
}
}
} else {
GuiPackage.showErrorMessage("Error loading results file - could not open file", "Result file loader");
}
}
use of org.apache.jorphan.util.JMeterError in project jmeter by apache.
the class DiskStoreSampleSender method testEnded.
@Override
@SuppressWarnings("FutureReturnValueIgnored")
public void testEnded(String host) {
log.info("Test Ended on {}", host);
singleExecutor.submit(() -> {
try {
// ensure output is flushed
oos.close();
} catch (IOException e) {
log.error("Failed to close data file.", e);
}
});
// finish processing samples
singleExecutor.shutdown();
try {
if (!singleExecutor.awaitTermination(3, TimeUnit.SECONDS)) {
log.error("Executor did not terminate in a timely fashion");
}
} catch (InterruptedException e) {
log.error("Executor did not terminate in a timely fashion", e);
Thread.currentThread().interrupt();
}
try (InputStream fis = new FileInputStream(temporaryFile);
ObjectInputStream ois = new ObjectInputStream(fis)) {
Object obj;
while ((obj = ois.readObject()) != null) {
if (obj instanceof SampleEvent) {
try {
listener.sampleOccurred((SampleEvent) obj);
} catch (RemoteException err) {
if (err.getCause() instanceof java.net.ConnectException) {
throw new JMeterError("Could not return sample", err);
}
log.error("returning sample", err);
}
} else {
log.error("Unexpected object type found in data file. {}", obj.getClass());
}
}
} catch (EOFException err) {
// expected
} catch (IOException | ClassNotFoundException err) {
log.error("returning sample", err);
} finally {
try {
listener.testEnded(host);
} catch (RemoteException e) {
log.error("returning sample", e);
}
if (!temporaryFile.delete()) {
if (log.isWarnEnabled()) {
log.warn("Could not delete file: {}", temporaryFile.getAbsolutePath());
}
}
}
}
use of org.apache.jorphan.util.JMeterError in project jmeter by apache.
the class SaveService method initProps.
private static void initProps() {
// Load the alias properties
try {
Properties nameMap = loadProperties();
try {
fileVersion = checksum(nameMap);
} catch (NoSuchAlgorithmException e) {
log.error("Can't compute checksum for saveservice properties file", e);
throw new JMeterError("JMeter requires the checksum of saveservice properties file to continue", e);
}
// now create the aliases
for (Map.Entry<Object, Object> me : nameMap.entrySet()) {
String key = (String) me.getKey();
String val = (String) me.getValue();
if (!key.startsWith("_")) {
// $NON-NLS-1$
makeAlias(key, val);
} else {
// process special keys
if (key.equalsIgnoreCase("_version")) {
// $NON-NLS-1$
propertiesVersion = val;
log.info("Using SaveService properties version {}", propertiesVersion);
} else if (key.equalsIgnoreCase("_file_version")) {
// $NON-NLS-1$
log.info("SaveService properties file version is now computed by a checksum," + "the property _file_version is not used anymore and can be removed.");
} else if (key.equalsIgnoreCase("_file_encoding")) {
// $NON-NLS-1$
fileEncoding = val;
log.info("Using SaveService properties file encoding {}", fileEncoding);
} else {
// Remove the leading "_"
key = key.substring(1);
registerConverter(key, val);
}
}
}
} catch (IOException e) {
log.error("Bad saveservice properties file", e);
throw new JMeterError("JMeter requires the saveservice properties file to continue");
}
}
Aggregations