diff options
author | Michal Duda <michal.duda@sonarsource.com> | 2019-04-04 17:27:02 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2019-04-05 20:21:06 +0200 |
commit | b727216b31e7e06559e5f38ccfab41c50245c6d4 (patch) | |
tree | deb8de07b7ec9bf042c7f8141be485f919348d76 /sonar-scanner-engine/src | |
parent | d08c839cb2433f58a35505da8f58e418c23ce1ae (diff) | |
download | sonarqube-b727216b31e7e06559e5f38ccfab41c50245c6d4.tar.gz sonarqube-b727216b31e7e06559e5f38ccfab41c50245c6d4.zip |
SONAR-11878 fix scanner behaviour on /batch/project timeout
Diffstat (limited to 'sonar-scanner-engine/src')
2 files changed, 15 insertions, 11 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java index 658939da426..f5136784e43 100644 --- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java +++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoader.java @@ -28,7 +28,6 @@ import java.util.Map; import javax.annotation.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.sonar.api.utils.MessageException; import org.sonar.scanner.bootstrap.ScannerWsClient; import org.sonar.scanner.util.ScannerUtils; import org.sonarqube.ws.Batch.WsProjectResponse; @@ -77,16 +76,12 @@ public class DefaultProjectRepositoriesLoader implements ProjectRepositoriesLoad private static boolean shouldThrow(Exception e) { for (Throwable t : Throwables.getCausalChain(e)) { - if (t instanceof HttpException) { - HttpException http = (HttpException) t; - return http.code() != HttpURLConnection.HTTP_NOT_FOUND; - } - if (t instanceof MessageException) { - return true; + if (t instanceof HttpException && ((HttpException) t).code() == HttpURLConnection.HTTP_NOT_FOUND) { + return false; } } - return false; + return true; } private static ProjectRepositories processStream(InputStream is) throws IOException { diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java index 6448b845c96..26bb3a6e1aa 100644 --- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java +++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultProjectRepositoriesLoaderTest.java @@ -24,6 +24,7 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.HttpURLConnection; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -38,6 +39,7 @@ import org.sonarqube.ws.client.WsRequest; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -58,16 +60,23 @@ public class DefaultProjectRepositoriesLoaderTest { } @Test - public void continueOnError() { + public void continueOnHttp404Exception() { + when(wsClient.call(any(WsRequest.class))).thenThrow(new HttpException("/batch/project.protobuf?key=foo%3F", HttpURLConnection.HTTP_NOT_FOUND, "")); + ProjectRepositories proj = loader.load(PROJECT_KEY, null); + assertThat(proj.exists()).isEqualTo(false); + } + + @Test(expected = IllegalStateException.class) + public void failOnNonHttp404Exception() { when(wsClient.call(any(WsRequest.class))).thenThrow(IllegalStateException.class); ProjectRepositories proj = loader.load(PROJECT_KEY, null); assertThat(proj.exists()).isEqualTo(false); } - @Test + @Test(expected = IllegalStateException.class) public void parsingError() throws IOException { InputStream is = mock(InputStream.class); - when(is.read()).thenThrow(IOException.class); + when(is.read(any(byte[].class), anyInt(), anyInt())).thenThrow(IOException.class); WsTestUtil.mockStream(wsClient, "/batch/project.protobuf?key=foo%3F", is); loader.load(PROJECT_KEY, null); } |