|
1 | 1 | /*
|
2 |
| - * Copyright 2015-2021 the original author or authors. |
| 2 | + * Copyright 2015-2025 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
23 | 23 | import io.rsocket.Closeable;
|
24 | 24 | import io.rsocket.FrameAssert;
|
25 | 25 | import io.rsocket.RSocket;
|
| 26 | +import io.rsocket.exceptions.RejectedSetupException; |
26 | 27 | import io.rsocket.frame.FrameType;
|
27 | 28 | import io.rsocket.frame.KeepAliveFrameCodec;
|
28 | 29 | import io.rsocket.frame.RequestResponseFrameCodec;
|
| 30 | +import io.rsocket.frame.SetupFrameCodec; |
29 | 31 | import io.rsocket.test.util.TestDuplexConnection;
|
30 | 32 | import io.rsocket.test.util.TestServerTransport;
|
| 33 | +import io.rsocket.util.EmptyPayload; |
31 | 34 | import java.time.Duration;
|
32 | 35 | import java.util.Random;
|
33 | 36 | import org.assertj.core.api.Assertions;
|
@@ -164,4 +167,35 @@ public void unexpectedFramesBeforeSetup() {
|
164 | 167 | server.dispose();
|
165 | 168 | transport.alloc().assertHasNoLeaks();
|
166 | 169 | }
|
| 170 | + |
| 171 | + @Test |
| 172 | + public void ensuresErrorFrameDeliveredPriorConnectionDisposal() { |
| 173 | + TestServerTransport transport = new TestServerTransport(); |
| 174 | + Closeable server = |
| 175 | + RSocketServer.create() |
| 176 | + .acceptor( |
| 177 | + (setup, sendingSocket) -> Mono.error(new RejectedSetupException("ACCESS_DENIED"))) |
| 178 | + .bind(transport) |
| 179 | + .block(); |
| 180 | + |
| 181 | + TestDuplexConnection connection = transport.connect(); |
| 182 | + connection.addToReceivedBuffer( |
| 183 | + SetupFrameCodec.encode( |
| 184 | + ByteBufAllocator.DEFAULT, |
| 185 | + false, |
| 186 | + 0, |
| 187 | + 1, |
| 188 | + Unpooled.EMPTY_BUFFER, |
| 189 | + "metadata_type", |
| 190 | + "data_type", |
| 191 | + EmptyPayload.INSTANCE)); |
| 192 | + |
| 193 | + StepVerifier.create(connection.onClose()).expectComplete().verify(Duration.ofSeconds(30)); |
| 194 | + FrameAssert.assertThat(connection.pollFrame()) |
| 195 | + .hasStreamIdZero() |
| 196 | + .hasData("ACCESS_DENIED") |
| 197 | + .hasNoLeaks(); |
| 198 | + server.dispose(); |
| 199 | + transport.alloc().assertHasNoLeaks(); |
| 200 | + } |
167 | 201 | }
|
0 commit comments