Added tests for Java compiler

This commit is contained in:
Akash Yadav
2022-08-11 17:06:48 +05:30
parent 953c02404f
commit 37dbe4e1f3
5 changed files with 105 additions and 2 deletions
Binary file not shown.
@@ -20,6 +20,7 @@ package com.itsaky.androidide.lsp.java
import com.itsaky.androidide.lsp.api.ILanguageServerRegistry
import com.itsaky.androidide.lsp.api.LSPTest
import com.itsaky.androidide.lsp.java.actions.AddImportTester
import com.itsaky.androidide.lsp.java.compiler.CompilerTest
import com.itsaky.androidide.lsp.java.compiler.JavaCompilerService
import com.itsaky.androidide.lsp.java.partial.PartialReparserImplTester
import com.itsaky.androidide.lsp.java.providers.JavaCompletionProviderTester
@@ -59,6 +60,7 @@ open class JavaLSPTest : LSPTest() {
@Test
override fun test() {
CompilerTest().test()
AddImportTester().test()
PartialReparserImplTester().test()
JavaCompletionProviderTester().test()
@@ -33,9 +33,12 @@ class AddImportTester : JavaLSPTest() {
openFile("AddImportAction")
val diagnostic =
server.analyze(file!!).diagnostics.first { it.code == "compiler.err.cant.resolve.location" }
server.analyze(file!!).diagnostics.firstOrNull { it.code == "compiler.err.cant.resolve.location" }
assertThat(diagnostic).isNotNull()
val file = this.file!!.toFile()
val data = createActionData(diagnostic, file, this.file!!, this.server)
val data = createActionData(diagnostic!!, file, this.file!!, this.server)
val action = AddImportAction()
action.prepare(data)
@@ -0,0 +1,98 @@
/*
* This file is part of AndroidIDE.
*
* AndroidIDE is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* AndroidIDE is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with AndroidIDE. If not, see <https://www.gnu.org/licenses/>.
*/
package com.itsaky.androidide.lsp.java.compiler
import com.google.common.truth.Truth.assertThat
import com.itsaky.androidide.lsp.java.JavaLSPTest
import java.time.Instant
/** @author Akash Yadav */
class CompilerTest : JavaLSPTest() {
override fun test() {
testConcurrentAccess()
testClosedFileChannel()
testMultipleThreads()
}
private fun testMultipleThreads() {
openFile("completion/MembersCompletionTest")
val threads = mutableListOf<Thread>()
val thread = Thread {
getCompiler().compile(file!!).run {
println(Thread.currentThread().name)
delay(1000)
}
}
thread.name = "Long running task"
threads.add(thread)
thread.start()
for (i in 0..300) {
val th = Thread {
getCompiler().compile(file!!).run {
println(Thread.currentThread().name)
}
}
th.name = "Thread #$i"
threads.add(th)
th.start()
}
threads.forEach { it.join() }
}
private fun testClosedFileChannel() {
openFile("completion/MembersCompletionTest")
Thread { getCompiler().compile(file!!).run { delay(500) } }.start()
Thread { getCompiler().compile(file!!).run { delay(200) } }.start()
getCompiler().compile(file!!).run { assertThat(it.diagnostics).isNotEmpty() }
}
private fun delay(millis: Long) {
Thread.sleep(millis)
}
private fun testConcurrentAccess() {
openFile("completion/MembersCompletionTest")
var task = getCompiler().compile(file!!)
var fileObject = SourceFileObject(file!!)
val threads = mutableListOf<Thread>()
for (i in 1..10) {
threads.add(
Thread {
task.run {
delay(100)
println(Thread.currentThread())
}
}
.apply { name = "CompileTask Acessor #$i" }
)
}
fileObject = SourceFileObject(file!!, fileObject.contents, Instant.now())
task = getCompiler().compile(listOf(fileObject))
threads.forEach { it.start() }
Thread { task.run { println("Writer thread") } }.start()
threads.forEach { it.join() }
}
}
Binary file not shown.