Skip to content

Commit a9df92b

Browse files
committed
Fix race condition in FileSourceTest regarding test directory creation
1 parent 357d459 commit a9df92b

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

src/test/java/com/arpnetworking/metrics/common/sources/FileSourceTest.java

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
public class FileSourceTest {
5656
@SuppressWarnings("unchecked")
5757
@Before
58-
public void setUp() {
58+
public void setUp() throws IOException {
59+
Files.createDirectories(_directory);
5960
_observer = Mockito.mock(Observer.class);
6061
_parser = Mockito.mock(Parser.class);
6162
_logger = Mockito.mock(Logger.class);
@@ -74,7 +75,6 @@ public void setUp() {
7475

7576
@Test
7677
public void testParseData() throws IOException, InterruptedException, ParsingException {
77-
Files.createDirectories(_directory);
7878
final Path file = _directory.resolve("testParseData.log");
7979
final Path state = _directory.resolve("testParseData.log.state");
8080
Files.deleteIfExists(file);
@@ -107,7 +107,6 @@ public void testParseData() throws IOException, InterruptedException, ParsingExc
107107

108108
@Test
109109
public void testTailFromEnd() throws IOException, InterruptedException, ParsingException {
110-
Files.createDirectories(_directory);
111110
final Path file = _directory.resolve("testTailFromEnd.log");
112111
Files.deleteIfExists(file);
113112
Files.createFile(file);
@@ -193,7 +192,6 @@ public void testTailerFileNotFoundAfterInterval() throws InterruptedException, I
193192

194193
@Test
195194
public void testTailerLogRotationRename() throws IOException, InterruptedException {
196-
Files.createDirectories(_directory);
197195
final Path file = _directory.resolve("testTailerLogRotationRename.log");
198196
final Path state = _directory.resolve("testTailerLogRotationRename.log.state");
199197
Files.deleteIfExists(file);
@@ -223,7 +221,6 @@ public void testTailerLogRotationRename() throws IOException, InterruptedExcepti
223221

224222
@Test
225223
public void testTailerLogRotationRenameSameDataLength() throws IOException, InterruptedException, ParsingException {
226-
Files.createDirectories(_directory);
227224
final Path file = _directory.resolve("testTailerLogRotationRenameSameDataLength.log");
228225
final Path state = _directory.resolve("testTailerLogRotationRenameSameDataLength.log.state");
229226
Files.deleteIfExists(file);
@@ -261,7 +258,6 @@ public void testTailerLogRotationRenameSameDataLength() throws IOException, Inte
261258
@Ignore
262259
@Test
263260
public void testTailerLogRotationRenameFromEmpty() throws IOException, InterruptedException {
264-
Files.createDirectories(_directory);
265261
final Path file = _directory.resolve("testTailerLogRotationRenameFromEmpty.log");
266262
final Path state = _directory.resolve("testTailerLogRotationRenameFromEmpty.log.state");
267263
Files.deleteIfExists(file);
@@ -288,7 +284,6 @@ public void testTailerLogRotationRenameFromEmpty() throws IOException, Interrupt
288284

289285
@Test
290286
public void testTailerLogRotationCopyTruncate() throws IOException, InterruptedException, ParsingException {
291-
Files.createDirectories(_directory);
292287
final Path file = _directory.resolve("testTailerLogRotationCopyTruncate.log");
293288
final Path state = _directory.resolve("testTailerLogRotationCopyTruncate.log.state");
294289
Files.deleteIfExists(file);
@@ -321,7 +316,6 @@ public void testTailerLogRotationCopyTruncate() throws IOException, InterruptedE
321316
@Ignore
322317
@Test
323318
public void testTailerLogRotationCopyTruncateFromEmpty() throws IOException, InterruptedException {
324-
Files.createDirectories(_directory);
325319
final Path file = _directory.resolve("testTailerLogRotationCopyTruncate.log");
326320
final Path state = _directory.resolve("testTailerLogRotationCopyTruncate.log.state");
327321
Files.deleteIfExists(file);
@@ -349,7 +343,6 @@ public void testTailerLogRotationCopyTruncateFromEmpty() throws IOException, Int
349343

350344
@Test
351345
public void testTailerLogRotationRenameWithData() throws IOException, InterruptedException, ParsingException {
352-
Files.createDirectories(_directory);
353346
final Path file = _directory.resolve("testTailerLogRotationRenameWithData.log");
354347
final Path state = _directory.resolve("testTailerLogRotationRenameWithData.log.state");
355348
Files.deleteIfExists(file);
@@ -394,7 +387,6 @@ public void testTailerLogRotationRenameWithData() throws IOException, Interrupte
394387
public void testTailerLogRotationCopyTruncateWithData() throws IOException, InterruptedException, ParsingException {
395388
final long interval = 500;
396389
final long sleepInterval = 600;
397-
Files.createDirectories(_directory);
398390
final Path file = _directory.resolve("testTailerLogRotationCopyTruncateWithData.log");
399391
final Path state = _directory.resolve("testTailerLogRotationCopyTruncateWithData.log.state");
400392
Files.deleteIfExists(file);
@@ -434,7 +426,6 @@ public void testTailerLogRotationCopyTruncateWithData() throws IOException, Inte
434426

435427
@Test
436428
public void testTailerLogRotationRenameWithDataToOldAndNew() throws IOException, InterruptedException, ParsingException {
437-
Files.createDirectories(_directory);
438429
final Path file = _directory.resolve("testTailerLogRotationRenameWithDataToOldAndNew.log");
439430
final Path state = _directory.resolve("testTailerLogRotationRenameWithDataToOldAndNew.log.state");
440431
Files.deleteIfExists(file);
@@ -501,7 +492,6 @@ public void testTailerLogRotationRenameWithDataToOldAndNew() throws IOException,
501492
@Test
502493
public void testTailerLogRotationCopyTruncateWithDataToOldAndNew() throws IOException, InterruptedException, ParsingException {
503494
final long interval = 500;
504-
Files.createDirectories(_directory);
505495
final Path file = _directory.resolve("testTailerLogRotationCopyTruncateWithDataToOldAndNew.log");
506496
final Path state = _directory.resolve("testTailerLogRotationCopyTruncateWithDataToOldAndNew.log.state");
507497
Files.deleteIfExists(file);
@@ -561,7 +551,6 @@ public void testTailerLogRotationCopyTruncateWithDataToOldAndNew() throws IOExce
561551
@SuppressWarnings("unchecked")
562552
@Test
563553
public void testTailerLogRotationRenameDroppedData() throws IOException, InterruptedException, ParsingException {
564-
Files.createDirectories(_directory);
565554
final Path file = _directory.resolve("testTailerLogRotationRenameDroppedData.log");
566555
final Path state = _directory.resolve("testTailerLogRotationRenameDroppedData.log.state");
567556
Files.deleteIfExists(file);
@@ -639,7 +628,6 @@ public void testTailerLogRotationRenameDroppedData() throws IOException, Interru
639628
public void testTailerLogCopyTruncateRenameDroppedData() throws IOException, InterruptedException, ParsingException {
640629
final long interval = 500;
641630
final long sleepInterval = 600;
642-
Files.createDirectories(_directory);
643631
final Path file = _directory.resolve("testTailerLogCopyTruncateRenameDroppedData.log");
644632
final Path state = _directory.resolve("testTailerLogCopyTruncateRenameDroppedData.log.state");
645633
Files.deleteIfExists(file);
@@ -708,7 +696,6 @@ public void testTailerLogCopyTruncateRenameDroppedData() throws IOException, Int
708696
@SuppressWarnings("unchecked")
709697
@Test
710698
public void testTailerLogRotationRenameSmallToLarge() throws IOException, InterruptedException, ParsingException {
711-
Files.createDirectories(_directory);
712699
final Path file = _directory.resolve("testTailerLogRotationRenameSmallToLarge.log");
713700
final Path state = _directory.resolve("testTailerLogRotationRenameSmallToLarge.log.state");
714701
Files.deleteIfExists(file);
@@ -779,7 +766,6 @@ public void testTailerLogRotationRenameSmallToLarge() throws IOException, Interr
779766
@Test
780767
public void testTailerLogRotationCopyTruncateSmallToLarge() throws IOException, InterruptedException, ParsingException {
781768
final long sleepInterval = 600;
782-
Files.createDirectories(_directory);
783769
final Path file = _directory.resolve("testTailerLogRotationCopyTruncateSmallToLarge.log");
784770
final Path state = _directory.resolve("testTailerLogRotationCopyTruncateSmallToLarge.log.state");
785771
Files.deleteIfExists(file);

0 commit comments

Comments
 (0)