Skip to content

Commit 7ea6f89

Browse files
yes
1 parent d40ac7f commit 7ea6f89

File tree

2 files changed

+64
-6
lines changed

2 files changed

+64
-6
lines changed

java/src/test/java/de/gdata/test/integration/RealApiIntegrationTests.java

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@
1515
import de.gdata.vaas.options.ForStreamOptions;
1616
import de.gdata.vaas.options.ForUrlOptions;
1717
import io.github.cdimascio.dotenv.Dotenv;
18+
import lombok.extern.slf4j.Slf4j;
1819
import org.junit.jupiter.api.Disabled;
1920
import org.junit.jupiter.api.Test;
2021
import org.junit.jupiter.params.ParameterizedTest;
2122
import org.junit.jupiter.params.provider.CsvSource;
2223
import org.mockito.ArgumentCaptor;
2324

2425
import java.io.ByteArrayOutputStream;
26+
import java.io.IOException;
2527
import java.net.URI;
2628
import java.net.http.HttpClient;
2729
import java.net.http.HttpRequest;
@@ -30,14 +32,17 @@
3032
import java.nio.file.Files;
3133
import java.nio.file.Path;
3234
import java.nio.file.StandardCopyOption;
35+
import java.util.List;
3336
import java.util.Objects;
37+
import java.util.UUID;
3438
import java.util.concurrent.*;
3539

3640
import static org.junit.jupiter.api.Assertions.*;
3741
import static org.mockito.ArgumentMatchers.any;
3842
import static org.mockito.ArgumentMatchers.argThat;
3943
import static org.mockito.Mockito.*;
4044

45+
@Slf4j
4146
public 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
}

java/src/test/java/de/gdata/test/integration/ScanS3Bucket.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,12 @@
1515
import de.gdata.vaas.VaasConfig;
1616
import de.gdata.vaas.authentication.ClientCredentialsGrantAuthenticator;
1717
import de.gdata.vaas.messages.VaasVerdict;
18-
import de.gdata.vaas.options.ForFileOptions;
1918
import io.github.cdimascio.dotenv.Dotenv;
2019

2120
import java.io.File;
2221
import java.io.FileOutputStream;
2322
import java.net.URI;
2423
import java.nio.file.Files;
25-
import java.time.Duration;
2624
import java.util.ArrayList;
2725
import java.util.HashMap;
2826
import java.util.List;
@@ -45,7 +43,7 @@ public static void main(String[] args) throws Exception {
4543
// Build VaaS
4644
long startTimeAll = System.currentTimeMillis();
4745
ClientCredentialsGrantAuthenticator authenticator = new ClientCredentialsGrantAuthenticator(CLIENT_ID, CLIENT_SECRET, new URI(TOKEN_URL));
48-
VaasConfig vaasConfig = new VaasConfig(Duration.ofSeconds(1).getSeconds() * 1000, false, true, new URI(VAAS_URL));
46+
VaasConfig vaasConfig = new VaasConfig(10000, false, false, new URI(VAAS_URL));
4947
Vaas vaas = new Vaas(vaasConfig, authenticator);
5048

5149
// List S3 bucket
@@ -92,8 +90,7 @@ public void refresh() {
9290

9391
// Scan file with VaaS and track time
9492
long startTime = System.currentTimeMillis();
95-
ForFileOptions forFileOptions = new ForFileOptions(false, true, "LD-big-big-files-01");
96-
VaasVerdict vaasVerdict = vaas.forFileAsync(tempFile.toPath(), forFileOptions).get();
93+
VaasVerdict vaasVerdict = vaas.forFileAsync(tempFile.toPath()).get();
9794
long endTime = System.currentTimeMillis();
9895
double executionTime = (endTime - startTime);
9996

@@ -115,7 +112,7 @@ public void refresh() {
115112
} catch (Exception e) {
116113
System.out.println("Error processing key: " + key);
117114
e.printStackTrace();
118-
}
115+
}
119116
});
120117

121118
// Write results to file

0 commit comments

Comments
 (0)