-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #34 from bluegroundltd/chore/sw-699-update-logging…
…-structure [SW-699] Update outbox handling logging
- Loading branch information
Showing
8 changed files
with
113 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
core/src/main/kotlin/io/github/bluegroundltd/outbox/processing/OutboxHandlerException.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.bluegroundltd.outbox.processing | ||
|
||
import io.github.bluegroundltd.outbox.item.OutboxItem | ||
|
||
internal data class OutboxHandlerException @JvmOverloads constructor( | ||
private val item: OutboxItem, | ||
override val cause: Throwable, | ||
override val message: String = formatDefaultMessage(item, cause), | ||
) : RuntimeException(message, cause) { | ||
companion object { | ||
private fun formatDefaultMessage(item: OutboxItem, cause: Throwable) = | ||
"Handler for outbox: ${item.id} failed${formatCauseMessage(cause.message)}." | ||
|
||
private fun formatCauseMessage(message: String?): String = | ||
message?.let { " with message: '$it'" } ?: "" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
...c/test/groovy/io/github/bluegroundltd/outbox/processing/OutboxHandlerExceptionSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package io.github.bluegroundltd.outbox.processing | ||
|
||
import io.github.bluegroundltd.outbox.item.OutboxItem | ||
import io.github.bluegroundltd.outbox.utils.OutboxItemBuilder | ||
import spock.lang.Specification | ||
|
||
class OutboxHandlerExceptionSpec extends Specification { | ||
def "Should build an [OutboxHandlerException] with default values"() { | ||
given: | ||
def outboxItem = OutboxItemBuilder.make().build() | ||
def cause = Mock(Throwable) | ||
def expectedMessage = outboxItem.with { | ||
"Handler for outbox: ${it.id} failed${expectedCauseMessage}." | ||
} | ||
|
||
when: | ||
def exception = new OutboxHandlerException(outboxItem, cause) | ||
|
||
then: | ||
1 * cause.getMessage() >> causeMessage | ||
0 * _ | ||
|
||
and: | ||
exception.cause == cause | ||
exception.message == expectedMessage | ||
0 * _ | ||
|
||
where: | ||
causeMessage || expectedCauseMessage | ||
"Exception Message" || " with message: 'Exception Message'" | ||
null || "" | ||
} | ||
|
||
def "Should build an [OutboxHandlerException] with the supplied values"() { | ||
given: | ||
def outboxItem = GroovyMock(OutboxItem) | ||
def cause = Mock(Throwable) | ||
def message = "Exception Message" | ||
|
||
when: | ||
def exception = new OutboxHandlerException(outboxItem, cause, message) | ||
|
||
then: | ||
0 * _ | ||
|
||
and: | ||
exception.message == message | ||
exception.cause == cause | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters