Skip to content

Commit

Permalink
Update Kotlin to 1.9.10, and related Maven packages. (#133)
Browse files Browse the repository at this point in the history
* Update Kotlin to 1.9.10, and related Maven packages.

Apply ktlint fixes from ktlint 0.50.0.

* [Squash] Add max_line_length to .editorconfig, and do resulting ktlint fixes.

* Use a dev version of dokka, which fixes a concurrency bug.
  • Loading branch information
JonathanLennox authored Sep 27, 2023
1 parent 02b0c86 commit 6c65524
Show file tree
Hide file tree
Showing 10 changed files with 96 additions and 18 deletions.
7 changes: 7 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
[*.{kt,kts}]
max_line_length = 120

# Comma-separated list of rules to disable (Since 0.34.0)
# Note that rules in any ruleset other than the standard ruleset will need to be prefixed
# by the ruleset identifier.

# I find trailing commas annoying
ktlint_standard_trailing-comma-on-call-site = disabled
ktlint_standard_trailing-comma-on-declaration-site = disabled

[pom.xml]
indent_style = space
indent_size = 4
max_line_length = 120
38 changes: 32 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spotbugs.version>4.6.0</spotbugs.version>
<org.junit.version>5.8.1</org.junit.version>
<org.junit.version>5.10.0</org.junit.version>
<java.version>11</java.version>
<kotlin.version>1.6.21</kotlin.version>
<kotest.version>5.3.0</kotest.version>
<kotlin.version>1.9.10</kotlin.version>
<!-- Note: when this is updated to a non-dev version, remove the pluginDependencies with the Jetbrains dev repo below. -->
<dokka.version>1.9.10-dev-234</dokka.version>
<kotest.version>5.7.2</kotest.version>
<mockk.version>1.13.8</mockk.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -115,6 +118,13 @@
<version>${kotest.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.mockk</groupId>
<artifactId>mockk-jvm</artifactId>
<version>${mockk.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -218,7 +228,7 @@
<plugin>
<groupId>com.github.gantsign.maven</groupId>
<artifactId>ktlint-maven-plugin</artifactId>
<version>1.13.1</version>
<version>2.0.0</version>
<configuration>
<sourceRoots>
<sourceRoot>${project.basedir}/src/main/kotlin</sourceRoot>
Expand Down Expand Up @@ -351,7 +361,7 @@
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<version>${dokka.version}</version>
<executions>
<execution>
<phase>prepare-package</phase>
Expand All @@ -367,7 +377,7 @@
<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>kotlin-as-java-plugin</artifactId>
<version>${kotlin.version}</version>
<version>${dokka.version}</version>
</plugin>
</dokkaPlugins>
</configuration>
Expand All @@ -380,6 +390,22 @@
</plugins>
</build>


<pluginRepositories>
<pluginRepository>
<id>jetbrains-dev</id>
<name>Jetbrains development Repository</name>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>

<url>https://maven.pkg.jetbrains.space/kotlin/p/dokka/dev/</url>
</pluginRepository>
</pluginRepositories>

<profiles>
<profile>
<id>coverage</id>
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/jitsi/utils/Delegates.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ inline fun <T> observableWhenChanged(
Delegates.observable(initialValue) { property, oldValue, newValue ->
if (oldValue != newValue) onChange(property, oldValue, newValue)
}

/**
* A delegate which runs a callback (with no arguments) whenever the setter is called and it results in the value
* changing.
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/org/jitsi/utils/JavaVersion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

@file:JvmName("JavaVersion")

package org.jitsi.utils

fun getJavaVersion(): Int {
Expand Down
27 changes: 24 additions & 3 deletions src/main/kotlin/org/jitsi/utils/RangedString.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,14 @@ fun Iterable<Int>.joinToRangedString(
postfix: CharSequence = "",
rangeLimit: Int = -1,
truncated: CharSequence = "..."
): String = this.iterator().joinToRangedString(separator = separator, rangeSeparator = rangeSeparator, prefix = prefix, postfix = postfix, rangeLimit = rangeLimit, truncated = truncated)
): String = this.iterator().joinToRangedString(
separator = separator,
rangeSeparator = rangeSeparator,
prefix = prefix,
postfix = postfix,
rangeLimit = rangeLimit,
truncated = truncated
)

fun Sequence<Int>.joinToRangedString(
separator: CharSequence = ", ",
Expand All @@ -103,7 +110,14 @@ fun Sequence<Int>.joinToRangedString(
postfix: CharSequence = "",
rangeLimit: Int = -1,
truncated: CharSequence = "..."
): String = this.iterator().joinToRangedString(separator = separator, rangeSeparator = rangeSeparator, prefix = prefix, postfix = postfix, rangeLimit = rangeLimit, truncated = truncated)
): String = this.iterator().joinToRangedString(
separator = separator,
rangeSeparator = rangeSeparator,
prefix = prefix,
postfix = postfix,
rangeLimit = rangeLimit,
truncated = truncated
)

fun Array<Int>.joinToRangedString(
separator: CharSequence = ", ",
Expand All @@ -112,4 +126,11 @@ fun Array<Int>.joinToRangedString(
postfix: CharSequence = "",
rangeLimit: Int = -1,
truncated: CharSequence = "..."
): String = this.iterator().joinToRangedString(separator = separator, rangeSeparator = rangeSeparator, prefix = prefix, postfix = postfix, rangeLimit = rangeLimit, truncated = truncated)
): String = this.iterator().joinToRangedString(
separator = separator,
rangeSeparator = rangeSeparator,
prefix = prefix,
postfix = postfix,
rangeLimit = rangeLimit,
truncated = truncated
)
16 changes: 12 additions & 4 deletions src/main/kotlin/org/jitsi/utils/queue/QueueStatistics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class QueueStatistics(queueSize: Int, val clock: Clock) {
totalPacketsRemoved.increment()
queueLengthStats.addValue(queueSize.toLong())
if (waitTime != null) {
queueWaitStats?.addValue(waitTime.toMillis()) /* TODO: measure in nanos? */
queueWaitStats?.addValue(waitTime.toMillis()) // TODO: measure in nanos?
}
}

Expand Down Expand Up @@ -127,7 +127,11 @@ class QueueStatistics(queueSize: Int, val clock: Clock) {
QueueStatistics(queue.capacity(), clock)
}

fun getStatistics() = OrderedJsonObject().apply { queueStatsById.entries.forEach { put(it.key, it.value.stats) } }
fun getStatistics() = OrderedJsonObject().apply {
queueStatsById.entries.forEach {
put(it.key, it.value.stats)
}
}

/**
* Calculate the capacity statistics buckets for a given queue capacity.
Expand Down Expand Up @@ -175,7 +179,11 @@ class QueueStatisticsObserver<T>(
/**
* A map of the time when objects were put in the queue
*/
private val insertionTime = if (QueueStatistics.TRACK_TIMES) Collections.synchronizedMap(IdentityHashMap<Any, Instant>()) else null
private val insertionTime = if (QueueStatistics.TRACK_TIMES) {
Collections.synchronizedMap(IdentityHashMap<Any, Instant>())
} else {
null
}

private val localStats = if (QueueStatistics.DEBUG) QueueStatistics(queue.capacity(), clock) else null
private val globalStats = QueueStatistics.globalStatsFor(queue, clock)
Expand Down Expand Up @@ -212,7 +220,7 @@ class QueueStatisticsObserver<T>(
*/
override fun dropped(pkt: T) {
queueSize.decrementAndGet()
insertionTime?.remove(pkt) /* TODO: track this time in stats? */
insertionTime?.remove(pkt) // TODO: track this time in stats?

localStats?.dropped()
globalStats.dropped()
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/org/jitsi/utils/stats/BucketStats.kt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ open class BucketStats(
private val totalCount = LongAdder()
private val average: Double
get() = totalValue.sum() / totalCount.sum().toDouble()

/** The maximum value that has been added. */
private val maxValue = AtomicLong(0)

/** The minimum value that has been added. */
private val minValue = AtomicLong(0)
private val buckets = Buckets(thresholds)
Expand Down Expand Up @@ -137,8 +139,10 @@ open class BucketStats(
enum class Format {
/** Include individual buckets, e.g. [min, 0), [0, 10), [10, 20), [20, max] */
Separate,

/** Combine buckets summing from the left, e.g. [min, 0), [min, 10), [min, 20) */
CumulativeLeft,

/** Combine buckets summing from the right, e.g. [0, max], [10, max], [20, max] */
CumulativeRight
}
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/org/jitsi/utils/stats/RateTracker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ open class RateTracker @JvmOverloads constructor(
)
}
}

/**
* Total count recorded in buckets.
*/
Expand Down Expand Up @@ -157,8 +158,10 @@ open class RateTracker @JvmOverloads constructor(
@JvmOverloads
fun update(count: Long = 1, nowMs: Long = clock.millis()) {
val now = coerceMs(nowMs)
if (now < oldestTime) // Too old data is ignored.
if (now < oldestTime) {
// Too old data is ignored.
return
}
if (firstInsertTimeMs < 0) firstInsertTimeMs = nowMs
eraseOld(now)
val nowOffset = (now - oldestTime).toInt()
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/org/jitsi/utils/time/FakeClock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ class FakeClock(
}

override fun withZone(zone: ZoneId?): Clock {
if (zone_ == zone)
if (zone_ == zone) {
return this
}
return FakeClock(zone_ = zone!!)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ class FakeScheduledExecutorServiceTest : ShouldSpec() {
{
numJobRuns++
},
5, 5, TimeUnit.SECONDS
5,
5,
TimeUnit.SECONDS
)
context("and then calling runOne") {
executor.runOne()
Expand Down Expand Up @@ -87,7 +89,9 @@ class FakeScheduledExecutorServiceTest : ShouldSpec() {
// Elapse time inside the job to simulate a long job
executor.clock.elapse(3.secs)
},
5, 5, TimeUnit.SECONDS
5,
5,
TimeUnit.SECONDS
)
should("run the job at a fixed rate") {
// Run the first job
Expand All @@ -107,7 +111,9 @@ class FakeScheduledExecutorServiceTest : ShouldSpec() {
// Elapse time inside the job to simulate a long job
executor.clock.elapse(3.secs)
},
5, 5, TimeUnit.SECONDS
5,
5,
TimeUnit.SECONDS
)
should("run the job with a fixed rate") {
// Run the first job
Expand Down

0 comments on commit 6c65524

Please sign in to comment.