reactor-core icon indicating copy to clipboard operation
reactor-core copied to clipboard

AssertSubscriber not in maven dependency

Open msoub opened this issue 10 years ago • 10 comments

Hello,

It seems that AssertSubscriber is not packaged in: <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-core</artifactId> <version>3.0.3.RELEASE</version> </dependency>

msoub avatar Nov 11 '16 10:11 msoub

It is not. You should use reactor-addons. Also the class name is StepVerifier, you can look at their example here

hsdmiranda avatar Nov 11 '16 12:11 hsdmiranda

Then the changelog is misleading: https://github.com/reactor/reactor-core/releases/tag/v3.0.3.RELEASE

if you used the test class TestSubscriber from the test sources, it has been renamed AssertSubscriber. Please note that in the future, it will be removed in favor of ScriptedSubscriber in the external project reactor-addons/reactor-tests...

Moreover, before I could use assertj to do something like: .assertValuesWith(output -> assertThat(output).contains("foo1", "foo2")) How can I do the equivalent with StepVerifier?

msoub avatar Nov 11 '16 12:11 msoub

You can just use consumeNextWith and you still able to use any assert you want

StepVerifier.create(productPromotionStamp) .consumeNextWith(promotionStamp -> { assertThat(promotionStamp.getGlobalId()).isEqualTo("9200000005286435"); assertThat(promotionStamp.hasImageUrl()).isFalse(); }) .expectComplete() .verify();

hsdmiranda avatar Nov 11 '16 12:11 hsdmiranda

@msoub good point, I will edit the release notes on github

simonbasle avatar Nov 11 '16 15:11 simonbasle

@msoub were you able to work with StepVerifier and does the release note do a better job at pointing to it now?

simonbasle avatar Nov 14 '16 11:11 simonbasle

Yes thank you. One feedback though: I think it's pretty error-prone that we have to explicitly verify the StepVerifier. If we forget the .verify(), no error will be thrown and nothing will be checked.

msoub avatar Nov 14 '16 13:11 msoub

And actually I'm struggling to convert that to the new way:

@Test
public void testProcessor() {
    DirectProcessor<String> processor = DirectProcessor.create();
    AssertSubscriber<String> subscriber = processor.log().subscribeWith(AssertSubscriber.create());

    processor.onNext("1");
    processor.onNext("2");
    processor.onComplete();

    subscriber
        .assertValues("1", "2")
        .assertComplete();
}

Any suggestion?

msoub avatar Nov 14 '16 13:11 msoub

Yes, there's the then() method that you can use to execute code during the verification:

@Test
public void testEmitter() {
    DirectProcessor<String> processor = DirectProcessor.create();

    StepVerifier.create(processor.log())
                // 2 optional checks if you want to ensure nothing comes in
                // before the processor is used
                .expectSubscription()
                .expectNoEvent(Duration.ofMillis(500))
                // manipulate the processor during verification
                .then(() -> {
                    processor.onNext("1");
                    processor.onNext("2");
                    processor.onComplete();
                })
                .expectNext("1", "2")
                .expectComplete()
                .verify();
}

simonbasle avatar Nov 14 '16 13:11 simonbasle

Thank you very much.

What do you think about my remark regarding verify()?

msoub avatar Nov 14 '16 16:11 msoub

Yeah, forgetting verify() is a possibility. The problem is that verify() step has quite a lot to deal with, plus there is a verify(Duration) timeout version... So it would be hard for us to remove that step. We'll try to keep that feedback in mind, see if we come up with an elegant solution.

simonbasle avatar Nov 14 '16 16:11 simonbasle