@@ -19,48 +19,49 @@ public class V2BatchTest {
1919
2020 @ Test
2121 public void testIsEmpty () {
22- V2Batch batch = new V2Batch ();
23- assertTrue (batch .isEmpty ());
24- ByteBuf content = messageContents ();
25- batch .addMessage (1 , content , content .readableBytes ());
26- assertFalse (batch .isEmpty ());
22+ try (V2Batch batch = new V2Batch ()){
23+ assertTrue (batch .isEmpty ());
24+ ByteBuf content = messageContents ();
25+ batch .addMessage (1 , content , content .readableBytes ());
26+ assertFalse (batch .isEmpty ());
27+ }
2728 }
2829
2930 @ Test
3031 public void testSize () {
31- V2Batch batch = new V2Batch ();
32- assertEquals (0 , batch .size ());
33- ByteBuf content = messageContents ();
34- batch .addMessage (1 , content , content .readableBytes ());
35- assertEquals (1 , batch .size ());
32+ try (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 ());
37+ }
3638 }
3739
3840 @ Test
39- public void TestGetProtocol () {
40- assertEquals (Protocol .VERSION_2 , new V2Batch ().getProtocol ());
41+ public void testGetProtocol () {
42+ try (V2Batch batch = new V2Batch ()) {
43+ assertEquals (Protocol .VERSION_2 , batch .getProtocol ());
44+ }
4145 }
4246
4347 @ Test
44- public void TestCompleteReturnTrueWhenIReceiveTheSameAmountOfEvent () {
45- V2Batch batch = new V2Batch ();
46- int numberOfEvent = 2 ;
47-
48- batch . setBatchSize ( numberOfEvent );
49-
50- for ( int i = 1 ; i <= numberOfEvent ; i ++) {
51- ByteBuf content = messageContents ();
52- batch .addMessage ( i , content , content . readableBytes ());
48+ public void testCompleteReturnTrueWhenIReceiveTheSameAmountOfEvent () {
49+ try ( V2Batch batch = new V2Batch ()) {
50+ int numberOfEvent = 2 ;
51+ batch . setBatchSize ( numberOfEvent );
52+ for ( int i = 1 ; i <= numberOfEvent ; i ++) {
53+ ByteBuf content = messageContents ();
54+ batch . addMessage ( i , content , content . readableBytes ());
55+ }
56+ assertTrue ( batch .isComplete ());
5357 }
54-
55- assertTrue (batch .isComplete ());
5658 }
5759
5860 @ Test
5961 public void testBigBatch () {
60- V2Batch batch = new V2Batch ();
61- int size = 4096 ;
62- assertEquals (0 , batch .size ());
63- try {
62+ try (V2Batch batch = new V2Batch ()) {
63+ int size = 4096 ;
64+ assertEquals (0 , batch .size ());
6465 ByteBuf content = messageContents ();
6566 for (int i = 0 ; i < size ; i ++) {
6667 batch .addMessage (i , content , content .readableBytes ());
@@ -70,22 +71,19 @@ public void testBigBatch() {
7071 for (Message message : batch ) {
7172 assertEquals (message .getSequence (), i ++);
7273 }
73- }finally {
74- batch .release ();
7574 }
76- }
7775
76+ }
7877
7978 @ Test
80- public void TestCompleteReturnWhenTheNumberOfEventDoesntMatchBatchSize () {
81- V2Batch batch = new V2Batch ();
82- int numberOfEvent = 2 ;
83-
84- batch .setBatchSize (numberOfEvent );
85- ByteBuf content = messageContents ();
86- batch .addMessage (1 , content , content .readableBytes ());
87-
88- assertFalse (batch .isComplete ());
79+ public void testCompleteReturnWhenTheNumberOfEventDoesntMatchBatchSize () {
80+ try (V2Batch batch = new V2Batch ()) {
81+ int numberOfEvent = 2 ;
82+ batch .setBatchSize (numberOfEvent );
83+ ByteBuf content = messageContents ();
84+ batch .addMessage (1 , content , content .readableBytes ());
85+ assertFalse (batch .isComplete ());
86+ }
8987 }
9088
9189 public static ByteBuf messageContents () {
@@ -98,4 +96,4 @@ public static ByteBuf messageContents() {
9896 throw new RuntimeException (e );
9997 }
10098 }
101- }
99+ }
0 commit comments