Skip to content

Commit

Permalink
remove SmallWebSocketDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
mostroverkhov committed Sep 3, 2024
1 parent 3d9c9fe commit d211857
Show file tree
Hide file tree
Showing 6 changed files with 2 additions and 412 deletions.
23 changes: 1 addition & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ websocket codecs, minimal heap allocations on frame path, and compatibility with

### use case & scope

* Intended for dense binary data & small text messages: no extensions (compression) support.
* Intended for dense binary data & text messages: no extensions (compression) support.

* No per-frame heap allocations in websocket frameFactory / decoder.

Expand All @@ -29,9 +29,6 @@ properly publish messages on eventloop thread.
frame encoder [[2]](https://github.com/jauntsdn/netty-websocket-http1/blob/fb7bbb12d4fc0e62a72845dee89fe8f1d86f9a0a/netty-websocket-http1-test/src/test/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketCodecTest.java#L1019) (encode frame prefix into provided bytebuffer),
frame bulk-encoder [[3]](https://github.com/jauntsdn/netty-websocket-http1/blob/fb7bbb12d4fc0e62a72845dee89fe8f1d86f9a0a/netty-websocket-http1-test/src/test/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketCodecTest.java#L707) (much more performant - encode multiple frames into provided bytebuffer).

* Dedicated decoder for case of exchanging tiny messages over TLS connection:
only non-masked frames with <= 125 bytes of payload for minimal per-webSocket state (memory) overhead.

### performance

Per-core throughput [this codec perf-test](https://github.com/jauntsdn/netty-websocket-http1/tree/develop/netty-websocket-http1-perftest/src/main/java/com/jauntsdn/netty/handler/codec/http/websocketx/perftest),
Expand Down Expand Up @@ -120,24 +117,6 @@ public interface WebSocketCallbacksHandler {
}
```

### configuration

#### default messages decoder

Always expects masked frames, allows mask mismatch [test example](https://github.com/jauntsdn/netty-websocket-http1/blob/bc942b19958c1486ef7414bee9c69ef36a55bfa5/netty-websocket-http1-test/src/test/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketHandshakeTest.java#L121)

server: `allowMaskMismatch: true, maxFramePayloadLength: 65_535`

client: `allowMaskMismatch: true, maxFramePayloadLength: 65_535`

#### small messages decoder

Always expects non-masking frames, disallows mask mismatch [test example](https://github.com/jauntsdn/netty-websocket-http1/blob/bc942b19958c1486ef7414bee9c69ef36a55bfa5/netty-websocket-http1-test/src/test/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketHandshakeTest.java#L140):

server: `expectMasked: false, allowMaskMismatch: false, maxFramePayloadLength: 125`

client: `mask: false, allowMaskMismatch: false, maxFramePayloadLength: 125`

### tests

* WebSocket frames [integration test](https://github.com/jauntsdn/netty-websocket-http1/blob/develop/netty-websocket-http1-test/src/test/java/com/jauntsdn/netty/handler/codec/http/websocketx/WebSocketCodecTest.java):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
import java.util.stream.Stream;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.params.ParameterizedTest;
Expand Down Expand Up @@ -268,26 +267,6 @@ void allSizeBinaryFramesDefaultDecoder(
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void binaryFramesSmallDecoder() throws Exception {
int maxFrameSize = SMALL_CODEC_MAX_FRAME_SIZE;
Channel s = server = nettyServer(new WebSocketFramesTestServerHandler(), false, false);
BinaryFramesTestClientHandler clientHandler = new BinaryFramesTestClientHandler(maxFrameSize);
Channel client =
webSocketCallbacksClient(s.localAddress(), false, false, maxFrameSize, clientHandler);

WebSocketFrameFactory webSocketFrameFactory = clientHandler.onHandshakeCompleted().join();
Assertions.assertThat(webSocketFrameFactory)
.isExactlyInstanceOf(NonMaskingWebSocketEncoder.FrameFactory.class);
Assertions.assertThat(client.pipeline().get(SmallWebSocketDecoder.class)).isNotNull();

CompletableFuture<Void> onCompleted = clientHandler.startFramesExchange();
onCompleted.join();
client.close();
}

@Timeout(300)
@MethodSource("maskingArgs")
@ParameterizedTest
Expand All @@ -311,28 +290,6 @@ void allSizeTextFramesDefaultDecoder(
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void textFramesSmallDecoder() throws Exception {
int maxFrameSize = SMALL_CODEC_MAX_FRAME_SIZE;
char content = 'a';
Channel s =
server = nettyServer(new TextFramesTestServerHandler(maxFrameSize, content), false, false);
TextFramesTestClientHandler clientHandler =
new TextFramesTestClientHandler(maxFrameSize, content);
Channel client =
webSocketCallbacksClient(s.localAddress(), false, false, maxFrameSize, clientHandler);

WebSocketFrameFactory webSocketFrameFactory = clientHandler.onHandshakeCompleted().join();
Assertions.assertThat(webSocketFrameFactory)
.isExactlyInstanceOf(NonMaskingWebSocketEncoder.FrameFactory.class);
Assertions.assertThat(client.pipeline().get(SmallWebSocketDecoder.class)).isNotNull();

clientHandler.onFrameExchangeCompleted().join();
client.close();
}

@Timeout(15)
@MethodSource("maskingArgs")
@ParameterizedTest
Expand All @@ -355,27 +312,6 @@ void pingFramesDefaultDecoder(
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void pingFramesSmallDecoder() throws Exception {
int maxFrameSize = SMALL_CODEC_MAX_FRAME_SIZE;
Channel s = server = nettyServer(new PingPongTestServerHandler(), false, false);
PingFramesTestClientHandler clientHandler =
new PingFramesTestClientHandler(maxFrameSize, (byte) 0xFE);
Channel client =
webSocketCallbacksClient(s.localAddress(), false, false, maxFrameSize, clientHandler);

WebSocketFrameFactory webSocketFrameFactory = clientHandler.onHandshakeCompleted().join();
Assertions.assertThat(webSocketFrameFactory)
.isExactlyInstanceOf(NonMaskingWebSocketEncoder.FrameFactory.class);
Assertions.assertThat(client.pipeline().get(SmallWebSocketDecoder.class)).isNotNull();

CompletableFuture<Void> onComplete = clientHandler.startFramesExchange();
onComplete.join();
client.close();
}

@Timeout(15)
@MethodSource("maskingArgs")
@ParameterizedTest
Expand All @@ -398,27 +334,6 @@ void pongFramesDefaultDecoder(
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void pongFramesSmallDecoder() throws Exception {
int maxFrameSize = SMALL_CODEC_MAX_FRAME_SIZE;
Channel s = server = nettyServer(new PingPongTestServerHandler(), false, false);
PongFramesTestClientHandler clientHandler =
new PongFramesTestClientHandler(maxFrameSize, (byte) 0xFE);
Channel client =
webSocketCallbacksClient(s.localAddress(), false, false, maxFrameSize, clientHandler);

WebSocketFrameFactory webSocketFrameFactory = clientHandler.onHandshakeCompleted().join();
Assertions.assertThat(webSocketFrameFactory)
.isExactlyInstanceOf(NonMaskingWebSocketEncoder.FrameFactory.class);
Assertions.assertThat(client.pipeline().get(SmallWebSocketDecoder.class)).isNotNull();

CompletableFuture<Void> onComplete = clientHandler.startFramesExchange();
onComplete.join();
client.close();
}

@Timeout(15)
@ParameterizedTest
@MethodSource("maskingArgs")
Expand All @@ -441,27 +356,6 @@ void closeFramesDefaultDecoder(
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void closeFramesSmallDecoder() throws Exception {
int maxFrameSize = SMALL_CODEC_MAX_FRAME_SIZE;
Channel s = server = nettyServer(new CloseTestServerHandler(), false, false);
CloseFramesTestClientHandler clientHandler =
new CloseFramesTestClientHandler(WebSocketCloseStatus.NORMAL_CLOSURE, "NORMAL_CLOSURE");
Channel client =
webSocketCallbacksClient(s.localAddress(), false, false, maxFrameSize, clientHandler);

WebSocketFrameFactory webSocketFrameFactory = clientHandler.onHandshakeCompleted().join();
Assertions.assertThat(webSocketFrameFactory)
.isExactlyInstanceOf(NonMaskingWebSocketEncoder.FrameFactory.class);
Assertions.assertThat(client.pipeline().get(SmallWebSocketDecoder.class)).isNotNull();

CompletableFuture<Void> onComplete = clientHandler.startFramesExchange();
onComplete.join();
client.close();
}

@Timeout(15)
@ParameterizedTest
@MethodSource("maskingArgs")
Expand All @@ -485,28 +379,6 @@ void fragmentDefaultDecoder(
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void fragmentSmallDecoder() throws Exception {
int maxFrameSize = SMALL_CODEC_MAX_FRAME_SIZE;

Channel s = server = nettyServer(new FragmentTestServerHandler(33), false, false);
InboundFragmentationFramesTestClientHandler clientHandler =
new InboundFragmentationFramesTestClientHandler(70);
Channel client =
webSocketCallbacksClient(s.localAddress(), false, false, maxFrameSize, clientHandler);

WebSocketFrameFactory webSocketFrameFactory = clientHandler.onHandshakeCompleted().join();
Assertions.assertThat(webSocketFrameFactory)
.isExactlyInstanceOf(NonMaskingWebSocketEncoder.FrameFactory.class);
Assertions.assertThat(client.pipeline().get(SmallWebSocketDecoder.class)).isNotNull();

CompletableFuture<Void> onComplete = clientHandler.startFramesExchange();
onComplete.join();
client.close();
}

@Timeout(15)
@Test
void strictMaskedDecoderUnmaskedFrame() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
import java.util.function.Consumer;
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

Expand Down Expand Up @@ -155,26 +154,6 @@ void defaultDecoderConfig() throws Exception {
client.close();
}

@Disabled("small decoder will be removed on next release")
@Timeout(15)
@Test
void smallDecoderConfig() throws Exception {
WebSocketDecoderConfig decoderConfig = webSocketDecoderConfig(false, false, 125);
TestWebSocketHandler serverHandler = new TestWebSocketHandler();
Channel s = server = testServer("/", decoderConfig, serverHandler);

TestWebSocketHandler clientHandler = new TestWebSocketHandler();
Channel client = testClient(s.localAddress(), "/", false, false, 125, clientHandler);

clientHandler.onOpen.join();
Assertions.assertThat(clientHandler.channel.pipeline().get(SmallWebSocketDecoder.class))
.isNotNull();
serverHandler.onOpen.join();
Assertions.assertThat(serverHandler.channel.pipeline().get(SmallWebSocketDecoder.class))
.isNotNull();
client.close();
}

@Timeout(15)
@Test
void clientTimeout() throws InterruptedException {
Expand Down
Loading

0 comments on commit d211857

Please sign in to comment.