Skip to content

Commit a113d7f

Browse files
authored
fix: Exceptions were not saved when Throwable had some fields (#147)
* fix: 특정 예외필드가 serialize가 안되는버그를 수정한다 * docs: version up
1 parent d9a9b33 commit a113d7f

File tree

7 files changed

+138
-3
lines changed

7 files changed

+138
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
55
<br>
66

7-
![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)
7+
![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)
88
![redis--stream](https://img.shields.io/badge/-redis--stream-da2020?style=flat-square&logo=Redis&logoColor=white)
99

1010
**TPS(6,000)** on my Macbook air m2(default options). _[link](#Test1-TPS)_

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ kotlin.code.style=official
22

33
### Project ###
44
group=org.rooftopmsa
5-
version=0.4.6
5+
version=0.4.7
66
compatibility=17
77

88
### Sonarcloud ###

gradle/test.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ dependencies {
1313

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

16+
testImplementation "io.jsonwebtoken:jjwt-api:0.12.5"
17+
runtimeOnly "io.jsonwebtoken:jjwt-impl:0.12.5"
18+
runtimeOnly "io.jsonwebtoken:jjwt-jackson:0.12.5"
1619
}

src/main/kotlin/org/rooftop/netx/engine/listen/AbstractOrchestrateListener.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ internal abstract class AbstractOrchestrateListener<T : Any, V : Any> internal c
7272
sagaEvent.setNextEvent(it)
7373
}
7474
.doOnError {
75-
it.printStackTrace()
7675
rollback(
7776
sagaEvent.id,
7877
it,

src/main/kotlin/org/rooftop/netx/redis/RedisSagaConfigurer.kt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package org.rooftop.netx.redis
22

33
import com.fasterxml.jackson.annotation.JsonAutoDetect
44
import com.fasterxml.jackson.annotation.JsonCreator
5+
import com.fasterxml.jackson.annotation.JsonIgnore
56
import com.fasterxml.jackson.annotation.PropertyAccessor
67
import com.fasterxml.jackson.databind.DeserializationFeature
78
import com.fasterxml.jackson.databind.ObjectMapper
@@ -127,6 +128,23 @@ class RedisSagaConfigurer(
127128
.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, true)
128129
.configure(DeserializationFeature.FAIL_ON_MISSING_CREATOR_PROPERTIES, true)
129130
.configure(DeserializationFeature.FAIL_ON_NULL_FOR_PRIMITIVES, true)
131+
.addMixIn(Throwable::class.java, ThrowableMixIn::class.java)
132+
133+
134+
abstract class ThrowableMixIn {
135+
@JsonIgnore
136+
private val detailMessage: String? = null
137+
138+
@JsonIgnore
139+
private val suppressedExceptions: List<Throwable> = listOf()
140+
141+
@JsonIgnore
142+
private val cause: String? = null
143+
144+
@JsonIgnore
145+
private val stackTrace: Array<StackTraceElement> = arrayOf()
146+
}
147+
130148

131149
@Bean
132150
@ConditionalOnProperty(prefix = "netx", name = ["mode"], havingValue = "redis")

src/test/kotlin/org/rooftop/netx/engine/OrchestratorConfigurer.kt

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package org.rooftop.netx.engine
22

3+
import io.jsonwebtoken.JwtException
34
import org.rooftop.netx.api.*
45
import org.rooftop.netx.api.OrchestratorFactory
6+
import org.rooftop.netx.engine.OrchestratorConfigurer.ListOrchestrate
57
import org.rooftop.netx.engine.OrchestratorTest.Companion.contextResult
68
import org.rooftop.netx.engine.OrchestratorTest.Companion.monoRollbackResult
79
import org.rooftop.netx.engine.OrchestratorTest.Companion.rollbackOrchestratorResult
@@ -259,6 +261,70 @@ internal class OrchestratorConfigurer(
259261
})
260262
}
261263

264+
@Bean(name = ["throwOnStartWithContextOrchestrator"])
265+
fun throwOnStartWithContextOrchestrator(): Orchestrator<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
266+
return OrchestratorFactory.instance()
267+
.create<List<OrchestratorTest.Home>>("throwOnStartWithContextOrchestrator")
268+
.startWithContext(ListOrchestrate { _, _ ->
269+
throw IllegalArgumentException("Throw error for test.")
270+
})
271+
.joinWithContext(ListOrchestrate { _, _ ->
272+
listOf(OrchestratorTest.Home("", mutableListOf()))
273+
})
274+
.commitWithContext(ListOrchestrate { _, _ ->
275+
listOf(OrchestratorTest.Home("", mutableListOf()))
276+
})
277+
}
278+
279+
@Bean(name = ["throwOnJoinWithContextOrchestrator"])
280+
fun throwOnJoinWithContextOrchestrator(): Orchestrator<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
281+
return OrchestratorFactory.instance()
282+
.create<List<OrchestratorTest.Home>>("throwOnJoinWithContextOrchestrator")
283+
.startWithContext(ListOrchestrate { _, _ ->
284+
listOf(OrchestratorTest.Home("", mutableListOf()))
285+
})
286+
.joinWithContext(ListOrchestrate { _, _ ->
287+
throw IllegalArgumentException("Throw error for test.")
288+
})
289+
.commitWithContext(ListOrchestrate { _, _ ->
290+
listOf(OrchestratorTest.Home("", mutableListOf()))
291+
})
292+
}
293+
294+
@Bean(name = ["throwOnCommitWithContextOrchestrator"])
295+
fun throwOnCommitWithContextOrchestrator(): Orchestrator<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
296+
return OrchestratorFactory.instance()
297+
.create<List<OrchestratorTest.Home>>("throwOnCommitWithContextOrchestrator")
298+
.startWithContext(ListOrchestrate { _, _ ->
299+
listOf(OrchestratorTest.Home("", mutableListOf()))
300+
})
301+
.joinWithContext(ListOrchestrate { _, _ ->
302+
listOf(OrchestratorTest.Home("", mutableListOf()))
303+
})
304+
.commitWithContext(ListOrchestrate { _, _ ->
305+
throw IllegalArgumentException("Throw error for test.")
306+
})
307+
}
308+
309+
@Bean(name = ["throwJwtExceptionOnStartOrchestrator"])
310+
fun throwJwtExceptionOnStartOrchestrator(): Orchestrator<String, String> {
311+
return OrchestratorFactory.instance()
312+
.create<String>("throwJwtExceptionOnStartOrchestrator")
313+
.startWithContext({ context, event ->
314+
throw JwtException("Authorization fail")
315+
})
316+
.joinWithContext({ _, _ -> "" })
317+
.commit { "" }
318+
}
319+
320+
fun interface ListOrchestrate :
321+
ContextOrchestrate<List<OrchestratorTest.Home>, List<OrchestratorTest.Home>> {
322+
323+
override fun reified(): TypeReference<List<OrchestratorTest.Home>>? {
324+
return object : TypeReference<List<OrchestratorTest.Home>>() {}
325+
}
326+
}
327+
262328
object PairOrchestrate :
263329
Orchestrate<Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>, Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>> {
264330
override fun orchestrate(request: Pair<OrchestratorTest.Foo, OrchestratorTest.Foo>): Pair<OrchestratorTest.Foo, OrchestratorTest.Foo> {

src/test/kotlin/org/rooftop/netx/engine/OrchestratorTest.kt

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.rooftop.netx.engine
22

3+
import io.jsonwebtoken.JwtException
34
import io.kotest.assertions.nondeterministic.eventually
45
import io.kotest.assertions.throwables.shouldThrowWithMessage
56
import io.kotest.core.annotation.DisplayName
@@ -40,6 +41,10 @@ internal class OrchestratorTest(
4041
private val privateOrchestrator: Orchestrator<Private, Private>,
4142
@Qualifier("throwOnStartOrchestrator") private val throwOnStartOrchestrator: Orchestrator<String, String>,
4243
@Qualifier("throwOnJoinOrchestrator") private val throwOnJoinOrchestrator: Orchestrator<String, String>,
44+
@Qualifier("throwOnStartWithContextOrchestrator") private val throwOnStartWithContextOrchestrator: Orchestrator<List<Home>, List<Home>>,
45+
@Qualifier("throwOnJoinWithContextOrchestrator") private val throwOnJoinWithContextOrchestrator: Orchestrator<List<Home>, List<Home>>,
46+
@Qualifier("throwOnCommitWithContextOrchestrator") private val throwOnCommitWithContextOrchestrator: Orchestrator<List<Home>, List<Home>>,
47+
@Qualifier("throwJwtExceptionOnStartOrchestrator") private val throwJwtExceptionOnStartOrchestrator: Orchestrator<String, String>,
4348
) : DescribeSpec({
4449

4550
describe("numberOrchestrator 구현채는") {
@@ -248,6 +253,50 @@ internal class OrchestratorTest(
248253
}
249254
}
250255
}
256+
257+
describe("throwOnStartWithContextOrchestrator 구현채는") {
258+
context("startWithContext에서 예외가 던져지면,") {
259+
it("해당 예외를 Result에서 throw한다.") {
260+
shouldThrowWithMessage<IllegalArgumentException>("Throw error for test.") {
261+
throwOnStartWithContextOrchestrator.sagaSync(listOf())
262+
.decodeResultOrThrow(object: TypeReference<List<Home>>(){})
263+
}
264+
}
265+
}
266+
}
267+
268+
describe("throwOnJoinWithContextOrchestrator 구현채는") {
269+
context("joinWithContext에서 예외가 던져지면,") {
270+
it("해당 예외를 Result에서 throw한다.") {
271+
shouldThrowWithMessage<IllegalArgumentException>("Throw error for test.") {
272+
throwOnJoinWithContextOrchestrator.sagaSync(listOf())
273+
.decodeResultOrThrow(object: TypeReference<List<Home>>(){})
274+
}
275+
}
276+
}
277+
}
278+
279+
describe("throwOnCommitWithContextOrchestrator 구현채는") {
280+
context("commitWithContext에서 예외가 던져지면,") {
281+
it("해당 예외를 Result에서 throw한다.") {
282+
shouldThrowWithMessage<IllegalArgumentException>("Throw error for test.") {
283+
throwOnCommitWithContextOrchestrator.sagaSync(listOf())
284+
.decodeResultOrThrow(object: TypeReference<List<Home>>(){})
285+
}
286+
}
287+
}
288+
}
289+
290+
describe("throwJwtExceptionOnStartOrchestrator 구현채는") {
291+
context("JwtException이 던져져도,") {
292+
it("해당 예외를 Result에 담고 timeout시간안에 예외를 반환한다") {
293+
shouldThrowWithMessage<JwtException>("Authorization fail") {
294+
throwJwtExceptionOnStartOrchestrator.sagaSync("")
295+
.decodeResultOrThrow(String::class)
296+
}
297+
}
298+
}
299+
}
251300
}) {
252301
data class Home(
253302
val address: String,

0 commit comments

Comments
 (0)