Skip to content

Commit 6f2d83a

Browse files
committed
Initial commit
1 parent 94c94b7 commit 6f2d83a

42 files changed

Lines changed: 206 additions & 138 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

build-logic/build-parameters/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ buildParameters {
3838
description.set("Collect test coverage")
3939
}
4040
integer("targetJavaVersion") {
41-
defaultValue.set(17)
41+
defaultValue.set(21)
4242
mandatory.set(true)
4343
description.set("Java version for source and target compatibility")
4444
}

src/components/src/main/java/org/apache/jmeter/visualizers/backend/influxdb/HttpMetricsSender.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package org.apache.jmeter.visualizers.backend.influxdb;
1919

20+
import java.net.URI;
2021
import java.net.URISyntaxException;
2122
import java.net.URL;
2223
import java.nio.charset.StandardCharsets;
@@ -120,7 +121,7 @@ public void setup(String influxdbUrl, String influxDBToken) throws Exception {
120121
.disableCookieManagement()
121122
.disableConnectionState()
122123
.build();
123-
url = new URL(influxdbUrl);
124+
url = URI.create(influxdbUrl).toURL();
124125
token = influxDBToken;
125126
httpRequest = createRequest(url, token);
126127
httpClient.start();

src/components/src/test/java/org/apache/jmeter/assertions/ResponseAssertionTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import static org.junit.jupiter.api.Assertions.assertTrue;
2626

2727
import java.net.MalformedURLException;
28+
import java.net.URI;
2829
import java.net.URL;
2930
import java.util.concurrent.CountDownLatch;
3031
import java.util.concurrent.atomic.AtomicInteger;
@@ -55,7 +56,7 @@ public void setUp() throws MalformedURLException {
5556
jmctx.setVariables(vars);
5657
jmctx.setPreviousResult(sample);
5758
sample.setResponseData("response Data\nline 2\n\nEOF", null);
58-
sample.setURL(new URL("http://localhost/Sampler/Data/"));
59+
sample.setURL(URI.create("http://localhost/Sampler/Data/").toURL());
5960
sample.setResponseCode("401");
6061
sample.setResponseHeaders("X-Header: abcd");
6162
sample.setRequestHeaders("X-reqHeader: cdef");

src/components/src/test/java/org/apache/jmeter/extractor/TestRegexExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static org.junit.jupiter.api.Assertions.assertNull;
2525
import static org.junit.jupiter.api.Assertions.assertTrue;
2626

27+
import java.net.URI;
2728
import java.net.URL;
2829

2930
import org.apache.jmeter.samplers.SampleResult;
@@ -314,7 +315,7 @@ public void testVariableExtraction8() throws Exception {
314315
assertTrue(extractor.useUrl(), "useURL should be true");
315316
extractor.process();
316317
assertNull(vars.get("regVal"));
317-
result.setURL(new URL("http://jakarta.apache.org/index.html?abcd"));
318+
result.setURL(URI.create("http://jakarta.apache.org/index.html?abcd").toURL());
318319
extractor.process();
319320
assertEquals("index", vars.get("regVal"));
320321
}

src/core/src/main/java/org/apache/jmeter/JMeter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ public void start(String[] args) {
382382

383383
Thread.setDefaultUncaughtExceptionHandler(
384384
(Thread t, Throwable e) -> {
385-
if (!(e instanceof ThreadDeath)) {
385+
if (!(e instanceof VirtualMachineError)) {
386386
log.error("Uncaught exception in thread {}", t, e);
387387
System.err.println("Uncaught Exception " + e + " in thread " + t + ". See log file for details.");//NOSONAR
388388
}

src/core/src/main/java/org/apache/jmeter/engine/StandardJMeterEngine.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
import java.util.concurrent.CopyOnWriteArrayList;
3131
import java.util.concurrent.ExecutionException;
3232
import java.util.concurrent.ExecutorService;
33+
import java.util.concurrent.Executors;
3334
import java.util.concurrent.Future;
34-
import java.util.concurrent.ThreadPoolExecutor;
3535
import java.util.concurrent.TimeUnit;
3636
import java.util.concurrent.TimeoutException;
37-
import java.util.concurrent.atomic.AtomicInteger;
37+
import java.util.concurrent.locks.ReentrantLock;
3838

3939
import org.apache.jmeter.JMeter;
4040
import org.apache.jmeter.samplers.SampleEvent;
@@ -92,19 +92,17 @@ public class StandardJMeterEngine implements JMeterEngine, Runnable {
9292
/** Whether to call System.exit(0) unconditionally at end of non-GUI test */
9393
private static final boolean SYSTEM_EXIT_FORCED = JMeterUtils.getPropDefault("jmeterengine.force.system.exit", false);
9494

95-
private static final AtomicInteger THREAD_COUNTER = new AtomicInteger(0);
96-
9795
/**
9896
* Executor service to execute management tasks like "start test", "stop test".
99-
* The use of {@link ExecutorService} allows propagating the exception from the threads.
100-
* Thread keepalive time is set to 1 second, so threads are released early,
101-
* so the application can shut down faster.
97+
* Uses platform threads to keep the JVM alive while tests run
98+
* (virtual threads are daemon threads and would allow premature JVM exit).
10299
*/
103100
private static final ExecutorService EXECUTOR_SERVICE =
104-
new ThreadPoolExecutor(0, Integer.MAX_VALUE,
105-
1L, TimeUnit.SECONDS,
106-
new java.util.concurrent.SynchronousQueue<>(),
107-
(runnable) -> new Thread(runnable, "StandardJMeterEngine-" + THREAD_COUNTER.incrementAndGet()));
101+
Executors.newThreadPerTaskExecutor(
102+
Thread.ofPlatform().name("StandardJMeterEngine-", 1).factory());
103+
104+
private static final ReentrantLock REGISTER_LOCK = new ReentrantLock();
105+
private final ReentrantLock stopTestLock = new ReentrantLock();
108106

109107
private volatile Future<?> runningTest;
110108

@@ -156,8 +154,13 @@ public static void stopEngine() {
156154
}
157155
}
158156

159-
public static synchronized void register(TestStateListener tl) {
160-
testList.add(tl);
157+
public static void register(TestStateListener tl) {
158+
REGISTER_LOCK.lock();
159+
try {
160+
testList.add(tl);
161+
} finally {
162+
REGISTER_LOCK.unlock();
163+
}
161164
}
162165

163166
public static boolean stopThread(String threadName) {
@@ -296,14 +299,19 @@ public void reset() {
296299
* Stop Test Now
297300
*/
298301
@Override
299-
public synchronized void stopTest() {
302+
public void stopTest() {
300303
stopTest(true);
301304
}
302305

303306
@Override
304307
@SuppressWarnings("FutureReturnValueIgnored")
305-
public synchronized void stopTest(boolean now) {
306-
EXECUTOR_SERVICE.submit(new StopTest(now));
308+
public void stopTest(boolean now) {
309+
stopTestLock.lock();
310+
try {
311+
EXECUTOR_SERVICE.submit(new StopTest(now));
312+
} finally {
313+
stopTestLock.unlock();
314+
}
307315
}
308316

309317
private class StopTest implements Runnable {

src/core/src/main/java/org/apache/jmeter/gui/AbstractJMeterGuiComponent.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ public String getStaticLabel() {
388388
@Override
389389
public String getDocAnchor() {
390390
// Ensure we use default bundle
391-
String label = JMeterUtils.getResString(getLabelResource(), new Locale("",""));
391+
String label = JMeterUtils.getResString(getLabelResource(), Locale.ROOT);
392392
return label.replace(' ', '_');
393393
}
394394

src/core/src/main/java/org/apache/jmeter/gui/action/ChangeLanguage.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ public void doActionAfterCheck(ActionEvent e) {
5353

5454
int sep = locale.indexOf('_');
5555
if (sep > 0) {
56-
loc = new Locale(locale.substring(0, sep), locale.substring(sep + 1));
56+
loc = Locale.of(locale.substring(0, sep), locale.substring(sep + 1));
5757
} else {
58-
loc = new Locale(locale, "");
58+
loc = Locale.of(locale);
5959
}
6060
log.debug("Changing locale to {}", loc);
6161
try {

src/core/src/main/java/org/apache/jmeter/testbeans/gui/TestBeanGUI.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public void localeChanged(LocaleChangeEvent event) {
490490
public String getDocAnchor() {
491491
ResourceBundle resourceBundle = ResourceBundle.getBundle(
492492
testBeanClass.getName() + "Resources", // $NON-NLS-1$
493-
new Locale("",""));
493+
Locale.ROOT);
494494

495495
String name = resourceBundle.getString("displayName");
496496
return name.replace(' ', '_');

src/core/src/main/java/org/apache/jmeter/threads/AbstractThreadGroup.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.time.Duration;
2222
import java.util.IdentityHashMap;
2323
import java.util.concurrent.atomic.AtomicInteger;
24+
import java.util.concurrent.locks.ReentrantLock;
2425

2526
import org.apache.jmeter.control.Controller;
2627
import org.apache.jmeter.control.IteratingController;
@@ -50,6 +51,7 @@ public abstract class AbstractThreadGroup extends AbstractTestElement
5051

5152
// Only create the map if it is required
5253
private final transient IdentityHashMap<TestElement, Object> children = new IdentityHashMap<>();
54+
private final transient ReentrantLock childrenLock = new ReentrantLock();
5355

5456
private static final Object DUMMY = new Object();
5557

@@ -166,11 +168,14 @@ public void addTestElement(TestElement child) {
166168
*/
167169
@Override
168170
public final boolean addTestElementOnce(TestElement child){
169-
synchronized (children) {
171+
childrenLock.lock();
172+
try {
170173
if (children.putIfAbsent(child, DUMMY) == null) {
171174
addTestElement(child);
172175
return true;
173176
}
177+
} finally {
178+
childrenLock.unlock();
174179
}
175180
return false;
176181
}

0 commit comments

Comments
 (0)