Search in sources :

Example 1 with QueryCancellationServlet

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);
}
Also used : StatementExecutorContext(org.apache.asterix.api.http.ctx.StatementExecutorContext) IStatementExecutorContext(org.apache.asterix.translator.IStatementExecutorContext) IHyracksClientConnection(org.apache.hyracks.api.client.IHyracksClientConnection) QueryCancellationServlet(org.apache.asterix.api.http.server.QueryCancellationServlet) IStatementExecutorContext(org.apache.asterix.translator.IStatementExecutorContext) IServletResponse(org.apache.hyracks.http.api.IServletResponse) JobId(org.apache.hyracks.api.job.JobId) IServletRequest(org.apache.hyracks.http.api.IServletRequest) Test(org.junit.Test)

Aggregations

StatementExecutorContext (org.apache.asterix.api.http.ctx.StatementExecutorContext)1 QueryCancellationServlet (org.apache.asterix.api.http.server.QueryCancellationServlet)1 IStatementExecutorContext (org.apache.asterix.translator.IStatementExecutorContext)1 IHyracksClientConnection (org.apache.hyracks.api.client.IHyracksClientConnection)1 JobId (org.apache.hyracks.api.job.JobId)1 IServletRequest (org.apache.hyracks.http.api.IServletRequest)1 IServletResponse (org.apache.hyracks.http.api.IServletResponse)1 Test (org.junit.Test)1