Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assert that a special event is raised in an integration test #415

Closed
d0x opened this Issue Jan 8, 2015 · 3 comments

Comments

Projects
None yet
3 participants
@d0x
Copy link

d0x commented Jan 8, 2015

I like to use Reactor in my Integration test.
For that it would be nice to have an assert method.

Smth. like this:

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = VotesAppApplication.class)
@WebAppConfiguration
public class VotesAppApplicationTest {

    @Autowired
    Reactor reactor;

    @Test
    public void ping_pong_test() throws InterruptedException {
        reactor.notify("group.inbox", Event.wrap("Ping"));

        // If the integration works well, the business logic should answer with "Pong" to "group.outbox"

        assertThat(reactor, receives("Pong").in("group.outbox"));
    }
}

If there is already a way of doing this, please update it in the wiki.

@smaldini

This comment has been minimized.

Copy link
Member

smaldini commented Jan 8, 2015

Nope there's not but that would be nice indeed!

@jbrisbin

This comment has been minimized.

Copy link

jbrisbin commented Jan 8, 2015

This would be nice indeed. But I think if we're to do it right, we would need to introduce another submodule: reactor-test.

@d0x

This comment has been minimized.

Copy link
Author

d0x commented Jan 8, 2015

For my usecase I did it now like this (better then nothing):

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = VotesAppApplication.class)
@WebAppConfiguration
public class VotesAppApplicationTest {

    @Autowired
    Reactor reactor;

    @Test(timeout = 1_000)
    public void contextLoads() throws InterruptedException {

        final AtomicBoolean success = new AtomicBoolean(false);

        // expect
        reactor.on(Selectors.$("group.outbox"), e -> {
            synchronized (reactor) {
                success.compareAndSet("Pong").equals(e.getData()));
                reactor.notifyAll();
            }
        });

        // given
        reactor.notify("group.inbox", Event.wrap("Ping")));

        // wait
        synchronized (reactor) {
            while (!success.get()) {
                reactor.wait();
            }
        }

        assertThat(success.get(), is(true));
    }
}

It's not nice because i use reactor for the lock, all the boilerplate and the wrong order of expect and given. Also the error messages is bad because i rely on the timeout...
If you have tips, be open :)

Maybe I'll open an Stackoverflow Question to find/discuss a better solution :)
(I will edit this comment when i do this)

@smaldini smaldini added the legacy label Jan 4, 2017

@smaldini smaldini closed this Jan 4, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.