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

fix: Exceptions were not saved when Throwable had some fields #147

Merged
merged 2 commits into from
Sep 23, 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 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<br>

![version 0.4.6](https://img.shields.io/badge/version-0.4.6-black?labelColor=black&style=flat-square) ![jdk 17](https://img.shields.io/badge/minimum_jdk-17-orange?labelColor=black&style=flat-square) ![load-test](https://img.shields.io/badge/load%20test%2010%2C000%2C000-success-brightgreen?labelColor=black&style=flat-square)
![version 0.4.7](https://img.shields.io/badge/version-0.4.7-black?labelColor=black&style=flat-square) ![jdk 17](https://img.shields.io/badge/minimum_jdk-17-orange?labelColor=black&style=flat-square) ![load-test](https://img.shields.io/badge/load%20test%2010%2C000%2C000-success-brightgreen?labelColor=black&style=flat-square)
![redis--stream](https://img.shields.io/badge/-redis--stream-da2020?style=flat-square&logo=Redis&logoColor=white)

**TPS(6,000)** on my Macbook air m2(default options). _[link](#Test1-TPS)_
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ kotlin.code.style=official

### Project ###
group=org.rooftopmsa
version=0.4.6
version=0.4.7
compatibility=17

### Sonarcloud ###
Expand Down
3 changes: 3 additions & 0 deletions gradle/test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ dependencies {

testImplementation "org.awaitility:awaitility:${awaitilityVersion}"

testImplementation "io.jsonwebtoken:jjwt-api:0.12.5"
runtimeOnly "io.jsonwebtoken:jjwt-impl:0.12.5"
runtimeOnly "io.jsonwebtoken:jjwt-jackson:0.12.5"
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ internal abstract class AbstractOrchestrateListener<T : Any, V : Any> internal c
sagaEvent.setNextEvent(it)
}
.doOnError {
it.printStackTrace()
rollback(
sagaEvent.id,
it,
Expand Down
18 changes: 18 additions & 0 deletions src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.rooftop.netx.redis

import com.fasterxml.jackson.annotation.JsonAutoDetect
import com.fasterxml.jackson.annotation.JsonCreator
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.PropertyAccessor
import com.fasterxml.jackson.databind.DeserializationFeature
import com.fasterxml.jackson.databind.ObjectMapper
Expand Down Expand Up @@ -127,6 +128,23 @@ class RedisSagaConfigurer(
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true)
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true)
.addMixIn(Throwable::class.java, ThrowableMixIn::class.java)


abstract class ThrowableMixIn {
@JsonIgnore
private val detailMessage: String? = null

@JsonIgnore
private val suppressedExceptions: List<Throwable> = listOf()

@JsonIgnore
private val cause: String? = null

@JsonIgnore
private val stackTrace: Array<StackTraceElement> = arrayOf()
}


@Bean
@ConditionalOnProperty(prefix = "netx", name = ["mode"], havingValue = "redis")
Expand Down
66 changes: 66 additions & 0 deletions src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package org.rooftop.netx.engine

import io.jsonwebtoken.JwtException
import org.rooftop.netx.api.*
import org.rooftop.netx.api.OrchestratorFactory
import org.rooftop.netx.engine.OrchestratorConfigurer.ListOrchestrate
import org.rooftop.netx.engine.OrchestratorTest.Companion.contextResult
import org.rooftop.netx.engine.OrchestratorTest.Companion.monoRollbackResult
import org.rooftop.netx.engine.OrchestratorTest.Companion.rollbackOrchestratorResult
Expand Down Expand Up @@ -259,6 +261,70 @@ internal class OrchestratorConfigurer(
})
}

@Bean(name = ["throwOnStartWithContextOrchestrator"])
fun throwOnStartWithContextOrchestrator(): Orchestrator<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
return OrchestratorFactory.instance()
.create<List<OrchestratorTest.Home>>("throwOnStartWithContextOrchestrator")
.startWithContext(ListOrchestrate { _, _ ->
throw IllegalArgumentException("Throw error for test.")
})
.joinWithContext(ListOrchestrate { _, _ ->
listOf(OrchestratorTest.Home("", mutableListOf()))
})
.commitWithContext(ListOrchestrate { _, _ ->
listOf(OrchestratorTest.Home("", mutableListOf()))
})
}

@Bean(name = ["throwOnJoinWithContextOrchestrator"])
fun throwOnJoinWithContextOrchestrator(): Orchestrator<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
return OrchestratorFactory.instance()
.create<List<OrchestratorTest.Home>>("throwOnJoinWithContextOrchestrator")
.startWithContext(ListOrchestrate { _, _ ->
listOf(OrchestratorTest.Home("", mutableListOf()))
})
.joinWithContext(ListOrchestrate { _, _ ->
throw IllegalArgumentException("Throw error for test.")
})
.commitWithContext(ListOrchestrate { _, _ ->
listOf(OrchestratorTest.Home("", mutableListOf()))
})
}

@Bean(name = ["throwOnCommitWithContextOrchestrator"])
fun throwOnCommitWithContextOrchestrator(): Orchestrator<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
return OrchestratorFactory.instance()
.create<List<OrchestratorTest.Home>>("throwOnCommitWithContextOrchestrator")
.startWithContext(ListOrchestrate { _, _ ->
listOf(OrchestratorTest.Home("", mutableListOf()))
})
.joinWithContext(ListOrchestrate { _, _ ->
listOf(OrchestratorTest.Home("", mutableListOf()))
})
.commitWithContext(ListOrchestrate { _, _ ->
throw IllegalArgumentException("Throw error for test.")
})
}

@Bean(name = ["throwJwtExceptionOnStartOrchestrator"])
fun throwJwtExceptionOnStartOrchestrator(): Orchestrator<String, String> {
return OrchestratorFactory.instance()
.create<String>("throwJwtExceptionOnStartOrchestrator")
.startWithContext({ context, event ->
throw JwtException("Authorization fail")
})
.joinWithContext({ _, _ -> "" })
.commit { "" }
}

fun interface ListOrchestrate :
ContextOrchestrate<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {

override fun reified(): TypeReference<List<OrchestratorTest.Home>>? {
return object : TypeReference<List<OrchestratorTest.Home>>() {}
}
}

object PairOrchestrate :
Orchestrate<Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>, Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>> {
override fun orchestrate(request: Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>): Pair<OrchestratorTest.Foo, OrchestratorTest.Foo> {
Expand Down
49 changes: 49 additions & 0 deletions src/test/kotlin/org/rooftop/netx/engine/OrchestratorTest.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.rooftop.netx.engine

import io.jsonwebtoken.JwtException
import io.kotest.assertions.nondeterministic.eventually
import io.kotest.assertions.throwables.shouldThrowWithMessage
import io.kotest.core.annotation.DisplayName
Expand Down Expand Up @@ -40,6 +41,10 @@ internal class OrchestratorTest(
private val privateOrchestrator: Orchestrator<Private, Private>,
@Qualifier("throwOnStartOrchestrator") private val throwOnStartOrchestrator: Orchestrator<String, String>,
@Qualifier("throwOnJoinOrchestrator") private val throwOnJoinOrchestrator: Orchestrator<String, String>,
@Qualifier("throwOnStartWithContextOrchestrator") private val throwOnStartWithContextOrchestrator: Orchestrator<List<Home>, List<Home>>,
@Qualifier("throwOnJoinWithContextOrchestrator") private val throwOnJoinWithContextOrchestrator: Orchestrator<List<Home>, List<Home>>,
@Qualifier("throwOnCommitWithContextOrchestrator") private val throwOnCommitWithContextOrchestrator: Orchestrator<List<Home>, List<Home>>,
@Qualifier("throwJwtExceptionOnStartOrchestrator") private val throwJwtExceptionOnStartOrchestrator: Orchestrator<String, String>,
) : DescribeSpec({

describe("numberOrchestrator 구현채는") {
Expand Down Expand Up @@ -248,6 +253,50 @@ internal class OrchestratorTest(
}
}
}

describe("throwOnStartWithContextOrchestrator 구현채는") {
context("startWithContext에서 예외가 던져지면,") {
it("해당 예외를 Result에서 throw한다.") {
shouldThrowWithMessage<IllegalArgumentException>("Throw error for test.") {
throwOnStartWithContextOrchestrator.sagaSync(listOf())
.decodeResultOrThrow(object: TypeReference<List<Home>>(){})
}
}
}
}

describe("throwOnJoinWithContextOrchestrator 구현채는") {
context("joinWithContext에서 예외가 던져지면,") {
it("해당 예외를 Result에서 throw한다.") {
shouldThrowWithMessage<IllegalArgumentException>("Throw error for test.") {
throwOnJoinWithContextOrchestrator.sagaSync(listOf())
.decodeResultOrThrow(object: TypeReference<List<Home>>(){})
}
}
}
}

describe("throwOnCommitWithContextOrchestrator 구현채는") {
context("commitWithContext에서 예외가 던져지면,") {
it("해당 예외를 Result에서 throw한다.") {
shouldThrowWithMessage<IllegalArgumentException>("Throw error for test.") {
throwOnCommitWithContextOrchestrator.sagaSync(listOf())
.decodeResultOrThrow(object: TypeReference<List<Home>>(){})
}
}
}
}

describe("throwJwtExceptionOnStartOrchestrator 구현채는") {
context("JwtException이 던져져도,") {
it("해당 예외를 Result에 담고 timeout시간안에 예외를 반환한다") {
shouldThrowWithMessage<JwtException>("Authorization fail") {
throwJwtExceptionOnStartOrchestrator.sagaSync("")
.decodeResultOrThrow(String::class)
}
}
}
}
}) {
data class Home(
val address: String,
Expand Down
Loading