jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject svn commit: r1720879 - in /jmeter/trunk/src: components/org/apache/jmeter/modifiers/SampleTimeout.java core/org/apache/jmeter/samplers/SampleMonitor.java core/org/apache/jmeter/threads/JMeterThread.java
Date Sat, 19 Dec 2015 02:02:36 GMT
Author: sebb
Date: Sat Dec 19 02:02:36 2015
New Revision: 1720879

URL: http://svn.apache.org/viewvc?rev=1720879&view=rev
Log:
Add Sample Timeout support
Use separate interface to avoid problems with RMI
Bugzilla Id: 58736

Added:
    jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleMonitor.java   (with props)
Modified:
    jmeter/trunk/src/components/org/apache/jmeter/modifiers/SampleTimeout.java
    jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java

Modified: jmeter/trunk/src/components/org/apache/jmeter/modifiers/SampleTimeout.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/modifiers/SampleTimeout.java?rev=1720879&r1=1720878&r2=1720879&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/modifiers/SampleTimeout.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/modifiers/SampleTimeout.java Sat Dec 19
02:02:36 2015
@@ -27,8 +27,7 @@ import java.util.concurrent.ThreadFactor
 import java.util.concurrent.TimeUnit;
 
 import org.apache.jmeter.samplers.Interruptible;
-import org.apache.jmeter.samplers.SampleEvent;
-import org.apache.jmeter.samplers.SampleListener;
+import org.apache.jmeter.samplers.SampleMonitor;
 import org.apache.jmeter.samplers.Sampler;
 import org.apache.jmeter.testelement.AbstractTestElement;
 import org.apache.jmeter.testelement.TestElement;
@@ -44,7 +43,7 @@ import org.apache.log.Logger;
  * Sample timeout implementation using Executor threads
  *
  */
-public class SampleTimeout extends AbstractTestElement implements Serializable, ThreadListener,
SampleListener {
+public class SampleTimeout extends AbstractTestElement implements Serializable, ThreadListener,
SampleMonitor {
 
     private static final long serialVersionUID = 1L;
 
@@ -109,17 +108,17 @@ public class SampleTimeout extends Abstr
     }
 
     @Override
-    public void sampleStarted(SampleEvent e) {
+    public void sampleStarting() {
         if (debug) {
-            LOG.debug(whoAmI("sampleStarted()", this));
+            LOG.debug(whoAmI("sampleStarting()", this));
         }
         createTask();
     }
 
     @Override
-    public void sampleStopped(SampleEvent e) {
+    public void sampleEnded() {
         if (debug) {
-            LOG.debug(whoAmI("sampleStopped()", this));
+            LOG.debug(whoAmI("sampleEnded()", this));
         }
         cancelTask();
     }
@@ -225,8 +224,4 @@ public class SampleTimeout extends Abstr
         }        
     }
 
-    @Override
-    public void sampleOccurred(SampleEvent e) {
-        // Not used
-    }
 }

Added: jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleMonitor.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleMonitor.java?rev=1720879&view=auto
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleMonitor.java (added)
+++ jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleMonitor.java Sat Dec 19 02:02:36
2015
@@ -0,0 +1,36 @@
+/*
+ * 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.samplers;
+
+/**
+ * Allows notification just before and just after a sample is invoked.
+ * Intended for the SampleTimeout test element
+ */
+public interface SampleMonitor {
+
+    /**
+     * A sample is about to start
+     */
+    void sampleStarting();
+
+    /**
+     * A sample has just finished
+     */
+    void sampleEnded();
+}

Propchange: jmeter/trunk/src/core/org/apache/jmeter/samplers/SampleMonitor.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java?rev=1720879&r1=1720878&r2=1720879&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java Sat Dec 19 02:02:36
2015
@@ -37,6 +37,7 @@ import org.apache.jmeter.processor.PrePr
 import org.apache.jmeter.samplers.Interruptible;
 import org.apache.jmeter.samplers.SampleEvent;
 import org.apache.jmeter.samplers.SampleListener;
+import org.apache.jmeter.samplers.SampleMonitor;
 import org.apache.jmeter.samplers.SampleResult;
 import org.apache.jmeter.samplers.Sampler;
 import org.apache.jmeter.testbeans.TestBeanHelper;
@@ -94,6 +95,8 @@ public class JMeterThread implements Run
     // The memory used will be released when the thread finishes
     private final Collection<TestIterationListener> testIterationStartListeners;
 
+    private final Collection<SampleMonitor> sampleMonitors;
+
     private final ListenerNotifier notifier;
 
     /*
@@ -146,6 +149,13 @@ public class JMeterThread implements Run
         SearchByClass<TestIterationListener> threadListenerSearcher = new SearchByClass<>(TestIterationListener.class);
// TL - IS
         test.traverse(threadListenerSearcher);
         testIterationStartListeners = threadListenerSearcher.getSearchResults();
+        if (IMPLEMENTS_SAMPLE_STARTED) {
+            SearchByClass<SampleMonitor> sampleMonitorSearcher = new SearchByClass<>(SampleMonitor.class);
+            test.traverse(sampleMonitorSearcher);
+            sampleMonitors = sampleMonitorSearcher.getSearchResults();
+        } else {
+            sampleMonitors = null;
+        }
         notifier = note;
         running = true;
     }
@@ -438,21 +448,14 @@ public class JMeterThread implements Run
         // Perform the actual sample
         currentSampler = sampler;
         if (IMPLEMENTS_SAMPLE_STARTED) {
-            for(SampleListener listener : pack.getSampleListeners()) {
-                try {
-                    TestBeanHelper.prepare((TestElement) listener);
-                    listener.sampleStarted(null);
-                } catch (RuntimeException e) {
-                    log.error("Detected problem in Listener: ", e);
-                    log.info("Continuing to process further listeners");
-                }
+            for(SampleMonitor monitor : sampleMonitors) {
+                monitor.sampleStarting();
             }                    
         }
         SampleResult result = sampler.sample(null); // TODO: remove this useless Entry parameter
         if (IMPLEMENTS_SAMPLE_STARTED) {
-            for(SampleListener listener : pack.getSampleListeners()) {
-                // We don't need to prepare these again here
-                listener.sampleStopped(null);
+            for(SampleMonitor monitor : sampleMonitors) {
+                monitor.sampleEnded();
             }                    
         }
         currentSampler = null;



Mime
View raw message