Fixing integration tests

Allowing MessageDeframer.request to be called after the deframer has
been closed.  The stub helpers blindly call request after receiving each
message.
This commit is contained in:
nmittler 2015-01-30 09:59:47 -08:00
parent 89b8d7ff47
commit d0e883ac20
1 changed files with 21 additions and 3 deletions

View File

@ -127,19 +127,30 @@ public class MessageDeframer implements Closeable {
/** /**
* Requests up to the given number of messages from the call to be delivered to * Requests up to the given number of messages from the call to be delivered to
* {@link Listener#messageRead(InputStream, int)}. No additional messages will be delivered. * {@link Listener#messageRead(InputStream)}. No additional messages will be delivered.
*
* <p>If {@link #close()} has been called, this method will have no effect.
* *
* @param numMessages the requested number of messages to be delivered to the listener. * @param numMessages the requested number of messages to be delivered to the listener.
*/ */
public void request(int numMessages) { public void request(int numMessages) {
checkNotClosed();
Preconditions.checkArgument(numMessages > 0, "numMessages must be > 0"); Preconditions.checkArgument(numMessages > 0, "numMessages must be > 0");
if (isClosed()) {
return;
}
pendingDeliveries += numMessages; pendingDeliveries += numMessages;
deliver(); deliver();
} }
/** /**
* Adds the given data to this deframer and attempts delivery to the sink. * Adds the given data to this deframer and attempts delivery to the sink.
*
* @param data the raw data read from the remote endpoint. Must be non-null.
* @param endOfStream if {@code true}, indicates that {@code data} is the end of the stream from
* the remote endpoint.
* @throws IllegalStateException if {@link #close()} has been called previously or if
* {@link #deframe(Buffer, boolean)} has previously been called with
* {@code endOfStream=true}.
*/ */
public void deframe(Buffer data, boolean endOfStream) { public void deframe(Buffer data, boolean endOfStream) {
checkNotClosed(); checkNotClosed();
@ -178,11 +189,18 @@ public class MessageDeframer implements Closeable {
} }
} }
/**
* Indicates whether or not this deframer has been closed.
*/
public boolean isClosed() {
return unprocessed == null;
}
/** /**
* Throws if this deframer has already been closed. * Throws if this deframer has already been closed.
*/ */
private void checkNotClosed() { private void checkNotClosed() {
Preconditions.checkState(unprocessed != null, "MessageDeframer is already closed"); Preconditions.checkState(!isClosed(), "MessageDeframer is already closed");
} }
/** /**