GcpUtil { public static boolean isResourceExhausted(Throwable t) { return t instanceof GoogleJsonResponseException && isResourceExhausted((GoogleJsonResponseException) t); } private  GcpUtil(); static boolean isPermissionDenied(Throwable t); static boolean isPermissionDenied(GoogleJsonResponseException e); static boolean isPermissionDenied(GoogleJsonError error); static boolean isResourceExhausted(Throwable t); static boolean isResourceExhausted(GoogleJsonResponseException e); static boolean isResourceExhausted(GoogleJsonError error);  }
@Test public void responseIsResourceExhausted() { final Throwable resourceExhausted = new GoogleJsonResponseException( new HttpResponseException.Builder(429, "Too Many Requests", new HttpHeaders()), RESOURCE_EXHAUSTED_ERROR); assertThat(GcpUtil.isResourceExhausted(resourceExhausted), is(true)); }
@Test public void notFoundResponseIsNotPResourceExhausted() { assertThat(GcpUtil.isResourceExhausted(new GoogleJsonResponseException( new HttpResponseException.Builder(404, "Not Found", new HttpHeaders()), new GoogleJsonError())), is(false)); assertThat(GcpUtil.isResourceExhausted(new GoogleJsonResponseException( new HttpResponseException.Builder(404, "Not Found", new HttpHeaders()), null)), is(false)); }
@Test public void errorIsResourceExhausted() { assertThat(GcpUtil.isResourceExhausted(RESOURCE_EXHAUSTED_ERROR), is(true)); }
@Test public void errorIsNotResourceExhausted() { assertThat(GcpUtil.isResourceExhausted(new GoogleJsonError()), is(false)); assertThat(GcpUtil.isResourceExhausted(new GoogleJsonError().set("status", "foo failed")), is(false)); }