Skip to content

Commit

Permalink
fix(deps): Target Java 11 (#165)
Browse files Browse the repository at this point in the history
  • Loading branch information
gnarea authored Feb 9, 2023
1 parent d364d38 commit d3593ee
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 25 deletions.
10 changes: 2 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -71,21 +71,15 @@ java {
}

tasks.withType(KotlinCompile).configureEach {
kotlinOptions.jvmTarget = "1.8"
kotlinOptions.jvmTarget = JavaVersion.VERSION_11
}

tasks.withType(KotlinCompile).configureEach {
kotlinOptions.freeCompilerArgs = kotlinOptions.freeCompilerArgs + [
"-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-Xuse-experimental=kotlinx.coroutines.FlowPreview",
"-Xuse-experimental=kotlin.time.ExperimentalTime"
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
]
}

test {
useJUnitPlatform()
}

tasks.register('integrationTest', Test) {
description = 'Integration tests'
group = 'verification'
Expand Down
4 changes: 2 additions & 2 deletions jacoco.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ tasks.test {
testLogging {
events("passed", "skipped", "failed")
}
finalizedBy("jacocoTestReport")
doLast {
println("View code coverage at:")
println("file://$buildDir/reports/coverage/index.html")
}
}
finalizedBy("jacocoTestReport", "jacocoTestCoverageVerification")
}
21 changes: 10 additions & 11 deletions src/main/kotlin/tech/relaycorp/doh/DoHClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package tech.relaycorp.doh
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.engine.okhttp.OkHttp
import io.ktor.client.plugins.ClientRequestException
import io.ktor.client.request.accept
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import io.ktor.http.HttpStatusCode
import io.ktor.http.content.ByteArrayContent
import okhttp3.OkHttpClient
import org.xbill.DNS.DClass
Expand Down Expand Up @@ -45,8 +45,6 @@ public class DoHClient(public val resolverURL: String = DEFAULT_RESOLVER_URL) :
* @throws [InvalidQueryException] if [name] or [type] are invalid
* @throws [LookupFailureException] if the lookup was unsuccessful
*/
// https://github.com/dnsjava/dnsjava/issues/146
@Suppress("BlockingMethodInNonBlockingContext")
@Throws(DoHException::class)
public suspend fun lookUp(name: String, type: String): Answer {
val querySerialised = makeQuery(name, type)
Expand All @@ -55,11 +53,12 @@ public class DoHClient(public val resolverURL: String = DEFAULT_RESOLVER_URL) :
accept(DNS_MESSAGE_CONTENT_TYPE)
setBody(ByteArrayContent(querySerialised, DNS_MESSAGE_CONTENT_TYPE))
}
} catch (exc: ClientRequestException) {
throw LookupFailureException("Unexpected HTTP response code (${exc.response.status})")
} catch (exc: IOException) {
throw LookupFailureException("Failed to connect to $resolverURL", exc)
}
if (response.status != HttpStatusCode.OK) {
throw LookupFailureException("Unexpected HTTP response code (${response.status})")
}
return parseAnswer(response.body())
}

Expand Down Expand Up @@ -92,16 +91,16 @@ public class DoHClient(public val resolverURL: String = DEFAULT_RESOLVER_URL) :
return Answer(records.map { it.rdataToString() })
}

internal companion object {
internal const val DEFAULT_RESOLVER_URL: String = "https://cloudflare-dns.com/dns-query"

internal val DNS_MESSAGE_CONTENT_TYPE = ContentType("application", "dns-message")
}

/**
* Release the underlying resources used by the client.
*/
override fun close() {
ktorClient.close()
}

internal companion object {
internal const val DEFAULT_RESOLVER_URL: String = "https://cloudflare-dns.com/dns-query"

private val DNS_MESSAGE_CONTENT_TYPE = ContentType("application", "dns-message")
}
}
7 changes: 3 additions & 4 deletions src/test/kotlin/tech/relaycorp/doh/DoHClientTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ class DoHClientTest {
}
}

// https://github.com/dnsjava/dnsjava/issues/146
@Suppress("BlockingMethodInNonBlockingContext")
@Nested
inner class Lookup {
private val recordName = "example.com."
Expand Down Expand Up @@ -124,15 +122,16 @@ class DoHClientTest {

@Test
fun `Non-200 responses should be treated as errors`() = runBlocking {
val status = HttpStatusCode.BadRequest
val client = makeTestClient {
respond("Whoops", HttpStatusCode.BadRequest)
respond("Whoops", status)
}

val exception =
assertThrows<LookupFailureException> { client.lookUp(recordName, recordType) }

assertEquals(
"Returned DNS message is malformed",
"Unexpected HTTP response code ($status)",
exception.message
)
}
Expand Down

0 comments on commit d3593ee

Please sign in to comment.