Skip to content

Commit

Permalink
Update to Kotlin 1.5.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed May 10, 2021
1 parent a445e0c commit a3d7196
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 48 deletions.
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.4.32" apply false
kotlin("kapt") version "1.4.32" apply false
id("org.jmailen.kotlinter") version "3.4.1" apply false
kotlin("jvm") version "1.5.0" apply false
kotlin("kapt") version "1.5.0" apply false
id("org.jmailen.kotlinter") version "3.4.4" apply false
id("com.github.ben-manes.versions") version "0.38.0"
id("io.gitlab.arturbosch.detekt") version "1.16.0"
}
Expand All @@ -19,7 +19,7 @@ allprojects {
}
subprojects {
group = "com.github.cs125-illinois.jeed"
version = "2021.4.5"
version = "2021.5.0"
tasks.withType<KotlinCompile> {
val javaVersion = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = javaVersion
Expand All @@ -34,8 +34,8 @@ subprojects {
configurations.all {
resolutionStrategy {
force(
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.4.32",
"org.jetbrains.kotlin:kotlin-script-runtime:1.4.32"
"org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.5.0",
"org.jetbrains.kotlin:kotlin-script-runtime:1.5.0"
)
}
}
Expand Down
2 changes: 1 addition & 1 deletion containerrunner/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("io.github.microutils:kotlin-logging:2.0.6")
implementation("com.github.ajalt:clikt:2.8.0")
implementation("io.github.classgraph:classgraph:4.8.104")
implementation("io.github.classgraph:classgraph:4.8.105")
}
application {
@Suppress("DEPRECATION")
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.4.5
version=2021.5.0
8 changes: 4 additions & 4 deletions core/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ dependencies {
implementation(kotlin("compiler-embeddable"))
implementation(kotlin("reflect"))

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC-native-mt")
implementation("com.puppycrawl.tools:checkstyle:8.42")
implementation("com.pinterest.ktlint:ktlint-core:0.40.0")
implementation("com.pinterest.ktlint:ktlint-ruleset-standard:0.41.0")
Expand All @@ -31,11 +31,11 @@ dependencies {
implementation("org.slf4j:slf4j-api:1.7.30")
implementation("ch.qos.logback:logback-classic:1.2.3")
implementation("io.github.microutils:kotlin-logging:2.0.6")
implementation("io.github.classgraph:classgraph:4.8.104")
implementation("io.github.classgraph:classgraph:4.8.105")
implementation("net.java.dev.jna:jna:5.8.0")
api("com.github.ben-manes.caffeine:caffeine:3.0.1")
api("com.github.ben-manes.caffeine:caffeine:3.0.2")

testImplementation("io.kotest:kotest-runner-junit5:4.4.3")
testImplementation("io.kotest:kotest-runner-junit5:4.5.0")
}
tasks.test {
useJUnitPlatform()
Expand Down
8 changes: 5 additions & 3 deletions core/src/main/kotlin/Cache.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ package edu.illinois.cs.cs125.jeed.core

import com.github.benmanes.caffeine.cache.Cache
import com.github.benmanes.caffeine.cache.Caffeine
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.time.Instant
Expand Down Expand Up @@ -91,12 +92,13 @@ fun Source.tryCache(
)
}

private val compilationScope = CoroutineScope(Dispatchers.IO)
fun CompiledSource.cache(compilationArguments: CompilationArguments) {
val useCache = compilationArguments.useCache ?: useCompilationCache
if (cached || !useCache) {
return
}
GlobalScope.launch {
compilationScope.launch {
compilationCache.put(
source.md5,
CachedCompilationResults(
Expand Down Expand Up @@ -154,7 +156,7 @@ fun CompiledSource.cache(kompilationArguments: KompilationArguments) {
if (cached || !kompilationArguments.useCache) {
return
}
GlobalScope.launch {
compilationScope.launch {
compilationCache.put(
source.md5,
CachedCompilationResults(
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/kotlin/Container.kt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ suspend fun CompiledSource.cexecute(
val outputLines = listOf(stdoutLines.commandOutputLines, stderrLines.commandOutputLines)
.flatten()
.sortedBy { it.timestamp }
.filter {
!it.line.startsWith("OpenJDK 64-Bit Server VM warning:")
}
.also {
if (it.size > executionArguments.maxOutputLines) {
truncatedLines += it.size - executionArguments.maxOutputLines
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.4.5
version=2021.5.0
2 changes: 2 additions & 0 deletions core/src/test/kotlin/TestCoroutines.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import io.kotest.matchers.should
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNot
import io.kotest.matchers.shouldNotBe
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

@DelicateCoroutinesApi
@Suppress("ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE")
class TestCoroutines : StringSpec({
"should allow coroutines to run" {
Expand Down
8 changes: 4 additions & 4 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ dependencies {
implementation(kotlin("stdlib"))
implementation(kotlin("reflect"))

implementation("io.ktor:ktor-server-netty:1.5.3")
implementation("io.ktor:ktor-server-netty:1.5.4")
implementation("org.mongodb:mongodb-driver:3.12.8")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.3")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.0-RC-native-mt")
implementation("com.squareup.moshi:moshi-kotlin-codegen:1.12.0")
implementation("com.github.cs125-illinois:ktor-moshi:1.0.3")
implementation("ch.qos.logback:logback-classic:1.2.3")
Expand All @@ -31,9 +31,9 @@ dependencies {
implementation("com.google.api-client:google-api-client:1.31.4")
implementation("com.github.cs125-illinois.libcs1:libcs1:2021.4.1")

testImplementation("io.kotest:kotest-runner-junit5:4.4.3")
testImplementation("io.kotest:kotest-runner-junit5:4.5.0")
testImplementation("io.kotest:kotest-assertions-ktor:4.4.3")
testImplementation("io.ktor:ktor-server-test-host:1.5.3")
testImplementation("io.ktor:ktor-server-test-host:1.5.4")
}
application {
@Suppress("DEPRECATION")
Expand Down
33 changes: 13 additions & 20 deletions server/src/main/kotlin/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ import io.ktor.routing.post
import io.ktor.routing.routing
import io.ktor.server.engine.embeddedServer
import io.ktor.server.netty.Netty
import kotlinx.coroutines.CancellationException
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.time.delay
import kotlinx.coroutines.withContext
import mu.KotlinLogging
Expand Down Expand Up @@ -154,15 +156,17 @@ fun Application.jeed() {
}
}

fun main() {
private val backgroundScope = CoroutineScope(Dispatchers.IO)

fun main() = runBlocking<Unit> {
logger.info(configuration.toJson.toText())

val httpUri = URI(configuration[TopLevel.http])
assert(httpUri.scheme == "http")

configuration[TopLevel.mongodb]?.let {
val mongoUri = MongoClientURI(it)
val database = mongoUri.database ?: require { "MONGO must specify database to use" }
val database = mongoUri.database ?: error("MONGO must specify database to use")
val collection = configuration[TopLevel.Mongo.collection]
Request.mongoCollection = MongoClient(mongoUri)
.getDatabase(database)
Expand All @@ -176,32 +180,21 @@ fun main() {
}
}

GlobalScope.launch { warm(2) }
GlobalScope.launch { Request.mongoCollection?.find(Filters.eq("_id", "")) }
GlobalScope.launch {
backgroundScope.launch { warm(2) }
backgroundScope.launch { Request.mongoCollection?.find(Filters.eq("_id", "")) }
backgroundScope.launch {
delay(Duration.ofMinutes(configuration[TopLevel.sentinelDelay]))
@Suppress("TooGenericExceptionCaught")
try {
warm(2)
logger.debug("Sentinel succeeded")
} catch (e: CancellationException) {
return@launch
} catch (err: Throwable) {
logger.error("Restarting due to sentinel failure")
err.printStackTrace()
exitProcess(-1)
}
}

embeddedServer(Netty, host = httpUri.host, port = httpUri.port, module = Application::jeed).start(wait = true)
}

fun assert(block: () -> String): Nothing {
throw AssertionError(block())
}

fun check(block: () -> String): Nothing {
throw IllegalStateException(block())
}

fun require(block: () -> String): Nothing {
throw IllegalArgumentException(block())
embeddedServer(Netty, host = httpUri.host, port = httpUri.port, module = Application::jeed).start(true)
}
9 changes: 6 additions & 3 deletions server/src/main/kotlin/Request.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,16 @@ import edu.illinois.cs.cs125.jeed.core.moshi.TemplatedSourceResult
import edu.illinois.cs.cs125.jeed.core.server.FlatComplexityResults
import edu.illinois.cs.cs125.jeed.core.server.Task
import edu.illinois.cs.cs125.jeed.core.server.TaskArguments
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.async
import org.apache.http.auth.AuthenticationException
import org.bson.BsonDocument
import org.bson.BsonString
import java.time.Instant

private val mongoScope = CoroutineScope(Dispatchers.IO)

@Suppress("LongParameterList")
class Request(
passedSource: Map<String, String>?,
Expand Down Expand Up @@ -231,7 +234,7 @@ class Request(
arguments.snippet.fileType
}
}
Source.fromSnippet(snippet ?: assert { "should have a snippet" }, arguments.snippet).also {
Source.fromSnippet(snippet ?: error("should have a snippet"), arguments.snippet).also {
response.completedTasks.add(Task.snippet)
response.completed.snippet = it
}
Expand Down Expand Up @@ -317,7 +320,7 @@ class Request(
response.interval = Interval(started, Instant.now())
}
if (mongoCollection != null) {
val resultSave = GlobalScope.async {
val resultSave = mongoScope.async {
@Suppress("TooGenericExceptionCaught")
try {
mongoCollection?.insertOne(
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/kotlin/Response.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class Response(val request: Request) {
val RESPONSE_ADAPTER: JsonAdapter<Response> = moshi.adapter(Response::class.java)
fun from(response: String?): Response {
check(response != null) { "can't deserialize null string" }
return RESPONSE_ADAPTER.fromJson(response) ?: check { "failed to deserialize result" }
return RESPONSE_ADAPTER.fromJson(response) ?: error("failed to deserialize result")
}
}
}
2 changes: 1 addition & 1 deletion server/src/main/kotlin/Status.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Status(
private val statusAdapter: JsonAdapter<Status> = moshi.adapter(Status::class.java)
fun from(response: String?): Status {
check(response != null) { "can't deserialize null string" }
return statusAdapter.fromJson(response) ?: check { "failed to deserialize status" }
return statusAdapter.fromJson(response) ?: error("failed to deserialize status")
}
}
}
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2021.4.5
version=2021.5.0
7 changes: 5 additions & 2 deletions server/src/test/kotlin/TestHTTP.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class TestHTTP : StringSpec() {
override fun beforeSpec(spec: Spec) {
configuration[TopLevel.mongodb]?.let {
val mongoUri = MongoClientURI(it)
val database = mongoUri.database ?: require { "MONGO must specify database to use" }
val database = mongoUri.database ?: error("MONGO must specify database to use")
val collection = "${configuration[TopLevel.Mongo.collection]}-test"
Request.mongoCollection = MongoClient(mongoUri)
.getDatabase(database)
Expand Down Expand Up @@ -210,7 +210,10 @@ fun main() {
Request.mongoCollection?.countDocuments() shouldBe 1

val jeedResponse = Response.from(response.content)
println(jeedResponse.completed.execution?.permissionRequests?.filter { !it.granted }?.map { it.permission })
println(
jeedResponse.completed.execution?.permissionRequests?.filter { !it.granted }
?.map { it.permission }
)
jeedResponse.completed.execution?.klass shouldBe "MainKt"
jeedResponse.completed.execution?.outputLines?.joinToString(separator = "\n") {
it.line
Expand Down

0 comments on commit a3d7196

Please sign in to comment.