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

feat: Add kdoc and html docs in publishing artifacts #8

Merged
merged 3 commits into from
Jun 19, 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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ the issue you want to contribute to before starting to work on it.
### Supporting ❤️

If you found this library helpful, you can support me by giving a small tip
via [GitHub Sponsors](https://github.com/sponsors/starry-shivam) and/or joing the list of [stargazers](https://github.com/starry-shivam/KtScheduler/stargazers) by leaving a star! 🌟
via [GitHub Sponsors](https://github.com/sponsors/starry-shivam) and/or joing the list
of [stargazers](https://github.com/starry-shivam/KtScheduler/stargazers) by leaving a star! 🌟

------

Expand Down
26 changes: 26 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import javax.xml.parsers.DocumentBuilderFactory
plugins {
kotlin("jvm") version "2.0.0"
id("org.jetbrains.kotlinx.kover") version "0.8.1"
id("org.jetbrains.dokka") version "1.9.20"
`maven-publish`
}

Expand Down Expand Up @@ -38,10 +39,35 @@ publishing {
artifactId = "ktscheduler"
version = version.toString()
from(components["java"])

pom {
name.set("KtScheduler")
description.set("Coroutine-based task/job scheduler for Kotlin.")
url.set("https://github.com/Pool-Of-Tears/KtScheduler")

licenses {
license {
name.set("Apache-2.0")
url.set("https://www.apache.org/licenses/LICENSE-2.0.txt")
}
}
}

// Add Dokka and Javadoc artifacts.
artifact(tasks.dokkaJavadoc.get().outputDirectory)
artifact(tasks.dokkaHtml.get().outputDirectory)
}
}
}

tasks.dokkaHtml.configure {
outputDirectory.set(buildDir.resolve("dokka"))
}

tasks.dokkaJavadoc.configure {
outputDirectory.set(buildDir.resolve("javadoc"))
}

// Print line coverage percentage to console so we can generate badge in CI.
tasks.register("printLineCoverage") {
group = "verification"
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/scheduler/KtScheduler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ class KtScheduler(
*/
override fun shutdown() {
logger.info("Shutting down scheduler")
// Check if the scheduler is running or not.
if (!::coroutineScope.isInitialized || !coroutineScope.isActive) {
throw IllegalStateException("Scheduler is not running")
}
coroutineScope.cancel()
logger.info("Scheduler shut down")
}
Expand Down
35 changes: 34 additions & 1 deletion src/test/kotlin/KtSchedulerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import java.time.ZonedDateTime
import kotlin.test.assertEquals
import kotlin.test.assertNotNull
import kotlin.test.assertNull
import kotlin.test.fail

@OptIn(ExperimentalCoroutinesApi::class)
class KtSchedulerTest {
Expand All @@ -42,12 +43,44 @@ class KtSchedulerTest {
scheduler.start()
try {
scheduler.start()
fail("Should throw IllegalStateException")
} catch (e: IllegalStateException) {
assertEquals("Scheduler is already running", e.message)
}
scheduler.shutdown()
}

@Test
fun `scheduler should throw exception when shutting down if not running`() {
val scheduler = KtScheduler()
try {
scheduler.shutdown()
fail("Should throw IllegalStateException")
} catch (e: IllegalStateException) {
assertEquals("Scheduler is not running", e.message)
}
}

@Test
fun `scheduler should block main thread when idle`() {
val thread = Thread {
try {
val scheduler = KtScheduler()
scheduler.start()
scheduler.idle()
fail("Should not reach here")
} catch (_: InterruptedException) {
assertTrue(Thread.interrupted())
}
}
thread.start()
Thread.sleep(500)
if (thread.isAlive) {
thread.interrupt()
thread.join()
}
}

@Test
fun `addJob should add job to the scheduler`() {
val scheduler = KtScheduler()
Expand Down Expand Up @@ -234,7 +267,7 @@ class KtSchedulerTest {
scheduler.addEventListener(eventListener)

scheduler.start()
Thread.sleep(2100)
Thread.sleep(2200)

// Job 1 should be completed twice
assertEquals(2, eventListener.completedJobs.size)
Expand Down
Loading