Skip to content
Permalink
Browse files
Further silence error prone warnings
Replace JdkObsolete with JavaUtilDate where we can't replace usage of new Date()
Use Instant and other newer APIs from java.time, where we can replace Date() without
changing our API.

Part of #708
  • Loading branch information
FSchumacher committed Apr 13, 2022
1 parent 9362e18 commit aa13ae939f681590d4d2a8b99b3163b53cefdc0f
Showing 5 changed files with 41 additions and 15 deletions.
@@ -22,11 +22,15 @@
import java.io.PrintStream;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Properties;

@@ -116,15 +120,23 @@ public void init(List<String> addresses, HashTree tree) {
}
}

private static String formatLikeDate(Instant instant) {
return DateTimeFormatter
.ofLocalizedDateTime(FormatStyle.LONG)
.withLocale(Locale.ROOT)
.withZone(ZoneId.systemDefault())
.format(instant);
}

/**
* Starts a remote testing engines
*
* @param addresses list of the DNS names or IP addresses of the remote testing engines
*/
@SuppressWarnings("JdkObsolete")
public void start(List<String> addresses) {
long now = System.currentTimeMillis();
println("Starting distributed test with remote engines: " + addresses + " @ " + new Date(now) + " (" + now + ")");
Instant now = Instant.now();
println("Starting distributed test with remote engines: "
+ addresses + " @ " + formatLikeDate(now) + " (" + now.toEpochMilli() + ')');
List<String> startedEngines = new ArrayList<>(addresses.size());
List<String> failedEngines = new ArrayList<>(addresses.size());
for (String address : addresses) {
@@ -17,10 +17,14 @@

package org.apache.jmeter.engine;

import java.time.Instant;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Properties;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.TimeUnit;
@@ -171,11 +175,12 @@ public void configure(HashTree testTree) {
}

@Override
@SuppressWarnings("JdkObsolete")
public void runTest() throws JMeterEngineException {
if (host != null){
long now=System.currentTimeMillis();
System.out.println("Starting the test on host " + host + " @ "+new Date(now)+" ("+now+")"); // NOSONAR Intentional
Instant now = Instant.now();
String nowAsString = formatLikeDate(now);
System.out.println("Starting the test on host " // NOSONAR Intentional
+ host + " @ " + nowAsString + " (" + now.toEpochMilli() + ')');
}
try {
Thread runningThread = new Thread(this, "StandardJMeterEngine");
@@ -186,6 +191,14 @@ public void runTest() throws JMeterEngineException {
}
}

private String formatLikeDate(Instant instant) {
return DateTimeFormatter
.ofLocalizedDateTime(FormatStyle.LONG)
.withLocale(Locale.ROOT)
.withZone(ZoneId.systemDefault())
.format(instant);
}

private void removeThreadGroups(List<?> elements) {
Iterator<?> iter = elements.iterator();
while (iter.hasNext()) { // Can't use for loop here because we remove elements
@@ -209,7 +222,6 @@ private void notifyTestListenersOfStart(SearchByClass<TestStateListener> testLis
}
}

@SuppressWarnings("JdkObsolete")
private void notifyTestListenersOfEnd(SearchByClass<TestStateListener> testListeners) {
log.info("Notifying test listeners of end of test");
for (TestStateListener tl : testListeners.getSearchResults()) {
@@ -225,8 +237,10 @@ private void notifyTestListenersOfEnd(SearchByClass<TestStateListener> testListe
}
if (host != null) {
log.info("Test has ended on host {} ", host);
long now=System.currentTimeMillis();
System.out.println("Finished the test on host " + host + " @ "+new Date(now)+" ("+now+")" // NOSONAR Intentional
Instant now = Instant.now();
String nowAsString = formatLikeDate(now);
System.out.println("Finished the test on host " // NOSONAR Intentional
+ host + " @ " + nowAsString + " (" + now.toEpochMilli() + ')'
+(EXIT_AFTER_TEST ? " - exit requested." : ""));
if (EXIT_AFTER_TEST){
exit();
@@ -93,7 +93,7 @@ public JDateField(Date date) {
}

// Dummy constructor to allow JUnit tests to work
@SuppressWarnings("JdkObsolete")
@SuppressWarnings("JavaUtilDate")
public JDateField() {
this(new Date());
}
@@ -113,7 +113,7 @@ public void setDate(Date date) {
*
* @return The currently set date
*/
@SuppressWarnings("JdkObsolete")
@SuppressWarnings("JavaUtilDate")
public Date getDate() {
try {
return dateFormat.parse(getText());
@@ -208,7 +208,7 @@ public long getStartTime() {
* @return the start time using the specified format
* Intended for use from Functors
*/
@SuppressWarnings("JdkObsolete")
@SuppressWarnings("JavaUtilDate")
public String getStartTimeFormatted(Format format) {
return format.format(new Date(getStartTime()));
}
@@ -107,7 +107,7 @@ public long getStartTime() {
* @return the start time using the specified format
* Intended for use from Functors
*/
@SuppressWarnings("JdkObsolete")
@SuppressWarnings("JavaUtilDate")
public String getStartTimeFormatted(Format format) {
return format.format(new Date(getStartTime()));
}

0 comments on commit aa13ae9

Please sign in to comment.