@@ -81,7 +81,7 @@ public void setUp() {
81
81
@ Override
82
82
void addInput (ByteBufAllocator alloc , CompositeByteBuf composite , ByteBuf in ) {
83
83
// To limit the testing scope to NettyAdaptiveCumulator.cumulate(), always compose
84
- composite .addFlattenedComponents (true , in );
84
+ composite .addComponent (true , in );
85
85
}
86
86
};
87
87
@@ -208,8 +208,8 @@ public void setUp() {
208
208
in = ByteBufUtil .writeAscii (alloc , inData );
209
209
tail = ByteBufUtil .writeAscii (alloc , tailData );
210
210
composite = alloc .compositeBuffer (Integer .MAX_VALUE );
211
- // Note that addFlattenedComponents () will not add a new component when tail is not readable.
212
- composite .addFlattenedComponents (true , tail );
211
+ // Note that addComponent () will not add a new component when tail is not readable.
212
+ composite .addComponent (true , tail );
213
213
}
214
214
215
215
@ After
@@ -345,7 +345,7 @@ public void mergeWithCompositeTail_tailExpandable_write() {
345
345
assertThat (in .readableBytes ()).isAtMost (tail .writableBytes ());
346
346
347
347
// All fits, so tail capacity must stay the same.
348
- composite .addFlattenedComponents (true , tail );
348
+ composite .addComponent (true , tail );
349
349
assertTailExpanded (EXPECTED_TAIL_DATA , fitCapacity );
350
350
}
351
351
@@ -362,7 +362,7 @@ public void mergeWithCompositeTail_tailExpandable_fastWrite() {
362
362
alloc .calculateNewCapacity (EXPECTED_TAIL_DATA .length (), Integer .MAX_VALUE );
363
363
364
364
// Tail capacity is extended to its fast capacity.
365
- composite .addFlattenedComponents (true , tail );
365
+ composite .addComponent (true , tail );
366
366
assertTailExpanded (EXPECTED_TAIL_DATA , tailFastCapacity );
367
367
}
368
368
@@ -372,7 +372,7 @@ public void mergeWithCompositeTail_tailExpandable_reallocateInMemory() {
372
372
@ SuppressWarnings ("InlineMeInliner" ) // Requires Java 11
373
373
String inSuffixOverFastBytes = Strings .repeat ("a" , tailFastCapacity + 1 );
374
374
int newTailSize = tail .readableBytes () + inSuffixOverFastBytes .length ();
375
- composite .addFlattenedComponents (true , tail );
375
+ composite .addComponent (true , tail );
376
376
377
377
// Make input larger than tailFastCapacity
378
378
in .writeCharSequence (inSuffixOverFastBytes , US_ASCII );
@@ -435,21 +435,21 @@ public void mergeWithCompositeTail_tailNotExpandable_maxCapacityReached() {
435
435
@ SuppressWarnings ("InlineMeInliner" ) // Requires Java 11
436
436
String tailSuffixFullCapacity = Strings .repeat ("a" , tail .maxWritableBytes ());
437
437
tail .writeCharSequence (tailSuffixFullCapacity , US_ASCII );
438
- composite .addFlattenedComponents (true , tail );
438
+ composite .addComponent (true , tail );
439
439
assertTailReplaced ();
440
440
}
441
441
442
442
@ Test
443
443
public void mergeWithCompositeTail_tailNotExpandable_shared () {
444
444
tail .retain ();
445
- composite .addFlattenedComponents (true , tail );
445
+ composite .addComponent (true , tail );
446
446
assertTailReplaced ();
447
447
tail .release ();
448
448
}
449
449
450
450
@ Test
451
451
public void mergeWithCompositeTail_tailNotExpandable_readOnly () {
452
- composite .addFlattenedComponents (true , tail .asReadOnly ());
452
+ composite .addComponent (true , tail .asReadOnly ());
453
453
assertTailReplaced ();
454
454
}
455
455
@@ -527,8 +527,7 @@ public void mergeWithCompositeTail_tailExpandable_mergedReleaseOnThrow() {
527
527
CompositeByteBuf compositeThrows = new CompositeByteBuf (alloc , false , Integer .MAX_VALUE ,
528
528
tail ) {
529
529
@ Override
530
- public CompositeByteBuf addFlattenedComponents (boolean increaseWriterIndex ,
531
- ByteBuf buffer ) {
530
+ public CompositeByteBuf addComponent (boolean increaseWriterIndex , ByteBuf buffer ) {
532
531
throw expectedError ;
533
532
}
534
533
};
@@ -561,8 +560,7 @@ public void mergeWithCompositeTail_tailNotExpandable_mergedReleaseOnThrow() {
561
560
CompositeByteBuf compositeRo = new CompositeByteBuf (alloc , false , Integer .MAX_VALUE ,
562
561
tail .asReadOnly ()) {
563
562
@ Override
564
- public CompositeByteBuf addFlattenedComponents (boolean increaseWriterIndex ,
565
- ByteBuf buffer ) {
563
+ public CompositeByteBuf addComponent (boolean increaseWriterIndex , ByteBuf buffer ) {
566
564
throw expectedError ;
567
565
}
568
566
};
@@ -616,14 +614,14 @@ public void mergeWithCompositeTail_outOfSyncComposite() {
616
614
ByteBuf buf = alloc .buffer (32 ).writeBytes ("---01234" .getBytes (US_ASCII ));
617
615
618
616
// Start with a regular cumulation and add the buf as the only component.
619
- CompositeByteBuf composite1 = alloc .compositeBuffer (8 ).addFlattenedComponents (true , buf );
617
+ CompositeByteBuf composite1 = alloc .compositeBuffer (8 ).addComponent (true , buf );
620
618
// Read composite1 buf to the beginning of the numbers.
621
619
assertThat (composite1 .readCharSequence (3 , US_ASCII ).toString ()).isEqualTo ("---" );
622
620
623
621
// Wrap composite1 into another cumulation. This is similar to
624
622
// what NettyAdaptiveCumulator.cumulate() does in the case the cumulation has refCnt != 1.
625
623
CompositeByteBuf composite2 =
626
- alloc .compositeBuffer (8 ).addFlattenedComponents (true , composite1 );
624
+ alloc .compositeBuffer (8 ).addComponent (true , composite1 );
627
625
assertThat (composite2 .toString (US_ASCII )).isEqualTo ("01234" );
628
626
629
627
// The previous operation does not adjust the read indexes of the underlying buffers,
@@ -639,13 +637,27 @@ public void mergeWithCompositeTail_outOfSyncComposite() {
639
637
CompositeByteBuf cumulation = (CompositeByteBuf ) cumulator .cumulate (alloc , composite2 ,
640
638
ByteBufUtil .writeAscii (alloc , "56789" ));
641
639
assertThat (cumulation .toString (US_ASCII )).isEqualTo ("0123456789" );
640
+ }
641
+
642
+ @ Test
643
+ public void mergeWithNonCompositeTail () {
644
+ NettyAdaptiveCumulator cumulator = new NettyAdaptiveCumulator (1024 );
645
+ ByteBufAllocator alloc = new PooledByteBufAllocator ();
646
+ ByteBuf buf = alloc .buffer ().writeBytes ("tail" .getBytes (US_ASCII ));
647
+ ByteBuf in = alloc .buffer ().writeBytes ("-012345" .getBytes (US_ASCII ));
648
+
649
+ CompositeByteBuf composite = alloc .compositeBuffer ().addComponent (true , buf );
642
650
643
- // Correctness check: we still have a single component, and this component is still the
644
- // original underlying buffer.
645
- assertThat (cumulation .numComponents ()).isEqualTo (1 );
646
- // Replace '2' with '*', and '8' with '$'.
647
- buf .setByte (5 , '*' ).setByte (11 , '$' );
648
- assertThat (cumulation .toString (US_ASCII )).isEqualTo ("01*34567$9" );
651
+ CompositeByteBuf cumulation = (CompositeByteBuf ) cumulator .cumulate (alloc , composite , in );
652
+
653
+ assertEquals ("tail-012345" , cumulation .toString (US_ASCII ));
654
+ assertEquals (0 , in .refCnt ());
655
+ assertEquals (1 , cumulation .numComponents ());
656
+
657
+ buf .setByte (2 , '*' ).setByte (7 , '$' );
658
+ assertEquals ("ta*l-01$345" , cumulation .toString (US_ASCII ));
659
+
660
+ composite .release ();
649
661
}
650
662
}
651
663
}
0 commit comments