jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1842283 - in /jmeter/trunk: src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java xdocs/changes.xml
Date Fri, 28 Sep 2018 21:04:45 GMT
Author: pmouawad
Date: Fri Sep 28 21:04:45 2018
New Revision: 1842283

URL: http://svn.apache.org/viewvc?rev=1842283&view=rev
Log:
Bug 62775 - If many jars are in a folder referenced by user.classpath, startup can be extremely
slow due to JUnit
Bugzilla Id: 62775

Modified:
    jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
    jmeter/trunk/xdocs/changes.xml

Modified: jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java?rev=1842283&r1=1842282&r2=1842283&view=diff
==============================================================================
--- jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
(original)
+++ jmeter/trunk/src/junit/org/apache/jmeter/protocol/java/control/gui/JUnitTestSamplerGui.java
Fri Sep 28 21:04:45 2018
@@ -28,6 +28,7 @@ import java.io.IOException;
 import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
 
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
@@ -71,6 +72,7 @@ implements ChangeListener, ActionListene
     private static final String ONETIMETEARDOWN = "oneTimeTearDown"; //$NON-NLS-1$
     private static final String SUITE = "suite"; //$NON-NLS-1$
 
+    private static final AtomicBoolean IS_INITILIAZED = new AtomicBoolean(Boolean.FALSE);
     private static final String[] SPATHS;
 
     static {
@@ -138,6 +140,9 @@ implements ChangeListener, ActionListene
     private final transient ClassLoader contextClassLoader =
         Thread.currentThread().getContextClassLoader(); // Potentially expensive; do it once
 
+    private static List<String> annotatedTestClasses;
+    private static List<String> junitTestClasses;
+
     /**
      * Constructor for JUnitTestSamplerGui
      */
@@ -168,19 +173,28 @@ implements ChangeListener, ActionListene
     }
 
     @SuppressWarnings("unchecked")
-    private void setupClasslist(){
+    private void setupClasslist(boolean initialize){
         classnameCombo.removeAllItems();
         methodName.removeAllItems();
         try
         {
-            List<String> classList;
-            if (junit4.isSelected()){
-                classList = ClassFinder.findAnnotatedClasses(SPATHS,
-                    new Class[] {Test.class}, false);
-            } else {
-                classList = ClassFinder.findClassesThatExtend(SPATHS,
-                     new Class[] { TestCase.class });
+            List<String> classList = new ArrayList<>();
+            if(initialize) {
+                synchronized (IS_INITILIAZED) {
+                    if(IS_INITILIAZED.compareAndSet(false, true)) {
+                        annotatedTestClasses = ClassFinder.findAnnotatedClasses(SPATHS,
+                            new Class[] {Test.class}, false);
+                        junitTestClasses = ClassFinder.findClassesThatExtend(SPATHS,
+                             new Class[] { TestCase.class });
+                    }
+                    if (junit4.isSelected()){
+                        classList = annotatedTestClasses;
+                    } else {
+                        classList = junitTestClasses;
+                    }
+                }
             }
+            
             ClassFilter filter = new ClassFilter();
             filter.setPackges(JOrphanUtils.split(filterpkg.getText(),",")); //$NON-NLS-1$
             // change the classname drop down
@@ -209,7 +223,7 @@ implements ChangeListener, ActionListene
         methodName.addActionListener(this);
         methodLabel.setLabelFor(methodName);
 
-        setupClasslist();
+        setupClasslist(false);
 
         VerticalPanel panel = new VerticalPanel();
         panel.add(junit4);
@@ -252,6 +266,7 @@ implements ChangeListener, ActionListene
         failureMsg.setText(JMeterUtils.getResString("junit_failure_default_msg")); //$NON-NLS-1$
         errorMsg.setText(JMeterUtils.getResString("junit_error_default_msg")); //$NON-NLS-1$
         errorCode.setText(JMeterUtils.getResString("junit_error_default_code")); //$NON-NLS-1$
+        setupClasslist(true);
     }
 
     /** {@inheritDoc} */
@@ -364,7 +379,7 @@ implements ChangeListener, ActionListene
                 }
                 methodName.repaint();
             } catch (ClassNotFoundException e) {
-                throw new RuntimeException(e);
+                throw new IllegalStateException(e);
             }
         }
     }
@@ -390,7 +405,7 @@ implements ChangeListener, ActionListene
                 }
             }
         }
-        if (list.size() > 0){
+        if (!list.isEmpty()){
             return list.toArray(new String[list.size()]);
         }
         return new String[0];
@@ -418,7 +433,7 @@ implements ChangeListener, ActionListene
     @Override
     public void itemStateChanged(ItemEvent event) {
         if (event.getItem() == junit4){
-            setupClasslist();
+            setupClasslist(true);
         }
     }
 
@@ -429,7 +444,7 @@ implements ChangeListener, ActionListene
     @Override
     public void stateChanged(ChangeEvent event) {
         if ( event.getSource() == filterpkg) {
-            setupClasslist();
+            setupClasslist(true);
         }
     }
 }

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1842283&r1=1842282&r2=1842283&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Fri Sep 28 21:04:45 2018
@@ -127,6 +127,7 @@ Summary
 
 <h3>Other Samplers</h3>
 <ul>
+    <li><bug>62775</bug>If many jars are in a folder referenced by user.classpath,
startup can be extremely slow due to JUnit</li>
 </ul>
 
 <h3>Controllers</h3>



Mime
View raw message