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(SimpleCachePlugin.kt): add error handling for failed calls #20

Merged
merged 3 commits into from
Oct 15, 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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ allprojects {

group = "com.ucasoft.ktor"

version = "0.4.3"
version = "0.4.4"

repositories {
mavenCentral()
Expand Down
4 changes: 2 additions & 2 deletions ktor-simple-cache/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ktor Simple Cache
Base solution which provides the plugin implementation and abstract class for cache providers.

[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-cache/0.4.3?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-cache/0.4.3/jar)
[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-cache/0.4.4?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-cache/0.4.4/jar)
## Setup
### Gradle
```kotlin
repositories {
mavenCentral()
}

implementation("com.ucasoft.ktor:ktor-simple-cache:0.4.3")
implementation("com.ucasoft.ktor:ktor-simple-cache:0.4.4")
```
## Usage
```kotlin
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.ucasoft.ktor.simpleCache

import io.ktor.http.*
import io.ktor.server.application.*
import io.ktor.server.application.hooks.*
import io.ktor.server.request.*
import io.ktor.server.response.*
import io.ktor.util.*
Expand All @@ -24,6 +25,10 @@ val SimpleCachePlugin = createRouteScopedPlugin(name = "SimpleCachePlugin", ::Si
it.respond(cache)
}
}
on(CallFailed) { _, e ->
provider.badResponse()
throw e
}
onCallRespond { call, body ->
if ((call.response.status() ?: HttpStatusCode.OK) >= HttpStatusCode.BadRequest) {
provider.badResponse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,29 @@ internal class SimpleCacheTests {
}
}

@Test
fun `check route thrown exceptions aren not locked`() {
with(buildTestEngine(buildProvider(), Application::testApplication)) {

runBlocking {
val totalThreads = 100
val deferred = (1..totalThreads).map {
async {
shouldThrow<RuntimeException> {
client.get("/exception")
}
}
}

val result = deferred.awaitAll().map { it.message }.groupBy { it }
.map { it.key to it.value.size }
result.shouldBeSingleton {
it.second.shouldBe(totalThreads)
}
}
}
}

@Test
fun `check all parameters`() {
val firstCacheKey = "/check?param1=value1&param2=value2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ fun Application.testApplication() {
get("/bad") {
call.respond(HttpStatusCode.BadRequest, "Bad request")
}
get("/exception") {
throw RuntimeException("Just an exception")
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions ktor-simple-memory-cache/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ktor Simple Memory Cache
Memory cache provider for Ktor Simple Cache plugin

[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-memory-cache/0.4.3?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-memory-cache/0.4.3/jar)
[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-memory-cache/0.4.4?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-memory-cache/0.4.4/jar)
## Setup
### Gradle
```kotlin
repositories {
mavenCentral()
}

implementation("com.ucasoft.ktor:ktor-simple-memory-cache:0.4.3")
implementation("com.ucasoft.ktor:ktor-simple-memory-cache:0.4.4")
```
## Usage
```kotlin
Expand Down
4 changes: 2 additions & 2 deletions ktor-simple-redis-cache/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Ktor Simple Redis Cache
Redis cache provider for Ktor Simple Cache plugin

[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-redis-cache/0.4.3?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-redis-cache/0.4.3/jar)
[![Maven Central with version prefix filter](https://img.shields.io/maven-central/v/com.ucasoft.ktor/ktor-simple-redis-cache/0.4.4?color=blue)](https://search.maven.org/artifact/com.ucasoft.ktor/ktor-simple-redis-cache/0.4.4/jar)
## Setup
### Gradle
```kotlin
repositories {
mavenCentral()
}

implementation("com.ucasoft.ktor:ktor-simple-redis-cache:0.4.3")
implementation("com.ucasoft.ktor:ktor-simple-redis-cache:0.4.4")
```
## Usage
```kotlin
Expand Down
Loading