0

At unit test time, I try to bridge the Spring Integration default channel to a queued channel, since I want to check the correctness of the amount of message flow into this channel.

<int:filter input-channel="prevChannel" output-channel="myChannel">
<int:bridge input-channel="myChannel" output-channel="aggregateChannel">
// the reason I have above bridge is I want to check the amount of message after filter.
// I cannot check prevChannel since it is before filtering, and I cannot check aggregateChannel 
// because it has other processing branch

// in test xml I import above normal workflow xml and added below configuration to 
// redirect message from myChannel to checkMyChannel to checking.


<int:bridge input-channel="myChannel"
            output-channel="checkMyChannel"/>

<int:channel id="checkMyChannel">    
    <int:queue/> 
</int:channel>

I autowired checkMyChannel in my unit test but checkMyChannel.getqueuesize() always return 0.

Is there sth I did wrong?

edi
  • 223
  • 5
  • 12

2 Answers2

0

You missed to share test-case with us. We don't have the entire picture. And looks like you have a race condition there. Someone polls all your messages from the checkMyChannel before you start assert that getqueuesize().

In our tests we don't use <poller> for such a cases. We use PollableChannel.receive(timeout) manually.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Your code doesn't work, because I don't know what is `gateway.publish()` and you haven't explained why do you need `` – Artem Bilan Sep 19 '16 at 21:42
  • Wow! There is `aggregateChannel` as well. So, you have two `` for the same `myChannel`, which looks like `DirectChannel` with the default round-robin balancer. So, now your config is more complicated. Not sure which help are you seeking here, but it is difficult to help someone who doesn't cooperate... – Artem Bilan Sep 19 '16 at 21:45
0

got this fixed, I have to declare myChannel to be a publish-subscribe-channel

How to test Spring Integration This one helps, for my case there is a race condition since. "A regular channel with multiple subscribers will round-robin ..."

Community
  • 1
  • 1
edi
  • 223
  • 5
  • 12