546 Pipe.SourceChannel source = p.source(); |
546 Pipe.SourceChannel source = p.source(); |
547 |
547 |
548 // write to sink to ensure that the source is readable |
548 // write to sink to ensure that the source is readable |
549 sink.write(messageBuffer()); |
549 sink.write(messageBuffer()); |
550 |
550 |
|
551 source.configureBlocking(false); |
|
552 SelectionKey key1 = source.register(sel, SelectionKey.OP_READ); |
|
553 // make sure pipe source is readable before we do following checks. |
|
554 // this is sometime necessary on windows where pipe is implemented |
|
555 // as a pair of connected socket, so there is no guarantee that written |
|
556 // bytes on sink side is immediately available on source side. |
|
557 sel.select(); |
|
558 |
551 sink.configureBlocking(false); |
559 sink.configureBlocking(false); |
552 source.configureBlocking(false); |
560 SelectionKey key2 = sink.register(sel, SelectionKey.OP_WRITE); |
553 SelectionKey key1 = sink.register(sel, SelectionKey.OP_WRITE); |
|
554 SelectionKey key2 = source.register(sel, SelectionKey.OP_READ); |
|
555 |
|
556 sel.selectNow(); |
561 sel.selectNow(); |
|
562 |
557 assertTrue(sel.keys().contains(key1)); |
563 assertTrue(sel.keys().contains(key1)); |
558 assertTrue(sel.keys().contains(key2)); |
564 assertTrue(sel.keys().contains(key2)); |
559 assertTrue(sel.selectedKeys().contains(key1)); |
565 assertTrue(sel.selectedKeys().contains(key1)); |
560 assertTrue(sel.selectedKeys().contains(key2)); |
566 assertTrue(sel.selectedKeys().contains(key2)); |
561 |
567 |