### Question:
FlowControlCounter { public synchronized TryConsumeResult tryConsume(final long sid, final long offset) { checkArgument(offset > 0); final StreamCounter stream = streams.computeIfAbsent(sid, ignored -> new StreamCounter()); final long streamMax = stream.maxOffset.get(); final AtomicLong streamConsumed = stream.offset; final long connOffset = calculateConnectionOffset(); final long streamDelta = offset - streamConsumed.get(); final long resultingConnOffset; final long resultingStreamOffset; final boolean success; if (streamDelta < 0) { success = true; resultingConnOffset = connOffset; resultingStreamOffset = streamConsumed.get(); } else if (streamDelta > 0 && stream.finished) { throw new IllegalStateException("Stream finished"); } else if (offset > streamMax || connOffset + streamDelta > connectionMaxBytes.get()) { success = false; resultingConnOffset = connOffset + streamDelta; resultingStreamOffset = offset; } else { success = true; streamConsumed.updateAndGet(current -> max(current, offset)); resultingConnOffset = connOffset + streamDelta; resultingStreamOffset = streamConsumed.get(); } return new TryConsumeResult( success, resultingConnOffset, connectionMaxBytes.get(), resultingStreamOffset, streamMax); } FlowControlCounter(final long connectionMaxBytes, final long streamMaxBytes); synchronized TryConsumeResult tryConsume(final long sid, final long offset); void resetStream(final long sid, final long finalOffset); void setConnectionMaxBytes(final long connectionMaxBytes); long increaseStreamMax(final long sid); long increaseConnectionMax(); void setStreamMaxBytes(final long sid, final long streamMaxBytes);  }### Answer:
@Test public void tryConsumeOutOfOrder() { assertConsume(fcm.tryConsume(sid, 8), true, 8, maxConn, 8, maxStream); assertConsume(fcm.tryConsume(sid, 7), true, 8, maxConn, 8, maxStream); }
@Test(expected = IllegalArgumentException.class) public void tryConsumeNegative() { fcm.tryConsume(sid, -8); }