public void testHead() throws Exception { startServer(Resource.class); WebResource r = Client.create().resource(getUri().path("/").build()); ClientResponse cr = r.path("string").accept("text/plain").head(); assertEquals(200, cr.getStatus()); assertEquals(MediaType.TEXT_PLAIN_TYPE, cr.getType()); assertFalse(cr.hasEntity()); cr = r.path("byte").accept("application/octet-stream").head(); assertEquals(200, cr.getStatus()); String length = cr.getMetadata().getFirst("Content-Length"); assertNotNull(length); assertEquals(3, Integer.parseInt(length)); assertEquals(MediaType.APPLICATION_OCTET_STREAM_TYPE, cr.getType()); assertFalse(cr.hasEntity()); cr = r.path("ByteArrayInputStream").accept("application/octet-stream").head(); assertEquals(200, cr.getStatus()); length = cr.getMetadata().getFirst("Content-Length"); assertNotNull(length); assertEquals(3, Integer.parseInt(length)); assertEquals(MediaType.APPLICATION_OCTET_STREAM_TYPE, cr.getType()); assertFalse(cr.hasEntity()); }
@Test public void testNodeAppsState() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); MockApp app2 = new MockApp("foo", 1234, 2); nmContext.getApplications().put(app2.getAppId(), app2); HashMap<String, String> hash2 = addAppContainers(app2); app2.setState(ApplicationState.RUNNING); ClientResponse response = r.path("ws") .path("v1") .path("node") .path("apps") .queryParam("state", ApplicationState.RUNNING.toString()) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); JSONObject info = json.getJSONObject("apps"); assertEquals("incorrect number of elements", 1, info.length()); JSONArray appInfo = info.getJSONArray("app"); assertEquals("incorrect number of elements", 1, appInfo.length()); verifyNodeAppInfo(appInfo.getJSONObject(0), app2, hash2); }
@Test public void testJobTaskCountersXML() throws Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws") .path("v1") .path("history") .path("mapreduce") .path("jobs") .path(jobId) .path("tasks") .path(tid) .path("counters") .accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList info = dom.getElementsByTagName("jobTaskCounters"); verifyHsTaskCountersXML(info, task); } } }
@Test public void testTaskIdCountersDefault() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); for (Task task : jobsMap.get(id).getTasks().values()) { String tid = MRApps.toString(task.getID()); ClientResponse response = r.path("ws") .path("v1") .path("history") .path("mapreduce") .path("jobs") .path(jobId) .path("tasks") .path(tid) .path("counters") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject info = json.getJSONObject("jobTaskCounters"); verifyHsJobTaskCounters(info, task); } } }
// verify the exception object default format is JSON @Test public void testNodeAppsStateInvalidDefault() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp("foo", 1234, 2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); try { r.path("ws") .path("v1") .path("node") .path("apps") .queryParam("state", "FOO_STATE") .get(JSONObject.class); fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); verifyStateInvalidException(message, type, classname); } }
@Test public void testNodeSingleAppsXML() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); HashMap<String, String> hash = addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); ClientResponse response = r.path("ws") .path("v1") .path("node") .path("apps") .path(app.getAppId().toString() + "/") .accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("app"); assertEquals("incorrect number of elements", 1, nodes.getLength()); verifyNodeAppInfoXML(nodes, app, hash); }
@Test public void testTasksQueryReduce() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); String type = "r"; ClientResponse response = r.path("ws") .path("v1") .path("history") .path("mapreduce") .path("jobs") .path(jobId) .path("tasks") .queryParam("type", type) .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("incorrect number of elements", 1, json.length()); JSONObject tasks = json.getJSONObject("tasks"); JSONArray arr = tasks.getJSONArray("task"); assertEquals("incorrect number of elements", 1, arr.length()); verifyHsTask(arr, jobsMap.get(id), type); } }
@Test public void testTasksXML() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); ClientResponse response = r.path("ws") .path("v1") .path("history") .path("mapreduce") .path("jobs") .path(jobId) .path("tasks") .accept(MediaType.APPLICATION_XML) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList tasks = dom.getElementsByTagName("tasks"); assertEquals("incorrect number of elements", 1, tasks.getLength()); NodeList task = dom.getElementsByTagName("task"); verifyHsTaskXML(task, jobsMap.get(id)); } }
@Test( groups = {"wso2.esb"}, description = "Tests with filter mediator - JSON path Scenario - Filter condition true", enabled = false) public void testJSONFilterFromJSONPathConditionTrueTestScenario() throws Exception { String JSON_PAYLOAD = "{\"album\":\"Hello\",\"singer\":\"Peter\"}"; WebResource webResource = client.resource(getProxyServiceURLHttp("JSONPathFilterWithJSONProxy")); // sending post request ClientResponse postResponse = webResource.type("application/json").post(ClientResponse.class, JSON_PAYLOAD); assertEquals( postResponse.getType().toString(), "application/json", "Content-Type Should be application/json"); assertEquals(postResponse.getStatus(), 201, "Response status should be 201"); // Calling the GET request to verify Added album details ClientResponse getResponse = webResource.type("application/json").get(ClientResponse.class); assertNotNull(getResponse, "Received Null response for while getting Music album details"); assertEquals( getResponse.getEntity(String.class), JSON_PAYLOAD, "Response mismatch for HTTP Get call"); }
public void testNodeHelper(String path, String media) throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); HashMap<String, String> hash = addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); HashMap<String, String> hash2 = addAppContainers(app2); ClientResponse response = r.path("ws").path("v1").path("node").path(path).accept(media).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); JSONObject info = json.getJSONObject("apps"); assertEquals("incorrect number of elements", 1, info.length()); JSONArray appInfo = info.getJSONArray("app"); assertEquals("incorrect number of elements", 2, appInfo.length()); String id = appInfo.getJSONObject(0).getString("id"); if (id.matches(app.getAppId().toString())) { verifyNodeAppInfo(appInfo.getJSONObject(0), app, hash); verifyNodeAppInfo(appInfo.getJSONObject(1), app2, hash2); } else { verifyNodeAppInfo(appInfo.getJSONObject(0), app2, hash2); verifyNodeAppInfo(appInfo.getJSONObject(1), app, hash); } }
protected T get(URI uri) { ClientResponse response = ClientUtil.readEntity( uri, getHttpClient(), getResourceRepresentationType(), ClientResponse.class); if (logger.isDebugEnabled()) { logger.debug("Request Accept header: " + getResourceRepresentationType()); logger.debug("Response header: " + response.getType()); } final int status = response.getStatus(); if (followRedirectionEnabled && status == ClientResponse.Status.MOVED_PERMANENTLY.getStatusCode()) { final URI location = response.getLocation(); if (location != null) { this.thisResourceUri = location; this.absoluteThisResourceUri = generateAbsoluteUri(); return get(); } } if (followRedirectionEnabled && (status == ClientResponse.Status.FOUND.getStatusCode() || status == ClientResponse.Status.SEE_OTHER.getStatusCode())) { final URI location = response.getLocation(); if (location != null) { URI absolutionLocation = getHttpClient().getAbsoluteUri(location, getReferrerUri()); return get(absolutionLocation); } } if (status < 300 || (status == ClientResponse.Status.NOT_MODIFIED.getStatusCode())) { if (response.hasEntity() && response.getStatus() != ClientResponse.Status.NO_CONTENT.getStatusCode()) { lastReadStateOfEntity = response.getEntity(getEntityClass()); if (getClientUtil() != null) { try { getClientUtil().parseLinks(lastReadStateOfEntity, getRelatedResourceUris()); } catch (Exception ex) { logger.warn(ex.getMessage(), ex); } } if (invokeGet) { invokeGETOnNestedResources(); } } else { lastReadStateOfEntity = null; } getInvocationCount++; Map<String, Object> headers = new HashMap<String, Object>(); EntityTag tag = response.getEntityTag(); if (tag != null) { headers.put(HttpHeaders.ETAG, tag); } Date date = response.getLastModified(); if (date != null) { headers.put(HttpHeaders.LAST_MODIFIED, date); } cachedHeaders.put(uri.toString(), headers); return lastReadStateOfEntity; } throw new UniformInterfaceException(response); }
@Test public void testGetProblemFile() throws URISyntaxException { WebResource resource = resource(); ClientResponse response = resource.path("testClientId").path("target").path("problem").get(ClientResponse.class); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); assertEquals(MediaType.valueOf(MediaType.TEXT_PLAIN), response.getType()); }
@Test public void testClusterSchedulerFifoDefault() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws").path("v1").path("cluster").path("scheduler").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterSchedulerFifo(json); }
@Test public void testClusterDefault() throws JSONException, Exception { WebResource r = resource(); // test with trailing "/" to make sure acts same as without slash ClientResponse response = r.path("ws").path("v1").path("cluster").get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterInfo(json); }
@Test public void testNodeAppsNone() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws") .path("v1") .path("node") .path("apps") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("apps isn't NULL", JSONObject.NULL, json.get("apps")); }
@Test public void testClusterMetricsXML() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws") .path("v1") .path("cluster") .path("metrics") .accept("application/xml") .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String xml = response.getEntity(String.class); verifyClusterMetricsXML(xml); }
@Test public void testClusterMetricsSlash() throws JSONException, Exception { WebResource r = resource(); ClientResponse response = r.path("ws") .path("v1") .path("cluster") .path("metrics/") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyClusterMetricsJSON(json); }
public void testNodeSingleAppHelper(String media) throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); HashMap<String, String> hash = addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); ClientResponse response = r.path("ws") .path("v1") .path("node") .path("apps") .path(app.getAppId().toString()) .accept(media) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); verifyNodeAppInfo(json.getJSONObject("app"), app, hash); }
@Test public void testTasksQueryInvalid() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); // tasktype must be exactly either "m" or "r" String tasktype = "reduce"; try { r.path("ws") .path("v1") .path("history") .path("mapreduce") .path("jobs") .path(jobId) .path("tasks") .queryParam("type", tasktype) .accept(MediaType.APPLICATION_JSON) .get(JSONObject.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch( "exception message", "java.lang.Exception: tasktype must be either m or r", message); WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type); WebServicesTestUtils.checkStringMatch( "exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname); } } }
// test that the exception output also returns XML @Test public void testNodeAppsStateInvalidXML() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp("foo", 1234, 2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); try { r.path("ws") .path("v1") .path("node") .path("apps") .queryParam("state", "FOO_STATE") .accept(MediaType.APPLICATION_XML) .get(JSONObject.class); fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType()); String msg = response.getEntity(String.class); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(msg)); Document dom = db.parse(is); NodeList nodes = dom.getElementsByTagName("RemoteException"); Element element = (Element) nodes.item(0); String message = WebServicesTestUtils.getXmlString(element, "message"); String type = WebServicesTestUtils.getXmlString(element, "exception"); String classname = WebServicesTestUtils.getXmlString(element, "javaClassName"); verifyStateInvalidException(message, type, classname); } }
@Test public void testTaskIdInvalid() throws JSONException, Exception { WebResource r = resource(); Map<JobId, Job> jobsMap = appContext.getAllJobs(); for (JobId id : jobsMap.keySet()) { String jobId = MRApps.toString(id); String tid = "task_0_0000_d_000000"; try { r.path("ws") .path("v1") .path("history") .path("mapreduce") .path("jobs") .path(jobId) .path("tasks") .path(tid) .get(JSONObject.class); fail("should have thrown exception on invalid uri"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.NOT_FOUND, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch( "exception message", "java.lang.Exception: Bad TaskType identifier. TaskId string : " + "task_0_0000_d_000000 is not properly formed.", message); WebServicesTestUtils.checkStringMatch("exception type", "NotFoundException", type); WebServicesTestUtils.checkStringMatch( "exception classname", "org.apache.hadoop.yarn.webapp.NotFoundException", classname); } } }
@Test public void testNodeAppsUserEmpty() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp("foo", 1234, 2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); try { r.path("ws") .path("v1") .path("node") .path("apps") .queryParam("user", "") .accept(MediaType.APPLICATION_JSON) .get(JSONObject.class); fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch( "exception message", "java.lang.Exception: Error: You must specify a non-empty string for the user", message); WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type); WebServicesTestUtils.checkStringMatch( "exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname); } }
@Test public void testNodeAppsUserNone() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp("foo", 1234, 2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); ClientResponse response = r.path("ws") .path("v1") .path("node") .path("apps") .queryParam("user", "george") .accept(MediaType.APPLICATION_JSON) .get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); assertEquals("apps is not null", JSONObject.NULL, json.get("apps")); }
@Test public void testNodeSingleAppsMissing() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); try { r.path("ws") .path("v1") .path("node") .path("apps") .path("application_1234_0009") .accept(MediaType.APPLICATION_JSON) .get(JSONObject.class); fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.NOT_FOUND, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch( "exception message", "java.lang.Exception: app with id application_1234_0009 not found", message); WebServicesTestUtils.checkStringMatch("exception type", "NotFoundException", type); WebServicesTestUtils.checkStringMatch( "exception classname", "org.apache.hadoop.yarn.webapp.NotFoundException", classname); } }
@Test public void testNodeSingleAppsInvalid() throws JSONException, Exception { WebResource r = resource(); Application app = new MockApp(1); nmContext.getApplications().put(app.getAppId(), app); addAppContainers(app); Application app2 = new MockApp(2); nmContext.getApplications().put(app2.getAppId(), app2); addAppContainers(app2); try { r.path("ws") .path("v1") .path("node") .path("apps") .path("app_foo_0000") .accept(MediaType.APPLICATION_JSON) .get(JSONObject.class); fail("should have thrown exception on invalid user query"); } catch (UniformInterfaceException ue) { ClientResponse response = ue.getResponse(); assertEquals(Status.BAD_REQUEST, response.getClientResponseStatus()); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject msg = response.getEntity(JSONObject.class); JSONObject exception = msg.getJSONObject("RemoteException"); assertEquals("incorrect number of elements", 3, exception.length()); String message = exception.getString("message"); String type = exception.getString("exception"); String classname = exception.getString("javaClassName"); WebServicesTestUtils.checkStringMatch( "exception message", "For input string: \"foo\"", message); WebServicesTestUtils.checkStringMatch("exception type", "NumberFormatException", type); WebServicesTestUtils.checkStringMatch( "exception classname", "java.lang.NumberFormatException", classname); } }
/** * Verify the web service deployment and lifecycle functionality * * @throws Exception */ @Ignore // disabled due to web service init delay issue @Test public void testWebService() throws Exception { // single container topology of inline input and module Properties props = new Properties(); props.put( StreamingApplication.DT_PREFIX + "stream.input.classname", TestGeneratorInputOperator.class.getName()); props.put(StreamingApplication.DT_PREFIX + "stream.input.outputNode", "module1"); props.put( StreamingApplication.DT_PREFIX + "module.module1.classname", GenericTestOperator.class.getName()); LOG.info("Initializing Client"); LogicalPlanConfiguration tb = new LogicalPlanConfiguration(new Configuration(false)); tb.addFromProperties(props, null); StramClient client = new StramClient(new Configuration(yarnCluster.getConfig()), createDAG(tb)); if (StringUtils.isBlank(System.getenv("JAVA_HOME"))) { client.javaCmd = "java"; // JAVA_HOME not set in the yarn mini cluster } try { client.start(); client.startApplication(); // attempt web service connection ApplicationReport appReport = client.getApplicationReport(); Thread.sleep(5000); // delay to give web service time to fully initialize Client wsClient = Client.create(); wsClient.setFollowRedirects(true); WebResource r = wsClient .resource("http://" + appReport.getTrackingUrl()) .path(StramWebServices.PATH) .path(StramWebServices.PATH_INFO); LOG.info("Requesting: " + r.getURI()); ClientResponse response = r.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); JSONObject json = response.getEntity(JSONObject.class); LOG.info("Got response: " + json.toString()); assertEquals("incorrect number of elements", 1, json.length()); assertEquals("appId", appReport.getApplicationId().toString(), json.get("id")); r = wsClient .resource("http://" + appReport.getTrackingUrl()) .path(StramWebServices.PATH) .path(StramWebServices.PATH_PHYSICAL_PLAN_OPERATORS); LOG.info("Requesting: " + r.getURI()); response = r.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class); assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType()); json = response.getEntity(JSONObject.class); LOG.info("Got response: " + json.toString()); } finally { // LOG.info("waiting..."); // synchronized (this) { // this.wait(); // } // boolean result = client.monitorApplication(); client.killApplication(); client.stop(); } }