Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add bandwidth builder dsl #1

Merged
merged 3 commits into from
Mar 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import org.jetbrains.dokka.gradle.DokkaTask
import java.net.URL

plugins {
kotlin("jvm") version "1.8.10"
id("org.jetbrains.dokka") version "1.8.10"
id("org.jlleitschuh.gradle.ktlint") version "11.3.1"
kotlin("jvm")
id("org.jetbrains.dokka")
id("org.jlleitschuh.gradle.ktlint")

id("signing")
id("maven-publish")
id("io.github.gradle-nexus.publish-plugin") version "1.3.0"
id("io.github.gradle-nexus.publish-plugin")
}

group = "com.sletmoe.bucket4k"
Expand All @@ -22,7 +22,7 @@ repositories {

dependencies {
implementation(KotlinX.coroutines.core)
api("com.bucket4j:bucket4j-core:_")
api(libs.bucket4j.core)

testImplementation(kotlin("test"))
testImplementation(Testing.kotest.runner.junit5)
Expand Down Expand Up @@ -55,7 +55,7 @@ tasks.withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile>().configureEach
tasks.withType<DokkaTask>().configureEach {
moduleName.set(project.name)
moduleVersion.set(project.version.toString())
outputDirectory.set(buildDir.resolve("dokka/$name"))
outputDirectory.set(layout.buildDirectory.dir("dokka/$name"))
failOnWarning.set(false)
suppressObviousFunctions.set(true)
suppressInheritedMembers.set(false)
Expand Down
18 changes: 9 additions & 9 deletions buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import org.gradle.kotlin.dsl.`kotlin-dsl`
repositories {
jcenter()
}
plugins {
`kotlin-dsl`
}
import org.gradle.kotlin.dsl.`kotlin-dsl`

repositories {
mavenCentral()
}

plugins {
`kotlin-dsl`
}
43 changes: 43 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## Generated by $ ./gradlew refreshVersionsCatalog

[plugins]

org-jetbrains-kotlin-jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }

org-jetbrains-dokka = { id = "org.jetbrains.dokka", version = "1.9.20" }

org-jlleitschuh-gradle-ktlint = { id = "org.jlleitschuh.gradle.ktlint", version = "11.6.1" }

io-github-gradle-nexus-publish-plugin = { id = "io.github.gradle-nexus.publish-plugin", version = "1.3.0" }

[versions]

kotlin = "1.9.22"

kotlinx-coroutines = "1.8.0"

kotest = "5.8.0"

[libraries]

bucket4j-core = "com.bucket4j:bucket4j-core:8.9.0"

kotlinx-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" }

analysis-kotlin-descriptors = "org.jetbrains.dokka:analysis-kotlin-descriptors:1.9.20"

dokka-base = "org.jetbrains.dokka:dokka-base:1.9.20"

kotlin-scripting-compiler-embeddable = { group = "org.jetbrains.kotlin", name = "kotlin-scripting-compiler-embeddable", version.ref = "kotlin" }

ktlint = "com.pinterest:ktlint:0.47.1"

ktlint-reporter-baseline = "com.pinterest.ktlint:ktlint-reporter-baseline:0.47.1"

ktlint-ruleset-standard = "com.pinterest.ktlint:ktlint-ruleset-standard:0.47.1"

kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test" }

kotest-runner-junit5 = { group = "io.kotest", name = "kotest-runner-junit5", version.ref = "kotest" }

kotest-assertions-core = { group = "io.kotest", name = "kotest-assertions-core", version.ref = "kotest" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStorePath=wrapper/dists
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rootProject.name = "bucket4k"

plugins {
id("de.fayard.refreshVersions") version "0.51.0"
id("de.fayard.refreshVersions") version "0.60.5"
}

enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.sletmoe.bucket4k

import io.github.bucket4j.Bandwidth
import io.github.bucket4j.BandwidthBuilder.BandwidthBuilderBuildStage
import io.github.bucket4j.BandwidthBuilder.BandwidthBuilderCapacityStage
import io.github.bucket4j.TimeMeter

/**
Expand All @@ -10,11 +12,11 @@ data class SuspendingBucketConfiguration(
/**
* Set's the TimeMeter to be used by the underlying Bucket4j objects. By default, you may choose either
* TimeMeter.SYSTEM_MILLISECONDS or TimeMeter.SYSTEM_NANOSECONDS. Caution: see Bucket4j's
* [documentation about using nanoseconds](https://bucket4j.com/8.2.0/toc.html#customizing-time-measurement-choosing-nanotime-time-resolution)
* [documentation about using nanoseconds](https://bucket4j.com/8.9.0/toc.html#customizing-time-measurement-choosing-nanotime-time-resolution)
* before choosing that option.
*/
var timeMeter: TimeMeter = TimeMeter.SYSTEM_MILLISECONDS,
private var mutableLimits: MutableList<Bandwidth> = mutableListOf(),
private val mutableLimits: MutableList<Bandwidth> = mutableListOf(),
) {
internal val limits: List<Bandwidth>
get() = mutableLimits.toList()
Expand All @@ -23,7 +25,16 @@ data class SuspendingBucketConfiguration(
* Adds a [bandwidth] limit to the bucket. See the Bucket4j documentation on [Bandwidths](https://bucket4j.com/8.2.0/toc.html#bandwidth)
* for more information.
*/
@Deprecated("This method is deprecated, you should use `addLimit { ... }`")
fun addLimit(bandwidth: Bandwidth) {
mutableLimits.add(bandwidth)
}

/**
* Adds a [bandwidth] limit to the bucket. See the Bucket4j documentation on [Bandwidths](https://bucket4j.com/8.9.0/toc.html#bandwidth)
* for more information.
*/
fun addLimit(limit: BandwidthBuilderCapacityStage.() -> BandwidthBuilderBuildStage) {
mutableLimits.add(Bandwidth.builder().limit().build())
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.sletmoe.bucket4k

import io.github.bucket4j.Bandwidth
import io.github.bucket4j.Refill
import io.kotest.assertions.nondeterministic.eventually
import io.kotest.assertions.throwables.shouldThrow
import io.kotest.assertions.timing.eventually
import io.kotest.core.spec.style.FunSpec
import io.kotest.core.test.testCoroutineScheduler
import io.kotest.matchers.shouldBe
Expand All @@ -23,7 +21,7 @@ class SuspendingBucketTest : FunSpec() {
beforeEach {
// 5 tokens up front (with a max capacity of 5), add one token per 1 second interval
bucket = SuspendingBucket.build {
addLimit(Bandwidth.classic(5, Refill.intervally(1, 1.seconds.toJavaDuration())))
addLimit { capacity(5).refillIntervally(1, 1.seconds.toJavaDuration()).initialTokens(5) }
}
}

Expand Down
20 changes: 13 additions & 7 deletions versions.properties
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
#### Dependencies and Plugin versions with their available updates.
#### Generated by `./gradlew refreshVersions` version 0.51.0
#### Generated by `./gradlew refreshVersions` version 0.60.5
####
#### Don't manually edit or split the comments that start with four hashtags (####),
#### they will be overwritten by refreshVersions.
####
#### suppress inspection "SpellCheckingInspection" for whole file
#### suppress inspection "UnusedProperty" for whole file
####
#### NOTE: Some versions are filtered by the rejectVersionsIf predicate. See the settings.gradle.kts file.
#### NOTE: Some versions are filtered by the rejectVersionIf predicate. See the settings.gradle.kts file.

version.com.bucket4j..bucket4j-core=8.2.0
plugin.org.jlleitschuh.gradle.ktlint=11.6.1

version.kotest=5.5.5
## # available=5.6.0
## # available=5.6.1
version.kotlin=1.9.22

version.kotlinx.coroutines=1.6.4
plugin.org.jetbrains.dokka=1.9.20

plugin.io.github.gradle-nexus.publish-plugin=1.3.0

plugin.de.fayard.buildSrcLibs=0.60.5

version.kotest=5.8.0

version.kotlinx.coroutines=1.8.0
Loading