|
27 | 27 | import static org.junit.Assert.assertTrue; |
28 | 28 |
|
29 | 29 | import com.google.api.client.googleapis.json.GoogleJsonError; |
| 30 | +import com.google.api.client.http.HttpHeaders; |
| 31 | +import com.google.api.client.http.HttpResponseException; |
30 | 32 | import com.google.cloud.BaseServiceException; |
31 | 33 | import com.google.cloud.RetryHelper.RetryHelperException; |
32 | | - |
33 | | -import org.junit.Test; |
34 | | - |
35 | 34 | import java.io.IOException; |
36 | 35 | import java.net.SocketTimeoutException; |
| 36 | +import org.junit.Test; |
37 | 37 |
|
38 | 38 | public class StorageExceptionTest { |
39 | 39 |
|
@@ -112,6 +112,37 @@ public void testStorageException() { |
112 | 112 | assertFalse(exception.isRetryable()); |
113 | 113 | assertTrue(exception.isIdempotent()); |
114 | 114 | assertSame(cause, exception.getCause()); |
| 115 | + |
| 116 | + HttpResponseException httpResponseException = |
| 117 | + new HttpResponseException.Builder(404, "Service Unavailable", new HttpHeaders()).build(); |
| 118 | + exception = new StorageException(httpResponseException); |
| 119 | + assertEquals(404, exception.getCode()); |
| 120 | + assertFalse(exception.isRetryable()); |
| 121 | + |
| 122 | + httpResponseException = new HttpResponseException.Builder(503, null, new HttpHeaders()).build(); |
| 123 | + exception = new StorageException(httpResponseException); |
| 124 | + assertEquals(503, exception.getCode()); |
| 125 | + assertTrue(exception.isRetryable()); |
| 126 | + |
| 127 | + httpResponseException = new HttpResponseException.Builder(502, null, new HttpHeaders()).build(); |
| 128 | + exception = new StorageException(httpResponseException); |
| 129 | + assertEquals(502, exception.getCode()); |
| 130 | + assertTrue(exception.isRetryable()); |
| 131 | + |
| 132 | + httpResponseException = new HttpResponseException.Builder(500, null, new HttpHeaders()).build(); |
| 133 | + exception = new StorageException(httpResponseException); |
| 134 | + assertEquals(500, exception.getCode()); |
| 135 | + assertTrue(exception.isRetryable()); |
| 136 | + |
| 137 | + httpResponseException = new HttpResponseException.Builder(429, null, new HttpHeaders()).build(); |
| 138 | + exception = new StorageException(httpResponseException); |
| 139 | + assertEquals(429, exception.getCode()); |
| 140 | + assertTrue(exception.isRetryable()); |
| 141 | + |
| 142 | + httpResponseException = new HttpResponseException.Builder(408, null, new HttpHeaders()).build(); |
| 143 | + exception = new StorageException(httpResponseException); |
| 144 | + assertEquals(408, exception.getCode()); |
| 145 | + assertTrue(exception.isRetryable()); |
115 | 146 | } |
116 | 147 |
|
117 | 148 | @Test |
|
0 commit comments