@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"); }
.getTopicCreationRequestUrl("testTopic3", 8); Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic3, partition: 8}"); .getTopicExternalViewRequestUrl("testTopic3"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic3"); ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic4"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), "Failed to delete not existed topic: testTopic4"); .getTopicExternalViewRequestUrl("testTopic3"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND);
.getTopicCreationRequestUrl("testTopic2", 8); Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic2, partition: 8}"); .getTopicExpansionRequestUrl("testTopic2", 16); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully expand topic: {topic: testTopic2, partition: 16}"); .getTopicExpansionRequestUrl("testTopic22", 16); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(response.getEntityAsText(), "Failed to expand topic, topic: testTopic22 is not existed!"); ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic2"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic2");
.getTopicExternalViewRequestUrl(""); Response response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "No topic is added in MirrorMaker Controller!"); System.out.println(response.getEntityAsText()); .getTopicCreationRequestUrl("testTopic0", 8); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic0, partition: 8}"); .getTopicExternalViewRequestUrl(""); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Current serving topics: [testTopic0]"); System.out.println(response.getEntityAsText()); .getTopicExternalViewRequestUrl("testTopic0"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); JSONObject jsonObject = JSON.parseObject(response.getEntityAsText()); System.out.println(jsonObject); ControllerRequestURLBuilder.baseUrl(REQUEST_URL).getTopicDeleteRequestUrl("testTopic0"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic0");
/** * Indicates if the response is provisional or final. It relies on the {@link Status#isInformational()} method. * * @return True if the response is provisional. */ public boolean isProvisional() { return getStatus().isInformational(); }
/** * Returns the status. * * @return The status. */ @Override public Status getStatus() { return getWrappedResponse().getStatus(); }
/** * Indicates if the response is final or provisional. It relies on the {@link Status#isInformational()} method. * * @return True if the response is final. */ public boolean isFinal() { return !getStatus().isInformational(); }
/** * Returns the status. * * @return The status. * @see Response#getStatus() */ public Status getStatus() { return getResponse() == null ? null : getResponse().getStatus(); }
@Test(threadPoolSize = 10, invocationCount = 100, timeOut = 5000) public void makeCall() { Request request = new Request(Method.GET, "http://localhost:8111/"); Response response = component.handle(request); Assert.assertTrue(response.getStatus().isSuccess()); Assert.assertEquals("Welcome to the RESTful Mail Server application !", response.getEntityAsText()); }
@Override public Representation handleInbound(Response response) { Representation result = null; // Verify that the request was synchronous if (response.getRequest().isSynchronous()) { if (response.getStatus().isError()) { doError(response.getStatus()); // DO NOT DISPOSE THE RESPONSE. }/* else { */ result = (response == null) ? null : response.getEntity(); /* } */ } return result; }
/** * Displays a synthesis of the response like an HTTP status line. * * @return A synthesis of the response like an HTTP status line. */ public String toString() { return ((getRequest() == null) ? "?" : getRequest().getProtocol()) + " - " + getStatus(); } }
/** * Deletes a resource. * * @param uri * The resource URI. * @return The result status. */ public Status deleteResource(String uri) { return getClientDispatcher().handle(new Request(Method.DELETE, uri)) .getStatus(); }
/** * Deletes a resource. * * @param uri * The resource URI. * @return The result status. */ public Status deleteResource(String uri) { return getClientDispatcher().handle(new Request(Method.DELETE, uri)) .getStatus(); }
/** * Updates a resource representation. * * @param uri * The resource URI. * @return The resource representation. */ public Status updateResource(String uri, Representation updatedRepresentation) { return getClientDispatcher().handle( new Request(Method.PUT, uri, updatedRepresentation)) .getStatus(); }
/** * Updates a resource representation. * * @param uri * The resource URI. * @return The resource representation. */ public Status updateResource(String uri, Representation updatedRepresentation) { return getClientDispatcher().handle( new Request(Method.PUT, uri, updatedRepresentation)) .getStatus(); }
@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"); } }
@Override protected void afterHandle(Request request, Response response) { if (response.getStatus() != Status.REDIRECTION_NOT_MODIFIED) { if (UMLG.get().isTransactionActive()) { logger.log(Level.SEVERE, "Transaction is still active! Request = " + request.toString()); } UMLG.get().rollback(); UMLG.get().afterThreadContext(); } }
@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