Skip to content

Commit

Permalink
feat: Add kdoc and html docs in publishing artifacts (#8)
Browse files Browse the repository at this point in the history
* feat: Add Kdoc and HTML docs in publishing artifacts
* Increase some test coverage
---------
Signed-off-by: starry-shivam <starry@krsh.dev>
  • Loading branch information
starry-shivam authored Jun 19, 2024
1 parent 5988b1c commit 9729a59
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
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

0 comments on commit 9729a59

Please sign in to comment.