use of org.apache.asterix.api.http.server.QueryCancellationServlet in project asterixdb by apache.
the class QueryCancellationServletTest method testDelete.
@Test
public void testDelete() throws Exception {
// Creates a query cancellation servlet.
QueryCancellationServlet cancellationServlet = new QueryCancellationServlet(new ConcurrentHashMap<>(), new String[] { "/" });
// Adds mocked Hyracks client connection into the servlet context.
IHyracksClientConnection mockHcc = mock(IHyracksClientConnection.class);
cancellationServlet.ctx().put(ServletConstants.HYRACKS_CONNECTION_ATTR, mockHcc);
// Adds a query context into the servlet context.
IStatementExecutorContext queryCtx = new StatementExecutorContext();
cancellationServlet.ctx().put(ServletConstants.RUNNING_QUERIES_ATTR, queryCtx);
// Tests the case that query is not in the map.
IServletRequest mockRequest = mockRequest("1");
IServletResponse mockResponse = mock(IServletResponse.class);
cancellationServlet.handle(mockRequest, mockResponse);
verify(mockResponse, times(1)).setStatus(HttpResponseStatus.NOT_FOUND);
// Tests the case that query is in the map.
queryCtx.put("1", new JobId(1));
cancellationServlet.handle(mockRequest, mockResponse);
verify(mockResponse, times(1)).setStatus(HttpResponseStatus.OK);
// Tests the case the client_context_id is not provided.
mockRequest = mockRequest(null);
cancellationServlet.handle(mockRequest, mockResponse);
verify(mockResponse, times(1)).setStatus(HttpResponseStatus.BAD_REQUEST);
// Tests the case that the job cancellation hit some exception from Hyracks.
queryCtx.put("2", new JobId(2));
Mockito.doThrow(new Exception()).when(mockHcc).cancelJob(any());
mockRequest = mockRequest("2");
cancellationServlet.handle(mockRequest, mockResponse);
verify(mockResponse, times(1)).setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
Aggregations