OutgoingCommand extends UDPCommand<OutgoingCommand> { static int backoffMultiple(int sentCount) { if (sentCount >= BACKOFF_MULTIPLE.length) return BACKOFF_MULTIPLE[BACKOFF_MULTIPLE.length - 1]; return BACKOFF_MULTIPLE[sentCount]; } OutgoingCommand(); static OutgoingCommand newOutgoingCommand(CommandType commandType, byte[] payload, int payloadLength, boolean encrypt, byte channel); void setFragmentNum(short fragmentNum); void setStartSeqNum(long startSeqNum); void setFragmentCount(short fragmentCount); void setFragmentPayloadTotalLength(int fragmentPayloadTotalLength); void setFragmentOffset(int fragmentOffset); int getSentCount(); void increaseSentCount(); short getSerializedArrayLength(); byte[] serialize(); void setRetransmissionTimeout(long sentTime, long rtt, long deviation); long getRetransmissionTimeout(); void setSentTime(long sentTime); long getSentTime(); void setTimeout(long timeout); final static int MAX_RESEND_COUNT; }
@Test public void testBackoffMultiple() { int[] expectedBackOffMultiple = {1, 1, 2, 4, 8, 16}; for (int i = 0; i < 10; i++) { int backOff = OutgoingCommand.backoffMultiple(i); int index = (i >= expectedBackOffMultiple.length) ? (expectedBackOffMultiple.length - 1) : i; Assert.assertEquals(expectedBackOffMultiple[index], backOff); } }