Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ open class FileEventStream(
}
}

override fun read(): List<String> = (directory.listFiles() ?: emptyArray()).map { it.absolutePath }
override fun read(): List<String> = directory.walk()
.maxDepth(1)
.filter { it.isFile }
.take(1000)
.map { it.absolutePath }
.toList()

/**
* Remove the given file from disk
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,5 +266,43 @@ class EventStreamTest {
assertEquals("test", files[0])
assertFalse(eventStream.isOpened)
}

@Test
fun readLimitsTo1000FilesTest() {
// Create 1250 files in the directory
for (i in 1..1250) {
File(dir, "test$i.tmp").createNewFile()
}

val files = eventStream.read()

// Verify that read() returns at most 1000 files
assertTrue(files.size <= 1000, "Expected at most 1000 files, but got ${files.size}")

// Verify all returned paths are valid files
files.forEach { path ->
assertTrue(File(path).exists(), "File $path should exist")
assertTrue(File(path).isFile, "Path $path should be a file")
}
}

@Test
fun readReturnsAllFilesWhenUnder1000Test() {
// Create 50 files in the directory
for (i in 1..50) {
File(dir, "test$i.tmp").createNewFile()
}

val files = eventStream.read()

// Verify that all 50 files are returned when count is under 1000
assertEquals(50, files.size, "Expected 50 files, but got ${files.size}")

// Verify all returned paths are valid files
files.forEach { path ->
assertTrue(File(path).exists(), "File $path should exist")
assertTrue(File(path).isFile, "Path $path should be a file")
}
}
}
}