Skip to content

Commit a768a7b

Browse files
committed
Format
1 parent 8be5f90 commit a768a7b

File tree

3 files changed

+66
-61
lines changed

3 files changed

+66
-61
lines changed
Lines changed: 56 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// Copyright (c) 2018-2023 Broadcom. All Rights Reserved. The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
1+
// Copyright (c) 2018-2023 Broadcom. All Rights Reserved.
2+
// The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries.
23
//
34
// This software, the RabbitMQ Java client library, is triple-licensed under the
45
// Mozilla Public License 2.0 ("MPL"), the GNU General Public License version 2
@@ -12,77 +13,75 @@
1213
//
1314
// If you have any questions regarding licensing, please contact us at
1415
15-
1616
package com.rabbitmq.perf;
1717

1818
import ch.qos.logback.classic.LoggerContext;
1919
import ch.qos.logback.classic.joran.JoranConfigurator;
2020
import ch.qos.logback.core.joran.spi.JoranException;
2121
import ch.qos.logback.core.util.StatusPrinter;
22-
import org.slf4j.LoggerFactory;
23-
2422
import java.io.*;
2523
import java.nio.charset.StandardCharsets;
2624
import java.util.Map;
25+
import org.slf4j.LoggerFactory;
2726

28-
/**
29-
* Configure logback.
30-
*/
27+
/** Configure logback. */
3128
public class Log {
3229

33-
public static void configureLog() throws IOException {
34-
if (System.getProperty("logback.configurationFile") == null) {
35-
String loggers = System.getProperty("rabbitmq.perftest.loggers") == null ?
36-
System.getenv("RABBITMQ_PERF_TEST_LOGGERS") :
37-
System.getProperty("rabbitmq.perftest.loggers");
38-
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
39-
InputStream configurationFile = PerfTest.class.getResourceAsStream("/logback-perf-test.xml");
40-
try {
41-
String configuration = processConfigurationFile(configurationFile, PerfTest.convertKeyValuePairs(loggers));
42-
JoranConfigurator configurator = new JoranConfigurator();
43-
configurator.setContext(context);
44-
context.reset();
45-
configurator.doConfigure(new ByteArrayInputStream(
46-
configuration.getBytes(StandardCharsets.UTF_8)
47-
));
48-
} catch (JoranException je) {
49-
// StatusPrinter will handle this
50-
} finally {
51-
configurationFile.close();
52-
}
53-
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
54-
}
30+
public static void configureLog() throws IOException {
31+
if (System.getProperty("logback.configurationFile") == null) {
32+
String loggers =
33+
System.getProperty("rabbitmq.perftest.loggers") == null
34+
? System.getenv("RABBITMQ_PERF_TEST_LOGGERS")
35+
: System.getProperty("rabbitmq.perftest.loggers");
36+
LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
37+
InputStream configurationFile = PerfTest.class.getResourceAsStream("/logback-perf-test.xml");
38+
try {
39+
String configuration =
40+
processConfigurationFile(configurationFile, PerfTest.convertKeyValuePairs(loggers));
41+
JoranConfigurator configurator = new JoranConfigurator();
42+
configurator.setContext(context);
43+
context.reset();
44+
configurator.doConfigure(
45+
new ByteArrayInputStream(configuration.getBytes(StandardCharsets.UTF_8)));
46+
} catch (JoranException je) {
47+
// StatusPrinter will handle this
48+
} finally {
49+
configurationFile.close();
50+
}
51+
StatusPrinter.printInCaseOfErrorsOrWarnings(context);
5552
}
53+
}
5654

57-
/**
58-
* @param configurationFile
59-
* @param loggers
60-
* @return
61-
* @throws IOException
62-
* @since 2.11.0
63-
*/
64-
static String processConfigurationFile(InputStream configurationFile, Map<String, Object> loggers) throws IOException {
65-
StringBuilder loggersConfiguration = new StringBuilder();
66-
if (loggers != null) {
67-
for (Map.Entry<String, Object> logger : loggers.entrySet()) {
68-
loggersConfiguration.append(String.format(
69-
"\t<logger name=\"%s\" level=\"%s\" />%s",
70-
logger.getKey(), logger.getValue().toString(), System.getProperty("line.separator")
71-
));
72-
}
73-
}
74-
75-
BufferedReader in = new BufferedReader(new InputStreamReader(configurationFile));
76-
final int bufferSize = 1024;
77-
final char[] buffer = new char[bufferSize];
78-
StringBuilder builder = new StringBuilder();
79-
int charsRead;
80-
while ((charsRead = in.read(buffer, 0, buffer.length)) > 0) {
81-
builder.append(buffer, 0, charsRead);
82-
}
83-
84-
return builder.toString().replace("${loggers}", loggersConfiguration);
55+
/**
56+
* @param configurationFile
57+
* @param loggers
58+
* @return
59+
* @throws IOException
60+
* @since 2.11.0
61+
*/
62+
static String processConfigurationFile(InputStream configurationFile, Map<String, Object> loggers)
63+
throws IOException {
64+
StringBuilder loggersConfiguration = new StringBuilder();
65+
if (loggers != null) {
66+
for (Map.Entry<String, Object> logger : loggers.entrySet()) {
67+
loggersConfiguration.append(
68+
String.format(
69+
"\t<logger name=\"%s\" level=\"%s\" />%s",
70+
logger.getKey(),
71+
logger.getValue().toString(),
72+
System.getProperty("line.separator")));
73+
}
8574
}
8675

76+
BufferedReader in = new BufferedReader(new InputStreamReader(configurationFile));
77+
final int bufferSize = 1024;
78+
final char[] buffer = new char[bufferSize];
79+
StringBuilder builder = new StringBuilder();
80+
int charsRead;
81+
while ((charsRead = in.read(buffer, 0, buffer.length)) > 0) {
82+
builder.append(buffer, 0, charsRead);
83+
}
8784

85+
return builder.toString().replace("${loggers}", loggersConfiguration);
86+
}
8887
}

src/test/java/com/rabbitmq/perf/TestUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ static int randomNetworkPort() throws IOException {
4545
return port;
4646
}
4747

48-
public static void waitAtMost(int timeoutInSeconds, BooleanSupplier condition) throws InterruptedException {
48+
public static void waitAtMost(int timeoutInSeconds, BooleanSupplier condition)
49+
throws InterruptedException {
4950
waitAtMost(timeoutInSeconds, condition, null);
5051
}
5152

52-
public static void waitAtMost(int timeoutInSeconds, BooleanSupplier condition, Supplier<String> message)
53+
public static void waitAtMost(
54+
int timeoutInSeconds, BooleanSupplier condition, Supplier<String> message)
5355
throws InterruptedException {
5456
if (condition.getAsBoolean()) {
5557
return;

src/test/java/com/rabbitmq/perf/it/ConnectionRecoveryIT.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,12 @@ public void shouldRecoverWhenConnectionsAreKilledAndUsingPublishingInterval(
289289
long messageCountBeforeClosing = msgConsumed.get();
290290
closeAllConnections();
291291
long expectedMessageCount = 2 * messageCountBeforeClosing;
292-
waitAtMost(20, () -> msgConsumed.get() >= expectedMessageCount,
293-
() -> String.format("Expecting at least %d messages, got %d", expectedMessageCount, msgConsumed.get()));
292+
waitAtMost(
293+
20,
294+
() -> msgConsumed.get() >= expectedMessageCount,
295+
() ->
296+
String.format(
297+
"Expecting at least %d messages, got %d", expectedMessageCount, msgConsumed.get()));
294298
assertThat(testIsDone.get()).isFalse();
295299
}
296300

0 commit comments

Comments
 (0)