[CORDA-1356]: CashException is unable to derisalize with AMQP through RPC. (fix). (#3274)

This commit is contained in:
Michele Sollecito 2018-05-30 17:15:50 +01:00 committed by GitHub
parent ef2772e328
commit e44b6c6f4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 1 deletions

View File

@ -7,6 +7,8 @@ release, see :doc:`upgrade-notes`.
Unreleased
==========
* Fixed an issue with ``CashException`` not being able to deserialise after the introduction of AMQP for RPC.
* Removed -xmx VM argument from Explorer's Capsule setup. This helps avoiding out of memory errors.
* Shell now kills an ongoing flow when CTRL+C is pressed in the terminal.

View File

@ -0,0 +1,35 @@
package net.corda.finance.compat
import net.corda.core.flows.FlowLogic
import net.corda.core.flows.StartableByRPC
import net.corda.core.messaging.startFlow
import net.corda.core.utilities.getOrThrow
import net.corda.finance.flows.CashException
import net.corda.node.services.Permissions.Companion.all
import net.corda.testing.driver.DriverParameters
import net.corda.testing.driver.driver
import net.corda.testing.node.User
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.junit.Test
class CashExceptionSerialisationTest {
@Test
fun `cash exception with a cause can be serialised with AMQP`() {
driver(DriverParameters(startNodesInProcess = true)) {
val node = startNode(rpcUsers = listOf(User("mark", "dadada", setOf(all())))).getOrThrow()
val action = { node.rpc.startFlow(::CashExceptionThrowingFlow).returnValue.getOrThrow() }
assertThatThrownBy(action).isInstanceOfSatisfying(CashException::class.java) { thrown ->
assertThat(thrown).hasNoCause()
assertThat(thrown.stackTrace).isEmpty()
}
}
}
}
@StartableByRPC
class CashExceptionThrowingFlow : FlowLogic<Unit>() {
override fun call() {
throw CashException("BOOM!", IllegalStateException("Nope dude!"))
}
}

View File

@ -50,4 +50,7 @@ abstract class AbstractCashFlow<out T>(override val progressTracker: ProgressTra
abstract class AbstractRequest(val amount: Amount<Currency>)
}
class CashException(message: String, cause: Throwable) : FlowException(message, cause)
// The internal constructor here allows the ThrowableSerializer to find a suitable constructor even if the `cause` field is removed using reflection by the RPC proxies.
class CashException internal constructor(cause: Throwable?, message: String) : FlowException(message, cause) {
constructor(message: String, cause: Throwable) : this(cause, message)
}