|
26 | 26 | import static org.junit.Assert.assertSame; |
27 | 27 | import static org.junit.Assert.assertTrue; |
28 | 28 |
|
| 29 | +import com.google.api.client.http.HttpHeaders; |
| 30 | +import com.google.api.client.http.HttpResponseException; |
29 | 31 | import com.google.cloud.BaseServiceException; |
30 | 32 | import com.google.cloud.RetryHelper.RetryHelperException; |
31 | | - |
32 | | -import org.junit.Test; |
33 | | - |
34 | 33 | import java.io.IOException; |
35 | 34 | import java.net.SocketTimeoutException; |
| 35 | +import org.junit.Test; |
36 | 36 |
|
37 | 37 | public class BigQueryExceptionTest { |
38 | 38 |
|
@@ -105,6 +105,34 @@ public void testBigqueryException() { |
105 | 105 | assertTrue(exception.isRetryable()); |
106 | 106 | assertTrue(exception.isIdempotent()); |
107 | 107 | assertSame(cause, exception.getCause()); |
| 108 | + |
| 109 | + |
| 110 | + HttpResponseException httpResponseException = |
| 111 | + new HttpResponseException.Builder(404, "Service Unavailable", new HttpHeaders()).build(); |
| 112 | + exception = new BigQueryException(httpResponseException); |
| 113 | + assertEquals(404, exception.getCode()); |
| 114 | + assertFalse(exception.isRetryable()); |
| 115 | + |
| 116 | + httpResponseException = new HttpResponseException.Builder(504, null, new HttpHeaders()).build(); |
| 117 | + exception = new BigQueryException(httpResponseException); |
| 118 | + assertEquals(504, exception.getCode()); |
| 119 | + assertTrue(exception.isRetryable()); |
| 120 | + |
| 121 | + httpResponseException = new HttpResponseException.Builder(503, null, new HttpHeaders()).build(); |
| 122 | + exception = new BigQueryException(httpResponseException); |
| 123 | + assertEquals(503, exception.getCode()); |
| 124 | + assertTrue(exception.isRetryable()); |
| 125 | + |
| 126 | + httpResponseException = new HttpResponseException.Builder(502, null, new HttpHeaders()).build(); |
| 127 | + exception = new BigQueryException(httpResponseException); |
| 128 | + assertEquals(502, exception.getCode()); |
| 129 | + assertTrue(exception.isRetryable()); |
| 130 | + |
| 131 | + httpResponseException = new HttpResponseException.Builder(500, null, new HttpHeaders()).build(); |
| 132 | + exception = new BigQueryException(httpResponseException); |
| 133 | + assertEquals(500, exception.getCode()); |
| 134 | + assertTrue(exception.isRetryable()); |
| 135 | + |
108 | 136 | } |
109 | 137 |
|
110 | 138 | @Test |
|
0 commit comments