1515import de .gdata .vaas .options .ForStreamOptions ;
1616import de .gdata .vaas .options .ForUrlOptions ;
1717import io .github .cdimascio .dotenv .Dotenv ;
18+ import lombok .extern .slf4j .Slf4j ;
1819import org .junit .jupiter .api .Disabled ;
1920import org .junit .jupiter .api .Test ;
2021import org .junit .jupiter .params .ParameterizedTest ;
2122import org .junit .jupiter .params .provider .CsvSource ;
2223import org .mockito .ArgumentCaptor ;
2324
2425import java .io .ByteArrayOutputStream ;
26+ import java .io .IOException ;
2527import java .net .URI ;
2628import java .net .http .HttpClient ;
2729import java .net .http .HttpRequest ;
3032import java .nio .file .Files ;
3133import java .nio .file .Path ;
3234import java .nio .file .StandardCopyOption ;
35+ import java .util .List ;
3336import java .util .Objects ;
37+ import java .util .UUID ;
3438import java .util .concurrent .*;
3539
3640import static org .junit .jupiter .api .Assertions .*;
3741import static org .mockito .ArgumentMatchers .any ;
3842import static org .mockito .ArgumentMatchers .argThat ;
3943import static org .mockito .Mockito .*;
4044
45+ @ Slf4j
4146public class RealApiIntegrationTests {
4247 private static final String EICAR_URL = "https://secure.eicar.org/eicar.com.txt" ;
4348
@@ -1366,4 +1371,60 @@ public void forUrl_BigFileWithSmallTimeout_ThrowsTimeoutException()
13661371 var exception = assertThrows (ExecutionException .class , () -> vaas .forUrlAsync (url ).get ());
13671372 assertInstanceOf (TimeoutException .class , exception .getCause ());
13681373 }
1374+
1375+ @ Test
1376+ @ Disabled ()
1377+ public void forFileAsync_WithSmallTimeout_DoesNotShowNegativeResources () {
1378+ var config = new VaasConfig (45 , false , false , URI .create (getEnvironmentKey ("VAAS_URL" )));
1379+ var vaas = new Vaas (config , getAuthenticator ());
1380+ var file = Path .of (System .getProperty ("java.io.tmpdir" ), "file.txt" );
1381+ try (var writer = Files .newBufferedWriter (file )) {
1382+ writer .write (UUID .randomUUID ().toString ());
1383+ } catch (IOException e ) {
1384+ e .printStackTrace ();
1385+ }
1386+
1387+ while (true ) {
1388+ try {
1389+ vaas .forFile (file );
1390+ System .out .print ("+" );
1391+ System .out .flush ();
1392+ } catch (Exception e ) {
1393+ System .out .print ("-" );
1394+ System .out .flush ();
1395+ }
1396+ }
1397+ }
1398+
1399+ @ Test
1400+ @ Disabled ()
1401+ public void forFileAsync_WithSmallTimeoutInParallel_DoesNotShowNegativeResources () {
1402+ var config = new VaasConfig (45 , false , false , URI .create (getEnvironmentKey ("VAAS_URL" )));
1403+ var vaas = new Vaas (config , getAuthenticator ());
1404+ var file1 = Path .of (System .getProperty ("java.io.tmpdir" ), "file.txt" );
1405+ var file2 = Path .of (System .getProperty ("java.io.tmpdir" ), "file2.txt" );
1406+ var file3 = Path .of (System .getProperty ("java.io.tmpdir" ), "file3.txt" );
1407+ var file4 = Path .of (System .getProperty ("java.io.tmpdir" ), "file4.txt" );
1408+ var fileList = List .of (file1 , file2 , file3 , file4 );
1409+ for (var file : fileList ) {
1410+ try (var writer = Files .newBufferedWriter (file )) {
1411+ writer .write (UUID .randomUUID ().toString ());
1412+ } catch (IOException e ) {
1413+ e .printStackTrace ();
1414+ }
1415+ }
1416+
1417+ while (true ) {
1418+ fileList .parallelStream ().forEach ((key ) -> {
1419+ try {
1420+ vaas .forFile (key );
1421+ System .out .print ("+" );
1422+ System .out .flush ();
1423+ } catch (Exception e ) {
1424+ System .out .print ("-" );
1425+ System .out .flush ();
1426+ }
1427+ });
1428+ }
1429+ }
13691430}
0 commit comments