@@ -20,48 +20,49 @@ public class V2BatchTest {
20
20
21
21
@ Test
22
22
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
+ }
28
29
}
29
30
30
31
@ Test
31
32
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
+ }
37
39
}
38
40
39
41
@ 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
+ }
42
46
}
43
47
44
48
@ 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 ());
54
58
}
55
-
56
- assertTrue (batch .isComplete ());
57
59
}
58
60
59
61
@ Test
60
62
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 ());
65
66
ByteBuf content = messageContents ();
66
67
for (int i = 0 ; i < size ; i ++) {
67
68
batch .addMessage (i , content , content .readableBytes ());
@@ -71,8 +72,6 @@ public void testBigBatch() {
71
72
for (Message message : batch ) {
72
73
assertEquals (message .getSequence (), i ++);
73
74
}
74
- }finally {
75
- batch .release ();
76
75
}
77
76
}
78
77
@@ -91,17 +90,15 @@ public void testHighSequence(){
91
90
assertEquals (startSequenceNumber + numberOfEvent , batch .getHighestSequence ());
92
91
}
93
92
94
-
95
93
@ 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
+ }
105
102
}
106
103
107
104
public static ByteBuf messageContents () {
@@ -114,4 +111,4 @@ public static ByteBuf messageContents() {
114
111
throw new RuntimeException (e );
115
112
}
116
113
}
117
- }
114
+ }
0 commit comments