Skip to content

Commit 6a8b0bb

Browse files
committed
revert some
1 parent 6774954 commit 6a8b0bb

File tree

2 files changed

+39
-11
lines changed

2 files changed

+39
-11
lines changed

test-common/test-common-runtime/src/main/java/org/apache/kafka/common/test/TestUtils.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,15 @@
4040

4141
import static java.lang.String.format;
4242

43-
public class TestUtils {
43+
/**
44+
* Helper functions for writing unit tests.
45+
* <p>
46+
* <b>Package-private:</b> Not intended for use outside {@code org.apache.kafka.common.test}.
47+
*/
48+
class TestUtils {
4449
private static final Logger log = LoggerFactory.getLogger(TestUtils.class);
4550

51+
/* A consistent random number generator to make tests repeatable */
4652
public static final Random SEEDED_RANDOM = new Random(192348092834L);
4753

4854
public static final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
@@ -53,20 +59,34 @@ public class TestUtils {
5359
private static final long DEFAULT_MAX_WAIT_MS = 15_000;
5460
private static final Random RANDOM = new Random();
5561

62+
/**
63+
* Create an empty file in the default temporary-file directory, using `kafka` as the prefix and `tmp` as the
64+
* suffix to generate its name.
65+
*/
5666
public static File tempFile() throws IOException {
5767
final File file = Files.createTempFile("kafka", ".tmp").toFile();
5868
file.deleteOnExit();
5969
return file;
6070
}
6171

72+
/**
73+
* Generate a random string of letters and digits of the given length
74+
*
75+
* @param len The length of the string
76+
* @return The random string
77+
*/
6278
public static String randomString(final int len) {
6379
final StringBuilder b = new StringBuilder();
6480
for (int i = 0; i < len; i++)
6581
b.append(LETTERS_AND_DIGITS.charAt(SEEDED_RANDOM.nextInt(LETTERS_AND_DIGITS.length())));
6682
return b.toString();
6783
}
6884

69-
public static File tempDirectory() {
85+
/**
86+
* Create a temporary relative directory in the specified parent directory with the given prefix.
87+
*
88+
*/
89+
static File tempDirectory() {
7090
final File file;
7191
String prefix = "kafka-";
7292
try {
@@ -86,17 +106,19 @@ public static File tempDirectory() {
86106
return file;
87107
}
88108

89-
public static File tempRelativeDir(String parent) {
90-
File file = new File(parent, "kafka-" + SEEDED_RANDOM.nextInt(1000000));
91-
file.mkdirs();
92-
file.deleteOnExit();
93-
return file;
94-
}
95-
109+
/**
110+
* uses default value of 15 seconds for timeout
111+
*/
96112
public static void waitForCondition(final Supplier<Boolean> testCondition, final String conditionDetails) throws InterruptedException {
97113
waitForCondition(testCondition, DEFAULT_MAX_WAIT_MS, () -> conditionDetails);
98114
}
99115

116+
/**
117+
* Wait for condition to be met for at most {@code maxWaitMs} and throw assertion failure otherwise.
118+
* This should be used instead of {@code Thread.sleep} whenever possible as it allows a longer timeout to be used
119+
* without unnecessarily increasing test time (as the condition is checked frequently). The longer timeout is needed to
120+
* avoid transient failures due to slow or overloaded machines.
121+
*/
100122
public static void waitForCondition(final Supplier<Boolean> testCondition,
101123
final long maxWaitMs,
102124
final Supplier<String> conditionDetails) throws InterruptedException {
@@ -122,6 +144,12 @@ public static void waitForCondition(final Supplier<Boolean> testCondition,
122144
}
123145
}
124146

147+
/**
148+
* Wait for condition to be met for at most {@code maxWaitMs} and throw assertion failure otherwise.
149+
* This should be used instead of {@code Thread.sleep} whenever possible as it allows a longer timeout to be used
150+
* without unnecessarily increasing test time (as the condition is checked frequently). The longer timeout is needed to
151+
* avoid transient failures due to slow or overloaded machines.
152+
*/
125153
public static void waitForCondition(final Supplier<Boolean> testCondition,
126154
final long maxWaitMs,
127155
String conditionDetails) throws InterruptedException {

test-common/test-common-runtime/src/main/resources/log4j2.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ Configuration:
2727

2828
Loggers:
2929
Root:
30-
level: DEBUG
30+
level: INFO
3131
AppenderRef:
3232
- ref: STDOUT
3333
Logger:
3434
- name: org.apache.kafka
35-
level: DEBUG
35+
level: INFO

0 commit comments

Comments
 (0)