@@ -19,48 +19,49 @@ public class V2BatchTest {
19
19
20
20
@ Test
21
21
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
+ }
27
28
}
28
29
29
30
@ Test
30
31
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
+ }
36
38
}
37
39
38
40
@ 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
+ }
41
45
}
42
46
43
47
@ 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 ());
53
57
}
54
-
55
- assertTrue (batch .isComplete ());
56
58
}
57
59
58
60
@ Test
59
61
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 ());
64
65
ByteBuf content = messageContents ();
65
66
for (int i = 0 ; i < size ; i ++) {
66
67
batch .addMessage (i , content , content .readableBytes ());
@@ -70,22 +71,19 @@ public void testBigBatch() {
70
71
for (Message message : batch ) {
71
72
assertEquals (message .getSequence (), i ++);
72
73
}
73
- }finally {
74
- batch .release ();
75
74
}
76
- }
77
75
76
+ }
78
77
79
78
@ 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
+ }
89
87
}
90
88
91
89
public static ByteBuf messageContents () {
@@ -98,4 +96,4 @@ public static ByteBuf messageContents() {
98
96
throw new RuntimeException (e );
99
97
}
100
98
}
101
- }
99
+ }
0 commit comments