@Test public void testPost() { // Create topic Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL) .getTopicCreationRequestUrl("testTopic1", 16); Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic1, partition: 16}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic1")); // Create existed topic request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL) .getTopicCreationRequestUrl("testTopic1", 16); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), "Failed to add new topic: testTopic1, it is already existed!"); // Delete topic request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic1"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic1"); }
Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(),
Request request = ControllerRequestURLBuilder.baseUrl(REQUEST_URL) .getTopicCreationRequestUrl("testTopic3", 8); Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "No topic is added in MirrorMaker Controller!"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Current serving topics: [testTopic0]"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); JSONObject jsonObject = JSON.parseObject(response.getEntityAsText()); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(),
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param entryUri * The entry URI. * @throws IOException */ public Entry(Client clientDispatcher, String entryUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, entryUri)) .getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param feedUri * The feed URI. * @throws IOException */ public Feed(Client clientDispatcher, String feedUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, feedUri)) .getEntity()); }
/** * Handles a call. * * @param request * The request to handle. * @param response * The response to update. */ @Override public void handle(Request request, Response response) { super.handle(request, response); getHelper().handle(request, response); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param feedUri * The feed URI. * @throws IOException */ public Feed(Client clientDispatcher, String feedUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, feedUri)) .getEntity()); }
/** * Handles a call. * * @param request * The request to handle. * @param response * The response to update. */ @Override public void handle(Request request, Response response) { super.handle(request, response); getHelper().handle(request, response); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param categoriesUri * The feed URI. * @throws IOException */ public Categories(Client clientDispatcher, String categoriesUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, categoriesUri)) .getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param entryUri * The entry URI. * @throws IOException */ public Entry(Client clientDispatcher, String entryUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, entryUri)) .getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param serviceUri * The service URI. * @throws IOException */ public Service(Client clientDispatcher, String serviceUri) throws IOException { this(clientDispatcher, serviceUri, clientDispatcher.handle( new Request(Method.GET, serviceUri)).getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param serviceUri * The service URI. * @throws IOException */ public Service(Client clientDispatcher, String serviceUri) throws IOException { this(clientDispatcher, serviceUri, clientDispatcher.handle( new Request(Method.GET, serviceUri)).getEntity()); }
/** * Constructor. * * @param clientDispatcher * The client HTTP dispatcher. * @param categoriesUri * The feed URI. * @throws IOException */ public Categories(Client clientDispatcher, String categoriesUri) throws IOException { this(clientDispatcher.handle(new Request(Method.GET, categoriesUri)) .getEntity()); }
@Test public void testHealthCheck() { Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).getHealthCheck(); Response response = HTTP_CLIENT.handle(request); String responseString = response.getEntityAsText(); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(responseString, "OK\n"); } }
@Test public void testGetControllerRebalance() { Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).getControllerRebalanceStatus(); Response response = HTTP_CLIENT.handle(request); String responseString = response.getEntityAsText(); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(responseString, "{}"); }
@Test public void testPostRebalance() { Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postInstanceRebalance(true); Response response = HTTP_CLIENT.handle(request); String responseString = response.getEntityAsText(); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(responseString, "{\"status\":200}"); request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postInstanceRebalance(false); response = HTTP_CLIENT.handle(request); responseString = response.getEntityAsText(); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_BAD_REQUEST); Assert.assertEquals(responseString, "{\"message\":\"invalid operation\",\"status\":400}"); }
@Test public void testPostControllerRebalance() { Request request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postSetControllerRebalance(true); Response response = HTTP_CLIENT.handle(request); String responseString = response.getEntityAsText(); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(responseString, "{\"execution\":{},\"managerAutoscaling\":true,\"status\":{}}"); request = ManagerRequestURLBuilder.baseUrl(REQUEST_URL).postSetControllerRebalance("sjc1a", "sjc1-agg1", true); response = HTTP_CLIENT.handle(request); responseString = response.getEntityAsText(); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(responseString, "{\"execution\":{},\"managerAutoscaling\":true,\"status\":{}}"); } @Test
public Response sendRequest( Method method, String url, Representation representation ) { this.logger.debug( "Method: " + method.getName() + " url: " + url ); Request request = new Request(); request.setResourceRef( url ); request.setMethod( method ); if ( !Method.GET.equals( method ) && !Method.DELETE.equals( method ) ) { request.setEntity( representation ); } request.setChallengeResponse( this.challenge ); return this.restClient.handle( request ); }
private Response request(Method method, Reference uri, Representation representation, MediaType accepts, boolean checkSuccess) throws NotSuccessException { Request request = makeRequest(uri, accepts); request.setMethod(method); if (representation != null) { request.setEntity(representation); } Client client = new Client(Protocol.HTTP); Response response = client.handle(request); if (checkSuccess && !response.getStatus().isSuccess()) { logger.warn("Not success: " + response.getStatus()); throw new NotSuccessException(response.getStatus()); } return response; }