### Question:
QueryResource { @ResourceSecurity(AUTHENTICATED_USER) @GET @Path("{queryId}") public Response getQueryInfo(@PathParam("queryId") QueryId queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders) { requireNonNull(queryId, "queryId is null"); Optional<QueryInfo> queryInfo = dispatchManager.getFullQueryInfo(queryId); if (queryInfo.isEmpty()) { return Response.status(Status.GONE).build(); } try { checkCanViewQueryOwnedBy(extractAuthorizedIdentity(servletRequest, httpHeaders, accessControl, groupProvider), queryInfo.get().getSession().getUser(), accessControl); return Response.ok(queryInfo.get()).build(); } catch (AccessDeniedException e) { throw new ForbiddenException(); } } @Inject  QueryResource(DispatchManager dispatchManager, AccessControl accessControl, GroupProvider groupProvider); @ResourceSecurity(AUTHENTICATED_USER) @GET List<BasicQueryInfo> getAllQueryInfo(@QueryParam("state") String stateFilter, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders); @ResourceSecurity(AUTHENTICATED_USER) @GET @Path("{queryId}") Response getQueryInfo(@PathParam("queryId") QueryId queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders); @ResourceSecurity(AUTHENTICATED_USER) @DELETE @Path("{queryId}") void cancelQuery(@PathParam("queryId") QueryId queryId, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders); @ResourceSecurity(AUTHENTICATED_USER) @PUT @Path("{queryId}/killed") Response killQuery(@PathParam("queryId") QueryId queryId, String message, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders); @ResourceSecurity(AUTHENTICATED_USER) @PUT @Path("{queryId}/preempted") Response preemptQuery(@PathParam("queryId") QueryId queryId, String message, @Context HttpServletRequest servletRequest, @Context HttpHeaders httpHeaders);  }### Answer:
@Test public void testGetQueryInfoDispatchFailure() { String queryId = runToCompletion("SELECT"); QueryInfo info = getQueryInfo(queryId); assertFalse(info.isScheduled()); assertNotNull(info.getFailureInfo()); assertEquals(info.getFailureInfo().getErrorCode(), SYNTAX_ERROR.toErrorCode()); server.getAccessControl().deny(privilege("query", VIEW_QUERY)); try { assertThatThrownBy(() -> getQueryInfo(queryId)) .isInstanceOf(UnexpectedResponseException.class) .matches(throwable -> ((UnexpectedResponseException) throwable).getStatusCode() == 403); } finally { server.getAccessControl().reset(); } }
@Test public void testGetQueryInfoExecutionFailure() { String queryId = runToCompletion("SELECT cast(rand() AS integer) / 0"); QueryInfo info = getQueryInfo(queryId); assertTrue(info.isScheduled()); assertNotNull(info.getFailureInfo()); assertEquals(info.getFailureInfo().getErrorCode(), DIVISION_BY_ZERO.toErrorCode()); }
@Test public void testCancel() { String queryId = startQuery("SELECT * FROM tpch.sf100.lineitem"); server.getAccessControl().deny(privilege("query", KILL_QUERY)); try { assertEquals(cancelQueryInfo(queryId), 403); } finally { server.getAccessControl().reset(); } assertEquals(cancelQueryInfo(queryId), 204); assertEquals(cancelQueryInfo(queryId), 204); BasicQueryInfo queryInfo = server.getDispatchManager().getQueryInfo(new QueryId(queryId)); assertEquals(queryInfo.getState(), FAILED); assertEquals(queryInfo.getErrorCode(), USER_CANCELED.toErrorCode()); }