@@ -20,48 +20,49 @@ public class V2BatchTest {
2020
2121 @ Test
2222 public void testIsEmpty () {
23- V2Batch batch = new V2Batch ();
24- assertTrue (batch .isEmpty ());
25- ByteBuf content = messageContents ();
26- batch .addMessage (1 , content , content .readableBytes ());
27- assertFalse (batch .isEmpty ());
23+ try (V2Batch batch = new V2Batch ()){
24+ assertTrue (batch .isEmpty ());
25+ ByteBuf content = messageContents ();
26+ batch .addMessage (1 , content , content .readableBytes ());
27+ assertFalse (batch .isEmpty ());
28+ }
2829 }
2930
3031 @ Test
3132 public void testSize () {
32- V2Batch batch = new V2Batch ();
33- assertEquals (0 , batch .size ());
34- ByteBuf content = messageContents ();
35- batch .addMessage (1 , content , content .readableBytes ());
36- assertEquals (1 , batch .size ());
33+ try (V2Batch batch = new V2Batch ()) {
34+ assertEquals (0 , batch .size ());
35+ ByteBuf content = messageContents ();
36+ batch .addMessage (1 , content , content .readableBytes ());
37+ assertEquals (1 , batch .size ());
38+ }
3739 }
3840
3941 @ Test
40- public void TestGetProtocol () {
41- assertEquals (Protocol .VERSION_2 , new V2Batch ().getProtocol ());
42+ public void testGetProtocol () {
43+ try (V2Batch batch = new V2Batch ()) {
44+ assertEquals (Protocol .VERSION_2 , batch .getProtocol ());
45+ }
4246 }
4347
4448 @ Test
45- public void TestCompleteReturnTrueWhenIReceiveTheSameAmountOfEvent () {
46- V2Batch batch = new V2Batch ();
47- int numberOfEvent = 2 ;
48-
49- batch . setBatchSize ( numberOfEvent );
50-
51- for ( int i = 1 ; i <= numberOfEvent ; i ++) {
52- ByteBuf content = messageContents ();
53- batch .addMessage ( i , content , content . readableBytes ());
49+ public void testCompleteReturnTrueWhenIReceiveTheSameAmountOfEvent () {
50+ try ( V2Batch batch = new V2Batch ()) {
51+ int numberOfEvent = 2 ;
52+ batch . setBatchSize ( numberOfEvent );
53+ for ( int i = 1 ; i <= numberOfEvent ; i ++) {
54+ ByteBuf content = messageContents ();
55+ batch . addMessage ( i , content , content . readableBytes ());
56+ }
57+ assertTrue ( batch .isComplete ());
5458 }
55-
56- assertTrue (batch .isComplete ());
5759 }
5860
5961 @ Test
6062 public void testBigBatch () {
61- V2Batch batch = new V2Batch ();
62- int size = 4096 ;
63- assertEquals (0 , batch .size ());
64- try {
63+ try (V2Batch batch = new V2Batch ()) {
64+ int size = 4096 ;
65+ assertEquals (0 , batch .size ());
6566 ByteBuf content = messageContents ();
6667 for (int i = 0 ; i < size ; i ++) {
6768 batch .addMessage (i , content , content .readableBytes ());
@@ -71,8 +72,6 @@ public void testBigBatch() {
7172 for (Message message : batch ) {
7273 assertEquals (message .getSequence (), i ++);
7374 }
74- }finally {
75- batch .release ();
7675 }
7776 }
7877
@@ -91,17 +90,15 @@ public void testHighSequence(){
9190 assertEquals (startSequenceNumber + numberOfEvent , batch .getHighestSequence ());
9291 }
9392
94-
9593 @ Test
96- public void TestCompleteReturnWhenTheNumberOfEventDoesntMatchBatchSize () {
97- V2Batch batch = new V2Batch ();
98- int numberOfEvent = 2 ;
99-
100- batch .setBatchSize (numberOfEvent );
101- ByteBuf content = messageContents ();
102- batch .addMessage (1 , content , content .readableBytes ());
103-
104- assertFalse (batch .isComplete ());
94+ public void testCompleteReturnWhenTheNumberOfEventDoesntMatchBatchSize () {
95+ try (V2Batch batch = new V2Batch ()) {
96+ int numberOfEvent = 2 ;
97+ batch .setBatchSize (numberOfEvent );
98+ ByteBuf content = messageContents ();
99+ batch .addMessage (1 , content , content .readableBytes ());
100+ assertFalse (batch .isComplete ());
101+ }
105102 }
106103
107104 public static ByteBuf messageContents () {
@@ -114,4 +111,4 @@ public static ByteBuf messageContents() {
114111 throw new RuntimeException (e );
115112 }
116113 }
117- }
114+ }
0 commit comments