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

Commit 33da807

Browse files
authored
Merge pull request #33 from snyk/fix/ROAD-730_fileUpload_and_getAnalysis_resilience
make analysis retrieval more resilient [ROAD-730]
2 parents 980128b + 1a9b7e8 commit 33da807

18 files changed

+782
-433
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
## [2.2.2] - 2022-03
1+
## [2.3.0] - 2022-03
2+
- fix: make 5 consequent attempts to getAnalysis during polling if operation does not succeed with 404
3+
- fix: make 5 attempts to re-upload files if operation does not succeed
4+
- fix: do not try to getAnalysis if `upload files` is not succeed (i.e. `missingFiles` is not empty after uploads)
5+
- fix: avoid remove operation for empty immutable List
26
- fix: check file in marker for nullability before proceed
37
- feat: provide unique (per project) `shard` to getAnalysis call
8+
- chore: reshape/refactor REST API wrapper to be replaceable through constructor base DI
49

510
## [2.2.1] - 2021-12-10
611
- fix: don't upload empty files

build.gradle

Lines changed: 1 addition & 1 deletion
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.2.2"
9+
version = "2.3.0"
1010

1111
repositories {
1212
mavenLocal()

src/integTest/java/ai/deepcode/javaclient/DeepCodeRestApiTest.java renamed to src/integTest/java/ai/deepcode/javaclient/DeepCodeRestApiImplTest.java

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
import static org.junit.Assert.assertTrue;
3737

3838
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
39-
public class DeepCodeRestApiTest {
39+
public class DeepCodeRestApiImplTest {
4040

4141
private final String testFileContent =
4242
"public class AnnotatorTest {\n"
@@ -55,6 +55,8 @@ public class DeepCodeRestApiTest {
5555

5656
private static String bundleId = null;
5757

58+
private static final DeepCodeRestApi restApiClient = new DeepCodeRestApiImpl();
59+
5860
@Test
5961
public void _022_setBaseUrl() {
6062
System.out.println("\n--------------Set base URL----------------\n");
@@ -63,13 +65,13 @@ public void _022_setBaseUrl() {
6365
doSetBaseUrlTest("https://www.google.com/", 404);
6466
doSetBaseUrlTest("https://deeproxy.snyk.io/", 401);
6567
} finally {
66-
DeepCodeRestApi.setBaseUrl("");
68+
restApiClient.setBaseUrl("", false, false);
6769
}
6870
}
6971

7072
private void doSetBaseUrlTest(String baseUrl, int expectedStatusCode) {
71-
DeepCodeRestApi.setBaseUrl(baseUrl, false, true);
72-
EmptyResponse response = DeepCodeRestApi.checkBundle("blabla", "irrelevant");
73+
restApiClient.setBaseUrl(baseUrl, false, true);
74+
EmptyResponse response = restApiClient.checkBundle("blabla", "irrelevant");
7375
int status = response.getStatusCode();
7476
String description = response.getStatusDescription();
7577
System.out.printf(
@@ -81,7 +83,7 @@ private void doSetBaseUrlTest(String baseUrl, int expectedStatusCode) {
8183
@Test
8284
public void _025_getFilters() {
8385
System.out.println("\n--------------Get Filters----------------\n");
84-
GetFiltersResponse response = DeepCodeRestApi.getFilters(loggedToken);
86+
GetFiltersResponse response = restApiClient.getFilters(loggedToken);
8587
assertNotNull(response);
8688
final String errorMsg =
8789
"Get Filters return status code: ["
@@ -99,7 +101,7 @@ public void _025_getFilters() {
99101
@Test
100102
public void _030_createBundle_from_source() throws NoSuchAlgorithmException {
101103
System.out.println("\n--------------Create Bundle from Source----------------\n");
102-
DeepCodeRestApi.setBaseUrl(baseUrl, false, true);
104+
restApiClient.setBaseUrl(baseUrl, false, true);
103105
CreateBundleResponse response = createBundleFromSource(loggedToken);
104106
assertNotNull(response);
105107
System.out.printf(
@@ -116,7 +118,7 @@ private CreateBundleResponse createBundleFromSource(String token)
116118
fileContent.put(
117119
"/AnnotatorTest.java",
118120
new FileHash2ContentRequest(getHash(testFileContent), testFileContent));
119-
CreateBundleResponse response = DeepCodeRestApi.createBundle(token, fileContent);
121+
CreateBundleResponse response = restApiClient.createBundle(token, fileContent);
120122
return response;
121123
}
122124

@@ -145,7 +147,7 @@ public void _035_createBundle_with_hash() {
145147
@NotNull
146148
private CreateBundleResponse createBundleWithHash() {
147149
FileHashRequest files = createFileHashRequest(null);
148-
CreateBundleResponse response = DeepCodeRestApi.createBundle(loggedToken, files);
150+
CreateBundleResponse response = restApiClient.createBundle(loggedToken, files);
149151
assertNotNull(response);
150152
System.out.printf(
151153
"Create Bundle call return:\nStatus code [%1$d] %3$s \n bundleId: %2$s\n missingFiles: %4$s\n",
@@ -161,7 +163,7 @@ public void _036_Check_Bundle() {
161163
System.out.println("\n--------------Check Bundle----------------\n");
162164
FileHashRequest fileHashRequest = createFileHashRequest(null);
163165
CreateBundleResponse createBundleResponse =
164-
DeepCodeRestApi.createBundle(loggedToken, fileHashRequest);
166+
restApiClient.createBundle(loggedToken, fileHashRequest);
165167
assertNotNull(createBundleResponse);
166168
System.out.printf(
167169
"\nCreate Bundle call return:\nStatus code [%1$d] %3$s \n bundleId: %2$s\n missingFiles: %4$s\n",
@@ -173,7 +175,7 @@ public void _036_Check_Bundle() {
173175
assertFalse("List of missingFiles is empty.", createBundleResponse.getMissingFiles().isEmpty());
174176

175177
CreateBundleResponse checkBundleResponse =
176-
DeepCodeRestApi.checkBundle(loggedToken, createBundleResponse.getBundleHash());
178+
restApiClient.checkBundle(loggedToken, createBundleResponse.getBundleHash());
177179
assertNotNull(checkBundleResponse);
178180
System.out.printf(
179181
"\nCheck Bundle call return:\nStatus code [%1$d] %3$s \n bundleId: %2$s\n missingFiles: %4$s\n",
@@ -199,7 +201,7 @@ public void _036_Check_Bundle() {
199201
assertEquals(200, uploadFileResponse.getStatusCode());
200202

201203
CreateBundleResponse createBundleResponse1 =
202-
DeepCodeRestApi.checkBundle(loggedToken, createBundleResponse.getBundleHash());
204+
restApiClient.checkBundle(loggedToken, createBundleResponse.getBundleHash());
203205
assertNotNull(createBundleResponse1);
204206
System.out.printf(
205207
"\nCheck Bundle call return:\nStatus code [%1$d] %3$s \n bundleId: %2$s\n missingFiles: %4$s\n",
@@ -217,7 +219,7 @@ public void _036_Check_Bundle() {
217219
}
218220

219221
private FileHashRequest createFileHashRequest(String fakeFileName) {
220-
DeepCodeRestApi.setBaseUrl(baseUrl, false, true);
222+
restApiClient.setBaseUrl(baseUrl, false, true);
221223
final File testFile =
222224
new File(getClass().getClassLoader().getResource("AnnotatorTest.java").getFile());
223225
String absolutePath = testFile.getAbsolutePath();
@@ -284,7 +286,7 @@ public void _037_ExtendBundle() {
284286
ExtendBundleWithHashRequest extendBundleWithHashRequest =
285287
new ExtendBundleWithHashRequest(newFileHashRequest, Collections.emptyList());
286288
CreateBundleResponse extendBundleResponse =
287-
DeepCodeRestApi.extendBundle(
289+
restApiClient.extendBundle(
288290
loggedToken, createBundleResponse.getBundleHash(), extendBundleWithHashRequest);
289291
assertNotNull(extendBundleResponse);
290292
System.out.printf(
@@ -302,7 +304,7 @@ public void _040_UploadFiles() {
302304
System.out.println("\n--------------Upload Files by Hash----------------\n");
303305
FileHashRequest fileHashRequest = createFileHashRequest(null);
304306
CreateBundleResponse createBundleResponse =
305-
DeepCodeRestApi.createBundle(loggedToken, fileHashRequest);
307+
restApiClient.createBundle(loggedToken, fileHashRequest);
306308
assertNotNull(createBundleResponse);
307309
System.out.printf(
308310
"Create Bundle call return:\nStatus code [%1$d] %3$s \n bundleId: %2$s\n missingFiles: %4$s\n",
@@ -345,7 +347,7 @@ private EmptyResponse doUploadFile(
345347
map.put(filePath, new FileHash2ContentRequest(fileHash, fileText));
346348
ExtendBundleWithContentRequest ebr =
347349
new ExtendBundleWithContentRequest(map, Collections.emptyList());
348-
return DeepCodeRestApi.extendBundle(loggedToken, createBundleResponse.getBundleHash(), ebr);
350+
return restApiClient.extendBundle(loggedToken, createBundleResponse.getBundleHash(), ebr);
349351
}
350352

351353
@Test
@@ -370,7 +372,7 @@ private GetAnalysisResponse doAnalysisAndWait(List<String> analysedFiles, Intege
370372
throws InterruptedException {
371373
GetAnalysisResponse response = null;
372374
for (int i = 0; i < 120; i++) {
373-
response = DeepCodeRestApi.getAnalysis(loggedToken, bundleId, severity, analysedFiles, bundleId);
375+
response = restApiClient.getAnalysis(loggedToken, bundleId, severity, analysedFiles, bundleId);
374376
if (response.getStatus().equals("COMPLETE")) break;
375377
Thread.sleep(1000);
376378
}

0 commit comments

Comments
 (0)