96 |
96 |
97 SendFailedNotificationHandler handler = |
97 SendFailedNotificationHandler handler = |
98 new SendFailedNotificationHandler(); |
98 new SendFailedNotificationHandler(); |
99 ByteBuffer recvBuffer = direct ? allocateDirect(recvBufferSize) |
99 ByteBuffer recvBuffer = direct ? allocateDirect(recvBufferSize) |
100 : allocate((recvBufferSize)); |
100 : allocate((recvBufferSize)); |
101 channel.receive(recvBuffer, null, handler); |
101 MessageInfo info = channel.receive(recvBuffer, null, handler); |
102 |
102 debug("receive returned info:" + info); |
103 // verify sent buffer received by send failed notification |
103 |
104 ByteBuffer buffer = handler.getSendFailedByteBuffer(); |
104 if (handler.receivedSendFailed) { |
105 check(buffer.remaining() == sent); |
105 // verify sent buffer received by send failed notification |
106 check(buffer.position() == 0); |
106 ByteBuffer buffer = handler.getSendFailedByteBuffer(); |
107 check(buffer.limit() == sent); |
107 check(buffer.remaining() == sent); |
108 assertSameContent(sendBuffer, handler.getSendFailedByteBuffer()); |
108 check(buffer.position() == 0); |
|
109 check(buffer.limit() == sent); |
|
110 assertSameContent(sendBuffer, handler.getSendFailedByteBuffer()); |
|
111 } else { |
|
112 debug("Unexpected event or received data. Check output."); |
|
113 } |
109 } |
114 } |
110 } |
115 } |
111 |
116 |
112 class SendFailedNotificationHandler extends AbstractNotificationHandler<Object> |
117 class SendFailedNotificationHandler extends AbstractNotificationHandler<Object> |
113 { |
118 { |
114 /** Reference to the buffer captured in send failed notification */ |
119 /** Reference to the buffer captured in send failed notification */ |
115 private ByteBuffer sentBuffer; |
120 private ByteBuffer sentBuffer; |
|
121 boolean receivedSendFailed; |
116 |
122 |
117 @Override |
123 @Override |
118 public HandlerResult handleNotification( |
124 public HandlerResult handleNotification( |
119 Notification notification, Object attachment) { |
125 Notification notification, Object attachment) { |
120 fail("Unknown notification type"); |
126 fail("Unknown notification type"); |
133 |
139 |
134 @Override |
140 @Override |
135 public HandlerResult handleNotification( |
141 public HandlerResult handleNotification( |
136 SendFailedNotification notification, Object attachment) { |
142 SendFailedNotification notification, Object attachment) { |
137 debug("%nSendFailedNotification: %s. ", notification); |
143 debug("%nSendFailedNotification: %s. ", notification); |
|
144 receivedSendFailed = true; |
138 sentBuffer = notification.buffer(); |
145 sentBuffer = notification.buffer(); |
139 return HandlerResult.RETURN; |
146 return HandlerResult.RETURN; |
140 } |
147 } |
141 |
148 |
142 public ByteBuffer getSendFailedByteBuffer() { |
149 public ByteBuffer getSendFailedByteBuffer() { |