1111package io .vertx .tests .net .quic ;
1212
1313import io .netty .buffer .ByteBufUtil ;
14+ import io .netty .buffer .Unpooled ;
1415import io .netty .channel .nio .NioEventLoopGroup ;
16+ import io .netty .channel .socket .ChannelOutputShutdownException ;
1517import io .netty .handler .codec .quic .QuicClosedChannelException ;
1618import io .netty .util .NetUtil ;
1719import io .vertx .core .Context ;
1820import io .vertx .core .Future ;
21+ import io .vertx .core .Promise ;
1922import io .vertx .core .Vertx ;
2023import io .vertx .core .buffer .Buffer ;
2124import io .vertx .core .internal .quic .QuicConnectionInternal ;
4043import java .security .KeyStore ;
4144import java .time .Duration ;
4245import java .util .*;
46+ import java .util .concurrent .CompletableFuture ;
4347import java .util .concurrent .CountDownLatch ;
4448import java .util .concurrent .TimeUnit ;
4549import java .util .concurrent .atomic .AtomicBoolean ;
@@ -65,6 +69,10 @@ static QuicServerOptions serverOptions() {
6569 options .getTransportOptions ().setInitialMaxStreamsBidirectional (100L );
6670 options .getTransportOptions ().setInitialMaxStreamsUnidirectional (100L );
6771 options .getTransportOptions ().setActiveMigration (true );
72+
73+ // options.setClientAddressValidation(QuicClientAddressValidation.NONE);
74+ // options.setKeyLogFile("/Users/julien/keylogfile.txt");
75+
6876 return options ;
6977 }
7078
@@ -381,6 +389,82 @@ public void testClientReset() throws Exception {
381389 }
382390 }
383391
392+ @ Test
393+ public void testClientAbortReading () throws Exception {
394+ waitFor (3 );
395+ disableThreadChecks ();
396+ QuicServer server = QuicServer .create (vertx , serverOptions ());
397+ AtomicReference <QuicStream > streamRef = new AtomicReference <>();
398+ server .handler (conn -> {
399+ conn .streamHandler (stream -> {
400+ streamRef .set (stream );
401+ stream .handler (buff -> {
402+ stream .write (buff );
403+ });
404+ });
405+ });
406+ server .bind (SocketAddress .inetSocketAddress (9999 , "localhost" )).await ();
407+ QuicTestClient client = new QuicTestClient (new NioEventLoopGroup (1 ));
408+ try {
409+ client = new QuicTestClient (new NioEventLoopGroup (1 ));
410+ QuicTestClient .Connection connection = client .connect (new InetSocketAddress (NetUtil .LOCALHOST4 , 9999 ));
411+ QuicTestClient .Stream stream = connection .newStream ();
412+ stream .create ();
413+ AtomicInteger received = new AtomicInteger ();
414+ stream .handler (buff -> received .addAndGet (buff .length ));
415+ stream .write ("ping" );
416+ assertWaitUntil (() -> received .get () > 0 );
417+ stream .abort (10 );
418+ try {
419+ streamRef .get ().write ("test" ).await ();
420+ fail ();
421+ } catch (Exception e ) {
422+ assertEquals (ChannelOutputShutdownException .class , e .getClass ());
423+ assertEquals ("STOP_SENDING frame received" , e .getMessage ());
424+ }
425+ } finally {
426+ client .close ();
427+ server .close ().await ();
428+ }
429+ }
430+
431+ @ Test
432+ public void testServerAbortReading () throws Exception {
433+ waitFor (3 );
434+ disableThreadChecks ();
435+ QuicServer server = QuicServer .create (vertx , serverOptions ());
436+ Promise <Void > writeLatch = Promise .promise ();
437+ server .handler (conn -> {
438+ conn .streamHandler (stream -> {
439+ stream .handler (buff -> {
440+ stream
441+ .abort (10 )
442+ .onComplete (writeLatch );
443+ });
444+ });
445+ });
446+ server .bind (SocketAddress .inetSocketAddress (9999 , "localhost" )).await ();
447+ QuicTestClient client = new QuicTestClient (new NioEventLoopGroup (1 ));
448+ try {
449+ client = new QuicTestClient (new NioEventLoopGroup (1 ));
450+ QuicTestClient .Connection connection = client .connect (new InetSocketAddress (NetUtil .LOCALHOST4 , 9999 ));
451+ QuicTestClient .Stream stream = connection .newStream ();
452+ stream .create ();
453+ stream .write ("ping" );
454+ writeLatch .future ().await ();
455+ try {
456+ stream .streamChannel .writeAndFlush (Unpooled .copiedBuffer ("test" , StandardCharsets .UTF_8 )).sync ();
457+ fail ();
458+ } catch (Exception e ) {
459+ assertSame (ChannelOutputShutdownException .class , e .getClass ());
460+ assertEquals ("STOP_SENDING frame received" , e .getMessage ());
461+ }
462+ } finally {
463+ client .close ();
464+ server .close ().await ();
465+ }
466+ }
467+
384468 @ Test
385469 public void testServerReset () throws Exception {
386470 disableThreadChecks ();
0 commit comments