Skip to content

Commit 8ae9eb8

Browse files
committed
More Sonar fixes
1 parent 31a550e commit 8ae9eb8

File tree

4 files changed

+22
-13
lines changed

4 files changed

+22
-13
lines changed

pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,16 @@
223223

224224
<build>
225225

226+
<pluginManagement>
227+
<plugins>
228+
<plugin>
229+
<groupId>org.sonarsource.scanner.maven</groupId>
230+
<artifactId>sonar-maven-plugin</artifactId>
231+
<version>3.5.0.1254</version>
232+
</plugin>
233+
</plugins>
234+
</pluginManagement>
235+
226236
<resources>
227237
<resource>
228238
<directory>src/main/resources</directory>

src/main/java/com/rabbitmq/perf/AgentBase.java

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

1818
import com.rabbitmq.client.MissedHeartbeatException;
1919
import com.rabbitmq.client.ShutdownSignalException;
20+
import com.rabbitmq.client.impl.recovery.AutorecoveringConnection;
2021
import org.slf4j.Logger;
2122
import org.slf4j.LoggerFactory;
2223

@@ -31,11 +32,6 @@ public abstract class AgentBase {
3132

3233
private static final Logger LOGGER = LoggerFactory.getLogger(AgentBase.class);
3334

34-
// FIXME this is the condition to start connection recovery
35-
// ensure it's the appropriate condition and get it from the Java client code
36-
static final Predicate<ShutdownSignalException> CONNECTION_RECOVERY_TRIGGERED =
37-
e -> !e.isInitiatedByApplication() || (e.getCause() instanceof MissedHeartbeatException);
38-
3935
protected void delay(long now, AgentState state) {
4036

4137
long elapsed = now - state.getLastStatsTime();
@@ -56,7 +52,7 @@ protected void delay(long now, AgentState state) {
5652
}
5753

5854
protected boolean isConnectionRecoveryTriggered(ShutdownSignalException e) {
59-
return CONNECTION_RECOVERY_TRIGGERED.test(e);
55+
return AutorecoveringConnection.DEFAULT_CONNECTION_RECOVERY_TRIGGERING_CONDITION.test(e);
6056
}
6157

6258
protected void handleShutdownSignalExceptionOnWrite(Recovery.RecoveryProcess recoveryProcess, ShutdownSignalException e) {

src/main/java/com/rabbitmq/perf/PerfTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,12 @@ public static void main(String [] args, PerfTestOptions perfTestOptions) {
164164
if (outputFile != null) {
165165
File file = new File(outputFile);
166166
if (file.exists()) {
167-
file.delete();
167+
boolean deleted = file.delete();
168+
if (!deleted) {
169+
LOGGER.warn("Could not delete existing CSV file, will try to append at the end of the file");
170+
}
168171
}
169-
output = new PrintWriter(new BufferedWriter(new FileWriter(file)), true); //NOSONAR
172+
output = new PrintWriter(new BufferedWriter(new FileWriter(file, true)), true); //NOSONAR
170173
Runtime.getRuntime().addShutdownHook(new Thread(() -> output.close()));
171174
} else {
172175
output = null;
@@ -288,7 +291,7 @@ public static void main(String [] args, PerfTestOptions perfTestOptions) {
288291
usage(options);
289292
} catch (Exception e) {
290293
System.err.println("Main thread caught exception: " + e);
291-
e.printStackTrace();
294+
LOGGER.error("Main thread caught exception", e);
292295
systemExiter.exit(1);
293296
} finally {
294297
if (metrics != null) {
@@ -803,10 +806,10 @@ public void exit(int status) {
803806

804807
}
805808

806-
public static Function<String, String> LONG_OPTION_TO_ENVIRONMENT_VARIABLE = option ->
809+
static final Function<String, String> LONG_OPTION_TO_ENVIRONMENT_VARIABLE = option ->
807810
option.replace('-', '_').toUpperCase(Locale.ENGLISH);
808811

809-
public static Function<String, String> ENVIRONMENT_VARIABLE_PREFIX = name -> {
812+
private static final Function<String, String> ENVIRONMENT_VARIABLE_PREFIX = name -> {
810813
String prefix = System.getenv("RABBITMQ_PERF_TEST_ENV_PREFIX");
811814
if (prefix == null || prefix.trim().isEmpty()) {
812815
return name;
@@ -818,6 +821,6 @@ public void exit(int status) {
818821
}
819822
};
820823

821-
static Function<String, String> ENVIRONMENT_VARIABLE_LOOKUP = name -> System.getenv(name);
824+
private static final Function<String, String> ENVIRONMENT_VARIABLE_LOOKUP = name -> System.getenv(name);
822825

823826
}

src/main/java/com/rabbitmq/perf/Recovery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void handleRecovery(Recoverable recoverable) {
8888
}
8989
});
9090
connection.addShutdownListener(cause -> {
91-
if (AgentBase.CONNECTION_RECOVERY_TRIGGERED.test(cause)) {
91+
if (AutorecoveringConnection.DEFAULT_CONNECTION_RECOVERY_TRIGGERING_CONDITION.test(cause)) {
9292
LOGGER.debug("Setting recovery in progress flag for connection {}", connection.getClientProvidedName());
9393
recoveryInProgress.set(true);
9494
}

0 commit comments

Comments
 (0)