@@ -632,60 +632,68 @@ public void testFullRequestValidationSuccess() {
632
632
assertThat (netty4HttpHeaderValidator .getState (), equalTo (WAITING_TO_START ));
633
633
634
634
ByteBuf buf = channel .alloc ().buffer ();
635
- ByteBufUtil .copy (AsciiString .of ("test full http request" ), buf );
636
- final DefaultFullHttpRequest request = new DefaultFullHttpRequest (HttpVersion .HTTP_1_1 , HttpMethod .GET , "/uri" , buf );
637
- channel .writeInbound (request );
635
+ try {
636
+ ByteBufUtil .copy (AsciiString .of ("test full http request" ), buf );
637
+ final DefaultFullHttpRequest request = new DefaultFullHttpRequest (HttpVersion .HTTP_1_1 , HttpMethod .GET , "/uri" , buf );
638
+ channel .writeInbound (request );
638
639
639
- // request got through to validation
640
- assertThat (header .get (), sameInstance (request ));
641
- // channel is paused
642
- assertThat (channel .readInbound (), nullValue ());
643
- assertFalse (channel .config ().isAutoRead ());
640
+ // request got through to validation
641
+ assertThat (header .get (), sameInstance (request ));
642
+ // channel is paused
643
+ assertThat (channel .readInbound (), nullValue ());
644
+ assertFalse (channel .config ().isAutoRead ());
644
645
645
- // validation succeeds
646
- listener .get ().onResponse (null );
647
- channel .runPendingTasks ();
646
+ // validation succeeds
647
+ listener .get ().onResponse (null );
648
+ channel .runPendingTasks ();
648
649
649
- // channel is resumed and waiting for next request
650
- assertTrue (channel .config ().isAutoRead ());
651
- assertThat (netty4HttpHeaderValidator .getState (), equalTo (WAITING_TO_START ));
650
+ // channel is resumed and waiting for next request
651
+ assertTrue (channel .config ().isAutoRead ());
652
+ assertThat (netty4HttpHeaderValidator .getState (), equalTo (WAITING_TO_START ));
652
653
653
- DefaultFullHttpRequest throughRequest = channel .readInbound ();
654
- // request goes through unaltered
655
- assertThat (throughRequest , sameInstance (request ));
656
- assertFalse (throughRequest .decoderResult ().isFailure ());
657
- // the content is unaltered
658
- assertThat (new String (ByteBufUtil .getBytes (throughRequest .content ()), StandardCharsets .UTF_8 ), is ("test full http request" ));
659
- assertThat (buf .refCnt (), is (1 ));
660
- assertThat (throughRequest .decoderResult ().cause (), nullValue ());
654
+ DefaultFullHttpRequest throughRequest = channel .readInbound ();
655
+ // request goes through unaltered
656
+ assertThat (throughRequest , sameInstance (request ));
657
+ assertFalse (throughRequest .decoderResult ().isFailure ());
658
+ // the content is unaltered
659
+ assertThat (new String (ByteBufUtil .getBytes (throughRequest .content ()), StandardCharsets .UTF_8 ), is ("test full http request" ));
660
+ assertThat (buf .refCnt (), is (1 ));
661
+ assertThat (throughRequest .decoderResult ().cause (), nullValue ());
662
+ } finally {
663
+ buf .release ();
664
+ }
661
665
}
662
666
663
667
public void testFullRequestWithDecoderException () {
664
668
assertTrue (channel .config ().isAutoRead ());
665
669
assertThat (netty4HttpHeaderValidator .getState (), equalTo (WAITING_TO_START ));
666
670
667
671
ByteBuf buf = channel .alloc ().buffer ();
668
- ByteBufUtil .copy (AsciiString .of ("test full http request" ), buf );
669
- // a request with a decoder error prior to validation
670
- final DefaultFullHttpRequest request = new DefaultFullHttpRequest (HttpVersion .HTTP_1_1 , HttpMethod .GET , "/uri" , buf );
671
- Exception cause = new ElasticsearchException ("Boom" );
672
- request .setDecoderResult (DecoderResult .failure (cause ));
673
- channel .writeInbound (request );
672
+ try {
673
+ ByteBufUtil .copy (AsciiString .of ("test full http request" ), buf );
674
+ // a request with a decoder error prior to validation
675
+ final DefaultFullHttpRequest request = new DefaultFullHttpRequest (HttpVersion .HTTP_1_1 , HttpMethod .GET , "/uri" , buf );
676
+ Exception cause = new ElasticsearchException ("Boom" );
677
+ request .setDecoderResult (DecoderResult .failure (cause ));
678
+ channel .writeInbound (request );
674
679
675
- // request goes through without invoking the validator
676
- assertThat (header .get (), nullValue ());
677
- assertThat (listener .get (), nullValue ());
678
- // channel is NOT paused
679
- assertTrue (channel .config ().isAutoRead ());
680
- assertThat (netty4HttpHeaderValidator .getState (), equalTo (WAITING_TO_START ));
680
+ // request goes through without invoking the validator
681
+ assertThat (header .get (), nullValue ());
682
+ assertThat (listener .get (), nullValue ());
683
+ // channel is NOT paused
684
+ assertTrue (channel .config ().isAutoRead ());
685
+ assertThat (netty4HttpHeaderValidator .getState (), equalTo (WAITING_TO_START ));
681
686
682
- DefaultFullHttpRequest throughRequest = channel .readInbound ();
683
- // request goes through unaltered
684
- assertThat (throughRequest , sameInstance (request ));
685
- assertTrue (throughRequest .decoderResult ().isFailure ());
686
- assertThat (throughRequest .decoderResult ().cause (), equalTo (cause ));
687
- // the content is unaltered
688
- assertThat (new String (ByteBufUtil .getBytes (throughRequest .content ()), StandardCharsets .UTF_8 ), is ("test full http request" ));
689
- assertThat (buf .refCnt (), is (1 ));
687
+ DefaultFullHttpRequest throughRequest = channel .readInbound ();
688
+ // request goes through unaltered
689
+ assertThat (throughRequest , sameInstance (request ));
690
+ assertTrue (throughRequest .decoderResult ().isFailure ());
691
+ assertThat (throughRequest .decoderResult ().cause (), equalTo (cause ));
692
+ // the content is unaltered
693
+ assertThat (new String (ByteBufUtil .getBytes (throughRequest .content ()), StandardCharsets .UTF_8 ), is ("test full http request" ));
694
+ assertThat (buf .refCnt (), is (1 ));
695
+ } finally {
696
+ buf .release ();
697
+ }
690
698
}
691
699
}
0 commit comments