-
Hello! I've been writing some unit tests with Here's the sequence of events that led to my confusion: first, I wrote a test that depends on @Test
void testWriteOneInbound() {
// Note: normally, there would be some handlers in the pipeline, but I've
// left them out in the interest of brevity.
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
final String message = "This should pass through the embedded channel";
assertDoesNotThrow(() -> embeddedChannel.writeOneInbound(message).sync());
assertEquals(message, embeddedChannel.inboundMessages().poll());
assertTrue(embeddedChannel.inboundMessages().isEmpty());
} …but then I tried to write an analogous test for @Test
void testWriteOneOutbound() {
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
final String message = "This should pass through the embedded channel";
assertDoesNotThrow(() -> embeddedChannel.writeOneOutbound(message).sync());
assertEquals(message, embeddedChannel.outboundMessages().poll());
assertTrue(embeddedChannel.outboundMessages().isEmpty());
} Specifically, it fails because we detect a potential deadlock when waiting for the
…but if I do essentially the same thing with @Test
void testWriteAndFlush() {
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
final String message = "This should pass through the embedded channel";
assertDoesNotThrow(() -> embeddedChannel.writeAndFlush(message).sync());
assertEquals(message, embeddedChannel.outboundMessages().poll());
assertTrue(embeddedChannel.outboundMessages().isEmpty());
} Now, I'm sure I can dig into the code and figure out what's different between these cases, but I'm less confident that I'll be able to understand the design intent. I haven't been able to find much in the docs or other discussion threads, so I figured I'd ask here. Is this expected behavior? If so, how are we supposed to use Thanks kindly! EDIT: I've poked a little more and I think I can refine this question a bit. The docs for
…and fair enough! If I do a conventional @Test
void testWrite() {
final EmbeddedChannel embeddedChannel = new EmbeddedChannel();
final String message = "This should pass through the embedded channel";
assertDoesNotThrow(() -> embeddedChannel.write(message).sync());
assertEquals(message, embeddedChannel.outboundMessages().poll());
assertTrue(embeddedChannel.outboundMessages().isEmpty());
} …but then that brings me back to the headline question: is there a difference between these sets of methods? When should callers prefer one approach over another? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I really should have just dug into the source code 🤦♂️ The intent is clear: the
I will open a pull request to note these behaviors in the docs. That said: it does seem a little weird to me that the future returned by |
Beta Was this translation helpful? Give feedback.
I really should have just dug into the source code 🤦♂️
The intent is clear: the
writeOne{Inbound|Outbound}
methods:I will open a pull request to note these behaviors in the docs.
That said: it does seem a little weird to me that the future returned by
writeOneOutbound
is all but guaranteed to fail onawait
/sync
. …