Skip to content

Support StateMachineClient concept #781

Open
@jvalkeal

Description

@jvalkeal

As with a new reactive interfaces a communication layer is a bit more complicated than just calling a method to send an event as it used to be with old blocking layer. I think it would be beneficial for a new StateMachineClient to be able to send events in a reactive way and wait some things to happen, etc.

For example in tests we do something like:

	public static <T> Mono<Message<T>> eventAsMono(T event) {
		return Mono.just(MessageBuilder.withPayload(event).build());
	}

	public static <T> Mono<Message<T>> eventAsMono(Message<T> event) {
		return Mono.just(event);
	}

	@SafeVarargs
	public static <T> Flux<Message<T>> eventsAsFlux(T... events) {
		return Flux.fromArray(events).map(e -> MessageBuilder.withPayload(e).build());
	}

	public static <S, E> void doSendEventAndConsumeAll(StateMachine<S, E> stateMachine, E event) {
		StepVerifier.create(stateMachine.sendEvent(eventAsMono(event)))
			.thenConsumeWhile(eventResult -> true)
			.verifyComplete();
	}

	public static <S, E> void doSendEventAndConsumeAll(StateMachine<S, E> stateMachine, Message<E> event) {
		StepVerifier.create(stateMachine.sendEvent(eventAsMono(event)))
			.thenConsumeWhile(eventResult -> true)
			.verifyComplete();
	}

For a simple cases like just wanting to send an event we could just consume returned flux and then provide more higher level features like waiting a particular state, etc. Obviously StepVerifier is a reactor testing utility so we would not use it but provide our own client layer.

All this is just an idea for now and will probably evolve from initial prototyping into a fully usable client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions