public void receive(Frame keepAliveFrame) { this.lastReceivedMillis = System.currentTimeMillis(); if (Frame.Keepalive.hasRespondFlag(keepAliveFrame)) { doSend(Frame.Keepalive.from(Unpooled.wrappedBuffer(keepAliveFrame.getData()), false)); } }
@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)); }
@ParameterizedTest @MethodSource("testData") void keepAlives(Supplier<TestData> testDataSupplier) { TestData testData = testDataSupplier.get(); TestDuplexConnection connection = testData.connection(); Flux.interval(Duration.ofMillis(100)) .subscribe( n -> connection.addToReceivedBuffer(Frame.Keepalive.from(Unpooled.EMPTY_BUFFER, true))); Mono.delay(Duration.ofMillis(1500)).block(); RSocket rSocket = testData.rSocket(); List<Throwable> errors = testData.errors().errors(); Assertions.assertThat(rSocket.isDisposed()).isFalse(); Assertions.assertThat(errors).isEmpty(); }
@Override void onIntervalTick() { doCheckTimeout(); doSend(Frame.Keepalive.from(Unpooled.EMPTY_BUFFER, true)); } }
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)); }
@Override void onIntervalTick() { doCheckTimeout(); doSend(Frame.Keepalive.from(Unpooled.EMPTY_BUFFER, true)); } }