77
88import static com .linecorp .armeria .common .HttpStatus .INSUFFICIENT_STORAGE ;
99import static com .linecorp .armeria .common .HttpStatus .INTERNAL_SERVER_ERROR ;
10+ import static com .linecorp .armeria .common .HttpStatus .REQUEST_ENTITY_TOO_LARGE ;
1011import static org .hamcrest .MatcherAssert .assertThat ;
1112import static org .hamcrest .Matchers .equalTo ;
1213import static org .hamcrest .Matchers .hasItem ;
1314import static org .hamcrest .Matchers .is ;
1415import static org .hamcrest .Matchers .not ;
1516import static org .hamcrest .Matchers .nullValue ;
1617import static org .junit .jupiter .api .Assertions .assertEquals ;
18+ import static org .junit .jupiter .api .Assertions .assertInstanceOf ;
1719import static org .junit .jupiter .api .Assertions .assertThrows ;
1820import static org .junit .jupiter .api .Assertions .assertTrue ;
1921import static org .junit .jupiter .params .provider .Arguments .arguments ;
@@ -161,17 +163,20 @@ public void beforeEach() {
161163 lenient ().when (pluginFactory .loadPlugin (eq (GrpcAuthenticationProvider .class ), any (PluginSetting .class ))).thenReturn (authenticationProvider );
162164 pipelineDescription = mock (PipelineDescription .class );
163165 when (pipelineDescription .getPipelineName ()).thenReturn (TEST_PIPELINE_NAME );
164- SOURCE = new OTelLogsSource (createDefaultConfig (), pluginMetrics , pluginFactory , pipelineDescription );
165166 }
166167
167168 @ AfterEach
168169 public void afterEach () {
169170 SOURCE .stop ();
170171 }
171172
172- private void configureObjectUnderTest () {
173- SOURCE = new OTelLogsSource (createDefaultConfig (), pluginMetrics , pluginFactory , pipelineDescription );
174- assertTrue (SOURCE .getDecoder () instanceof OTelLogsDecoder );
173+ private void configureSource () {
174+ configureSource (createDefaultConfig ());
175+ }
176+
177+ private void configureSource (OTelLogsSourceConfig config ) {
178+ SOURCE = new OTelLogsSource (config , pluginMetrics , pluginFactory , pipelineDescription );
179+ assertInstanceOf (OTelLogsDecoder .class , SOURCE .getDecoder ());
175180 }
176181
177182 private RequestHeadersBuilder getDefaultRequestHeadersBuilder () {
@@ -186,10 +191,9 @@ private RequestHeadersBuilder getDefaultRequestHeadersBuilder() {
186191 @ ParameterizedTest
187192 @ MethodSource ("getPathParams" )
188193 void httpRequest_writesToBuffer_returnsSuccessfulResponse (String givenPath , String resolvedRequestPath ) throws Exception {
189- OTelLogsSource source = new OTelLogsSource (createDefaultConfigBuilder ()
190- .httpPath (givenPath )
191- .build (), pluginMetrics , pluginFactory , pipelineDescription );
192- source .start (buffer );
194+ OTelLogsSourceConfig config = createDefaultConfigBuilder ().httpPath (givenPath ).build ();
195+ configureSource (config );
196+ SOURCE .start (buffer );
193197 ExportLogsServiceRequest request = createExportLogsRequest ();
194198
195199 WebClient .of ().execute (
@@ -201,13 +205,12 @@ void httpRequest_writesToBuffer_returnsSuccessfulResponse(String givenPath, Stri
201205 .join ();
202206
203207 verify (buffer ).writeAll (any (), anyInt ());
204- source .stop ();
205208 }
206209
207210 @ Test
208211 void httpsRequest_requestIsProcessed_writesToBufferAndReturnsSuccessfulResponse () throws Exception {
209- OTelLogsSource source = new OTelLogsSource (createBuilderForConfigWithSsl ().build (), pluginMetrics , pluginFactory , pipelineDescription );
210- source .start (buffer );
212+ configureSource (createBuilderForConfigWithSsl ().build ());
213+ SOURCE .start (buffer );
211214 ExportLogsServiceRequest request = createExportLogsRequest ();
212215
213216 WebClient .builder ()
@@ -221,7 +224,6 @@ void httpsRequest_requestIsProcessed_writesToBufferAndReturnsSuccessfulResponse(
221224 .join ();
222225
223226 verify (buffer ).writeAll (any (), anyInt ());
224- source .stop ();
225227 }
226228
227229 private static Stream <Arguments > getPathParams () {
@@ -233,6 +235,7 @@ private static Stream<Arguments> getPathParams() {
233235
234236 @ Test
235237 void httpRequest_oneConnectionIsEstablished_metricsReflectCorrectConnectionCount () throws InvalidProtocolBufferException {
238+ configureSource ();
236239 SOURCE .start (buffer );
237240
238241 WebClient .of ().execute (getDefaultRequestHeadersBuilder ().build (), createJsonHttpPayload ())
@@ -249,12 +252,8 @@ void httpRequest_oneConnectionIsEstablished_metricsReflectCorrectConnectionCount
249252
250253 @ Test
251254 void httpRequest_payloadIsCompressed_returns200 () throws IOException {
252- OTelLogsSource source = new OTelLogsSource (
253- createDefaultConfigBuilder ().compression (CompressionOption .GZIP ).build (),
254- pluginMetrics ,
255- pluginFactory ,
256- pipelineDescription );
257- source .start (buffer );
255+ configureSource ( createDefaultConfigBuilder ().compression (CompressionOption .GZIP ).build ());
256+ SOURCE .start (buffer );
258257
259258 WebClient .of ().execute (getDefaultRequestHeadersBuilder ()
260259 .add (HttpHeaderNames .CONTENT_ENCODING , "gzip" )
@@ -263,9 +262,6 @@ void httpRequest_payloadIsCompressed_returns200() throws IOException {
263262 .aggregate ()
264263 .whenComplete ((response , throwable ) -> assertSecureResponseWithStatusCode (response , HttpStatus .OK , throwable ))
265264 .join ();
266-
267-
268- source .stop ();
269265 }
270266
271267 @ ParameterizedTest
@@ -274,8 +270,8 @@ void httpRequest_withBasicAuth_returnsAppropriateResponse(String givenUsername,
274270 final HttpBasicAuthenticationConfig basicAuthConfig = new HttpBasicAuthenticationConfig (BASIC_AUTH_USERNAME , BASIC_AUTH_PASSWORD );
275271 final HttpBasicArmeriaHttpAuthenticationProvider authProvider = new HttpBasicArmeriaHttpAuthenticationProvider (basicAuthConfig );
276272 when (pluginFactory .loadPlugin (eq (ArmeriaHttpAuthenticationProvider .class ), any (PluginSetting .class ))).thenReturn (authProvider );
277- final OTelLogsSource source = new OTelLogsSource (createConfigBuilderWithBasicAuth ().build (), pluginMetrics , pluginFactory , pipelineDescription );
278- source .start (buffer );
273+ configureSource (createConfigBuilderWithBasicAuth ().build ());
274+ SOURCE .start (buffer );
279275
280276 final String encodedCredentials = Base64 .getEncoder ().encodeToString (String .format ("%s:%s" , givenUsername , givenPassword ).getBytes (StandardCharsets .UTF_8 ));
281277 WebClient .of ().execute (getDefaultRequestHeadersBuilder ()
@@ -287,7 +283,6 @@ void httpRequest_withBasicAuth_returnsAppropriateResponse(String givenUsername,
287283 .join ();
288284
289285 verify (buffer , expectedBufferWrites ).writeAll (any (), anyInt ());
290- source .stop ();
291286 }
292287
293288 private static Stream <Arguments > getBasicAuthTestData () {
@@ -300,13 +295,8 @@ private static Stream<Arguments> getBasicAuthTestData() {
300295 @ ParameterizedTest
301296 @ MethodSource ("getHealthCheckParams" )
302297 void healthCheckRequest_requestIsProcesses_returnsStatusCodeAccordingToConfig (boolean givenHealthCheckConfig , HttpStatus expectedStatus ) throws IOException {
303- final OTelLogsSource source = new OTelLogsSource (
304- createDefaultConfigBuilder ().healthCheck (givenHealthCheckConfig ).build (),
305- pluginMetrics ,
306- pluginFactory ,
307- pipelineDescription
308- );
309- source .start (buffer );
298+ configureSource (createDefaultConfigBuilder ().healthCheck (givenHealthCheckConfig ).build ());
299+ SOURCE .start (buffer );
310300
311301 WebClient .of ().execute (getDefaultRequestHeadersBuilder ()
312302 .path ("/health" )
@@ -316,8 +306,6 @@ void healthCheckRequest_requestIsProcesses_returnsStatusCodeAccordingToConfig(bo
316306 .aggregate ()
317307 .whenComplete ((response , throwable ) -> assertSecureResponseWithStatusCode (response , expectedStatus , throwable ))
318308 .join ();
319-
320- source .stop ();
321309 }
322310
323311 private static Stream <Arguments > getHealthCheckParams () {
@@ -329,6 +317,7 @@ private static Stream<Arguments> getHealthCheckParams() {
329317
330318 @ Test
331319 void testStartWithEmptyBuffer () {
320+ configureSource ();
332321 assertThrows (IllegalStateException .class , () -> SOURCE .start (null ));
333322 }
334323
@@ -337,7 +326,7 @@ void testStartWithEmptyBuffer() {
337326 void httpRequest_writingToBufferThrowsAnException_correctHttpStatusIsReturned (
338327 final Class <Exception > bufferExceptionClass ,
339328 final HttpStatus expectedStatus ) throws Exception {
340- configureObjectUnderTest ();
329+ configureSource ();
341330 SOURCE .start (buffer );
342331 doThrow (bufferExceptionClass )
343332 .when (buffer )
@@ -353,17 +342,17 @@ void httpRequest_writingToBufferThrowsAnException_correctHttpStatusIsReturned(
353342 }
354343
355344 @ Test
356- void httpRequest_requestBodyIsTooLarge_returns507 () throws InvalidProtocolBufferException {
357- OTelLogsSource source = new OTelLogsSource (createDefaultConfigBuilder ().maxRequestLength (ByteCount .ofBytes (4 )).build (), pluginMetrics , pluginFactory , pipelineDescription );
358- source .start (buffer );
345+ void httpRequest_requestBodyIsTooLarge_returns413 () throws InvalidProtocolBufferException {
346+ configureSource (createDefaultConfigBuilder ().maxRequestLength (ByteCount .ofBytes (4 )).build ());
347+ SOURCE .start (buffer );
359348
360349 WebClient .of ()
361350 .execute (getDefaultRequestHeadersBuilder ().build (), createJsonHttpPayload ())
362351 .aggregate ()
363- .whenComplete ((response , throwable ) -> assertSecureResponseWithStatusCode (response , INSUFFICIENT_STORAGE , throwable ))
352+ .whenComplete ((response , throwable ) -> {
353+ assertSecureResponseWithStatusCode (response , REQUEST_ENTITY_TOO_LARGE , throwable );
354+ })
364355 .join ();
365-
366- source .stop ();
367356 }
368357
369358 static class BufferExceptionToStatusArgumentsProvider implements ArgumentsProvider {
0 commit comments