Skip to content

Commit dd65c02

Browse files
committed
Added KtLint
1 parent 467c5bd commit dd65c02

File tree

76 files changed

+735
-509
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+735
-509
lines changed

build.gradle.kts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins {
1212
id("com.avast.gradle.docker-compose")
1313
id("com.github.ben-manes.versions")
1414
id("io.github.gradle-nexus.publish-plugin")
15+
id("org.jlleitschuh.gradle.ktlint") version "10.3.0"
1516
}
1617

1718
group = "org.radarbase"
@@ -24,8 +25,8 @@ repositories {
2425
description = "RADAR-base output restructuring"
2526
val website = "https://radar-base.org"
2627
val githubRepoName = "RADAR-base/radar-output-restructure"
27-
val githubUrl = "https://github.com/${githubRepoName}"
28-
val issueUrl = "${githubUrl}/issues"
28+
val githubUrl = "https://github.com/$githubRepoName"
29+
val issueUrl = "$githubUrl/issues"
2930

3031
sourceSets {
3132
create("integrationTest") {
@@ -120,8 +121,8 @@ dependencies {
120121
application {
121122
mainClass.set("org.radarbase.output.Application")
122123
applicationDefaultJvmArgs = listOf(
123-
"-Djava.security.egd=file:/dev/./urandom",
124-
"-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager",
124+
"-Djava.security.egd=file:/dev/./urandom",
125+
"-Djava.util.logging.manager=org.apache.logging.log4j.jul.LogManager",
125126
)
126127
}
127128

@@ -204,7 +205,6 @@ publishing {
204205
email.set("[email protected]")
205206
organization.set("The Hyve")
206207
}
207-
208208
}
209209
issueManagement {
210210
system.set("GitHub")
@@ -215,7 +215,7 @@ publishing {
215215
url.set(website)
216216
}
217217
scm {
218-
connection.set("scm:git:${githubUrl}")
218+
connection.set("scm:git:$githubUrl")
219219
url.set(githubUrl)
220220
}
221221
}
@@ -308,6 +308,11 @@ tasks.named<DependencyUpdatesTask>("dependencyUpdates").configure {
308308
}
309309
}
310310

311+
ktlint {
312+
version.set("0.45.2")
313+
disabledRules.set(setOf("no-wildcard-imports"))
314+
}
315+
311316
tasks.wrapper {
312317
gradleVersion = "7.4.2"
313318
}

src/integrationTest/java/org/radarbase/output/RestructureS3IntegrationTest.kt

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,26 @@ class RestructureS3IntegrationTest {
1919
fun integration() = runTest {
2020
Timer.isEnabled = true
2121
val sourceConfig = S3Config(
22-
endpoint ="http://localhost:9000",
23-
accessToken = "minioadmin",
24-
secretKey = "minioadmin",
25-
bucket = "source")
22+
endpoint = "http://localhost:9000",
23+
accessToken = "minioadmin",
24+
secretKey = "minioadmin",
25+
bucket = "source")
2626
val targetConfig = S3Config(
27-
endpoint ="http://localhost:9000",
28-
accessToken = "minioadmin",
29-
secretKey = "minioadmin",
30-
bucket = "target")
27+
endpoint = "http://localhost:9000",
28+
accessToken = "minioadmin",
29+
secretKey = "minioadmin",
30+
bucket = "target")
3131
val config = RestructureConfig(
32-
source = ResourceConfig("s3", s3 = sourceConfig),
33-
target = ResourceConfig("s3", s3 = targetConfig),
34-
paths = PathConfig(inputs = listOf(Paths.get("in"))),
35-
worker = WorkerConfig(minimumFileAge = 0L)
32+
source = ResourceConfig("s3", s3 = sourceConfig),
33+
target = ResourceConfig("s3", s3 = targetConfig),
34+
paths = PathConfig(inputs = listOf(Paths.get("in"))),
35+
worker = WorkerConfig(minimumFileAge = 0L)
3636
)
3737
val application = Application(config)
3838
val sourceClient = sourceConfig.createS3Client()
39-
if (!sourceClient.bucketExists(BucketExistsArgs.Builder().bucketBuild(sourceConfig.bucket))) {
39+
if (!sourceClient.bucketExists(BucketExistsArgs.Builder()
40+
.bucketBuild(sourceConfig.bucket))
41+
) {
4042
sourceClient.makeBucket(MakeBucketArgs.Builder().bucketBuild(sourceConfig.bucket))
4143
}
4244

@@ -67,8 +69,10 @@ class RestructureS3IntegrationTest {
6769
launch { assertEquals(1L, redis.del("offsets/android_phone_acceleration.json")) }
6870
}
6971

70-
val firstParticipantOutput = "output/STAGING_PROJECT/1543bc93-3c17-4381-89a5-c5d6272b827c/application_server_status"
71-
val secondParticipantOutput = "output/radar-test-root/4ab9b985-6eec-4e51-9a29-f4c571c89f99/android_phone_acceleration"
72+
val firstParticipantOutput =
73+
"output/STAGING_PROJECT/1543bc93-3c17-4381-89a5-c5d6272b827c/application_server_status"
74+
val secondParticipantOutput =
75+
"output/radar-test-root/4ab9b985-6eec-4e51-9a29-f4c571c89f99/android_phone_acceleration"
7276

7377
val files = coroutineScope {
7478
launch(Dispatchers.IO) {

src/integrationTest/java/org/radarbase/output/accounting/OffsetRangeRedisTest.kt

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,21 @@ class OffsetRangeRedisTest {
8080

8181
redisHolder.execute { redis ->
8282
val range = redisOffsetReader.readValue<OffsetRedisPersistence.Companion.RedisOffsetRangeSet>(redis.get(testFile.toString()))
83-
assertEquals(OffsetRedisPersistence.Companion.RedisOffsetRangeSet(listOf(
84-
OffsetRedisPersistence.Companion.RedisOffsetIntervals("a", 0, listOf(
85-
OffsetRangeSet.Range(0, 2, lastModified),
86-
OffsetRangeSet.Range(4, 4, lastModified)))
87-
)), range)
83+
assertEquals(
84+
OffsetRedisPersistence.Companion.RedisOffsetRangeSet(
85+
listOf(
86+
OffsetRedisPersistence.Companion.RedisOffsetIntervals(
87+
topic = "a",
88+
partition = 0,
89+
ranges = listOf(
90+
OffsetRangeSet.Range(0, 2, lastModified),
91+
OffsetRangeSet.Range(4, 4, lastModified),
92+
),
93+
),
94+
),
95+
),
96+
range
97+
)
8898
}
8999

90100
val rangeSet = offsetPersistence.read(testFile)

src/main/java/org/radarbase/output/Application.kt

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ import kotlin.system.exitProcess
4949

5050
/** Main application. */
5151
class Application(
52-
config: RestructureConfig
52+
config: RestructureConfig,
5353
) : FileStoreFactory {
5454

5555
override val config = config.apply { validate() }
@@ -64,13 +64,15 @@ class Application(
6464
override val sourceStorage: SourceStorage
6565
get() = sourceStorageFactory.createSourceStorage()
6666

67-
override val targetStorage: TargetStorage = TargetStorageFactory(config.target).createTargetStorage()
67+
override val targetStorage: TargetStorage =
68+
TargetStorageFactory(config.target).createTargetStorage()
6869

6970
override val redisHolder: RedisHolder = RedisHolder(JedisPool(config.redis.uri))
7071
override val remoteLockManager: RemoteLockManager = RedisRemoteLockManager(
71-
redisHolder, config.redis.lockPrefix)
72+
redisHolder, config.redis.lockPrefix)
7273

73-
override val offsetPersistenceFactory: OffsetPersistenceFactory = OffsetRedisPersistence(redisHolder)
74+
override val offsetPersistenceFactory: OffsetPersistenceFactory =
75+
OffsetRedisPersistence(redisHolder)
7476

7577
override val workerSemaphore = Semaphore(config.worker.numThreads * 2)
7678

@@ -116,7 +118,8 @@ class Application(
116118
}
117119

118120
private fun runService() {
119-
logger.info("Running as a Service with poll interval of {} seconds", config.service.interval)
121+
logger.info("Running as a Service with poll interval of {} seconds",
122+
config.service.interval)
120123
logger.info("Press Ctrl+C to exit...")
121124

122125
runBlocking {
@@ -131,7 +134,7 @@ class Application(
131134
const val CACHE_SIZE_DEFAULT = 100
132135

133136
internal fun LongAdder.format(): String =
134-
NumberFormat.getNumberInstance().format(sum())
137+
NumberFormat.getNumberInstance().format(sum())
135138

136139
private fun parseArgs(args: Array<String>): CommandLineArgs {
137140
val commandLineArgs = CommandLineArgs()
@@ -161,7 +164,7 @@ class Application(
161164
val commandLineArgs = parseArgs(args)
162165

163166
logger.info("Starting at {}...",
164-
DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now()))
167+
DateTimeFormatter.ISO_LOCAL_DATE_TIME.format(LocalDateTime.now()))
165168

166169
// Enable singleton timer statements in the code.
167170
Timer.isEnabled = commandLineArgs.enableTimer

src/main/java/org/radarbase/output/accounting/Accountant.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ interface Accountant : SuspendedCloseable {
4444
internal val lastModified: Instant,
4545
)
4646
}
47-

src/main/java/org/radarbase/output/accounting/AccountantImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import kotlin.io.path.exists
1414
open class AccountantImpl(
1515
private val factory: FileStoreFactory,
1616
private val topic: String,
17-
): Accountant {
17+
) : Accountant {
1818
private lateinit var offsetFile: OffsetPersistenceFactory.Writer
1919

2020
override val offsets: OffsetRangeSet
@@ -38,15 +38,15 @@ open class AccountantImpl(
3838
private suspend fun readDeprecatedOffsets(
3939
config: RestructureConfig,
4040
targetStorage: TargetStorage,
41-
topic: String
41+
topic: String,
4242
): OffsetRangeSet? {
4343
val offsetsPath = config.paths.output
4444
.resolve(OFFSETS_FILE_NAME)
4545
.resolve("$topic.csv")
4646

4747
return if (offsetsPath.exists()) {
4848
OffsetFilePersistence(targetStorage).read(offsetsPath)
49-
.also { offsetsPath.deleteExisting() }
49+
.also { offsetsPath.deleteExisting() }
5050
} else null
5151
}
5252

src/main/java/org/radarbase/output/accounting/OffsetFilePersistence.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ import kotlin.io.path.createTempFile
3737
* not present.
3838
*/
3939
class OffsetFilePersistence(
40-
private val targetStorage: TargetStorage
41-
): OffsetPersistenceFactory {
40+
private val targetStorage: TargetStorage,
41+
) : OffsetPersistenceFactory {
4242
override suspend fun read(path: Path): OffsetRangeSet? {
4343
return try {
4444
if (targetStorage.status(path) != null) {
4545
withContext(Dispatchers.IO) {
4646
OffsetRangeSet().also { set ->
4747
targetStorage.newBufferedReader(path).useLines { lines ->
4848
lines
49-
.drop(1) // ignore header
49+
.drop(1) // ignore header
5050
.map(::parseLine)
5151
.forEach(set::add)
5252
}
@@ -62,7 +62,7 @@ class OffsetFilePersistence(
6262
override fun writer(
6363
scope: CoroutineScope,
6464
path: Path,
65-
startSet: OffsetRangeSet?
65+
startSet: OffsetRangeSet?,
6666
): OffsetPersistenceFactory.Writer = FileWriter(scope, path, startSet)
6767

6868
private fun parseLine(line: String): TopicPartitionOffsetRange {
@@ -79,11 +79,12 @@ class OffsetFilePersistence(
7979
} else Instant.now()
8080

8181
return TopicPartitionOffsetRange(
82-
topic,
83-
cols[2].toInt(),
84-
cols[0].toLong(),
85-
cols[1].toLong(),
86-
lastModified)
82+
topic,
83+
cols[2].toInt(),
84+
cols[0].toLong(),
85+
cols[1].toLong(),
86+
lastModified,
87+
)
8788
}
8889

8990
companion object {
@@ -94,9 +95,9 @@ class OffsetFilePersistence(
9495
private inner class FileWriter(
9596
scope: CoroutineScope,
9697
private val path: Path,
97-
startSet: OffsetRangeSet?
98-
): PostponedWriter(scope, "offsets", 1, TimeUnit.SECONDS),
99-
OffsetPersistenceFactory.Writer {
98+
startSet: OffsetRangeSet?,
99+
) : PostponedWriter(scope, "offsets", 1, TimeUnit.SECONDS),
100+
OffsetPersistenceFactory.Writer {
100101
override val offsets: OffsetRangeSet = startSet ?: OffsetRangeSet()
101102

102103
override suspend fun doWrite() = time("accounting.offsets") {

src/main/java/org/radarbase/output/accounting/OffsetIntervals.kt

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class OffsetIntervals {
2525
val searchIndex = offsetsFrom.binarySearch(range.from)
2626
val index = if (searchIndex >= 0) searchIndex else -searchIndex - 2
2727
val rangeTo = range.to ?: range.from
28-
return (index >= 0
29-
&& rangeTo <= offsetsTo[index]
30-
&& range.lastProcessed <= lastProcessed[index])
28+
return index >= 0 &&
29+
rangeTo <= offsetsTo[index] &&
30+
range.lastProcessed <= lastProcessed[index]
3131
}
3232

3333
fun contains(offset: Long, lastModified: Instant): Boolean {
@@ -38,9 +38,9 @@ class OffsetIntervals {
3838
}
3939

4040
val indexBefore = -searchIndex - 2
41-
return (indexBefore >= 0
42-
&& offset <= offsetsTo[indexBefore]
43-
&& lastModified <= lastProcessed[indexBefore])
41+
return indexBefore >= 0 &&
42+
offset <= offsetsTo[indexBefore] &&
43+
lastModified <= lastProcessed[indexBefore]
4444
}
4545

4646
fun add(offset: Long, lastModified: Instant) {
@@ -122,7 +122,7 @@ class OffsetIntervals {
122122
}
123123

124124
fun forEach(
125-
action: (offsetFrom: Long, offsetTo: Long, lastModified: Instant) -> Unit
125+
action: (offsetFrom: Long, offsetTo: Long, lastModified: Instant) -> Unit,
126126
) = repeat(lastProcessed.size) { i ->
127127
action(offsetsFrom[i], offsetsTo[i], lastProcessed[i])
128128
}
@@ -133,10 +133,12 @@ class OffsetIntervals {
133133

134134
fun size(): Int = offsetsFrom.size()
135135

136-
override fun toString(): String {
137-
return ("[" + lastProcessed.indices.joinToString(", ") { i ->
136+
override fun toString(): String = buildString {
137+
append('[')
138+
lastProcessed.indices.joinTo(this@buildString, separator = ", ") { i ->
138139
"(${offsetsFrom[i]} - ${offsetsTo[i]}, ${lastProcessed[i]})"
139-
} + "]")
140+
}
141+
append(']')
140142
}
141143

142144
fun remove(range: OffsetRangeSet.Range) {
@@ -145,12 +147,12 @@ class OffsetIntervals {
145147

146148
var index = offsetsFrom.binarySearch(from)
147149

148-
if (index < 0) { // search comes between -index - 2 and -index - 1
150+
if (index < 0) { // search comes between -index - 2 and -index - 1
149151
index = -index - 1 // is the next stored offsetFrom index after from
150152
// There is a previous from index. Check for overlap
151153
if (index > 0) {
152154
val prevIndex = index - 1
153-
if (from <= offsetsTo[prevIndex]) { // there is overlap
155+
if (from <= offsetsTo[prevIndex]) { // there is overlap
154156
if (to < offsetsTo[prevIndex]) { // the range falls inside an existing interval
155157
// create new interval after the removed range. The interval before the
156158
// range remains.
@@ -165,7 +167,7 @@ class OffsetIntervals {
165167
// remove intervals inside range
166168
while (offsetsFrom[index] >= from && offsetsTo[index] <= to) {
167169
removeAt(index)
168-
if (index == offsetsTo.size()) { // last interval has been removed
170+
if (index == offsetsTo.size()) { // last interval has been removed
169171
return
170172
}
171173
}
@@ -199,6 +201,6 @@ class OffsetIntervals {
199201
}
200202

201203
companion object {
202-
private fun <T: Comparable<T>> max(a: T, b: T): T = if (a >= b) a else b
204+
private fun <T : Comparable<T>> max(a: T, b: T): T = if (a >= b) a else b
203205
}
204206
}

src/main/java/org/radarbase/output/accounting/OffsetPersistenceFactory.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ interface OffsetPersistenceFactory {
3737
fun writer(scope: CoroutineScope, path: Path, startSet: OffsetRangeSet? = null): Writer
3838

3939
/** Offset Writer to given persistence type. */
40-
interface Writer: SuspendedCloseable {
40+
interface Writer : SuspendedCloseable {
4141
/** Current offsets. */
4242
val offsets: OffsetRangeSet
4343

0 commit comments

Comments
 (0)