Skip to content

Commit b346279

Browse files
author
Kyle Sletmoe
committed
Merge branch 'pinut-add-bandwidth-builder-dsl' into mainline
* pinut-add-bandwidth-builder-dsl: Bump version number to 1.1.0 add support for bandwidth builder update versions and migrate refresh versions to version catalog only
2 parents 0bc52ef + 8e0f2aa commit b346279

11 files changed

Lines changed: 93 additions & 32 deletions

File tree

build.gradle.kts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import org.jetbrains.dokka.gradle.DokkaTask
44
import java.net.URL
55

66
plugins {
7-
kotlin("jvm") version "1.8.10"
8-
id("org.jetbrains.dokka") version "1.8.10"
9-
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
7+
kotlin("jvm")
8+
id("org.jetbrains.dokka")
9+
id("org.jlleitschuh.gradle.ktlint")
1010

1111
id("signing")
1212
id("maven-publish")
13-
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
13+
id("io.github.gradle-nexus.publish-plugin")
1414
}
1515

1616
group = "com.sletmoe.bucket4k"
@@ -22,7 +22,7 @@ repositories {
2222

2323
dependencies {
2424
implementation(KotlinX.coroutines.core)
25-
api("com.bucket4j:bucket4j-core:_")
25+
api(libs.bucket4j.core)
2626

2727
testImplementation(kotlin("test"))
2828
testImplementation(Testing.kotest.runner.junit5)
@@ -55,7 +55,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
5555
tasks.withType<DokkaTask>().configureEach {
5656
moduleName.set(project.name)
5757
moduleVersion.set(project.version.toString())
58-
outputDirectory.set(buildDir.resolve("dokka/$name"))
58+
outputDirectory.set(layout.buildDirectory.dir("dokka/$name"))
5959
failOnWarning.set(false)
6060
suppressObviousFunctions.set(true)
6161
suppressInheritedMembers.set(false)

buildSrc/build.gradle.kts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import org.gradle.kotlin.dsl.`kotlin-dsl`
2-
3-
repositories {
4-
jcenter()
5-
}
6-
7-
plugins {
8-
`kotlin-dsl`
9-
}
1+
import org.gradle.kotlin.dsl.`kotlin-dsl`
2+
3+
repositories {
4+
mavenCentral()
5+
}
6+
7+
plugins {
8+
`kotlin-dsl`
9+
}

buildSrc/src/main/kotlin/Ci.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
object Ci {
33
// this is the version used for building snapshots
44
// .GITHUB_RUN_NUMBER-snapshot will be appended
5-
private const val snapshotBase = "1.0.0"
5+
private const val snapshotBase = "1.1.0"
66

77
private val githubRunNumber = System.getenv("GITHUB_RUN_NUMBER")
88

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
# Changelog
22

3+
#### 1.1.0
4+
Updated Bucket4J to version 8.9.0 and added support for the new [Bandwidth builder API](https://bucket4j.com/8.9.0/toc.html#bandwidth).
5+
36
#### 1.0.0
47
Initial release.

gradle/libs.versions.toml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Generated by $ ./gradlew refreshVersionsCatalog
2+
3+
[plugins]
4+
5+
org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
6+
7+
org-jetbrains-dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }
8+
9+
org-jlleitschuh-gradle-ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.6.1" }
10+
11+
io-github-gradle-nexus-publish-plugin = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" }
12+
13+
[versions]
14+
15+
kotlin = "1.9.22"
16+
17+
kotlinx-coroutines = "1.8.0"
18+
19+
kotest = "5.8.0"
20+
21+
[libraries]
22+
23+
bucket4j-core = "com.bucket4j:bucket4j-core:8.9.0"
24+
25+
kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }
26+
27+
analysis-kotlin-descriptors = "org.jetbrains.dokka:analysis-kotlin-descriptors:1.9.20"
28+
29+
dokka-base = "org.jetbrains.dokka:dokka-base:1.9.20"
30+
31+
kotlin-scripting-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-scripting-compiler-embeddable", version.ref = "kotlin" }
32+
33+
ktlint = "com.pinterest:ktlint:0.47.1"
34+
35+
ktlint-reporter-baseline = "com.pinterest.ktlint:ktlint-reporter-baseline:0.47.1"
36+
37+
ktlint-ruleset-standard = "com.pinterest.ktlint:ktlint-ruleset-standard:0.47.1"
38+
39+
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" }
40+
41+
kotest-runner-junit5 = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" }
42+
43+
kotest-assertions-core = { group = "io.kotest", name = "kotest-assertions-core", version.ref = "kotest" }

gradle/wrapper/gradle-wrapper.jar

-935 Bytes
Binary file not shown.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
zipStoreBase=GRADLE_USER_HOME
5-
zipStorePath=wrapper/dists
5+
zipStorePath=wrapper/dists

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
rootProject.name = "bucket4k"
22

33
plugins {
4-
id("de.fayard.refreshVersions") version "0.51.0"
4+
id("de.fayard.refreshVersions") version "0.60.5"
55
}
66

77
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")

src/main/kotlin/com/sletmoe/bucket4k/SuspendingBucketConfiguration.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.sletmoe.bucket4k
22

33
import io.github.bucket4j.Bandwidth
4+
import io.github.bucket4j.BandwidthBuilder.BandwidthBuilderBuildStage
5+
import io.github.bucket4j.BandwidthBuilder.BandwidthBuilderCapacityStage
46
import io.github.bucket4j.TimeMeter
57

68
/**
@@ -10,11 +12,11 @@ data class SuspendingBucketConfiguration(
1012
/**
1113
* Set's the TimeMeter to be used by the underlying Bucket4j objects. By default, you may choose either
1214
* TimeMeter.SYSTEM_MILLISECONDS or TimeMeter.SYSTEM_NANOSECONDS. Caution: see Bucket4j's
13-
* [documentation about using nanoseconds](https://bucket4j.com/8.2.0/toc.html#customizing-time-measurement-choosing-nanotime-time-resolution)
15+
* [documentation about using nanoseconds](https://bucket4j.com/8.9.0/toc.html#customizing-time-measurement-choosing-nanotime-time-resolution)
1416
* before choosing that option.
1517
*/
1618
var timeMeter: TimeMeter = TimeMeter.SYSTEM_MILLISECONDS,
17-
private var mutableLimits: MutableList<Bandwidth> = mutableListOf(),
19+
private val mutableLimits: MutableList<Bandwidth> = mutableListOf(),
1820
) {
1921
internal val limits: List<Bandwidth>
2022
get() = mutableLimits.toList()
@@ -23,7 +25,16 @@ data class SuspendingBucketConfiguration(
2325
* Adds a [bandwidth] limit to the bucket. See the Bucket4j documentation on [Bandwidths](https://bucket4j.com/8.2.0/toc.html#bandwidth)
2426
* for more information.
2527
*/
28+
@Deprecated("This method is deprecated, you should use `addLimit { ... }`")
2629
fun addLimit(bandwidth: Bandwidth) {
2730
mutableLimits.add(bandwidth)
2831
}
32+
33+
/**
34+
* Adds a [bandwidth] limit to the bucket. See the Bucket4j documentation on [Bandwidths](https://bucket4j.com/8.9.0/toc.html#bandwidth)
35+
* for more information.
36+
*/
37+
fun addLimit(limit: BandwidthBuilderCapacityStage.() -> BandwidthBuilderBuildStage) {
38+
mutableLimits.add(Bandwidth.builder().limit().build())
39+
}
2940
}

src/test/kotlin/com/sletmoe/bucket4k/SuspendingBucketTest.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
package com.sletmoe.bucket4k
22

3-
import io.github.bucket4j.Bandwidth
4-
import io.github.bucket4j.Refill
3+
import io.kotest.assertions.nondeterministic.eventually
54
import io.kotest.assertions.throwables.shouldThrow
6-
import io.kotest.assertions.timing.eventually
75
import io.kotest.core.spec.style.FunSpec
86
import io.kotest.core.test.testCoroutineScheduler
97
import io.kotest.matchers.shouldBe
@@ -23,7 +21,7 @@ class SuspendingBucketTest : FunSpec() {
2321
beforeEach {
2422
// 5 tokens up front (with a max capacity of 5), add one token per 1 second interval
2523
bucket = SuspendingBucket.build {
26-
addLimit(Bandwidth.classic(5, Refill.intervally(1, 1.seconds.toJavaDuration())))
24+
addLimit { capacity(5).refillIntervally(1, 1.seconds.toJavaDuration()).initialTokens(5) }
2725
}
2826
}
2927

0 commit comments

Comments
 (0)