Author: pmouawad
Date: Fri Mar 4 22:36:40 2016
New Revision: 1733668
URL: http://svn.apache.org/viewvc?rev=1733668&view=rev
Log:
Move some tests in a dedicated class
Contribution by Benoit Wiart
#resolve #147
https://github.com/apache/jmeter/pull/147/
Added:
jmeter/trunk/test/src/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
(with props)
jmeter/trunk/test/src/org/apache/jmeter/util/StringUtilitiesTest.java
(with props)
Modified:
jmeter/trunk/test/src/org/apache/jmeter/timers/PackageTest.java
jmeter/trunk/test/src/org/apache/jmeter/util/PackageTest.java
Added:
jmeter/trunk/test/src/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/timers/ConstantThroughputTimerTest.java?rev=1733668&view=auto
==============================================================================
---
jmeter/trunk/test/src/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
(added)
+++
jmeter/trunk/test/src/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
Fri Mar 4 22:36:40 2016
@@ -0,0 +1,99 @@
+/*
+ * 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.timers;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.jmeter.threads.JMeterContextService;
+import org.apache.jmeter.threads.TestJMeterContextService;
+import org.apache.jmeter.util.BeanShellInterpreter;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+import org.junit.Test;
+
+public class ConstantThroughputTimerTest {
+
+ private static final Logger LOG = LoggingManager.getLoggerForClass();
+
+ @Test
+ public void testTimer1() throws Exception {
+ ConstantThroughputTimer timer = new ConstantThroughputTimer();
+ assertEquals(0,timer.getCalcMode());// Assume this thread only
+ timer.setThroughput(60.0);// 1 per second
+ long delay = timer.delay(); // Initialise
+ assertEquals(0,delay);
+ Thread.sleep(500);
+ assertEquals("Expected delay of approx 500", 500, timer.delay(), 50);
+ }
+
+ @Test
+ public void testTimer2() throws Exception {
+ ConstantThroughputTimer timer = new ConstantThroughputTimer();
+ assertEquals(0,timer.getCalcMode());// Assume this thread only
+ timer.setThroughput(60.0);// 1 per second
+ assertEquals(1000,timer.calculateCurrentTarget(0)); // Should delay
for 1 second
+ timer.setThroughput(60000.0);// 1 per milli-second
+ assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1
milli-second
+ }
+
+ @Test
+ public void testTimer3() throws Exception {
+ ConstantThroughputTimer timer = new ConstantThroughputTimer();
+ timer.setMode(ConstantThroughputTimer.Mode.AllActiveThreads);
//$NON-NLS-1$ - all threads
+ assertEquals(1,timer.getCalcMode());// All threads
+ for(int i=1; i<=10; i++){
+ TestJMeterContextService.incrNumberOfThreads();
+ }
+ assertEquals(10,JMeterContextService.getNumberOfThreads());
+ timer.setThroughput(600.0);// 10 per second
+ assertEquals(1000,timer.calculateCurrentTarget(0)); // Should delay
for 1 second
+ timer.setThroughput(600000.0);// 10 per milli-second
+ assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1
milli-second
+ for(int i=1; i<=990; i++){
+ TestJMeterContextService.incrNumberOfThreads();
+ }
+ assertEquals(1000,JMeterContextService.getNumberOfThreads());
+ timer.setThroughput(60000000.0);// 1000 per milli-second
+ assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1
milli-second
+ }
+
+ @Test
+ public void testTimerBSH() throws Exception {
+ if (!BeanShellInterpreter.isInterpreterPresent()){
+ final String msg = "BeanShell jar not present, test ignored";
+ LOG.warn(msg);
+ return;
+ }
+ BeanShellTimer timer = new BeanShellTimer();
+ long delay;
+
+ timer.setScript("\"60\"");
+ delay = timer.delay();
+ assertEquals(60,delay);
+
+ timer.setScript("60");
+ delay = timer.delay();
+ assertEquals(60,delay);
+
+ timer.setScript("5*3*4");
+ delay = timer.delay();
+ assertEquals(60,delay);
+ }
+
+}
Propchange:
jmeter/trunk/test/src/org/apache/jmeter/timers/ConstantThroughputTimerTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: jmeter/trunk/test/src/org/apache/jmeter/timers/PackageTest.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/timers/PackageTest.java?rev=1733668&r1=1733667&r2=1733668&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/timers/PackageTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/timers/PackageTest.java Fri Mar 4
22:36:40 2016
@@ -21,8 +21,6 @@ package org.apache.jmeter.timers;
import static org.junit.Assert.assertEquals;
import org.apache.jmeter.junit.JMeterTestCase;
-import org.apache.jmeter.threads.JMeterContextService;
-import org.apache.jmeter.threads.TestJMeterContextService;
import org.apache.jmeter.util.BeanShellInterpreter;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
@@ -30,56 +28,14 @@ import org.junit.Test;
public class PackageTest extends JMeterTestCase {
- private static final Logger log = LoggingManager.getLoggerForClass();
+ private static final Logger LOG = LoggingManager.getLoggerForClass();
@Test
- public void testTimer1() throws Exception {
- ConstantThroughputTimer timer = new ConstantThroughputTimer();
- assertEquals(0,timer.getCalcMode());// Assume this thread only
- timer.setThroughput(60.0);// 1 per second
- long delay = timer.delay(); // Initialise
- assertEquals(0,delay);
- Thread.sleep(500);
- assertEquals("Expected delay of approx 500",500, timer.delay(), 50);
- }
-
- @Test
- public void testTimer2() throws Exception {
- ConstantThroughputTimer timer = new ConstantThroughputTimer();
- assertEquals(0,timer.getCalcMode());// Assume this thread only
- timer.setThroughput(60.0);// 1 per second
- assertEquals(1000,timer.calculateCurrentTarget(0)); // Should delay
for 1 second
- timer.setThroughput(60000.0);// 1 per milli-second
- assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1
milli-second
- }
-
- @Test
- public void testTimer3() throws Exception {
- ConstantThroughputTimer timer = new ConstantThroughputTimer();
- timer.setMode(ConstantThroughputTimer.Mode.AllActiveThreads);
//$NON-NLS-1$ - all threads
- assertEquals(1,timer.getCalcMode());// All threads
- for(int i=1; i<=10; i++){
- TestJMeterContextService.incrNumberOfThreads();
- }
- assertEquals(10,JMeterContextService.getNumberOfThreads());
- timer.setThroughput(600.0);// 10 per second
- assertEquals(1000,timer.calculateCurrentTarget(0)); // Should delay
for 1 second
- timer.setThroughput(600000.0);// 10 per milli-second
- assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1
milli-second
- for(int i=1; i<=990; i++){
- TestJMeterContextService.incrNumberOfThreads();
- }
- assertEquals(1000,JMeterContextService.getNumberOfThreads());
- timer.setThroughput(60000000.0);// 1000 per milli-second
- assertEquals(1,timer.calculateCurrentTarget(0)); // Should delay for 1
milli-second
- }
-
- @Test
public void testTimerBSH() throws Exception {
if (!BeanShellInterpreter.isInterpreterPresent()){
final String msg = "BeanShell jar not present, test ignored";
- log.warn(msg);
+ LOG.warn(msg);
return;
}
BeanShellTimer timer = new BeanShellTimer();
Modified: jmeter/trunk/test/src/org/apache/jmeter/util/PackageTest.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/util/PackageTest.java?rev=1733668&r1=1733667&r2=1733668&view=diff
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/util/PackageTest.java (original)
+++ jmeter/trunk/test/src/org/apache/jmeter/util/PackageTest.java Fri Mar 4
22:36:40 2016
@@ -18,14 +18,12 @@
package org.apache.jmeter.util;
-import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import org.junit.Test;
public class PackageTest {
-
@Test
public void testServer() throws Exception {
BeanShellServer bshs = new BeanShellServer(9876, "");
@@ -33,36 +31,4 @@ public class PackageTest {
// Not sure we can test anything else here
}
- @Test
- public void testSub1() throws Exception {
- String input = "http://jakarta.apache.org/jmeter/index.html";
- String pattern = "jakarta.apache.org";
- String sub = "${server}";
- assertEquals("http://${server}/jmeter/index.html",
StringUtilities.substitute(input, pattern, sub));
- }
-
- @Test
- public void testSub2() throws Exception {
- String input = "arg1=param1;param1";
- String pattern = "param1";
- String sub = "${value}";
- assertEquals("arg1=${value};${value}",
StringUtilities.substitute(input, pattern, sub));
- }
-
- @Test
- public void testSub3() throws Exception {
- String input = "jakarta.apache.org";
- String pattern = "jakarta.apache.org";
- String sub = "${server}";
- assertEquals("${server}", StringUtilities.substitute(input, pattern,
sub));
- }
-
- @Test
- public void testSub4() throws Exception {
- String input = "//a///b////c";
- String pattern = "//";
- String sub = "/";
- assertEquals("/a//b//c", StringUtilities.substitute(input, pattern,
sub));
- }
-
}
Added: jmeter/trunk/test/src/org/apache/jmeter/util/StringUtilitiesTest.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/test/src/org/apache/jmeter/util/StringUtilitiesTest.java?rev=1733668&view=auto
==============================================================================
--- jmeter/trunk/test/src/org/apache/jmeter/util/StringUtilitiesTest.java
(added)
+++ jmeter/trunk/test/src/org/apache/jmeter/util/StringUtilitiesTest.java Fri
Mar 4 22:36:40 2016
@@ -0,0 +1,68 @@
+/*
+ * 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.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class StringUtilitiesTest {
+
+
+ @Test
+ public void testServer() throws Exception {
+ BeanShellServer bshs = new BeanShellServer(9876, "");
+ assertNotNull(bshs);
+ // Not sure we can test anything else here
+ }
+
+ @Test
+ public void testSub1() throws Exception {
+ String input = "http://jakarta.apache.org/jmeter/index.html";
+ String pattern = "jakarta.apache.org";
+ String sub = "${server}";
+ assertEquals("http://${server}/jmeter/index.html",
StringUtilities.substitute(input, pattern, sub));
+ }
+
+ @Test
+ public void testSub2() throws Exception {
+ String input = "arg1=param1;param1";
+ String pattern = "param1";
+ String sub = "${value}";
+ assertEquals("arg1=${value};${value}",
StringUtilities.substitute(input, pattern, sub));
+ }
+
+ @Test
+ public void testSub3() throws Exception {
+ String input = "jakarta.apache.org";
+ String pattern = "jakarta.apache.org";
+ String sub = "${server}";
+ assertEquals("${server}", StringUtilities.substitute(input, pattern,
sub));
+ }
+
+ @Test
+ public void testSub4() throws Exception {
+ String input = "//a///b////c";
+ String pattern = "//";
+ String sub = "/";
+ assertEquals("/a//b//c", StringUtilities.substitute(input, pattern,
sub));
+ }
+
+}
Propchange:
jmeter/trunk/test/src/org/apache/jmeter/util/StringUtilitiesTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain