@@ -266,16 +266,21 @@ void whenAllTsTooLargeEmptyMessageListReturned() {
266
266
267
267
@ Test
268
268
void splitsWhenExactlyExceedingMaxByComma () {
269
+ // @formatter:off
269
270
// comma needs to be considered when there is more than one time series
270
- List <DynatraceBatchedPayload > messages = exporter .createPostMessages ("my.type" , "my.group" ,
271
+ List <DynatraceBatchedPayload > messages = exporter .createPostMessages (
272
+ "my.type" ,
273
+ "my.group" ,
271
274
// Max bytes: 15330 (excluding header/footer, 15360 with header/footer)
272
- Arrays .asList (createTimeSeriesWithDimensions ( 750 ), // 14861 bytes
273
- createTimeSeriesWithDimensions (23 , "asdfg" ), // 469 bytes
274
- // (overflows due to
275
- // comma)
275
+ Arrays .asList (
276
+ createTimeSeriesWithDimensions (750 ), // 14861 bytes
277
+ // 469 bytes (overflows due to comma)
278
+ createTimeSeriesWithDimensions ( 23 , "asdfg" ),
276
279
createTimeSeriesWithDimensions (750 ), // 14861 bytes
277
280
createTimeSeriesWithDimensions (22 , "asd" ) // 468 bytes + comma
278
- ));
281
+ )
282
+ );
283
+ // @formatter:on
279
284
assertThat (messages ).hasSize (3 );
280
285
assertThat (messages .get (0 ).metricCount ).isEqualTo (1 );
281
286
assertThat (messages .get (1 ).metricCount ).isEqualTo (1 );
@@ -286,14 +291,19 @@ void splitsWhenExactlyExceedingMaxByComma() {
286
291
287
292
@ Test
288
293
void countsPreviousAndNextComma () {
289
- List <DynatraceBatchedPayload > messages = exporter .createPostMessages ("my.type" , null ,
294
+ // @formatter:off
295
+ List <DynatraceBatchedPayload > messages = exporter .createPostMessages (
296
+ "my.type" ,
297
+ null ,
290
298
// Max bytes: 15330 (excluding header/footer, 15360 with header/footer)
291
- Arrays .asList (createTimeSeriesWithDimensions (750 ), // 14861 bytes
299
+ Arrays .asList (
300
+ createTimeSeriesWithDimensions (750 ), // 14861 bytes
292
301
createTimeSeriesWithDimensions (10 , "asdf" ), // 234 bytes + comma
293
- createTimeSeriesWithDimensions (10 , "asdf" ) // 234 bytes + comma =
294
- // 15331 bytes
295
- // (overflow)
296
- ));
302
+ // 234 bytes + comma = 15331 bytes (overflow)
303
+ createTimeSeriesWithDimensions (10 , "asdf" )
304
+ )
305
+ );
306
+ // @formatter:on
297
307
assertThat (messages ).hasSize (2 );
298
308
assertThat (messages .get (0 ).metricCount ).isEqualTo (2 );
299
309
assertThat (messages .get (1 ).metricCount ).isEqualTo (1 );
@@ -416,7 +426,7 @@ void testTokenShouldBeRedactedInPostFailure() throws Throwable {
416
426
String apiToken = "this.is.a.fake.apiToken" ;
417
427
418
428
HttpSender .Request .Builder builder = HttpSender .Request .build ("http://localhost" , httpClient );
419
- // mock the PUT call, so we can even run the post call.
429
+ // mock the PUT call, so we can even run the post call
420
430
doReturn (builder ).when (httpClient ).put (anyString ());
421
431
doReturn (new HttpSender .Response (200 , "" )).when (httpClient ).send (any (HttpSender .Request .class ));
422
432
@@ -432,7 +442,7 @@ void testTokenShouldBeRedactedInPostFailure() throws Throwable {
432
442
.extracting (LogEvent ::getMessage ).containsExactly (
433
443
// the custom metric was created, meaning the PUT call succeeded
434
444
"created custom:my.gauge as custom metric in Dynatrace" ,
435
- // the POST call now threw, and the token is redacted.
445
+ // the POST call throws an exception and the token is redacted
436
446
String .format (
437
447
"failed to build request: Illegal character in fragment at index 17: %s/api/v1/entity/infrastructure/custom/?api-token=<redacted>" ,
438
448
invalidUrl ));
@@ -459,8 +469,7 @@ void trySendHttpRequestErrorCode() throws Throwable {
459
469
DynatraceExporterV1 exporter = FACTORY .injectLogger (() -> createExporter (httpClient ));
460
470
HttpSender .Request .Builder reqBuilder = mock (HttpSender .Request .Builder .class );
461
471
462
- // simulate a failure response. This should be accepted, it will be handled
463
- // elsewhere
472
+ // simulate a failure response, errors are handled elsewhere
464
473
when (reqBuilder .send ()).thenReturn (new HttpSender .Response (400 , "" ));
465
474
466
475
// test that everything works and no error is logged
@@ -477,9 +486,8 @@ void trySendHttpRequestThrowsAndRedacts() throws Throwable {
477
486
478
487
HttpSender .Request .Builder reqBuilder = mock (HttpSender .Request .Builder .class );
479
488
480
- // simulate that the request builder throws. This should not happen if the
481
- // endpoint is invalid,
482
- // as the URI is validated elsewhere.
489
+ // Simulate that the request builder throws an exception.
490
+ // Should not happen if the endpoint is invalid, the URI is validated elsewhere.
483
491
String exceptionMessageTemplate = "Exception with the token: %s" ;
484
492
when (reqBuilder .send ()).thenThrow (new Throwable (String .format (exceptionMessageTemplate , apiToken )));
485
493
0 commit comments