mirror of
https://github.com/corda/corda.git
synced 2025-05-30 06:04:24 +00:00
client: Some refactor of Expect dsl, docs
This commit is contained in:
parent
bdb22e1b74
commit
cb956e0979
@ -1,6 +1,5 @@
|
|||||||
package com.r3corda.client
|
package com.r3corda.client
|
||||||
|
|
||||||
import co.paralleluniverse.strands.SettableFuture
|
|
||||||
import com.r3corda.core.contracts.*
|
import com.r3corda.core.contracts.*
|
||||||
import com.r3corda.core.serialization.OpaqueBytes
|
import com.r3corda.core.serialization.OpaqueBytes
|
||||||
import com.r3corda.node.driver.driver
|
import com.r3corda.node.driver.driver
|
||||||
@ -21,7 +20,6 @@ val log: Logger = LoggerFactory.getLogger(WalletMonitorServiceTests::class.java)
|
|||||||
class WalletMonitorServiceTests {
|
class WalletMonitorServiceTests {
|
||||||
@Test
|
@Test
|
||||||
fun cashIssueWorksEndToEnd() {
|
fun cashIssueWorksEndToEnd() {
|
||||||
|
|
||||||
driver {
|
driver {
|
||||||
val aliceNodeFuture = startNode("Alice")
|
val aliceNodeFuture = startNode("Alice")
|
||||||
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(SimpleNotaryService.Type))
|
val notaryNodeFuture = startNode("Notary", advertisedServices = setOf(SimpleNotaryService.Type))
|
||||||
@ -46,26 +44,20 @@ class WalletMonitorServiceTests {
|
|||||||
notary = notaryNode.identity
|
notary = notaryNode.identity
|
||||||
))
|
))
|
||||||
|
|
||||||
val buildFuture = SettableFuture<ServiceToClientEvent.TransactionBuild>()
|
aliceInStream.expectEvents(isStrict = false) {
|
||||||
val eventFuture = SettableFuture<ServiceToClientEvent.OutputState>()
|
parallel(
|
||||||
aliceInStream.subscribe {
|
expect { build: ServiceToClientEvent.TransactionBuild ->
|
||||||
if (it is ServiceToClientEvent.OutputState)
|
val state = build.state
|
||||||
eventFuture.set(it)
|
if (state is TransactionBuildResult.Failed) {
|
||||||
else if (it is ServiceToClientEvent.TransactionBuild)
|
fail(state.message)
|
||||||
buildFuture.set(it)
|
}
|
||||||
else
|
},
|
||||||
log.warn("Unexpected event $it")
|
expect { output: ServiceToClientEvent.OutputState ->
|
||||||
|
require(output.consumed.size == 0)
|
||||||
|
require(output.produced.size == 1)
|
||||||
|
}
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val buildEvent = buildFuture.get()
|
|
||||||
val state = buildEvent.state
|
|
||||||
if (state is TransactionBuildResult.Failed) {
|
|
||||||
fail(state.message)
|
|
||||||
}
|
|
||||||
|
|
||||||
val outputEvent = eventFuture.get()
|
|
||||||
require(outputEvent.consumed.size == 0)
|
|
||||||
require(outputEvent.produced.size == 1)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -13,12 +13,12 @@ import rx.Observable
|
|||||||
* The only restriction on [parallel] is that we should be able to discriminate which branch to take based on the
|
* The only restriction on [parallel] is that we should be able to discriminate which branch to take based on the
|
||||||
* arrived event's type. If this is ambiguous the first matching piece of DSL will be run.
|
* arrived event's type. If this is ambiguous the first matching piece of DSL will be run.
|
||||||
|
|
||||||
* [sequence]s and [parallel]s can be nested arbitrarily
|
* [sequence]s and [parallel]s can be nested arbitrarily.
|
||||||
*
|
*
|
||||||
* Example usage:
|
* Example usage:
|
||||||
*
|
*
|
||||||
* val stream: Observable<SomeEvent> = (..)
|
* val stream: EventStream<SomeEvent> = (..)
|
||||||
* stream.expectEvents(
|
* stream.expectEvents {
|
||||||
* sequence(
|
* sequence(
|
||||||
* expect { event: SomeEvent.A -> require(event.isOk()) },
|
* expect { event: SomeEvent.A -> require(event.isOk()) },
|
||||||
* parallel(
|
* parallel(
|
||||||
@ -26,7 +26,7 @@ import rx.Observable
|
|||||||
* expect { event.SomeEvent.C -> }
|
* expect { event.SomeEvent.C -> }
|
||||||
* )
|
* )
|
||||||
* )
|
* )
|
||||||
* )
|
* }
|
||||||
*
|
*
|
||||||
* The above will test our expectation that the stream should first emit an A, and then a B and C in unspecified order.
|
* The above will test our expectation that the stream should first emit an A, and then a B and C in unspecified order.
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user