36
36
import org .springframework .util .MimeType ;
37
37
38
38
import static java .util .Collections .emptyMap ;
39
- import static org .junit .Assert .assertFalse ;
40
- import static org .junit .Assert .assertTrue ;
39
+ import static org .junit .Assert .*;
41
40
import static org .springframework .core .ResolvableType .forClass ;
42
41
43
42
/**
@@ -81,7 +80,7 @@ public void canDecode() {
81
80
82
81
@ Test
83
82
public void decodeToMono () {
84
- DataBuffer data = this . bufferFactory . wrap (testMsg .toByteArray ());
83
+ DataBuffer data = byteBuffer (testMsg .toByteArray ());
85
84
ResolvableType elementType = forClass (Msg .class );
86
85
87
86
Mono <Message > mono = this .decoder .decodeToMono (Flux .just (data ), elementType , null , emptyMap ());
@@ -106,12 +105,12 @@ public void decodeToMonoWithLargerDataBuffer() {
106
105
107
106
@ Test
108
107
public void decodeChunksToMono () {
109
- DataBuffer buffer = this . bufferFactory . wrap (testMsg .toByteArray ());
108
+ DataBuffer buffer = byteBuffer (testMsg .toByteArray ());
110
109
Flux <DataBuffer > chunks = Flux .just (
111
- buffer .slice (0 , 4 ),
112
- buffer .slice (4 , buffer .readableByteCount () - 4 ));
113
- DataBufferUtils .retain (buffer );
110
+ DataBufferUtils .retain (buffer .slice (0 , 4 )),
111
+ DataBufferUtils .retain (buffer .slice (4 , buffer .readableByteCount () - 4 )));
114
112
ResolvableType elementType = forClass (Msg .class );
113
+ release (buffer );
115
114
116
115
Mono <Message > mono = this .decoder .decodeToMono (chunks , elementType , null ,
117
116
emptyMap ());
@@ -123,10 +122,11 @@ public void decodeChunksToMono() {
123
122
124
123
@ Test
125
124
public void decode () throws IOException {
126
- DataBuffer buffer = bufferFactory .allocateBuffer ();
125
+ DataBuffer buffer = this . bufferFactory .allocateBuffer ();
127
126
testMsg .writeDelimitedTo (buffer .asOutputStream ());
128
- DataBuffer buffer2 = bufferFactory .allocateBuffer ();
127
+ DataBuffer buffer2 = this . bufferFactory .allocateBuffer ();
129
128
testMsg2 .writeDelimitedTo (buffer2 .asOutputStream ());
129
+
130
130
Flux <DataBuffer > source = Flux .just (buffer , buffer2 );
131
131
ResolvableType elementType = forClass (Msg .class );
132
132
@@ -136,22 +136,22 @@ public void decode() throws IOException {
136
136
.expectNext (testMsg )
137
137
.expectNext (testMsg2 )
138
138
.verifyComplete ();
139
-
140
- DataBufferUtils .release (buffer );
141
- DataBufferUtils .release (buffer2 );
142
139
}
143
140
144
141
@ Test
145
142
public void decodeSplitChunks () throws IOException {
146
- DataBuffer buffer = bufferFactory .allocateBuffer ();
143
+ DataBuffer buffer = this . bufferFactory .allocateBuffer ();
147
144
testMsg .writeDelimitedTo (buffer .asOutputStream ());
148
- DataBuffer buffer2 = bufferFactory .allocateBuffer ();
145
+ DataBuffer buffer2 = this . bufferFactory .allocateBuffer ();
149
146
testMsg2 .writeDelimitedTo (buffer2 .asOutputStream ());
147
+
150
148
Flux <DataBuffer > chunks = Flux .just (
151
- buffer .slice (0 , 4 ),
152
- buffer .slice (4 , buffer .readableByteCount () - 4 ),
153
- buffer2 .slice (0 , 2 ),
154
- buffer2 .slice (2 , buffer2 .readableByteCount () - 2 ));
149
+ DataBufferUtils .retain (buffer .slice (0 , 4 )),
150
+ DataBufferUtils .retain (buffer .slice (4 , buffer .readableByteCount () - 4 )),
151
+ DataBufferUtils .retain (buffer2 .slice (0 , 2 )),
152
+ DataBufferUtils .retain (buffer2
153
+ .slice (2 , buffer2 .readableByteCount () - 2 )));
154
+ release (buffer , buffer2 );
155
155
156
156
ResolvableType elementType = forClass (Msg .class );
157
157
Flux <Message > messages = this .decoder .decode (chunks , elementType , null , emptyMap ());
@@ -160,9 +160,6 @@ public void decodeSplitChunks() throws IOException {
160
160
.expectNext (testMsg )
161
161
.expectNext (testMsg2 )
162
162
.verifyComplete ();
163
-
164
- DataBufferUtils .release (buffer );
165
- DataBufferUtils .release (buffer2 );
166
163
}
167
164
168
165
@ Test
@@ -178,15 +175,12 @@ public void decodeMergedChunks() throws IOException {
178
175
.expectNext (testMsg )
179
176
.expectNext (testMsg )
180
177
.verifyComplete ();
181
-
182
- DataBufferUtils .release (buffer );
183
178
}
184
179
185
180
@ Test
186
181
public void exceedMaxSize () {
187
182
this .decoder .setMaxMessageSize (1 );
188
- byte [] body = testMsg .toByteArray ();
189
- Flux <DataBuffer > source = Flux .just (this .bufferFactory .wrap (body ));
183
+ Flux <DataBuffer > source = Flux .just (byteBuffer (testMsg .toByteArray ()));
190
184
ResolvableType elementType = forClass (Msg .class );
191
185
Flux <Message > messages = this .decoder .decode (source , elementType , null ,
192
186
emptyMap ());
0 commit comments