public void execute(String query) { Request request = buildQueryRequest(session, query); StatusResponse response = httpClient.execute(request, createStatusResponseHandler()); if (response.getStatusCode() != 200) { throw new RuntimeException( "Query failed: [" + response.getStatusCode() + "] " + response.getStatusMessage()); } }
@Test(enabled = false) public void testQuery() throws Exception { URI location = client.execute( preparePost() .setUri(uriFor("/v1/query")) .setBodyGenerator(createStaticBodyGenerator("query", UTF_8)) .build(), new CreatedResponseHandler()); assertQueryStatus(location, QueryState.RUNNING); QueryInfo queryInfo = client.execute( prepareGet().setUri(location).build(), createJsonResponseHandler(jsonCodec(QueryInfo.class))); TaskInfo taskInfo = queryInfo.getOutputStage().getTasks().get(0); URI outputLocation = uriFor("/v1/task/" + taskInfo.getTaskId() + "/results/out"); long sequenceId = 0; PagesResponse response = client.execute( prepareGet() .setUri( uriBuilderFrom(outputLocation).appendPath(String.valueOf(sequenceId)).build()) .build(), new PageResponseHandler()); List<Page> pages = response.getPages(); assertEquals(countPositions(pages), 220); assertQueryStatus(location, QueryState.RUNNING); sequenceId += pages.size(); response = client.execute( prepareGet() .setUri( uriBuilderFrom(outputLocation).appendPath(String.valueOf(sequenceId)).build()) .build(), new PageResponseHandler()); pages = response.getPages(); assertEquals(countPositions(pages), 44 + 48); sequenceId += pages.size(); response = client.execute( prepareGet() .setUri( uriBuilderFrom(outputLocation).appendPath(String.valueOf(sequenceId)).build()) .build(), new PageResponseHandler()); pages = response.getPages(); assertEquals(countPositions(pages), 0); assertQueryStatus(location, QueryState.FINISHED); // cancel the query StatusResponse cancelResponse = client.execute(prepareDelete().setUri(location).build(), createStatusResponseHandler()); assertQueryStatus(location, QueryState.FINISHED); assertEquals(cancelResponse.getStatusCode(), HttpStatus.NO_CONTENT.code()); }
@Test public void testLifecycleUnknown() throws Exception { initializeOneAgent(); Request request = Request.Builder.preparePut() .setUri( coordinatorUriBuilder() .appendPath("/v1/slot/lifecycle") .addParameter("binary", "apple:*") .build()) .setBodyGenerator(createStaticBodyGenerator("unknown", UTF_8)) .build(); StatusResponse response = httpClient.execute(request, createStatusResponseHandler()); AgentStatus agentStatus = coordinator.getAgentByAgentId(agentId); SlotStatus apple1Status = agentStatus.getSlotStatus(apple1SotId); SlotStatus apple2Status = agentStatus.getSlotStatus(apple2SlotId); SlotStatus bananaStatus = agentStatus.getSlotStatus(bananaSlotId); assertEquals(response.getStatusCode(), Status.BAD_REQUEST.getStatusCode()); assertEquals(apple1Status.getState(), STOPPED); assertEquals(apple2Status.getState(), STOPPED); assertEquals(bananaStatus.getState(), STOPPED); }