Return-Path: X-Original-To: apmail-hc-commits-archive@www.apache.org Delivered-To: apmail-hc-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id BB31918F78 for ; Fri, 30 Oct 2015 13:06:54 +0000 (UTC) Received: (qmail 62097 invoked by uid 500); 30 Oct 2015 13:06:42 -0000 Delivered-To: apmail-hc-commits-archive@hc.apache.org Received: (qmail 62054 invoked by uid 500); 30 Oct 2015 13:06:40 -0000 Mailing-List: contact commits-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpComponents Project" Delivered-To: mailing list commits@hc.apache.org Received: (qmail 61985 invoked by uid 99); 30 Oct 2015 13:06:39 -0000 Received: from Unknown (HELO spamd4-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 30 Oct 2015 13:06:39 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd4-us-west.apache.org (ASF Mail Server at spamd4-us-west.apache.org) with ESMTP id D7E9BC0FE4 for ; Fri, 30 Oct 2015 13:06:38 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd4-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -0.01 X-Spam-Level: X-Spam-Status: No, score=-0.01 tagged_above=-999 required=6.31 tests=[T_RP_MATCHES_RCVD=-0.01] autolearn=disabled Received: from mx1-us-west.apache.org ([10.40.0.8]) by localhost (spamd4-us-west.apache.org [10.40.0.11]) (amavisd-new, port 10024) with ESMTP id 1feUxmdbVEtP for ; Fri, 30 Oct 2015 13:06:15 +0000 (UTC) Received: from mailrelay1-us-west.apache.org (mailrelay1-us-west.apache.org [209.188.14.139]) by mx1-us-west.apache.org (ASF Mail Server at mx1-us-west.apache.org) with ESMTP id C614A21342 for ; Fri, 30 Oct 2015 13:06:14 +0000 (UTC) Received: from svn01-us-west.apache.org (svn.apache.org [10.41.0.6]) by mailrelay1-us-west.apache.org (ASF Mail Server at mailrelay1-us-west.apache.org) with ESMTP id CB136E0E5C for ; Fri, 30 Oct 2015 13:06:13 +0000 (UTC) Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id C63A73A0288 for ; Fri, 30 Oct 2015 13:06:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1711465 [14/34] - in /httpcomponents/site/httpcomponents-core-4.4.x: ./ httpcore-ab/ httpcore-nio/ httpcore-nio/apidocs/ httpcore-nio/apidocs/org/apache/http/impl/nio/ httpcore-nio/apidocs/org/apache/http/impl/nio/bootstrap/ httpcore-nio/a... Date: Fri, 30 Oct 2015 13:06:04 -0000 To: commits@hc.apache.org From: olegk@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20151030130613.C63A73A0288@svn01-us-west.apache.org> Modified: httpcomponents/site/httpcomponents-core-4.4.x/httpcore-nio/xref-test/org/apache/http/nio/protocol/TestHttpAsyncService.html URL: http://svn.apache.org/viewvc/httpcomponents/site/httpcomponents-core-4.4.x/httpcore-nio/xref-test/org/apache/http/nio/protocol/TestHttpAsyncService.html?rev=1711465&r1=1711464&r2=1711465&view=diff ============================================================================== --- httpcomponents/site/httpcomponents-core-4.4.x/httpcore-nio/xref-test/org/apache/http/nio/protocol/TestHttpAsyncService.html (original) +++ httpcomponents/site/httpcomponents-core-4.4.x/httpcore-nio/xref-test/org/apache/http/nio/protocol/TestHttpAsyncService.html Fri Oct 30 13:05:47 2015 @@ -837,555 +837,554 @@ 827 Mockito.verify(this.conn).submitResponse(response); 828 Mockito.verify(this.responseProducer).responseCompleted(exchangeContext); 829 Mockito.verify(this.conn).requestInput(); -830 Mockito.verify(this.conn).suspendOutput(); -831 Mockito.verify(this.conn, Mockito.never()).close(); -832 } -833 -834 @Test -835 public void testBasicResponseWithPipelining() throws Exception { -836 final State state = new State(); -837 final HttpContext exchangeContext = new BasicHttpContext(); -838 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -839 final Incoming incoming = new Incoming( -840 request, this.requestHandler, this.requestConsumer, exchangeContext); -841 state.setIncoming(incoming); -842 state.setRequestState(MessageState.COMPLETED); -843 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -844 final Outgoing outgoing = new Outgoing( -845 request, response, this.responseProducer, exchangeContext); -846 response.setEntity(new NStringEntity("stuff")); -847 state.setOutgoing(outgoing); -848 -849 final Queue<PipelineEntry> pipeline = state.getPipeline(); -850 -851 final HttpContext exchangeContext2 = new BasicHttpContext(); -852 final HttpRequest pipelinedRequest = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -853 final PipelineEntry entry = new PipelineEntry(pipelinedRequest, pipelinedRequest, -854 null, requestHandler, exchangeContext2); -855 pipeline.add(entry); -856 -857 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -858 -859 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -860 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.TRUE); -861 -862 this.protocolHandler.responseReady(this.conn); -863 -864 Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState()); -865 -866 Mockito.verify(this.httpProcessor).process(response, exchangeContext); -867 Mockito.verify(this.conn).suspendOutput(); -868 Mockito.verify(this.conn).submitResponse(response); -869 Mockito.verify(this.conn, Mockito.never()).close(); -870 } -871 -872 @Test -873 public void testBasicResponseNoKeepAlive() throws Exception { -874 final State state = new State(); -875 final HttpContext exchangeContext = new BasicHttpContext(); -876 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -877 final Incoming incoming = new Incoming( -878 request, this.requestHandler, this.requestConsumer, exchangeContext); -879 state.setIncoming(incoming); -880 state.setRequestState(MessageState.COMPLETED); -881 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -882 final Outgoing outgoing = new Outgoing( -883 request, response, this.responseProducer, exchangeContext); -884 state.setOutgoing(outgoing); -885 state.setResponseState(MessageState.INIT); -886 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -887 -888 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -889 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.FALSE); -890 -891 this.protocolHandler.responseReady(this.conn); -892 -893 Assert.assertEquals(MessageState.READY, state.getResponseState()); -894 -895 Mockito.verify(this.httpProcessor).process(response, exchangeContext); -896 Mockito.verify(this.conn).submitResponse(response); -897 Mockito.verify(this.responseProducer).responseCompleted(exchangeContext); -898 Mockito.verify(this.conn).close(); -899 } -900 -901 @Test -902 public void testEntityEnclosingResponse() throws Exception { -903 final State state = new State(); -904 final HttpContext exchangeContext = new BasicHttpContext(); -905 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -906 final Incoming incoming = new Incoming( -907 request, this.requestHandler, this.requestConsumer, exchangeContext); -908 state.setIncoming(incoming); -909 state.setRequestState(MessageState.COMPLETED); -910 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -911 final Outgoing outgoing = new Outgoing( -912 request, response, this.responseProducer, exchangeContext); -913 state.setOutgoing(outgoing); -914 state.setResponseState(MessageState.INIT); -915 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -916 -917 response.setEntity(new NStringEntity("stuff")); -918 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -919 -920 this.protocolHandler.responseReady(this.conn); -921 -922 Assert.assertEquals(MessageState.COMPLETED, state.getRequestState()); -923 Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState()); -924 Assert.assertEquals("[incoming COMPLETED GET / HTTP/1.1; outgoing BODY_STREAM HTTP/1.1 200 OK]", -925 state.toString()); -926 -927 Mockito.verify(this.httpProcessor).process(response, exchangeContext); -928 Mockito.verify(this.conn).submitResponse(response); -929 Mockito.verify(this.responseProducer, Mockito.never()).responseCompleted(exchangeContext); -930 } -931 -932 @Test -933 public void testResponseToHead() throws Exception { -934 final State state = new State(); -935 final HttpContext exchangeContext = new BasicHttpContext(); -936 final HttpRequest request = new BasicHttpRequest("HEAD", "/", HttpVersion.HTTP_1_1); -937 final Incoming incoming = new Incoming( -938 request, this.requestHandler, this.requestConsumer, exchangeContext); -939 state.setIncoming(incoming); -940 state.setRequestState(MessageState.COMPLETED); -941 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -942 final Outgoing outgoing = new Outgoing( -943 request, response, this.responseProducer, exchangeContext); -944 state.setOutgoing(outgoing); -945 state.setResponseState(MessageState.INIT); -946 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -947 -948 response.setEntity(new NStringEntity("stuff")); -949 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -950 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.TRUE); -951 -952 this.protocolHandler.responseReady(this.conn); -953 -954 Assert.assertEquals(MessageState.READY, state.getResponseState()); -955 -956 Mockito.verify(this.httpProcessor).process(response, exchangeContext); -957 Mockito.verify(this.conn).submitResponse(response); -958 Mockito.verify(this.responseProducer).responseCompleted(exchangeContext); -959 Mockito.verify(this.conn).requestInput(); -960 Mockito.verify(this.conn, Mockito.never()).close(); -961 } -962 -963 @Test -964 public void testResponseNotModified() throws Exception { -965 final State state = new State(); -966 final HttpContext exchangeContext = new BasicHttpContext(); -967 final HttpRequest request = new BasicHttpRequest("HEAD", "/", HttpVersion.HTTP_1_1); -968 final Incoming incoming = new Incoming( -969 request, this.requestHandler, this.requestConsumer, exchangeContext); -970 state.setIncoming(incoming); -971 state.setRequestState(MessageState.COMPLETED); -972 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, -973 HttpStatus.SC_NOT_MODIFIED, "Not modified"); -974 final Outgoing outgoing = new Outgoing( -975 request, response, this.responseProducer, exchangeContext); -976 state.setOutgoing(outgoing); -977 state.setResponseState(MessageState.INIT); -978 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -979 -980 response.setEntity(new NStringEntity("stuff")); -981 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -982 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.TRUE); -983 -984 this.protocolHandler.responseReady(this.conn); -985 -986 Assert.assertEquals(MessageState.READY, state.getResponseState()); -987 -988 Mockito.verify(this.httpProcessor).process(response, exchangeContext); -989 Mockito.verify(this.conn).submitResponse(response); -990 Mockito.verify(this.responseProducer).responseCompleted(exchangeContext); -991 Mockito.verify(this.conn).requestInput(); -992 Mockito.verify(this.conn, Mockito.never()).close(); -993 } -994 -995 @Test -996 public void testResponseContinue() throws Exception { -997 final State state = new State(); -998 final HttpContext exchangeContext = new BasicHttpContext(); -999 final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/", -1000 HttpVersion.HTTP_1_1); -1001 final Incoming incoming = new Incoming( -1002 request, this.requestHandler, this.requestConsumer, exchangeContext); -1003 state.setIncoming(incoming); -1004 state.setRequestState(MessageState.ACK_EXPECTED); -1005 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, -1006 HttpStatus.SC_CONTINUE, "Continue"); -1007 final Outgoing outgoing = new Outgoing( -1008 request, response, this.responseProducer, exchangeContext); -1009 state.setOutgoing(outgoing); -1010 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1011 -1012 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -1013 -1014 this.protocolHandler.responseReady(this.conn); -1015 -1016 Assert.assertEquals(MessageState.BODY_STREAM, state.getRequestState()); -1017 Assert.assertEquals(MessageState.READY, state.getResponseState()); -1018 -1019 Mockito.verify(this.conn).requestInput(); -1020 Mockito.verify(this.conn).submitResponse(Mockito.argThat(new ArgumentMatcher<HttpResponse>() { -1021 -1022 @Override -1023 public boolean matches(final Object argument) { -1024 final int status = ((HttpResponse) argument).getStatusLine().getStatusCode(); -1025 return status == 100; -1026 } -1027 -1028 })); -1029 } -1030 -1031 @Test -1032 public void testResponseFailedExpectation() throws Exception { -1033 final State state = new State(); -1034 final HttpContext exchangeContext = new BasicHttpContext(); -1035 final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/", -1036 HttpVersion.HTTP_1_1); -1037 final Incoming incoming = new Incoming( -1038 request, this.requestHandler, this.requestConsumer, exchangeContext); -1039 state.setIncoming(incoming); -1040 state.setRequestState(MessageState.ACK_EXPECTED); -1041 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, -1042 417, "Expectation failed"); -1043 final Outgoing outgoing = new Outgoing( -1044 request, response, this.responseProducer, exchangeContext); -1045 state.setOutgoing(outgoing); -1046 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1047 -1048 response.setEntity(new NStringEntity("stuff")); -1049 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -1050 -1051 this.protocolHandler.responseReady(this.conn); -1052 -1053 Assert.assertEquals(MessageState.READY, state.getRequestState()); -1054 Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState()); -1055 -1056 Mockito.verify(this.conn).resetInput(); -1057 Mockito.verify(this.httpProcessor).process(response, exchangeContext); -1058 Mockito.verify(this.conn).submitResponse(response); -1059 Mockito.verify(this.responseProducer, Mockito.never()).responseCompleted(exchangeContext); -1060 } -1061 -1062 @Test -1063 public void testResponsePipelinedEmpty() throws Exception { -1064 final State state = new State(); -1065 -1066 state.setRequestState(MessageState.READY); -1067 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1068 -1069 this.protocolHandler.responseReady(this.conn); -1070 -1071 Assert.assertEquals(MessageState.READY, state.getRequestState()); -1072 Assert.assertEquals(MessageState.READY, state.getResponseState()); -1073 Assert.assertNull(state.getOutgoing()); -1074 -1075 Mockito.verify(conn).suspendOutput(); -1076 Mockito.verifyNoMoreInteractions(requestHandler); -1077 } -1078 -1079 @Test -1080 public void testResponseHandlePipelinedRequest() throws Exception { -1081 final State state = new State(); -1082 final Queue<PipelineEntry> pipeline = state.getPipeline(); -1083 -1084 final HttpContext exchangeContext = new BasicHttpContext(); -1085 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -1086 final PipelineEntry entry = new PipelineEntry(request, request, null, requestHandler, exchangeContext); -1087 pipeline.add(entry); -1088 -1089 state.setRequestState(MessageState.READY); -1090 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1091 -1092 this.protocolHandler.responseReady(this.conn); -1093 -1094 Assert.assertEquals(MessageState.READY, state.getRequestState()); -1095 Assert.assertEquals(MessageState.INIT, state.getResponseState()); -1096 Assert.assertNull(state.getOutgoing()); -1097 -1098 final ArgumentCaptor<HttpAsyncExchange> argCaptor = ArgumentCaptor.forClass(HttpAsyncExchange.class); -1099 Mockito.verify(this.requestHandler).handle(Mockito.same(request), -1100 argCaptor.capture(), Mockito.same(exchangeContext)); -1101 final HttpAsyncExchange exchange = argCaptor.getValue(); -1102 -1103 Assert.assertNotNull(exchange); -1104 Assert.assertSame(request, exchange.getRequest()); -1105 Assert.assertNotNull(exchange.getResponse()); -1106 Assert.assertEquals(200, exchange.getResponse().getStatusLine().getStatusCode()); -1107 } -1108 -1109 @Test -1110 public void testResponseHandleFailedPipelinedRequest() throws Exception { -1111 final State state = new State(); -1112 final Queue<PipelineEntry> pipeline = state.getPipeline(); -1113 -1114 final HttpContext exchangeContext = new BasicHttpContext(); -1115 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -1116 final Exception ex = new Exception("Opppsie"); -1117 final PipelineEntry entry = new PipelineEntry(request, null, ex, requestHandler, exchangeContext); -1118 pipeline.add(entry); -1119 -1120 state.setRequestState(MessageState.READY); -1121 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1122 -1123 this.protocolHandler.responseReady(this.conn); -1124 -1125 Assert.assertEquals(MessageState.READY, state.getRequestState()); -1126 Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState()); -1127 -1128 final Outgoing outgoing = state.getOutgoing(); -1129 Assert.assertNotNull(outgoing.getProducer()); -1130 final HttpResponse response = outgoing.getResponse(); -1131 Assert.assertNotNull(response); -1132 Assert.assertEquals(500, response.getStatusLine().getStatusCode()); -1133 -1134 Mockito.verify(this.requestHandler, Mockito.never()).handle(Mockito.<HttpRequest>any(), -1135 Mockito.<HttpAsyncExchange>any(), Mockito.<HttpContext>any()); -1136 Mockito.verify(this.conn).submitResponse(Mockito.same(response)); -1137 } -1138 -1139 @Test(expected=HttpException.class) -1140 public void testInvalidResponseStatus() throws Exception { -1141 final State state = new State(); -1142 final HttpContext exchangeContext = new BasicHttpContext(); -1143 final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/", -1144 HttpVersion.HTTP_1_1); -1145 final Incoming incoming = new Incoming( -1146 request, this.requestHandler, this.requestConsumer, exchangeContext); -1147 state.setIncoming(incoming); -1148 state.setRequestState(MessageState.COMPLETED); -1149 state.setResponseState(MessageState.INIT); -1150 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 112, "Something stupid"); -1151 final Outgoing outgoing = new Outgoing( -1152 request, response, this.responseProducer, exchangeContext); -1153 state.setOutgoing(outgoing); -1154 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1155 -1156 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -1157 Mockito.when(this.conn.isResponseSubmitted()).thenReturn(Boolean.FALSE); -1158 -1159 this.protocolHandler.responseReady(this.conn); -1160 } -1161 -1162 @Test(expected=HttpException.class) -1163 public void testInvalidResponseStatusToExpection() throws Exception { -1164 final State state = new State(); -1165 final HttpContext exchangeContext = new BasicHttpContext(); -1166 final HttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/", -1167 HttpVersion.HTTP_1_1); -1168 final Incoming incoming = new Incoming( -1169 request, this.requestHandler, this.requestConsumer, exchangeContext); -1170 state.setIncoming(incoming); -1171 state.setRequestState(MessageState.ACK_EXPECTED); -1172 state.setResponseState(MessageState.READY); -1173 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -1174 response.setEntity(new NStringEntity("stuff")); -1175 final Outgoing outgoing = new Outgoing( -1176 request, response, this.responseProducer, exchangeContext); -1177 state.setOutgoing(outgoing); -1178 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1179 -1180 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); -1181 Mockito.when(this.conn.isResponseSubmitted()).thenReturn(Boolean.FALSE); -1182 -1183 this.protocolHandler.responseReady(this.conn); -1184 } -1185 -1186 @Test -1187 public void testResponseTrigger() throws Exception { -1188 final State state = new State(); -1189 state.setRequestState(MessageState.COMPLETED); -1190 state.setResponseState(MessageState.READY); -1191 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1192 -1193 final HttpContext exchangeContext = new BasicHttpContext(); -1194 final HttpAsyncExchange httpexchanage = protocolHandler.new HttpAsyncExchangeImpl( -1195 new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), -1196 new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"), -1197 state, this.conn, exchangeContext); -1198 Assert.assertFalse(httpexchanage.isCompleted()); -1199 httpexchanage.submitResponse(this.responseProducer); -1200 Assert.assertTrue(httpexchanage.isCompleted()); -1201 -1202 Assert.assertEquals(MessageState.COMPLETED, state.getRequestState()); -1203 Assert.assertEquals(MessageState.READY, state.getResponseState()); -1204 final Outgoing outgoing = state.getOutgoing(); -1205 Assert.assertNotNull(outgoing); -1206 Assert.assertSame(this.responseProducer, outgoing.getProducer()); -1207 -1208 Mockito.verify(this.conn).requestOutput(); -1209 -1210 try { -1211 httpexchanage.submitResponse(Mockito.mock(HttpAsyncResponseProducer.class)); -1212 Assert.fail("IllegalStateException expected"); -1213 } catch (final IllegalStateException ex) { -1214 } -1215 } -1216 -1217 @Test(expected=IllegalArgumentException.class) -1218 public void testResponseTriggerInvalidResponseProducer() throws Exception { -1219 final State state = new State(); -1220 state.setRequestState(MessageState.ACK_EXPECTED); -1221 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1222 -1223 final HttpContext exchangeContext = new BasicHttpContext(); -1224 final HttpAsyncExchange httpexchanage = protocolHandler.new HttpAsyncExchangeImpl( -1225 new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1), -1226 new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"), -1227 state, this.conn, exchangeContext); -1228 httpexchanage.submitResponse(null); -1229 } -1230 -1231 @Test -1232 public void testResponseContent() throws Exception { -1233 final State state = new State(); -1234 state.setRequestState(MessageState.COMPLETED); -1235 state.setResponseState(MessageState.BODY_STREAM); -1236 final HttpContext exchangeContext = new BasicHttpContext(); -1237 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -1238 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -1239 response.setEntity(new NStringEntity("stuff")); -1240 final Outgoing outgoing = new Outgoing( -1241 request, response, this.responseProducer, exchangeContext); -1242 state.setOutgoing(outgoing); -1243 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1244 Mockito.when(this.encoder.isCompleted()).thenReturn(Boolean.FALSE); -1245 -1246 this.protocolHandler.outputReady(conn, this.encoder); -1247 -1248 Assert.assertEquals(MessageState.COMPLETED, state.getRequestState()); -1249 Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState()); -1250 -1251 Mockito.verify(this.responseProducer).produceContent(this.encoder, this.conn); -1252 Mockito.verify(this.conn, Mockito.never()).requestInput(); -1253 Mockito.verify(this.conn, Mockito.never()).close(); -1254 } -1255 -1256 @Test -1257 public void testResponseContentCompleted() throws Exception { -1258 final State state = new State(); -1259 state.setRequestState(MessageState.COMPLETED); -1260 state.setResponseState(MessageState.BODY_STREAM); -1261 final HttpContext exchangeContext = new BasicHttpContext(); -1262 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -1263 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -1264 response.setEntity(new NStringEntity("stuff")); -1265 final Outgoing outgoing = new Outgoing( -1266 request, response, this.responseProducer, exchangeContext); -1267 state.setOutgoing(outgoing); -1268 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1269 Mockito.when(this.encoder.isCompleted()).thenReturn(true); -1270 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.TRUE); -1271 -1272 this.protocolHandler.outputReady(conn, this.encoder); -1273 -1274 Assert.assertEquals(MessageState.READY, state.getResponseState()); -1275 -1276 Mockito.verify(this.responseProducer).produceContent(this.encoder, this.conn); -1277 Mockito.verify(this.responseProducer).responseCompleted(exchangeContext); -1278 Mockito.verify(this.conn).requestInput(); -1279 Mockito.verify(this.conn, Mockito.never()).close(); -1280 } -1281 -1282 @Test -1283 public void testResponseContentCompletedNoKeepAlive() throws Exception { -1284 final State state = new State(); -1285 state.setRequestState(MessageState.COMPLETED); -1286 state.setResponseState(MessageState.BODY_STREAM); -1287 final HttpContext exchangeContext = new BasicHttpContext(); -1288 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -1289 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -1290 response.setEntity(new NStringEntity("stuff")); -1291 final Outgoing outgoing = new Outgoing( -1292 request, response, this.responseProducer, exchangeContext); -1293 state.setOutgoing(outgoing); -1294 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1295 Mockito.when(this.encoder.isCompleted()).thenReturn(true); -1296 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.FALSE); -1297 -1298 this.protocolHandler.outputReady(conn, this.encoder); -1299 -1300 Assert.assertEquals(MessageState.READY, state.getResponseState()); -1301 -1302 Mockito.verify(this.responseProducer).produceContent(this.encoder, this.conn); -1303 Mockito.verify(this.responseProducer).responseCompleted(exchangeContext); -1304 Mockito.verify(this.conn, Mockito.never()).requestInput(); -1305 Mockito.verify(this.conn).close(); -1306 } -1307 -1308 @Test -1309 public void testEndOfInput() throws Exception { -1310 -1311 Mockito.when(this.conn.getSocketTimeout()).thenReturn(1000); -1312 -1313 this.protocolHandler.endOfInput(this.conn); -1314 -1315 Mockito.verify(this.conn, Mockito.never()).setSocketTimeout(Mockito.anyInt()); -1316 Mockito.verify(this.conn).close(); -1317 } -1318 -1319 @Test -1320 public void testEndOfInputNoTimeout() throws Exception { -1321 -1322 Mockito.when(this.conn.getSocketTimeout()).thenReturn(0); -1323 -1324 this.protocolHandler.endOfInput(this.conn); -1325 -1326 Mockito.verify(this.conn).setSocketTimeout(1000); -1327 Mockito.verify(this.conn).close(); -1328 } -1329 -1330 @Test -1331 public void testTimeoutActiveConnection() throws Exception { -1332 final State state = new State(); -1333 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1334 Mockito.when(this.conn.getStatus()).thenReturn(NHttpClientConnection.ACTIVE, NHttpClientConnection.CLOSED); -1335 -1336 this.protocolHandler.timeout(this.conn); -1337 -1338 Mockito.verify(this.conn).close(); -1339 Mockito.verify(this.conn, Mockito.never()).setSocketTimeout(Mockito.anyInt()); -1340 } -1341 -1342 @Test -1343 public void testTimeoutActiveConnectionBufferedData() throws Exception { -1344 final State state = new State(); -1345 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1346 Mockito.when(this.conn.getStatus()).thenReturn(NHttpClientConnection.ACTIVE, NHttpClientConnection.CLOSING); -1347 -1348 this.protocolHandler.timeout(this.conn); -1349 -1350 Mockito.verify(this.conn).close(); -1351 Mockito.verify(this.conn).setSocketTimeout(250); -1352 } -1353 -1354 @Test -1355 public void testTimeoutClosingConnection() throws Exception { -1356 final State state = new State(); -1357 final HttpContext exchangeContext = new BasicHttpContext(); -1358 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); -1359 final Incoming incoming = new Incoming( -1360 request, this.requestHandler, this.requestConsumer, exchangeContext); -1361 state.setIncoming(incoming); -1362 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); -1363 final Outgoing outgoing = new Outgoing( -1364 request, response, this.responseProducer, exchangeContext); -1365 state.setOutgoing(outgoing); -1366 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); -1367 Mockito.when(this.conn.getStatus()).thenReturn(NHttpClientConnection.CLOSING); -1368 -1369 this.protocolHandler.timeout(this.conn); -1370 -1371 Mockito.verify(this.conn).shutdown(); -1372 Mockito.verify(this.requestConsumer).failed(Mockito.any(SocketTimeoutException.class)); -1373 Mockito.verify(this.requestConsumer).close(); -1374 Mockito.verify(this.responseProducer).failed(Mockito.any(SocketTimeoutException.class)); -1375 Mockito.verify(this.responseProducer).close(); -1376 } -1377 -1378 } +830 Mockito.verify(this.conn, Mockito.never()).close(); +831 } +832 +833 @Test +834 public void testBasicResponseWithPipelining() throws Exception { +835 final State state = new State(); +836 final HttpContext exchangeContext = new BasicHttpContext(); +837 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); +838 final Incoming incoming = new Incoming( +839 request, this.requestHandler, this.requestConsumer, exchangeContext); +840 state.setIncoming(incoming); +841 state.setRequestState(MessageState.COMPLETED); +842 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); +843 final Outgoing outgoing = new Outgoing( +844 request, response, this.responseProducer, exchangeContext); +845 response.setEntity(new NStringEntity("stuff")); +846 state.setOutgoing(outgoing); +847 +848 final Queue<PipelineEntry> pipeline = state.getPipeline(); +849 +850 final HttpContext exchangeContext2 = new BasicHttpContext(); +851 final HttpRequest pipelinedRequest = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); +852 final PipelineEntry entry = new PipelineEntry(pipelinedRequest, pipelinedRequest, +853 null, requestHandler, exchangeContext2); +854 pipeline.add(entry); +855 +856 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); +857 +858 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); +859 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.TRUE); +860 +861 this.protocolHandler.responseReady(this.conn); +862 +863 Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState()); +864 +865 Mockito.verify(this.httpProcessor).process(response, exchangeContext); +866 Mockito.verify(this.conn).suspendOutput(); +867 Mockito.verify(this.conn).submitResponse(response); +868 Mockito.verify(this.conn, Mockito.never()).close(); +869 } +870 +871 @Test +872 public void testBasicResponseNoKeepAlive() throws Exception { +873 final State state = new State(); +874 final HttpContext exchangeContext = new BasicHttpContext(); +875 final HttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1); +876 final Incoming incoming = new Incoming( +877 request, this.requestHandler, this.requestConsumer, exchangeContext); +878 state.setIncoming(incoming); +879 state.setRequestState(MessageState.COMPLETED); +880 final HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"); +881 final Outgoing outgoing = new Outgoing( +882 request, response, this.responseProducer, exchangeContext); +883 state.setOutgoing(outgoing); +884 state.setResponseState(MessageState.INIT); +885 this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state); +886 +887 Mockito.when(this.responseProducer.generateResponse()).thenReturn(response); +888 Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(Boolean.FALSE); +889 [... 492 lines stripped ...]