public void receive(Frame keepAliveFrame) { this.lastReceivedMillis = System.currentTimeMillis(); if (Frame.Keepalive.hasRespondFlag(keepAliveFrame)) { doSend(Frame.Keepalive.from(Unpooled.wrappedBuffer(keepAliveFrame.getData()), false)); } }
break; case KEEPALIVE: additionalFlags = " Respond flag: " + Keepalive.hasRespondFlag(this); break; case REQUEST_STREAM:
@Test(timeout = 2000) @Ignore public void testHandleKeepAlive() throws Exception { rule.connection.addToReceivedBuffer(Frame.Keepalive.from(Unpooled.EMPTY_BUFFER, true)); Frame sent = rule.connection.awaitSend(); assertThat("Unexpected frame sent.", sent.getType(), is(FrameType.KEEPALIVE)); /*Keep alive ack must not have respond flag else, it will result in infinite ping-pong of keep alive frames.*/ assertThat( "Unexpected keep-alive frame respond flag.", Frame.Keepalive.hasRespondFlag(sent), is(false)); }
break; case KEEPALIVE: additionalFlags = " Respond flag: " + Keepalive.hasRespondFlag(this); break; case REQUEST_STREAM:
public void receive(Frame keepAliveFrame) { this.lastReceivedMillis = System.currentTimeMillis(); if (Frame.Keepalive.hasRespondFlag(keepAliveFrame)) { doSend(Frame.Keepalive.from(Unpooled.wrappedBuffer(keepAliveFrame.getData()), false)); } }
@Test void clientRequesterRespondsToKeepAlives() { TestData testData = requester(100, 700, 3).get(); TestDuplexConnection connection = testData.connection(); Mono.delay(Duration.ofMillis(100)) .subscribe( l -> connection.addToReceivedBuffer(Frame.Keepalive.from(Unpooled.EMPTY_BUFFER, true))); Mono<Void> keepAliveResponse = Flux.from(connection.getSentAsPublisher()) .filter(f -> f.getType() == FrameType.KEEPALIVE && !Frame.Keepalive.hasRespondFlag(f)) .next() .then(); StepVerifier.create(keepAliveResponse).expectComplete().verify(Duration.ofSeconds(5)); }