@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(), "Successfully add new topic: {topic: testTopic2, partition: 8}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic2")); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully expand topic: {topic: testTopic2, partition: 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!"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic2");
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()); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic0, partition: 8}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic0")); 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()); try { Thread.sleep(4000); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); JSONObject jsonObject = JSON.parseObject(response.getEntityAsText()); System.out.println(jsonObject); Assert.assertEquals(jsonObject.getJSONObject("serverToNumPartitionsMapping").size(), 4); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic0");
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}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic3")); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic3"); 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");
@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()); }
protected void throwServiceException(ClientResource service, Exception e) throws ServiceException { if (e instanceof ResourceException) { log.error("Unexpected HTTP status code returned: {}", service.getStatus().getCode()); throwServiceException(service.getResponse().getEntityAsText()); } else { log.error("Unexpected Exception", e); throw new ServiceException(e); } } }
@Override public Object readResponse( Response response, Class<?> resultType ) throws ResourceException { if( MediaType.APPLICATION_JSON.equals( response.getEntity().getMediaType() ) ) { if( resultType.equals( String.class ) || Number.class.isAssignableFrom( resultType ) ) { try { return jsonDeserializer.deserialize( module, resultType, response.getEntityAsText() ); } catch( Exception e ) { throw new ResourceException( e ); } } } return null; } }
@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
@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(), "Successfully add new topic: {topic: testTopic2, partition: 8}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic2")); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully expand topic: {topic: testTopic2, partition: 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!"); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic2");
JSONObject json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!"); .getTopicCreationRequestUrl("testTopic0", "cluster2", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Failed to whitelist topic testTopic0 on uReplicator because of not valid pipeline from cluster2 to cluster3"); .getTopicCreationRequestUrl("testTopic1", "cluster1", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Failed to whitelist new topic: testTopic1, it's not existed in source Kafka cluster!"); .getTopicCreationRequestUrl("testTopic0", "cluster1", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Failed to add new topic: testTopic0 from: cluster1 to: cluster3, it is already existed!"); .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Successfully delete topic: testTopic0 from cluster1 to cluster3");
JSONObject json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!"); .getTopicDeleteRequestUrl("testTopic0", "cluster2", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Failed to delete not existed topic: testTopic0 in pipeline: @cluster2@cluster3"); .getTopicDeleteRequestUrl("testTopic1", "cluster1", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Failed to delete not existed topic: testTopic1 in pipeline: @cluster1@cluster3"); .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Successfully delete topic: testTopic0 from cluster1 to cluster3"); .getTopicDeleteRequestUrl("@cluster2@cluster3", "cluster2", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Failed to delete not existed pipeline: @cluster2@cluster3"); .getTopicDeleteRequestUrl("@cluster1@cluster3", "cluster1", "cluster3");
JSONObject json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!"); .getTopicExpansionRequestUrl("testTopic0", "cluster1", "cluster3", 1); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Failed to expand the topic testTopic0 in pipeline @cluster1@cluster3 to 1 partitions due to exception: java.lang.Exception: New partition 1 is not bigger than current partition 1 of topic testTopic0, abandon expanding topic!"); .getTopicExpansionRequestUrl("testTopic0", "cluster2", "cluster3", 2); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Topic testTopic0 doesn't exist in pipeline @cluster2@cluster3, abandon expanding topic!"); .getTopicExpansionRequestUrl("testTopic1", "cluster1", "cluster3", 2); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Topic testTopic1 doesn't exist in pipeline @cluster1@cluster3, abandon expanding topic!"); .getTopicExpansionRequestUrl("testTopic0", "cluster1", "cluster3", 2); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Successfully expand the topic testTopic0 in pipeline @cluster1@cluster3 to 2 partitions"); .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3");
JSONObject json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "No topic is added in uReplicator!"); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getJSONObject("message").getString("topics"), "[\"testTopic0\"]"); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getJSONObject("message").getJSONObject("managerView").getString("topic"), "testTopic0"); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Failed to find topic: testTopic1"); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getJSONObject("message").getString("topic"), "@cluster1@cluster3"); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.CLIENT_ERROR_NOT_FOUND); Assert.assertEquals(json.getString("message"), "Failed to get view for route: @cluster1@cluster4, it is not existed!"); .getTopicDeleteRequestUrl("testTopic0", "cluster1", "cluster3"); response = HTTP_CLIENT.handle(request); json = JSONObject.parseObject(response.getEntityAsText()); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(json.getString("message"), "Successfully delete topic: testTopic0 from cluster1 to cluster3");
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()); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully add new topic: {topic: testTopic0, partition: 8}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic0")); 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()); try { Thread.sleep(4000); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); JSONObject jsonObject = JSON.parseObject(response.getEntityAsText()); System.out.println(jsonObject); Assert.assertEquals(jsonObject.getJSONObject("serverToNumPartitionsMapping").size(), 4); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic0");
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}"); Assert.assertTrue(ZK_CLIENT.exists("/" + HELIX_CLUSTER_NAME + "/CONFIGS/RESOURCE/testTopic3")); response = HTTP_CLIENT.handle(request); Assert.assertEquals(response.getStatus(), Status.SUCCESS_OK); Assert.assertEquals(response.getEntityAsText(), "Successfully finished delete topic: testTopic3"); 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");
String jsonValue = response.getEntityAsText(); ValueCompositeType valueType = module.valueDescriptor( resultType.getName() ).valueType(); return jsonDeserializer.deserialize( module, valueType, jsonValue );