protected void sendStreamOfCommands(int[] sequenceNumbers, boolean expected, int expectedCount) { for (int i = 0; i < sequenceNumbers.length; i++) { int commandId = sequenceNumbers[i]; ConsumerInfo info = new ConsumerInfo(); info.setSelector("Cheese: " + commandId); info.setCommandId(commandId); transport.onCommand(info); } Queue<Object> exceptions = listener.getExceptions(); Queue<Object> commands = listener.getCommands(); if (expected) { if (!exceptions.isEmpty()) { Exception e = (Exception) exceptions.remove(); e.printStackTrace(); fail("Caught exception: " + e); } assertEquals("number of messages received", expectedCount, commands.size()); assertEquals("Should have no buffered commands", 0, transport.getBufferedCommandCount()); } else { assertTrue("Should have received an exception!", exceptions.size() > 0); Exception e = (Exception) exceptions.remove(); LOG.info("Caught expected response: " + e); } }
@Override protected void setUp() throws Exception { if (replayStrategy == null) { replayStrategy = new ExceptionIfDroppedReplayStrategy(); } transport = new ReliableTransport(new StubTransport(), replayStrategy); transport.setTransportListener(listener); transport.start(); }
public void testOldDuplicatePacketsDroppedUsingNegativeCounters() throws Exception { int[] sequenceNumbers = {-3, -1, -3, -2, -1, 0, 1, -1, 3, 2, 0, 2, 4}; transport.setExpectedCounter(-3); sendStreamOfCommands(sequenceNumbers, true, 8); }
public void testValidWrapAroundPackets() throws Exception { int[] sequenceNumbers = new int[10]; int value = Integer.MAX_VALUE - 3; transport.setExpectedCounter(value); for (int i = 0; i < 10; i++) { LOG.info("command: " + i + " = " + value); sequenceNumbers[i] = value++; } sendStreamOfCommands(sequenceNumbers, true); }