10
10
11
11
import org .assertj .core .api .Assertions ;
12
12
import org .assertj .core .api .Assumptions ;
13
+ import org .assertj .core .api .Condition ;
13
14
import org .hamcrest .CoreMatchers ;
14
15
import org .hamcrest .Matchers ;
15
16
import org .jboss .logging .Logger ;
16
17
import org .junit .jupiter .api .BeforeEach ;
18
+ import org .junit .jupiter .api .Test ;
17
19
import org .junit .jupiter .params .ParameterizedTest ;
18
20
import org .junit .jupiter .params .provider .ValueSource ;
19
21
20
22
import io .quarkiverse .cxf .HTTPConduitImpl ;
21
23
import io .quarkiverse .cxf .it .large .slow .LargeSlowServiceImpl ;
24
+ import io .quarkiverse .cxf .it .redirect .retransmitcache .RetransmitCacheServiceImpl ;
22
25
import io .quarkus .runtime .configuration .MemorySizeConverter ;
23
26
import io .quarkus .test .common .QuarkusTestResource ;
24
27
import io .quarkus .test .junit .QuarkusTest ;
@@ -188,99 +191,132 @@ static ValidatableResponse getResponse(String endpoint, int sizeBytes) {
188
191
.then ();
189
192
}
190
193
191
- @ ParameterizedTest
192
- @ ValueSource (strings = { //
193
- "retransmitCacheSync" , //
194
- "retransmitCacheAsyncBlocking" //
195
- })
196
- void retransmitCache (String endpoint ) throws IOException {
194
+ /*
195
+ * 1k is smaller than 500K we set in quarkus.cxf.retransmit-cache.threshold
196
+ * Hence the file should not be cached on disk
197
+ */
198
+ @ Test
199
+ void retransmitCacheSync1k () throws IOException {
200
+ retransmitCache ("retransmitCacheSync" , "1k" , 0 );
201
+ }
202
+
203
+ @ Test
204
+ void retransmitCacheAsyncBlocking1k () throws IOException {
205
+ retransmitCache ("retransmitCacheAsyncBlocking" , "1k" , 0 );
206
+ }
207
+
208
+ /*
209
+ * 9M is greater than the 500K we set in quarkus.cxf.retransmit-cache.threshold
210
+ * Hence the file should not be cached on disk
211
+ */
212
+ @ Test
213
+ void retransmitCacheSync9m () throws IOException {
214
+ retransmitCache ("retransmitCacheSync" , "9m" , 1 );
215
+ }
216
+
217
+ @ Test
218
+ void retransmitCacheAsyncBlocking9m () throws IOException {
219
+ retransmitCache ("retransmitCacheAsyncBlocking" , "9m" , 1 );
220
+ }
221
+
222
+ /*
223
+ * Let server return 500
224
+ */
225
+ @ Test
226
+ void retransmitCacheSync500 () throws IOException {
227
+ retransmitCache500 ("retransmitCacheSync" );
228
+ }
197
229
230
+ @ Test
231
+ void retransmitCacheAsyncBlocking500 () throws IOException {
232
+ retransmitCache500 ("retransmitCacheAsyncBlocking" );
233
+ }
234
+
235
+ private static void retransmitCache500 (String endpoint ) throws IOException {
198
236
if (endpoint .contains ("Async" )) {
199
237
/* URLConnectionHTTPConduitFactory does not support async */
200
238
Assumptions .assumeThat (HTTPConduitImpl .findDefaultHTTPConduitImpl ())
201
239
.isNotEqualTo (HTTPConduitImpl .URLConnectionHTTPConduitFactory );
202
240
}
203
241
204
242
final MemorySizeConverter converter = new MemorySizeConverter ();
205
- {
206
- /*
207
- * 1k is smaller than 500K we set in quarkus.cxf.retransmit-cache.threshold
208
- * Hence the file should not be cached on disk
209
- */
210
- final int payloadLen = (int ) converter .convert ("1K" ).asLongValue ();
211
- final Properties props = retransmitCache (payloadLen , 0 , endpoint );
212
- Assertions .assertThat (props .size ()).isEqualTo (1 );
213
- }
214
243
215
- {
216
- /*
217
- * 9M is greater than the 500K we set in quarkus.cxf.retransmit-cache.threshold
218
- * Hence the file should not be cached on disk
219
- */
220
- final int payloadLen = (int ) converter .convert ("9M" ).asLongValue ();
221
- final Properties props = retransmitCache (payloadLen , 1 , endpoint );
222
- Assertions .assertThat (props .size ()).isEqualTo (2 );
223
-
224
- for (Entry <Object , Object > en : props .entrySet ()) {
225
- String path = (String ) en .getKey ();
226
- if (path .contains ("qcxf-TempStore-" )) {
227
- Assertions .assertThat (Path .of (path )).doesNotExist ();
228
- Assertions .assertThat ((String ) en .getValue ())
229
- .startsWith ("<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" >"
230
- + "<soap:Body><ns2:retransmitCache xmlns:ns2=\" https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test\" >"
231
- + "<expectedFileCount>" );
232
- Assertions .assertThat ((String ) en .getValue ())
233
- .endsWith ("</payload></ns2:retransmitCache></soap:Body></soap:Envelope>" );
234
- Assertions .assertThat ((String ) en .getValue ())
235
- .contains ("<payload>" + LargeSlowServiceImpl .largeString (payloadLen ) + "</payload>" );
236
- }
244
+ final int payloadLen = (int ) converter .convert ("501K" ).asLongValue ();
245
+ final String reqId = UUID .randomUUID ().toString ();
246
+ RestAssured .given ()
247
+ .header (RedirectRest .EXPECTED_FILE_COUNT_HEADER , "1" )
248
+ .header (RedirectRest .REQUEST_ID_HEADER , reqId )
249
+ .header (RedirectRest .STATUS_CODE_HEADER , "500" )
250
+ .body (LargeSlowServiceImpl .largeString (payloadLen ))
251
+ .post ("/RedirectRest/" + endpoint )
252
+ .then ()
253
+ .statusCode (500 );
254
+
255
+ final String propString = RestAssured .given ()
256
+ .get ("/RedirectRest/retransmitCache-tempFiles/" + reqId )
257
+ .then ()
258
+ .statusCode (200 )
259
+ .extract ().body ().asString ();
260
+
261
+ Properties props = new Properties ();
262
+ props .load (new StringReader (propString ));
263
+
264
+ Assertions .assertThat (props .size ()).isEqualTo (1 );
265
+ for (Entry <Object , Object > en : props .entrySet ()) {
266
+ final String path = (String ) en .getKey ();
267
+ final Path p = Path .of (path );
268
+ if (path .contains ("qcxf-TempStore-" )) {
269
+ Assertions .assertThat (p ).doesNotExist ();
237
270
}
271
+ Assertions .assertThat (p ).satisfies (new Condition <Path >(RetransmitCacheServiceImpl ::isRetransmitFile ,
272
+ "a retransmit file matching 'qcxf-TempStore-*' or 'cos*tmp'" , "fairy" ));
273
+ assertContent ((String ) en .getValue (), payloadLen );
274
+ }
275
+
276
+ }
277
+
278
+ private static void retransmitCache (String endpoint , String payloadSize , int expectedFileCount ) throws IOException {
238
279
280
+ if (endpoint .contains ("Async" )) {
281
+ /* URLConnectionHTTPConduitFactory does not support async */
282
+ Assumptions .assumeThat (HTTPConduitImpl .findDefaultHTTPConduitImpl ())
283
+ .isNotEqualTo (HTTPConduitImpl .URLConnectionHTTPConduitFactory );
239
284
}
240
- {
241
- /*
242
- * Let server return 500
243
- */
244
- final int payloadLen = (int ) converter .convert ("501K" ).asLongValue ();
245
- final String reqId = UUID .randomUUID ().toString ();
246
- RestAssured .given ()
247
- .header (RedirectRest .EXPECTED_FILE_COUNT_HEADER , "1" )
248
- .header (RedirectRest .REQUEST_ID_HEADER , reqId )
249
- .header (RedirectRest .STATUS_CODE_HEADER , "500" )
250
- .body (LargeSlowServiceImpl .largeString (payloadLen ))
251
- .post ("/RedirectRest/" + endpoint )
252
- .then ()
253
- .statusCode (500 );
254
285
255
- final String propString = RestAssured .given ()
256
- .get ("/RedirectRest/retransmitCache-tempFiles/" + reqId )
257
- .then ()
258
- .statusCode (200 )
259
- .extract ().body ().asString ();
260
-
261
- Properties props = new Properties ();
262
- props .load (new StringReader (propString ));
263
-
264
- Assertions .assertThat (props .size ()).isEqualTo (1 );
265
- for (Entry <Object , Object > en : props .entrySet ()) {
266
- String path = (String ) en .getKey ();
267
- if (path .contains ("qcxf-TempStore-" )) {
268
- Assertions .assertThat (Path .of (path )).doesNotExist ();
269
- Assertions .assertThat ((String ) en .getValue ())
270
- .startsWith ("<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" >"
271
- + "<soap:Body><ns2:retransmitCache xmlns:ns2=\" https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test\" >"
272
- + "<expectedFileCount>" );
273
- Assertions .assertThat ((String ) en .getValue ())
274
- .endsWith ("</payload></ns2:retransmitCache></soap:Body></soap:Envelope>" );
275
- Assertions .assertThat ((String ) en .getValue ())
276
- .contains ("<payload>" + LargeSlowServiceImpl .largeString (payloadLen ) + "</payload>" );
286
+ final MemorySizeConverter converter = new MemorySizeConverter ();
287
+ {
288
+ final int payloadLen = (int ) converter .convert (payloadSize ).asLongValue ();
289
+ final Properties props = retransmitCache (payloadLen , 0 , endpoint );
290
+ Assertions .assertThat (props .size ()).isEqualTo (expectedFileCount );
291
+
292
+ if (expectedFileCount >= 1 ) {
293
+ for (Entry <Object , Object > en : props .entrySet ()) {
294
+ final String path = (String ) en .getKey ();
295
+ Path p = Path .of (path );
296
+ if (path .contains ("qcxf-TempStore-" )) {
297
+ Assertions .assertThat (p ).doesNotExist ();
298
+ }
299
+ Assertions .assertThat (p ).satisfies (new Condition <Path >(RetransmitCacheServiceImpl ::isRetransmitFile ,
300
+ "a retransmit file matching 'qcxf-TempStore-*' or 'cos*tmp'" , "fairy" ));
301
+ assertContent ((String ) en .getValue (), payloadLen );
277
302
}
278
303
}
279
-
280
304
}
281
305
}
282
306
283
- private Properties retransmitCache (final int payloadLen , int expectedFileCount , String syncAsync ) throws IOException {
307
+ private static void assertContent (String content , int payloadLen ) {
308
+ Assertions .assertThat (content )
309
+ .startsWith ("<soap:Envelope xmlns:soap=\" http://schemas.xmlsoap.org/soap/envelope/\" >"
310
+ + "<soap:Body><ns2:retransmitCache xmlns:ns2=\" https://quarkiverse.github.io/quarkiverse-docs/quarkus-cxf/test\" >"
311
+ + "<expectedFileCount>" );
312
+ Assertions .assertThat (content )
313
+ .endsWith ("</payload></ns2:retransmitCache></soap:Body></soap:Envelope>" );
314
+ Assertions .assertThat (content )
315
+ .contains ("<payload>" + LargeSlowServiceImpl .largeString (payloadLen ) + "</payload>" );
316
+ }
317
+
318
+ private static Properties retransmitCache (final int payloadLen , int expectedFileCount , String syncAsync )
319
+ throws IOException {
284
320
String body = RestAssured .given ()
285
321
.header (RedirectRest .EXPECTED_FILE_COUNT_HEADER , String .valueOf (expectedFileCount ))
286
322
.body (LargeSlowServiceImpl .largeString (payloadLen ))
@@ -292,6 +328,7 @@ private Properties retransmitCache(final int payloadLen, int expectedFileCount,
292
328
final Properties props = new Properties ();
293
329
props .load (new StringReader (body ));
294
330
Assertions .assertThat (props .get ("payload.length" )).isEqualTo (String .valueOf (payloadLen ));
331
+ props .remove ("payload.length" );
295
332
return props ;
296
333
}
297
334
0 commit comments