Skip to content
This repository was archived by the owner on Feb 1, 2023. It is now read-only.

Commit 4d21c1f

Browse files
fix: 🐛 enforce lower and upper file size limit when triggering analysis [ROAD-799][ROAD-814] (#37)
* feat: check for min and max file size when triggering analysis [ROAD-799] also bump upload tries to 10
1 parent cc044e1 commit 4d21c1f

File tree

6 files changed

+29
-7
lines changed

6 files changed

+29
-7
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## [2.3.1] - 2022-04
2+
- fix: adjust max file size to the correct size of 1MB (previously: 4000 bytes)
3+
- chore: update upload attemps to 10
4+
15
## [2.3.0] - 2022-03
26
- fix: make 5 consequent attempts to getAnalysis during polling if operation does not succeed with 404
37
- fix: make 5 attempts to re-upload files if operation does not succeed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66

77
group = "io.snyk.code.sdk"
88
archivesBaseName = "snyk-code-client"
9-
version = "2.3.0"
9+
version = "2.3.1"
1010

1111
repositories {
1212
mavenLocal()

src/main/java/ai/deepcode/javaclient/core/AnalysisDataBase.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
public abstract class AnalysisDataBase {
3737

3838
public static final String COMPLETE = "COMPLETE";
39+
public static final int MAX_FILE_SIZE = 1024 * 1024;
3940
private final PlatformDependentUtilsBase pdUtils;
4041
private final HashContentUtilsBase hashContentUtils;
4142
private final DeepCodeParamsBase deepCodeParams;
@@ -411,7 +412,7 @@ private boolean uploadFilesStep(
411412
} else if (missingFiles.isEmpty()) {
412413
dcLogger.logInfo("No missingFiles to Upload");
413414
} else {
414-
final int attempts = 5;
415+
final int attempts = 10;
415416
int counter = 0;
416417
while (!missingFiles.isEmpty() && counter < attempts) {
417418
if (counter > 0) {

src/main/java/ai/deepcode/javaclient/core/DeepCodeUtilsBase.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public List<Object> getAllSupportedFilesInProject(
7070

7171
protected abstract Collection<Object> allProjectFiles(@NotNull Object project);
7272

73-
private static final long MAX_FILE_SIZE = 4000000; // ~ 4MB in bytes
73+
private static final long MAX_FILE_SIZE = 1024*1024; // 1MB in bytes
7474

7575
public boolean isSupportedFileFormat(@NotNull Object file) {
7676
// DCLogger.getInstance().info("isSupportedFileFormat started for " + psiFile.getName());

src/main/java/ai/deepcode/javaclient/requests/GetAnalysisRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public class GetAnalysisRequest {
1616
* @param severity
1717
* @param shard uniq String (hash) per Project to optimize jobs on backend (run on the same worker to reuse caches)
1818
* @param ideProductName specific IDE
19-
* @param orgDisplayName client’s snyk organization name
19+
* @param orgDisplayName clients snyk organization name
2020
* @param prioritized
2121
* @param legacy
2222
*/

src/test/java/ai/deepcode/javaclient/core/AnalysisDataTest.java

+20-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import org.jetbrains.annotations.NotNull;
1616
import org.junit.Test;
1717

18+
import java.io.File;
19+
import java.io.IOException;
20+
import java.nio.file.Files;
1821
import java.util.Arrays;
1922
import java.util.Collections;
2023
import java.util.LinkedList;
@@ -38,6 +41,16 @@ public class AnalysisDataTest {
3841
public @NotNull String getProjectName(@NotNull Object project) {
3942
return project.toString();
4043
}
44+
45+
@Override
46+
public @NotNull String getFileName(@NotNull Object file) {
47+
return "testFileName";
48+
}
49+
50+
@Override
51+
public long getFileSize(@NotNull Object file) {
52+
return getFileName(file).length();
53+
}
4154
};
4255

4356
final DCLoggerBase dcLogger = new LoggerMock();
@@ -77,7 +90,7 @@ private static class RestApiMockWithBrokenFileUpload extends DeepCodeRestApiMock
7790

7891
// make 5 attempts to re-upload files if operation does not succeed
7992
@Test
80-
public void reupload_files_if_initial_upload_does_not_succeed() {
93+
public void reupload_files_if_initial_upload_does_not_succeed() throws IOException {
8194
final int[] reUploadCounter = {0};
8295
restApi = new RestApiMockWithBrokenFileUpload() {
8396
@Override
@@ -94,9 +107,13 @@ public void reupload_files_if_initial_upload_does_not_succeed() {
94107
final String project = "Project1";
95108
final String progress = "Progress Indicator";
96109

97-
analysisData.updateCachedResultsForFiles(project, Collections.singleton("File"), progress);
110+
File file = File.createTempFile("analysisDataTest","tmp");
111+
file.deleteOnExit();
112+
Files.writeString(file.toPath(), "testtestest");
113+
114+
analysisData.updateCachedResultsForFiles(project, Collections.singleton(file), progress);
98115

99-
assertEquals("Should be made 5 attempts to re-upload files if operation does not succeed", 5, reUploadCounter[0]);
116+
assertEquals("Should have made 10 attempts to re-upload files if operation does not succeed", 10, reUploadCounter[0]);
100117
}
101118

102119
// do not try to getAnalysis if `upload files` is not succeed (i.e. `missingFiles` is not empty after uploads)

0 commit comments

Comments
 (0)