Skip to content

Commit e878b6c

Browse files
committed
Avoid deprecated scala.App
1 parent 0449664 commit e878b6c

1 file changed

Lines changed: 66 additions & 64 deletions

File tree

test/utils/GitFileRepositoryPerformanceTest.scala

Lines changed: 66 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -9,81 +9,83 @@ import org.apache.commons.io.IOUtils
99
import scala.concurrent.duration.Duration
1010
import java.util.concurrent.atomic.AtomicLong
1111

12-
object GitFileRepositoryPerformanceTest extends App {
12+
object GitFileRepositoryPerformanceTest {
13+
def main(args: Array[String]): Unit = {
1314

14-
// Performance test should be performed on the actual Play git repository.
15-
// Substitute here with the path to your own git repository to run this test.
16-
val repo = new PlayGitRepository(new File("data/main"))
17-
val basePath = "documentation/manual"
15+
// Performance test should be performed on the actual Play git repository.
16+
// Substitute here with the path to your own git repository to run this test.
17+
val repo = new PlayGitRepository(new File("data/main"))
18+
val basePath = "documentation/manual"
1819

19-
// First, find all the files that we might want to look up
20-
val tags = repo.allTags
21-
val allFiles = tags.flatMap { case (_, ref) =>
22-
repo.listAllFilesInPath(ref, basePath).map((ref, _))
23-
}
24-
// Filter markdown files
25-
val allMarkdown = allFiles.filter(_._2.endsWith(".md")).toIndexedSeq
26-
println("Testing with " + allMarkdown.size + " markdown files")
20+
// First, find all the files that we might want to look up
21+
val tags = repo.allTags
22+
val allFiles = tags.flatMap { case (_, ref) =>
23+
repo.listAllFilesInPath(ref, basePath).map((ref, _))
24+
}
25+
// Filter markdown files
26+
val allMarkdown = allFiles.filter(_._2.endsWith(".md")).toIndexedSeq
27+
println("Testing with " + allMarkdown.size + " markdown files")
2728

28-
def runTest(threads: Int, seconds: Long) = {
29-
@volatile var running = true
30-
val findFileWithNameTiming = new AtomicLong()
31-
val loadFileTiming = new AtomicLong()
32-
val tasks = Future.sequence(for (i <- 0 to threads) yield {
33-
Future {
34-
var markdownLoaded = 0
29+
def runTest(threads: Int, seconds: Long) = {
30+
@volatile var running = true
31+
val findFileWithNameTiming = new AtomicLong()
32+
val loadFileTiming = new AtomicLong()
33+
val tasks = Future.sequence(for (i <- 0 to threads) yield {
34+
Future {
35+
var markdownLoaded = 0
3536

36-
while (running) {
37-
// Get a random markdown file
38-
val (ref, file) = allMarkdown(Random.nextInt(allMarkdown.size))
39-
// Strip the path off it, this is how requests come in
40-
val name = file.drop(file.lastIndexOf('/') + 1)
41-
// Find and then load it
42-
val fileRepo = new GitFileRepository(repo, ref, Some(basePath))
37+
while (running) {
38+
// Get a random markdown file
39+
val (ref, file) = allMarkdown(Random.nextInt(allMarkdown.size))
40+
// Strip the path off it, this is how requests come in
41+
val name = file.drop(file.lastIndexOf('/') + 1)
42+
// Find and then load it
43+
val fileRepo = new GitFileRepository(repo, ref, Some(basePath))
4344

44-
def findFileWithName(name: String) = {
45-
val start = System.nanoTime()
46-
val result = fileRepo.findFileWithName(name)
47-
findFileWithNameTiming.addAndGet(System.nanoTime() - start)
48-
result
49-
}
45+
def findFileWithName(name: String) = {
46+
val start = System.nanoTime()
47+
val result = fileRepo.findFileWithName(name)
48+
findFileWithNameTiming.addAndGet(System.nanoTime() - start)
49+
result
50+
}
5051

51-
def loadFile(path: String) = {
52-
val start = System.nanoTime()
53-
val result = fileRepo.loadFile(path)(IOUtils.toString(_, "utf-8"))
54-
loadFileTiming.addAndGet(System.nanoTime() - start)
55-
result
56-
}
52+
def loadFile(path: String) = {
53+
val start = System.nanoTime()
54+
val result = fileRepo.loadFile(path)(IOUtils.toString(_, "utf-8"))
55+
loadFileTiming.addAndGet(System.nanoTime() - start)
56+
result
57+
}
5758

58-
markdownLoaded += findFileWithName(name).flatMap(loadFile).map(_ => 1).getOrElse(0)
59+
markdownLoaded += findFileWithName(name).flatMap(loadFile).map(_ => 1).getOrElse(0)
60+
}
61+
markdownLoaded
5962
}
60-
markdownLoaded
61-
}
62-
})
63+
})
6364

64-
Thread.sleep(seconds * 1000)
65-
println("Stopping tests...")
66-
running = false
67-
val loaded = Await.result(tasks, Duration.Inf).reduce((a, b) => a + b)
65+
Thread.sleep(seconds * 1000)
66+
println("Stopping tests...")
67+
running = false
68+
val loaded = Await.result(tasks, Duration.Inf).reduce((a, b) => a + b)
6869

69-
println("Loaded " + loaded + " files in " + seconds + " seconds")
70-
println("That's " + (loaded / seconds) + " files a second")
71-
println(s"Total time spent finding markdown files: ${findFileWithNameTiming.get() / 1000000}ms")
72-
println(s"Total time spent loading markdown files: ${loadFileTiming.get() / 1000000}ms")
73-
}
70+
println("Loaded " + loaded + " files in " + seconds + " seconds")
71+
println("That's " + (loaded / seconds) + " files a second")
72+
println(s"Total time spent finding markdown files: ${findFileWithNameTiming.get() / 1000000}ms")
73+
println(s"Total time spent loading markdown files: ${loadFileTiming.get() / 1000000}ms")
74+
}
7475

75-
println()
76-
println("Test run 1:")
77-
println()
78-
runTest(10, 10)
76+
println()
77+
println("Test run 1:")
78+
println()
79+
runTest(10, 10)
7980

80-
println()
81-
println("Test run 2:")
82-
println()
83-
runTest(10, 10)
81+
println()
82+
println("Test run 2:")
83+
println()
84+
runTest(10, 10)
8485

85-
println()
86-
println("Test run 3:")
87-
println()
88-
runTest(10, 10)
86+
println()
87+
println("Test run 3:")
88+
println()
89+
runTest(10, 10)
90+
}
8991
}

0 commit comments

Comments
 (0)