From 5bc48096c759936aed4797ca5d2993d50339f277 Mon Sep 17 00:00:00 2001 From: Joris Borgdorff Date: Thu, 21 Sep 2023 11:01:47 +0200 Subject: [PATCH] Use Kotlin official style guide --- .editorconfig | 4 - gradle/publishing.gradle | 86 ------------------- .../radarbase/kotlin/coroutines/Extensions.kt | 9 +- .../org/radarbase/ktor/auth/Extensions.kt | 4 +- .../ktor/auth/OAuthClientProvider.kt | 30 ++++--- .../kotlin/coroutines/CachedValueTest.kt | 4 +- .../collector/NumericAggregateCollector.kt | 2 +- .../java/org/radarbase/mock/MockProducer.kt | 24 ++++-- .../org/radarbase/mock/data/MockCsvParser.kt | 7 +- .../mock/data/MockRecordValidatorTest.kt | 1 - .../org/radarbase/util/OscilloscopeTest.kt | 5 +- .../org/radarbase/producer/KafkaSender.kt | 4 - .../producer/avro/AvroDataMapperFactory.kt | 8 +- .../producer/io/DirectBinaryEncoder.kt | 26 ++---- .../producer/io/HttpClientExtensions.kt | 6 +- .../io/UnsupportedMediaTypeException.kt | 2 +- .../producer/rest/AvroContentConverter.kt | 12 +-- .../producer/rest/RestKafkaSender.kt | 37 +++++--- .../producer/schema/SchemaRestClient.kt | 25 ++++-- .../producer/schema/SchemaRetriever.kt | 9 +- .../java/org/radarbase/topic/AvroTopic.kt | 1 - .../producer/rest/BinaryRecordContentTest.kt | 7 +- .../producer/rest/RestKafkaSenderTest.kt | 15 +++- .../producer/schema/SchemaRestClientTest.kt | 6 +- .../producer/schema/SchemaRetrieverTest.kt | 2 +- .../org/radarbase/topic/KafkaTopicTest.kt | 24 +++--- .../java/org/radarbase/util/Base64Test.kt | 2 +- 27 files changed, 155 insertions(+), 207 deletions(-) delete mode 100644 gradle/publishing.gradle diff --git a/.editorconfig b/.editorconfig index ce7dcfe8..d340b76d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -15,12 +15,8 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[*.{kt,kts}] -ktlint_standard_no-wildcard-imports = disabled - [*.md] trim_trailing_whitespace = false [*.{json,yaml,yml}] -indent_style = space indent_size = 2 diff --git a/gradle/publishing.gradle b/gradle/publishing.gradle deleted file mode 100644 index 2b8935dd..00000000 --- a/gradle/publishing.gradle +++ /dev/null @@ -1,86 +0,0 @@ -apply plugin: 'maven-publish' -apply plugin: 'signing' - -def sharedManifest = manifest { - attributes("Implementation-Title": project.name, - "Implementation-Version": version) -} - -jar { - manifest.from sharedManifest -} - -// custom tasks for creating source/javadoc jars -task sourcesJar(type: Jar, dependsOn: classes) { - archiveClassifier.set('sources') - from sourceSets.main.allSource - manifest.from sharedManifest -} - -task javadocJar(type: Jar, dependsOn: javadoc) { - archiveClassifier.set('javadoc') - from javadoc.destinationDir - manifest.from sharedManifest -} - -assemble.dependsOn(javadocJar, sourcesJar) - -publishing { - publications { - mavenJar(MavenPublication) { - from components.java - artifact sourcesJar - artifact javadocJar - - pom { - name = project.name - description = project.description - url = githubUrl - licenses { - license { - name = 'The Apache Software License, Version 2.0' - url = 'http://www.apache.org/licenses/LICENSE-2.0.txt' - distribution = 'repo' - } - } - developers { - developer { - id = 'blootsvoets' - name = 'Joris Borgdorff' - email = 'joris@thehyve.nl' - organization = 'The Hyve' - } - developer { - id = 'nivemaham' - name = 'Nivethika Mahasivam' - email = 'nivethika@thehyve.nl' - organization = 'The Hyve' - } - } - issueManagement { - system = 'GitHub' - url = githubUrl + '/issues' - } - organization { - name = 'RADAR-base' - url = website - } - scm { - connection = 'scm:git:' + githubUrl - url = githubUrl - } - } - } - } -} - -signing { - useGpgCmd() - required { true } - sign(tasks["sourcesJar"], tasks["javadocJar"]) - sign(publishing.publications["mavenJar"]) -} - -tasks.withType(Sign).configureEach { - onlyIf { gradle.taskGraph.hasTask(project.tasks["publish"]) } -} diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/Extensions.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/Extensions.kt index e3f48ca7..0329c62b 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/Extensions.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/kotlin/coroutines/Extensions.kt @@ -2,10 +2,17 @@ package org.radarbase.kotlin.coroutines -import kotlinx.coroutines.* +import kotlinx.coroutines.CancellationException +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.async +import kotlinx.coroutines.awaitAll import kotlinx.coroutines.channels.Channel import kotlinx.coroutines.channels.consume +import kotlinx.coroutines.coroutineScope +import kotlinx.coroutines.launch import kotlinx.coroutines.sync.Semaphore +import kotlinx.coroutines.withContext import java.util.concurrent.Future import java.util.concurrent.TimeUnit import kotlin.coroutines.CoroutineContext diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/Extensions.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/Extensions.kt index c48bab65..2831edbb 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/Extensions.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/Extensions.kt @@ -1,7 +1,7 @@ package org.radarbase.ktor.auth -import io.ktor.client.request.* -import io.ktor.http.* +import io.ktor.client.request.HttpRequestBuilder +import io.ktor.http.HttpHeaders fun HttpRequestBuilder.bearer(token: String) { headers[HttpHeaders.Authorization] = "Bearer $token" diff --git a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt index 785096e5..9a2fd00b 100644 --- a/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt +++ b/radar-commons-kotlin/src/main/kotlin/org/radarbase/ktor/auth/OAuthClientProvider.kt @@ -1,15 +1,25 @@ package org.radarbase.ktor.auth -import io.ktor.client.* -import io.ktor.client.call.* -import io.ktor.client.plugins.auth.* -import io.ktor.client.plugins.auth.providers.* -import io.ktor.client.request.* -import io.ktor.client.request.forms.* -import io.ktor.client.statement.* -import io.ktor.http.* -import io.ktor.http.auth.* -import io.ktor.util.* +import io.ktor.client.HttpClient +import io.ktor.client.call.body +import io.ktor.client.plugins.auth.Auth +import io.ktor.client.plugins.auth.AuthProvider +import io.ktor.client.plugins.auth.providers.BearerAuthConfig +import io.ktor.client.plugins.auth.providers.BearerAuthProvider +import io.ktor.client.request.HttpRequestBuilder +import io.ktor.client.request.accept +import io.ktor.client.request.forms.submitForm +import io.ktor.client.request.headers +import io.ktor.client.statement.HttpResponse +import io.ktor.client.statement.bodyAsText +import io.ktor.http.ContentType +import io.ktor.http.HttpHeaders +import io.ktor.http.HttpStatusCode +import io.ktor.http.Parameters +import io.ktor.http.auth.AuthScheme +import io.ktor.http.auth.HttpAuthHeader +import io.ktor.http.isSuccess +import io.ktor.util.KtorDsl import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow import org.slf4j.LoggerFactory diff --git a/radar-commons-kotlin/src/test/kotlin/org/radarbase/kotlin/coroutines/CachedValueTest.kt b/radar-commons-kotlin/src/test/kotlin/org/radarbase/kotlin/coroutines/CachedValueTest.kt index bbb90c14..bfc91508 100644 --- a/radar-commons-kotlin/src/test/kotlin/org/radarbase/kotlin/coroutines/CachedValueTest.kt +++ b/radar-commons-kotlin/src/test/kotlin/org/radarbase/kotlin/coroutines/CachedValueTest.kt @@ -5,7 +5,9 @@ import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.delay import kotlinx.coroutines.runBlocking import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.* +import org.hamcrest.Matchers.equalTo +import org.hamcrest.Matchers.`is` +import org.hamcrest.Matchers.lessThan import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows diff --git a/radar-commons-server/src/main/java/org/radarbase/stream/collector/NumericAggregateCollector.kt b/radar-commons-server/src/main/java/org/radarbase/stream/collector/NumericAggregateCollector.kt index 904b3007..2062a41a 100644 --- a/radar-commons-server/src/main/java/org/radarbase/stream/collector/NumericAggregateCollector.kt +++ b/radar-commons-server/src/main/java/org/radarbase/stream/collector/NumericAggregateCollector.kt @@ -23,7 +23,7 @@ import java.math.BigDecimal import java.math.BigDecimal.valueOf import java.math.BigInteger import java.nio.ByteBuffer -import java.util.* +import java.util.Objects /** * Java class to aggregate data using Kafka Streams. Double is the base type. diff --git a/radar-commons-testing/src/main/java/org/radarbase/mock/MockProducer.kt b/radar-commons-testing/src/main/java/org/radarbase/mock/MockProducer.kt index 193fd371..78eebe14 100644 --- a/radar-commons-testing/src/main/java/org/radarbase/mock/MockProducer.kt +++ b/radar-commons-testing/src/main/java/org/radarbase/mock/MockProducer.kt @@ -16,13 +16,15 @@ package org.radarbase.mock import com.opencsv.exceptions.CsvValidationException -import io.ktor.client.call.* -import io.ktor.client.plugins.* -import io.ktor.client.plugins.auth.* -import io.ktor.client.plugins.auth.providers.* -import io.ktor.client.request.forms.* -import io.ktor.http.* -import kotlinx.coroutines.* +import io.ktor.client.plugins.auth.Auth +import io.ktor.client.plugins.defaultRequest +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.Job +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.launch +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.withContext import org.apache.avro.SchemaValidationException import org.radarbase.config.ServerConfig import org.radarbase.config.YamlConfigLoader @@ -41,13 +43,17 @@ import org.radarbase.producer.rest.RestKafkaSender.Companion.restKafkaSender import org.radarbase.producer.schema.SchemaRetriever import org.radarbase.producer.schema.SchemaRetriever.Companion.schemaRetriever import org.radarcns.kafka.ObservationKey -import org.radarcns.passive.empatica.* +import org.radarcns.passive.empatica.EmpaticaE4Acceleration +import org.radarcns.passive.empatica.EmpaticaE4BatteryLevel +import org.radarcns.passive.empatica.EmpaticaE4BloodVolumePulse +import org.radarcns.passive.empatica.EmpaticaE4ElectroDermalActivity +import org.radarcns.passive.empatica.EmpaticaE4InterBeatInterval +import org.radarcns.passive.empatica.EmpaticaE4Temperature import org.slf4j.LoggerFactory import java.io.IOException import java.nio.file.Path import java.nio.file.Paths import java.time.Instant -import java.util.* import java.util.concurrent.atomic.AtomicBoolean import kotlin.system.exitProcess import kotlin.time.Duration.Companion.seconds diff --git a/radar-commons-testing/src/main/java/org/radarbase/mock/data/MockCsvParser.kt b/radar-commons-testing/src/main/java/org/radarbase/mock/data/MockCsvParser.kt index 2c68a6a0..457bbc2a 100644 --- a/radar-commons-testing/src/main/java/org/radarbase/mock/data/MockCsvParser.kt +++ b/radar-commons-testing/src/main/java/org/radarbase/mock/data/MockCsvParser.kt @@ -35,7 +35,8 @@ import java.nio.charset.StandardCharsets import java.nio.file.Path import java.time.Duration import java.time.Instant -import java.util.* +import kotlin.io.encoding.Base64 +import kotlin.io.encoding.ExperimentalEncodingApi import kotlin.io.path.bufferedReader /** @@ -277,9 +278,9 @@ class MockCsvParser( } } + @OptIn(ExperimentalEncodingApi::class) private fun parseBytes(fieldString: String?): ByteBuffer { - val result = Base64.getDecoder() - .decode(fieldString!!.toByteArray(StandardCharsets.UTF_8)) + val result = Base64.decode(fieldString!!.toByteArray(StandardCharsets.UTF_8)) return ByteBuffer.wrap(result) } diff --git a/radar-commons-testing/src/test/java/org/radarbase/mock/data/MockRecordValidatorTest.kt b/radar-commons-testing/src/test/java/org/radarbase/mock/data/MockRecordValidatorTest.kt index c1b23eec..ec1d68d8 100644 --- a/radar-commons-testing/src/test/java/org/radarbase/mock/data/MockRecordValidatorTest.kt +++ b/radar-commons-testing/src/test/java/org/radarbase/mock/data/MockRecordValidatorTest.kt @@ -32,7 +32,6 @@ import java.io.IOException import java.io.Writer import java.nio.file.Files import java.nio.file.Path -import java.util.* import kotlin.io.path.bufferedWriter class MockRecordValidatorTest { diff --git a/radar-commons-testing/src/test/java/org/radarbase/util/OscilloscopeTest.kt b/radar-commons-testing/src/test/java/org/radarbase/util/OscilloscopeTest.kt index 5fe6ba08..0945237b 100644 --- a/radar-commons-testing/src/test/java/org/radarbase/util/OscilloscopeTest.kt +++ b/radar-commons-testing/src/test/java/org/radarbase/util/OscilloscopeTest.kt @@ -17,7 +17,10 @@ package org.radarbase.util import kotlinx.coroutines.runBlocking import org.hamcrest.MatcherAssert.assertThat -import org.hamcrest.Matchers.* +import org.hamcrest.Matchers.greaterThanOrEqualTo +import org.hamcrest.Matchers.`is` +import org.hamcrest.Matchers.lessThan +import org.hamcrest.Matchers.lessThanOrEqualTo import org.junit.jupiter.api.Test class OscilloscopeTest { diff --git a/radar-commons/src/main/java/org/radarbase/producer/KafkaSender.kt b/radar-commons/src/main/java/org/radarbase/producer/KafkaSender.kt index 8b816c11..e8337da8 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/KafkaSender.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/KafkaSender.kt @@ -15,10 +15,6 @@ */ package org.radarbase.producer -import io.ktor.client.* -import io.ktor.client.engine.* -import io.ktor.client.engine.cio.* -import io.ktor.client.plugins.* import kotlinx.coroutines.flow.Flow import org.apache.avro.SchemaValidationException import org.radarbase.producer.rest.ConnectionState diff --git a/radar-commons/src/main/java/org/radarbase/producer/avro/AvroDataMapperFactory.kt b/radar-commons/src/main/java/org/radarbase/producer/avro/AvroDataMapperFactory.kt index 3b839860..ef68d6cd 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/avro/AvroDataMapperFactory.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/avro/AvroDataMapperFactory.kt @@ -3,12 +3,16 @@ package org.radarbase.producer.avro import org.apache.avro.JsonProperties import org.apache.avro.Schema import org.apache.avro.SchemaValidationException -import org.apache.avro.generic.* +import org.apache.avro.generic.GenericData +import org.apache.avro.generic.GenericEnumSymbol +import org.apache.avro.generic.GenericRecord +import org.apache.avro.generic.GenericRecordBuilder +import org.apache.avro.generic.IndexedRecord import org.radarbase.util.Base64Encoder import org.slf4j.Logger import org.slf4j.LoggerFactory import java.nio.ByteBuffer -import java.util.* +import java.util.EnumSet object AvroDataMapperFactory { /** diff --git a/radar-commons/src/main/java/org/radarbase/producer/io/DirectBinaryEncoder.kt b/radar-commons/src/main/java/org/radarbase/producer/io/DirectBinaryEncoder.kt index 0b51276b..9107e7d4 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/io/DirectBinaryEncoder.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/io/DirectBinaryEncoder.kt @@ -17,34 +17,18 @@ */ package org.radarbase.producer.io -import io.ktor.utils.io.* +import io.ktor.utils.io.ByteWriteChannel +import io.ktor.utils.io.close +import io.ktor.utils.io.writeByte import org.apache.avro.io.BinaryData import java.io.IOException -import java.util.* /** * An [Encoder] for Avro's binary encoding that does not buffer output. - * - * - * This encoder does not buffer writes, and as a result is slower than - * [BufferedBinaryEncoder]. However, it is lighter-weight and useful when - * the buffering in BufferedBinaryEncoder is not desired and/or the Encoder is - * very short lived. - * - * - * To construct, use - * [EncoderFactory.directBinaryEncoder] - * - * * DirectBinaryEncoder is not thread-safe * * @see BinaryEncoder - * - * @see EncoderFactory - * * @see Encoder - * - * @see Decoder */ class DirectBinaryEncoder( var out: ByteWriteChannel, @@ -95,10 +79,10 @@ class DirectBinaryEncoder( if (`val` and 0x7FFFFFFFL.inv() == 0L) { var i = `val`.toInt() while (i and 0x7F.inv() != 0) { - out.writeByte((0x80 or i and 0xFF).toByte().toInt()) + out.writeByte((0x80 or i and 0xFF).toByte()) i = i ushr 7 } - out.writeByte(i.toByte().toInt()) + out.writeByte(i.toByte()) return } val len = BinaryData.encodeLong(n, buf, 0) diff --git a/radar-commons/src/main/java/org/radarbase/producer/io/HttpClientExtensions.kt b/radar-commons/src/main/java/org/radarbase/producer/io/HttpClientExtensions.kt index 99e1ece4..bb8412e8 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/io/HttpClientExtensions.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/io/HttpClientExtensions.kt @@ -1,8 +1,8 @@ package org.radarbase.producer.io -import io.ktor.client.* -import io.ktor.client.engine.cio.* -import io.ktor.client.plugins.* +import io.ktor.client.HttpClientConfig +import io.ktor.client.engine.cio.CIOEngineConfig +import io.ktor.client.plugins.HttpTimeout import java.security.cert.X509Certificate import javax.net.ssl.X509TrustManager import kotlin.time.Duration diff --git a/radar-commons/src/main/java/org/radarbase/producer/io/UnsupportedMediaTypeException.kt b/radar-commons/src/main/java/org/radarbase/producer/io/UnsupportedMediaTypeException.kt index 34de28a1..69a24a1a 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/io/UnsupportedMediaTypeException.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/io/UnsupportedMediaTypeException.kt @@ -1,6 +1,6 @@ package org.radarbase.producer.io -import io.ktor.http.* +import io.ktor.http.ContentType import java.io.IOException class UnsupportedMediaTypeException( diff --git a/radar-commons/src/main/java/org/radarbase/producer/rest/AvroContentConverter.kt b/radar-commons/src/main/java/org/radarbase/producer/rest/AvroContentConverter.kt index 7aa19f61..9b3a184f 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/rest/AvroContentConverter.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/rest/AvroContentConverter.kt @@ -1,11 +1,11 @@ package org.radarbase.producer.rest -import io.ktor.http.* -import io.ktor.http.content.* -import io.ktor.serialization.* -import io.ktor.util.reflect.* -import io.ktor.utils.io.* -import io.ktor.utils.io.charsets.* +import io.ktor.http.ContentType +import io.ktor.http.content.OutgoingContent +import io.ktor.serialization.ContentConverter +import io.ktor.util.reflect.TypeInfo +import io.ktor.utils.io.ByteReadChannel +import io.ktor.utils.io.charsets.Charset import kotlinx.coroutines.async import kotlinx.coroutines.coroutineScope import org.radarbase.data.RecordData diff --git a/radar-commons/src/main/java/org/radarbase/producer/rest/RestKafkaSender.kt b/radar-commons/src/main/java/org/radarbase/producer/rest/RestKafkaSender.kt index 22e3022f..f5a6974d 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/rest/RestKafkaSender.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/rest/RestKafkaSender.kt @@ -15,19 +15,35 @@ */ package org.radarbase.producer.rest -import io.ktor.client.* -import io.ktor.client.call.* -import io.ktor.client.engine.cio.* -import io.ktor.client.plugins.* -import io.ktor.client.plugins.contentnegotiation.* -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.* +import io.ktor.client.HttpClient +import io.ktor.client.HttpClientConfig +import io.ktor.client.engine.cio.CIO +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.client.plugins.defaultRequest +import io.ktor.client.request.accept +import io.ktor.client.request.head +import io.ktor.client.request.headers +import io.ktor.client.request.post +import io.ktor.client.request.setBody +import io.ktor.client.request.url +import io.ktor.client.statement.HttpResponse +import io.ktor.client.statement.bodyAsText +import io.ktor.client.statement.request +import io.ktor.http.ContentType +import io.ktor.http.Headers +import io.ktor.http.HeadersBuilder +import io.ktor.http.HttpHeaders +import io.ktor.http.HttpStatusCode +import io.ktor.http.contentType +import io.ktor.http.isSuccess import io.ktor.serialization.kotlinx.serialization -import io.ktor.util.reflect.* -import kotlinx.coroutines.* +import io.ktor.util.reflect.TypeInfo +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.first +import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json import org.apache.avro.SchemaValidationException import org.radarbase.data.RecordData @@ -44,7 +60,6 @@ import org.radarbase.topic.AvroTopic import org.radarbase.util.RadarProducerDsl import org.slf4j.LoggerFactory import java.io.IOException -import java.util.* import kotlin.reflect.javaType import kotlin.reflect.typeOf import kotlin.time.Duration diff --git a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt index a7d97677..59fa1d11 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRestClient.kt @@ -1,14 +1,21 @@ package org.radarbase.producer.schema -import io.ktor.client.* -import io.ktor.client.call.* -import io.ktor.client.plugins.* -import io.ktor.client.plugins.contentnegotiation.* -import io.ktor.client.request.* -import io.ktor.client.statement.* -import io.ktor.http.* -import io.ktor.serialization.kotlinx.json.* -import io.ktor.util.reflect.* +import io.ktor.client.HttpClient +import io.ktor.client.call.body +import io.ktor.client.plugins.contentnegotiation.ContentNegotiation +import io.ktor.client.plugins.defaultRequest +import io.ktor.client.request.HttpRequestBuilder +import io.ktor.client.request.accept +import io.ktor.client.request.request +import io.ktor.client.request.setBody +import io.ktor.client.request.url +import io.ktor.http.ContentType +import io.ktor.http.HttpMethod +import io.ktor.http.contentType +import io.ktor.http.isSuccess +import io.ktor.serialization.kotlinx.json.json +import io.ktor.util.reflect.TypeInfo +import io.ktor.util.reflect.typeInfo import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import kotlinx.serialization.json.Json diff --git a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt index 09b396e2..29d792b2 100644 --- a/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt +++ b/radar-commons/src/main/java/org/radarbase/producer/schema/SchemaRetriever.kt @@ -15,11 +15,9 @@ */ package org.radarbase.producer.schema -import io.ktor.client.* -import io.ktor.client.engine.cio.* -import io.ktor.client.plugins.* -import io.ktor.client.request.* -import io.ktor.http.* +import io.ktor.client.HttpClient +import io.ktor.client.HttpClientConfig +import io.ktor.client.engine.cio.CIO import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.launch @@ -29,7 +27,6 @@ import org.radarbase.kotlin.coroutines.CachedValue import org.radarbase.util.RadarProducerDsl import java.io.IOException import java.lang.ref.SoftReference -import java.util.* import java.util.Objects.hash import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentMap diff --git a/radar-commons/src/main/java/org/radarbase/topic/AvroTopic.kt b/radar-commons/src/main/java/org/radarbase/topic/AvroTopic.kt index b678fc8e..86148f90 100644 --- a/radar-commons/src/main/java/org/radarbase/topic/AvroTopic.kt +++ b/radar-commons/src/main/java/org/radarbase/topic/AvroTopic.kt @@ -18,7 +18,6 @@ package org.radarbase.topic import org.apache.avro.Schema import org.apache.avro.specific.SpecificData import org.apache.avro.specific.SpecificRecord -import java.util.* /** * Kafka topic with Avro schema. diff --git a/radar-commons/src/test/java/org/radarbase/producer/rest/BinaryRecordContentTest.kt b/radar-commons/src/test/java/org/radarbase/producer/rest/BinaryRecordContentTest.kt index bd68f98d..dc13b515 100644 --- a/radar-commons/src/test/java/org/radarbase/producer/rest/BinaryRecordContentTest.kt +++ b/radar-commons/src/test/java/org/radarbase/producer/rest/BinaryRecordContentTest.kt @@ -1,8 +1,9 @@ package org.radarbase.producer.rest -import io.ktor.http.content.* -import io.ktor.util.* -import io.ktor.utils.io.* +import io.ktor.http.content.OutgoingContent +import io.ktor.util.toByteArray +import io.ktor.utils.io.ByteChannel +import io.ktor.utils.io.close import kotlinx.coroutines.launch import kotlinx.coroutines.test.runTest import org.apache.avro.SchemaValidationException diff --git a/radar-commons/src/test/java/org/radarbase/producer/rest/RestKafkaSenderTest.kt b/radar-commons/src/test/java/org/radarbase/producer/rest/RestKafkaSenderTest.kt index e419590d..2194ba9a 100644 --- a/radar-commons/src/test/java/org/radarbase/producer/rest/RestKafkaSenderTest.kt +++ b/radar-commons/src/test/java/org/radarbase/producer/rest/RestKafkaSenderTest.kt @@ -19,7 +19,7 @@ import com.fasterxml.jackson.core.JsonFactory import com.fasterxml.jackson.databind.JsonNode import com.fasterxml.jackson.databind.ObjectMapper import com.fasterxml.jackson.databind.node.JsonNodeType -import io.ktor.util.* +import io.ktor.util.moveToByteArray import kotlinx.coroutines.test.runTest import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer @@ -27,10 +27,18 @@ import org.apache.avro.SchemaValidationException import org.apache.avro.io.DecoderFactory import org.apache.avro.specific.SpecificDatumReader import org.junit.jupiter.api.AfterEach -import org.junit.jupiter.api.Assertions.* +import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.assertFalse +import org.junit.jupiter.api.Assertions.assertNull +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.Assertions.fail import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.mockito.kotlin.* +import org.mockito.Mockito.mock +import org.mockito.kotlin.doReturn +import org.mockito.kotlin.stub +import org.mockito.kotlin.times +import org.mockito.kotlin.verify import org.radarbase.data.AvroRecordData import org.radarbase.producer.AuthenticationException import org.radarbase.producer.rest.RestKafkaSender.Companion.restKafkaSender @@ -43,7 +51,6 @@ import org.radarcns.passive.phone.PhoneLight import org.slf4j.LoggerFactory import java.io.IOException import java.nio.charset.StandardCharsets -import java.util.* import java.util.zip.GZIPInputStream class RestKafkaSenderTest { diff --git a/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRestClientTest.kt b/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRestClientTest.kt index 47e0a964..fa11b132 100644 --- a/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRestClientTest.kt +++ b/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRestClientTest.kt @@ -15,9 +15,8 @@ */ package org.radarbase.producer.schema -import io.ktor.client.* -import io.ktor.client.engine.cio.* -import io.ktor.client.plugins.* +import io.ktor.client.HttpClient +import io.ktor.client.engine.cio.CIO import kotlinx.coroutines.test.runTest import okhttp3.mockwebserver.MockWebServer import org.apache.avro.Schema @@ -28,7 +27,6 @@ import org.junit.jupiter.api.Test import org.radarbase.producer.io.timeout import org.radarbase.producer.rest.RestKafkaSenderTest.Companion.enqueueJson import java.io.IOException -import java.util.* import kotlin.time.Duration.Companion.seconds class SchemaRestClientTest { diff --git a/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRetrieverTest.kt b/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRetrieverTest.kt index d5d302ec..8b77de94 100644 --- a/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRetrieverTest.kt +++ b/radar-commons/src/test/java/org/radarbase/producer/schema/SchemaRetrieverTest.kt @@ -15,7 +15,7 @@ */ package org.radarbase.producer.schema -import io.ktor.client.plugins.* +import io.ktor.client.plugins.defaultRequest import kotlinx.coroutines.test.runTest import okhttp3.mockwebserver.MockResponse import okhttp3.mockwebserver.MockWebServer diff --git a/radar-commons/src/test/java/org/radarbase/topic/KafkaTopicTest.kt b/radar-commons/src/test/java/org/radarbase/topic/KafkaTopicTest.kt index 26cbefde..fdcfc4e0 100644 --- a/radar-commons/src/test/java/org/radarbase/topic/KafkaTopicTest.kt +++ b/radar-commons/src/test/java/org/radarbase/topic/KafkaTopicTest.kt @@ -3,7 +3,7 @@ package org.radarbase.topic import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test import org.junit.jupiter.api.assertThrows -import java.util.* +import java.util.UUID class KafkaTopicTest { @Test @@ -23,17 +23,19 @@ class KafkaTopicTest { @Throws(Exception::class) fun compare() { val randomSize = 100 - val randomString: MutableList = ArrayList(randomSize) - val randomTopic: MutableList = ArrayList(randomSize) - for (i in 0 until randomSize) { - val str = 'a'.toString() + UUID.randomUUID().toString().replace('-', '_') - randomString.add(str) - randomTopic.add(KafkaTopic(str)) - } + val randomString: MutableList = (0 until randomSize) + .mapTo(ArrayList(randomSize)) { 'a'.toString() + UUID.randomUUID().toString().replace('-', '_') } + val randomTopic: MutableList = randomString + .mapTo(ArrayList(randomSize)) { KafkaTopic(it) } + + randomString.shuffle() + randomTopic.shuffle() randomString.sort() randomTopic.sort() - for (i in 0 until randomSize) { - assertEquals(randomString[i], randomTopic[i].name) - } + + randomString.zip(randomTopic) + .forEach { (s, t) -> + assertEquals(s, t.name) + } } } diff --git a/radar-commons/src/test/java/org/radarbase/util/Base64Test.kt b/radar-commons/src/test/java/org/radarbase/util/Base64Test.kt index 66fd0bbc..d24decd6 100644 --- a/radar-commons/src/test/java/org/radarbase/util/Base64Test.kt +++ b/radar-commons/src/test/java/org/radarbase/util/Base64Test.kt @@ -2,7 +2,7 @@ package org.radarbase.util import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test -import java.util.* +import java.util.Base64 import java.util.concurrent.ThreadLocalRandom import kotlin.text.Charsets.UTF_8