jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1859615 - in /jmeter/trunk: src/core/org/apache/jmeter/JMeter.java test/src/org/apache/jmeter/JMeterTest.java xdocs/changes.xml
Date Tue, 21 May 2019 08:32:37 GMT
Author: pmouawad
Date: Tue May 21 08:32:36 2019
New Revision: 1859615

URL: http://svn.apache.org/viewvc?rev=1859615&view=rev
Log:
Bug 63394 - JMeter should fail with non-zero when test execution fails (due to missing test
plan or other reason)

Contributed by UbikLoadPack

This closes #458
This closes #456
Bugzilla Id: 63394

Added:
    jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java   (with props)
Modified:
    jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java?rev=1859615&r1=1859614&r2=1859615&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/JMeter.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/JMeter.java Tue May 21 08:32:36 2019
@@ -992,12 +992,12 @@ public class JMeter implements JMeterPlu
     }
 
     // run test in batch mode
-    private void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString,
boolean generateReportDashboard) {
+     void runNonGui(String testFile, String logFile, boolean remoteStart, String remoteHostsString,
boolean generateReportDashboard) 
+            throws ConfigurationException {
         try {
             File f = new File(testFile);
             if (!f.exists() || !f.isFile()) {
-                println("Could not open " + testFile);
-                return;
+                throw new ConfigurationException("The file " + f.getAbsolutePath() + " doesn't
exist or can't be opened");
             }
             FileServer.getFileServer().setBaseForScript(f);
 
@@ -1089,9 +1089,12 @@ public class JMeter implements JMeterPlu
                 distributedRunner.start();
             }
             startUdpDdaemon(engines);
+        } catch (ConfigurationException e) {
+            throw e;
         } catch (Exception e) {
             System.out.println("Error in NonGUIDriver " + e.toString());//NOSONAR
             log.error("Error in NonGUIDriver", e);
+            throw new ConfigurationException("Error in NonGUIDriver " + e.getMessage(), e);
         }
     }
     

Added: jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java?rev=1859615&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java (added)
+++ jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java Tue May 21 08:32:36 2019
@@ -0,0 +1,121 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.jmeter;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+
+import org.apache.jmeter.junit.JMeterTestCase;
+import org.apache.jmeter.report.config.ConfigurationException;
+import org.apache.jorphan.test.JMeterSerialTest;
+import org.junit.Test;
+
+public class JMeterTest extends JMeterTestCase implements JMeterSerialTest {
+    @Test
+    public void testFailureWhenJmxDoesntExist() {
+        JMeter jmeter = new JMeter();
+        try {
+            jmeter.runNonGui("testPlan.jmx", null, false, null, false);
+            fail("Expected ConfigurationException to be thrown");
+        } catch (ConfigurationException e) {
+            assertTrue("When the plugin doesn't exist, the method 'runNonGui' should throw
a ConfigurationException",
+                    e instanceof ConfigurationException);
+            assertTrue("When the file doesn't exist, this method 'runNonGui' should have
a detailed message",
+                    e.getMessage().contains("doesn't exist or can't be opened"));
+        }
+    }
+
+    @Test
+    public void testSuccessWhenJmxExists() throws IOException, ConfigurationException {
+        File temp = File.createTempFile("testPlan", ".jmx");
+        String testPlan = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                + "<jmeterTestPlan version=\"1.2\" properties=\"5.0\" jmeter=\"5.2-SNAPSHOT\">\n"
+ "  <hashTree>\n"
+                + "    <TestPlan guiclass=\"TestPlanGui\" testclass=\"TestPlan\" testname=\"Test
Plan\" enabled=\"true\">\n"
+                + "      <stringProp name=\"TestPlan.comments\"></stringProp>\n"
+                + "      <boolProp name=\"TestPlan.functional_mode\">false</boolProp>\n"
+                + "      <boolProp name=\"TestPlan.tearDown_on_shutdown\">true</boolProp>\n"
+                + "      <boolProp name=\"TestPlan.serialize_threadgroups\">false</boolProp>\n"
+                + "      <elementProp name=\"TestPlan.user_defined_variables\" elementType=\"Arguments\"
guiclass=\"ArgumentsPanel\" "
+                + "testclass=\"Arguments\" testname=\"User Defined Variables\" enabled=\"true\">\n"
+                + "        <collectionProp name=\"Arguments.arguments\"/>\n" + "  
   </elementProp>\n"
+                + "      <stringProp name=\"TestPlan.user_define_classpath\"></stringProp></TestPlan>"
+                + "    <hashTree/></hashTree></jmeterTestPlan>";
+        try (FileWriter fw = new FileWriter(temp); BufferedWriter out = new BufferedWriter(fw))
{
+            out.write(testPlan);
+        }
+        
+        try {
+            JMeter jmeter = new JMeter();
+            jmeter.runNonGui(temp.getAbsolutePath(), null, false, null, false);
+        } finally {
+            assertTrue("File "+ temp.getAbsolutePath()+ " should have been deleted", temp.delete());
+        }
+    }
+
+    @Test
+    public void testFailureWithMissingPlugin() throws IOException, ConfigurationException
{
+        File temp = File.createTempFile("testPlan", ".jmx");
+        String testPlan = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
+                + "<jmeterTestPlan version=\"1.2\" properties=\"5.0\" jmeter=\"5.2-SNAPSHOT.20190506\">\n"
+                + "  <hashTree>\n"
+                + "    <TestPlan guiclass=\"TestPlanGui\" testclass=\"TestPlan\" testname=\"Test
Plan\" enabled=\"true\">\n"
+                + "      <stringProp name=\"TestPlan.comments\"></stringProp>\n"
+                + "      <boolProp name=\"TestPlan.functional_mode\">false</boolProp>\n"
+                + "      <boolProp name=\"TestPlan.tearDown_on_shutdown\">true</boolProp>\n"
+                + "      <boolProp name=\"TestPlan.serialize_threadgroups\">false</boolProp>\n"
+                + "      <elementProp name=\"TestPlan.user_defined_variables\" elementType=\"Arguments\"
"
+                + "guiclass=\"ArgumentsPanel\" testclass=\"Arguments\" testname=\"User Defined
Variables\" enabled=\"true\">\n"
+                + "        <collectionProp name=\"Arguments.arguments\"/>\n" + "  
   </elementProp>\n"
+                + "      <stringProp name=\"TestPlan.user_define_classpath\"></stringProp>\n"
+ "    </TestPlan>\n"
+                + "    <hashTree>\n" + "      <hashTree>\n"
+                + "        <kg.apc.jmeter.samplers.DummySampler guiclass=\"kg.apc.jmeter.samplers.DummySamplerGui\"
"
+                + "testclass=\"kg.apc.jmeter.samplers.DummySampler\" testname=\"jp@gc - Dummy
Sampler\" enabled=\"true\">\n"
+                + "          <boolProp name=\"WAITING\">true</boolProp>\n"
+                + "          <boolProp name=\"SUCCESFULL\">true</boolProp>\n"
+                + "          <stringProp name=\"RESPONSE_CODE\">200</stringProp>\n"
+                + "          <stringProp name=\"RESPONSE_MESSAGE\">OK</stringProp>\n"
+                + "          <stringProp name=\"REQUEST_DATA\">{&quot;email&quot;:&quot;user1&quot;,
&quot;password&quot;:&quot;password1&quot;};"
+                + "</stringProp>\n"
+                + "          <stringProp name=\"RESPONSE_DATA\">{&quot;successful&quot;:
true, &quot;account_id&quot;:&quot;0123456789&quot;}</stringProp>\n"
+                + "          <stringProp name=\"RESPONSE_TIME\">${__Random(50,500)}</stringProp>\n"
+                + "          <stringProp name=\"LATENCY\">${__Random(1,50)}</stringProp>\n"
+                + "          <stringProp name=\"CONNECT\">${__Random(1,5)}</stringProp>\n"
+                + "        </kg.apc.jmeter.samplers.DummySampler></hashTree></hashTree>\n"
+                + "  </hashTree></jmeterTestPlan><hashTree/></hashTree>\n"
+ "</jmeterTestPlan>";
+        try (FileWriter fw = new FileWriter(temp); BufferedWriter out = new BufferedWriter(fw))
{
+            out.write(testPlan);
+        }
+        JMeter jmeter = new JMeter();
+        try {
+            jmeter.runNonGui(temp.getAbsolutePath(), null, false, null, false);
+            fail("Expected ConfigurationException to be thrown");
+        } catch (ConfigurationException e) {
+            assertTrue("When the plugin doesn't exist, the method 'runNonGui' should throw
a ConfigurationException",
+                    e instanceof ConfigurationException);
+            assertTrue("When the plugin doesn't exist, the method 'runNonGui' should have
a detailed message",
+                    e.getMessage().contains("Error in NonGUIDriver Problem loading XML from"));
+        } finally {
+            assertTrue("File "+ temp.getAbsolutePath()+ " should have been deleted", temp.delete());
+        }
+    }
+}

Propchange: jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jmeter/trunk/test/src/org/apache/jmeter/JMeterTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1859615&r1=1859614&r2=1859615&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Tue May 21 08:32:36 2019
@@ -177,6 +177,7 @@ to view the last major behaviors with th
 
 <h3>General</h3>
 <ul>
+    <li><bug>63394</bug>JMeter should fail with non-zero when test execution
fails (due to missing test plan or other reason). Contributed by Ubik Load Pack (support at
ubikloadpack.com)</li>
 </ul>
 
  <!--  =================== Thanks =================== -->
@@ -194,6 +195,7 @@ to view the last major behaviors with th
 <ul>
     <li>Sergiy Iampol (sergiy.iampol at playtech.com)</li>
     <li>Brian Tully (brian.tully at acquia.com)</li>
+    <li>Amer Ghazal (amerghazal at gmail.com)</li>
 </ul>
 <p>
 Apologies if we have omitted anyone else.



Mime
View raw message