public Flux<Frame> resend(int remotePosition) { updateRemotePosition(remotePosition); if (remotePosition == currentPosition) { return Flux.empty(); } List<Frame> resend = new ArrayList<>(); for (Map.Entry<Integer, Frame> cachePosition : frames.entrySet()) { if (remotePosition < cachePosition.getKey()) { resend.add(cachePosition.getValue()); } // TODO error handling } return Flux.fromIterable(resend); }
public int getEarliestResendPosition() { if (frames.isEmpty()) { return currentPosition; } else { return first(frames); } }
@Test public void supportsZeroBuffer() { cache = new ResumeCache(ResumePositionCounter.frames(), 0); cache.sent(STREAM); cache.sent(STREAM); cache.sent(STREAM); assertEquals(0, cache.getRemotePosition()); assertEquals(42, cache.getCurrentPosition()); assertEquals(42, cache.getEarliestResendPosition()); assertEquals(0, cache.size()); }
@Test public void startsEmpty() { Flux<Frame> x = cache.resend(0); assertEquals(0L, (long) x.count().block()); cache.updateRemotePosition(0); }
@Test(expected = IllegalStateException.class) public void failsForFutureResend() { cache.resend(1); }
@Test public void supportsFrameCountBuffers() { cache = new ResumeCache(ResumePositionCounter.size(), 100); assertEquals(0, cache.getRemotePosition()); assertEquals(0, cache.getCurrentPosition()); assertEquals(0, cache.getEarliestResendPosition()); assertEquals(0, cache.size()); cache.sent(STREAM); assertEquals(0, cache.getRemotePosition()); assertEquals(14, cache.getCurrentPosition()); assertEquals(0, cache.getEarliestResendPosition()); assertEquals(14, cache.size()); cache.updateRemotePosition(14); assertEquals(14, cache.getRemotePosition()); assertEquals(14, cache.getCurrentPosition()); assertEquals(14, cache.getEarliestResendPosition()); assertEquals(0, cache.size()); cache.sent(CANCEL); assertEquals(14, cache.getRemotePosition()); assertEquals(20, cache.getCurrentPosition()); assertEquals(14, cache.getEarliestResendPosition()); assertEquals(6, cache.size());
@Test(expected = IllegalStateException.class) public void failsForFutureUpdatePosition() { cache.updateRemotePosition(1); }
public void sent(Frame frame) { if (ResumeUtil.isTracked(frame)) { frames.put(currentPosition, frame.copy()); bufferSize += strategy.cost(frame); currentPosition += ResumeUtil.offset(frame); if (frames.size() > maxBufferSize) { Frame f = frames.remove(first(frames)); bufferSize -= strategy.cost(f); } } }
@Test public void updatesPositions() { assertEquals(0, cache.getRemotePosition()); assertEquals(0, cache.getCurrentPosition()); assertEquals(0, cache.getEarliestResendPosition()); assertEquals(0, cache.size()); cache.sent(STREAM); assertEquals(0, cache.getRemotePosition()); assertEquals(14, cache.getCurrentPosition()); assertEquals(0, cache.getEarliestResendPosition()); assertEquals(1, cache.size()); cache.updateRemotePosition(14); assertEquals(14, cache.getRemotePosition()); assertEquals(14, cache.getCurrentPosition()); assertEquals(14, cache.getEarliestResendPosition()); assertEquals(0, cache.size()); cache.sent(CANCEL); assertEquals(14, cache.getRemotePosition()); assertEquals(20, cache.getCurrentPosition()); assertEquals(14, cache.getEarliestResendPosition()); assertEquals(1, cache.size()); cache.updateRemotePosition(20);
public Flux<Frame> resend(int remotePosition) { updateRemotePosition(remotePosition); if (remotePosition == currentPosition) { return Flux.empty(); } List<Frame> resend = new ArrayList<>(); for (Map.Entry<Integer, Frame> cachePosition : frames.entrySet()) { if (remotePosition < cachePosition.getKey()) { resend.add(cachePosition.getValue()); } // TODO error handling } return Flux.fromIterable(resend); }
public int getEarliestResendPosition() { if (frames.isEmpty()) { return currentPosition; } else { return first(frames); } }
public void sent(Frame frame) { if (ResumeUtil.isTracked(frame)) { frames.put(currentPosition, frame.copy()); bufferSize += strategy.cost(frame); currentPosition += ResumeUtil.offset(frame); if (frames.size() > maxBufferSize) { Frame f = frames.remove(first(frames)); bufferSize -= strategy.cost(f); } } }