Skip to content

Commit 6eb4fa0

Browse files
committed
Give test threads better names for debugging
1 parent b44a564 commit 6eb4fa0

5 files changed

Lines changed: 21 additions & 21 deletions

File tree

src/main/java/org/apache/commons/io/FileCleaningTracker.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ private final class Reaper extends Thread {
5454

5555
/** Constructs a new Reaper */
5656
Reaper() {
57-
super("File Reaper");
57+
super("commons-io-FileCleaningTracker-Reaper");
5858
setPriority(MAX_PRIORITY);
5959
setDaemon(true);
6060
}

src/test/java/org/apache/commons/io/FileUtilsWaitForTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void testIO_488() throws InterruptedException {
4848
// This will wait (assuming the file is not found)
4949
assertFalse(FileUtils.waitFor(NOSUCHFILE, seconds), "Should not find file");
5050
wasInterrupted.set(Thread.currentThread().isInterrupted());
51-
});
51+
}, "commos-io-Test-IO-488-Thread");
5252
thread1.start();
5353
Thread.sleep(500); // This should be enough to ensure the waitFor loop has been entered
5454
thread1.interrupt(); // Try to interrupt waitFor

src/test/java/org/apache/commons/io/input/QueueInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ void testTimeoutInterrupted() throws Exception {
326326
assertTrue(Thread.currentThread().isInterrupted());
327327
result.set(true);
328328
latch.countDown();
329-
});
329+
}, "commons-io-QueueInputStreamTest-testTimeoutInterrupted");
330330
thread.setDaemon(true);
331331
thread.start();
332332

src/test/java/org/apache/commons/io/input/TailerTest.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ void testBufferBreak() throws Exception {
239239
writeStrings(file, data);
240240
final TestTailerListener listener = new TestTailerListener();
241241
try (Tailer tailer = new Tailer(file, listener, delay, false, 1)) {
242-
final Thread thread = new Thread(tailer);
242+
final Thread thread = new Thread(tailer, "commons-io-tailer-testBufferBreak");
243243
thread.start();
244244
List<String> lines = listener.getLines();
245245
assertEquals(data.length(), tailer.getTailable().size());
@@ -347,7 +347,7 @@ void testInterrupt() throws Exception {
347347
final int delay = 1000;
348348
final int idle = 50; // allow time for thread to work
349349
try (Tailer tailer = new Tailer(file, listener, delay, false, IOUtils.DEFAULT_BUFFER_SIZE)) {
350-
final Thread thread = new Thread(tailer);
350+
final Thread thread = new Thread(tailer, "commons-io-tailer-testInterrupt");
351351
thread.setDaemon(true);
352352
thread.start();
353353
TestUtils.sleep(idle);
@@ -370,7 +370,7 @@ void testIO335() throws Exception { // test CR behavior
370370
createFile(file, 0);
371371
final TestTailerListener listener = new TestTailerListener();
372372
try (Tailer tailer = new Tailer(file, listener, delayMillis, false)) {
373-
final Thread thread = new Thread(tailer);
373+
final Thread thread = new Thread(tailer, "commons-io-tailer-testIO335");
374374
thread.start();
375375

376376
// Write some lines to the file
@@ -400,7 +400,7 @@ void testLongFile() throws Exception {
400400
final TestTailerListener listener = new TestTailerListener();
401401
try (Tailer tailer = new Tailer(file, listener, delay, false)) {
402402
// final long start = System.currentTimeMillis();
403-
final Thread thread = new Thread(tailer);
403+
final Thread thread = new Thread(tailer, "commons-io-tailer-testLongFile");
404404
thread.start();
405405
List<String> lines = listener.getLines();
406406
while (lines.isEmpty() || !lines.get(lines.size() - 1).equals("SBTOURIST")) {
@@ -425,7 +425,7 @@ void testMultiByteBreak() throws Exception {
425425
// Need to use UTF-8 to read & write the file otherwise it can be corrupted (depending on the default charset)
426426
final Charset charsetUTF8 = StandardCharsets.UTF_8;
427427
try (Tailer tailer = new Tailer(file, charsetUTF8, listener, delay, false, isWindows, IOUtils.DEFAULT_BUFFER_SIZE)) {
428-
final Thread thread = new Thread(tailer);
428+
final Thread thread = new Thread(tailer, "commons-io-tailer-testMultiByteBreak");
429429
thread.start();
430430
try (Writer out = new OutputStreamWriter(Files.newOutputStream(file.toPath()), charsetUTF8);
431431
BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(origin.toPath()), charsetUTF8))) {
@@ -458,7 +458,7 @@ void testSimpleConstructor() throws Exception {
458458
createFile(file, 0);
459459
final TestTailerListener listener = new TestTailerListener(1);
460460
try (Tailer tailer = new Tailer(file, listener)) {
461-
final Thread thread = new Thread(tailer);
461+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructor");
462462
thread.start();
463463
validateTailer(listener, file);
464464
}
@@ -470,7 +470,7 @@ void testSimpleConstructorWithDelay() throws Exception {
470470
createFile(file, 0);
471471
final TestTailerListener listener = new TestTailerListener(1);
472472
try (Tailer tailer = new Tailer(file, listener, TEST_DELAY_MILLIS)) {
473-
final Thread thread = new Thread(tailer);
473+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructorWithDelay");
474474
thread.start();
475475
validateTailer(listener, file);
476476
}
@@ -482,7 +482,7 @@ void testSimpleConstructorWithDelayAndFromStart() throws Exception {
482482
createFile(file, 0);
483483
final TestTailerListener listener = new TestTailerListener(1);
484484
try (Tailer tailer = new Tailer(file, listener, TEST_DELAY_MILLIS, false)) {
485-
final Thread thread = new Thread(tailer);
485+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructorWithDelayAndFromStart");
486486
thread.start();
487487
validateTailer(listener, file);
488488
}
@@ -494,7 +494,7 @@ void testSimpleConstructorWithDelayAndFromStartWithBufferSize() throws Exception
494494
createFile(file, 0);
495495
final TestTailerListener listener = new TestTailerListener(1);
496496
try (Tailer tailer = new Tailer(file, listener, TEST_DELAY_MILLIS, false, TEST_BUFFER_SIZE)) {
497-
final Thread thread = new Thread(tailer);
497+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructorWithDelayAndFromStartWithBufferSize");
498498
thread.start();
499499
validateTailer(listener, file);
500500
}
@@ -506,7 +506,7 @@ void testSimpleConstructorWithDelayAndFromStartWithReopen() throws Exception {
506506
createFile(file, 0);
507507
final TestTailerListener listener = new TestTailerListener(1);
508508
try (Tailer tailer = new Tailer(file, listener, TEST_DELAY_MILLIS, false, false)) {
509-
final Thread thread = new Thread(tailer);
509+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructorWithDelayAndFromStartWithReopen");
510510
thread.start();
511511
validateTailer(listener, file);
512512
}
@@ -518,7 +518,7 @@ void testSimpleConstructorWithDelayAndFromStartWithReopenAndBufferSize() throws
518518
createFile(file, 0);
519519
final TestTailerListener listener = new TestTailerListener(1);
520520
try (Tailer tailer = new Tailer(file, listener, TEST_DELAY_MILLIS, false, true, TEST_BUFFER_SIZE)) {
521-
final Thread thread = new Thread(tailer);
521+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructorWithDelayAndFromStartWithReopenAndBufferSize");
522522
thread.start();
523523
validateTailer(listener, file);
524524
}
@@ -530,7 +530,7 @@ void testSimpleConstructorWithDelayAndFromStartWithReopenAndBufferSizeAndCharset
530530
createFile(file, 0);
531531
final TestTailerListener listener = new TestTailerListener(1);
532532
try (Tailer tailer = new Tailer(file, StandardCharsets.UTF_8, listener, TEST_DELAY_MILLIS, false, true, TEST_BUFFER_SIZE)) {
533-
final Thread thread = new Thread(tailer);
533+
final Thread thread = new Thread(tailer, "commons-io-tailer-testSimpleConstructorWithDelayAndFromStartWithReopenAndBufferSizeAndCharset");
534534
thread.start();
535535
validateTailer(listener, file);
536536
}
@@ -587,7 +587,7 @@ void testTailer() throws Exception {
587587
final String osname = SystemProperties.getOsName();
588588
final boolean isWindows = osname.startsWith("Windows");
589589
try (Tailer tailer = new Tailer(file, listener, delayMillis, false, isWindows)) {
590-
final Thread thread = new Thread(tailer);
590+
final Thread thread = new Thread(tailer, "commons-io-tailer-testTailer");
591591
thread.start();
592592
// Write some lines to the file
593593
writeLines(file, "Line one", "Line two");
@@ -649,7 +649,7 @@ void testTailerEndOfFileReached() throws Exception {
649649
final String osname = SystemProperties.getOsName();
650650
final boolean isWindows = osname.startsWith("Windows");
651651
try (Tailer tailer = new Tailer(file, listener, delayMillis, false, isWindows)) {
652-
final Thread thread = new Thread(tailer);
652+
final Thread thread = new Thread(tailer, "commons-io-tailer-testTailerEndOfFileReached");
653653
thread.start();
654654
// write a few lines
655655
writeLines(file, "line1", "line2", "line3");
@@ -673,7 +673,7 @@ void testTailerEof() throws Exception {
673673
createFile(file, 0);
674674
final TestTailerListener listener = new TestTailerListener();
675675
try (Tailer tailer = new Tailer(file, listener, delayMillis, false)) {
676-
final Thread thread = new Thread(tailer);
676+
final Thread thread = new Thread(tailer, "commons-io-tailer-testTailerEof");
677677
thread.start();
678678
// Write some lines to the file
679679
writeStrings(file, "Line");
@@ -698,7 +698,7 @@ void testTailerIgnoreTouch() throws Exception {
698698
final TestTailerListener listener = new TestTailerListener();
699699
try (Tailer tailer = Tailer.builder().setFile(file).setTailerListener(listener).setDelayDuration(Duration.ofMillis(delayMillis)).setStartThread(false)
700700
.setIgnoreTouch(true).get()) {
701-
final Thread thread = new Thread(tailer);
701+
final Thread thread = new Thread(tailer, "commons-io-tailer-testTailerIgnoreTouch");
702702
thread.start();
703703
// Write some lines to the file
704704
writeLines(file, "Line one");
@@ -724,7 +724,7 @@ void testTailerReissueOnTouch() throws Exception {
724724
final TestTailerListener listener = new TestTailerListener();
725725
try (Tailer tailer = Tailer.builder().setFile(file).setTailerListener(listener).setDelayDuration(Duration.ofMillis(delayMillis)).setStartThread(false)
726726
.setIgnoreTouch(false).get()) {
727-
final Thread thread = new Thread(tailer);
727+
final Thread thread = new Thread(tailer, "commons-io-tailer-testTailerReissueOnTouch");
728728
thread.start();
729729
// Write some lines to the file
730730
writeLines(file, "Line one");

src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public int read(final byte[] buf, final int offset, final int length) {
148148
} catch (final Exception e) {
149149
// Ignored
150150
}
151-
});
151+
}, "commons-io-UnsynchronizedBufferedInputStream-close");
152152
thread.start();
153153
assertThrows(IOException.class, () -> bufin.read(new byte[100], 0, 99), "Should throw IOException");
154154
}

0 commit comments

Comments
 (0)