Java 类com.sun.jersey.api.client.WebResource 实例源码

项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStateNone() throws JSONException, Exception {
  WebResource r = resource();

   ArrayList<JobState> JOB_STATES = 
       new ArrayList<JobState>(Arrays.asList(JobState.values()));

    // find a state that isn't in use
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    for (Map.Entry<JobId, Job> entry : jobsMap.entrySet()) {
      JOB_STATES.remove(entry.getValue().getState());
    }

  assertTrue("No unused job states", JOB_STATES.size() > 0);
  JobState notInUse = JOB_STATES.get(0);

  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs").queryParam("state", notInUse.toString())
      .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());
  assertEquals("jobs is not null", JSONObject.NULL, json.get("jobs"));
}
项目:hadoop    文件:TestAMWebServicesTasks.java   
@Test
public void testTaskIdSlash() 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("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid + "/")
          .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 info = json.getJSONObject("task");
      verifyAMSingleTask(info, task);
    }
  }
}
项目:https-github.com-apache-zookeeper    文件:RootTest.java   
@Test
public void testCreate() throws Exception {
    String path = "/";
    String name = "roottest-create";
    byte[] data = "foo".getBytes();

    WebResource wr = znodesr.path(path).queryParam("dataformat", "utf8")
        .queryParam("name", name);
    Builder builder = wr.accept(MediaType.APPLICATION_JSON);

    ClientResponse cr;
    cr = builder.post(ClientResponse.class, data);
    Assert.assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());

    ZPath zpath = cr.getEntity(ZPath.class);
    Assert.assertEquals(new ZPath(path + name), zpath);
    Assert.assertEquals(znodesr.path(path).toString(), zpath.uri);

    // use out-of-band method to verify
    byte[] rdata = zk.getData(zpath.path, false, new Stat());
    Assert.assertTrue(new String(rdata) + " == " + new String(data),
            Arrays.equals(rdata, data));
}
项目:hadoop    文件:TestTimelineWebServices.java   
@Test
public void testFromTs() throws Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .path("type_1").queryParam("fromTs", Long.toString(beforeTime))
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(0, response.getEntity(TimelineEntities.class).getEntities()
      .size());

  response = r.path("ws").path("v1").path("timeline")
      .path("type_1").queryParam("fromTs", Long.toString(
          System.currentTimeMillis()))
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(3, response.getEntity(TimelineEntities.class).getEntities()
      .size());
}
项目:fuck_zookeeper    文件:SessionTest.java   
@Test
public void testSendHeartbeat() throws InterruptedException {
    ZSession session = createSession("2");

    Thread.sleep(1000);
    WebResource wr = sessionsr.path(session.id);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);

    ClientResponse cr = b.put(ClientResponse.class, null);
    assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus());

    Thread.sleep(1500);
    assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));

    Thread.sleep(1000);
    assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
项目:ZooKeeper    文件:RootTest.java   
@Test
public void testCreate() throws Exception {
    LOG.info("STARTING " + getName());

    String path = "/";
    String name = "roottest-create";
    byte[] data = "foo".getBytes();

    WebResource wr = znodesr.path(path).queryParam("dataformat", "utf8")
        .queryParam("name", name);
    Builder builder = wr.accept(MediaType.APPLICATION_JSON);

    ClientResponse cr;
    cr = builder.post(ClientResponse.class, data);
    assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());

    ZPath zpath = cr.getEntity(ZPath.class);
    assertEquals(new ZPath(path + name), zpath);
    assertEquals(znodesr.path(path).toString(), zpath.uri);

    // use out-of-band method to verify
    byte[] rdata = zk.getData(zpath.path, false, new Stat());
    assertTrue(new String(rdata) + " == " + new String(data),
            Arrays.equals(rdata, data));
}
项目:hadoop    文件:TestNMWebServicesApps.java   
@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);

}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testInvalidAttempt() {
  ApplicationId appId = ApplicationId.newInstance(0, 1);
  ApplicationAttemptId appAttemptId =
      ApplicationAttemptId.newInstance(appId, MAX_APPS + 1);
  WebResource r = resource();
  ClientResponse response =
      r.path("ws").path("v1").path("applicationhistory").path("apps")
        .path(appId.toString()).path("appattempts")
        .path(appAttemptId.toString())
        .queryParam("user.name", USERS[round])
        .accept(MediaType.APPLICATION_JSON)
        .get(ClientResponse.class);
  if (round == 1) {
    assertEquals(Status.FORBIDDEN, response.getClientResponseStatus());
    return;
  }
  assertEquals("404 not found expected", Status.NOT_FOUND,
          response.getClientResponseStatus());
}
项目:hadoop    文件:TestAMWebServicesTasks.java   
@Test
public void testTaskIdCounters() 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("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("counters")
          .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 info = json.getJSONObject("jobTaskCounters");
      verifyAMJobTaskCounters(info, task);
    }
  }
}
项目:hadoop    文件:TestRMWebServicesNodes.java   
@Test
public void testNonexistNodeDefault() throws JSONException, Exception {
  rm.registerNode("h1:1234", 5120);
  rm.registerNode("h2:1235", 5121);
  WebResource r = resource();
  try {
    r.path("ws").path("v1").path("cluster").path("nodes")
        .path("node_invalid:99").get(JSONObject.class);

    fail("should have thrown exception on non-existent nodeid");
  } 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");
    verifyNonexistNodeException(message, type, classname);
  } finally {
    rm.stop();
  }
}
项目:hadoop    文件:TestAMWebServicesTasks.java   
@Test
public void testTasksQueryMap() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    String type = "m";
    ClientResponse response = r.path("ws").path("v1").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());
    verifyAMTask(arr, jobsMap.get(id), type);
  }
}
项目:hadoop    文件:TimelineClientImpl.java   
@Private
@VisibleForTesting
public ClientResponse doPostingObject(Object object, String path) {
  WebResource webResource = client.resource(resURI);
  if (path == null) {
    return webResource.accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, object);
  } else if (path.equals("domain")) {
    return webResource.path(path).accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .put(ClientResponse.class, object);
  } else {
    throw new YarnRuntimeException("Unknown resource type");
  }
}
项目:hadoop    文件:TestHsWebServicesTasks.java   
@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));
  }
}
项目:hadoop    文件:TestHsWebServicesJobs.java   
@Test
public void testJobAttemptsSlash() 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("jobattempts/")
        .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 info = json.getJSONObject("jobAttempts");
    verifyHsJobAttempts(info, appContext.getJob(id));
  }
}
项目:hadoop    文件:TestHsWebServicesJobConf.java   
@Test
public void testJobConf() 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("conf")
        .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 info = json.getJSONObject("conf");
    verifyHsJobConf(info, jobsMap.get(id));
  }
}
项目:hadoop    文件:TestTimelineWebServices.java   
@Test
public void testFromId() throws Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("timeline")
      .path("type_1").queryParam("fromId", "id_2")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(2, response.getEntity(TimelineEntities.class).getEntities()
      .size());

  response = r.path("ws").path("v1").path("timeline")
      .path("type_1").queryParam("fromId", "id_1")
      .accept(MediaType.APPLICATION_JSON)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
  assertEquals(3, response.getEntity(TimelineEntities.class).getEntities()
      .size());
}
项目:hadoop    文件:TestHsWebServicesTasks.java   
@Test
public void testTasksSlash() 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_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", 2, arr.length());

    verifyHsTask(arr, jobsMap.get(id), null);
  }
}
项目:hadoop    文件:TestRMWebServicesNodes.java   
@Test
public void testNodesQueryHealthyFalse() throws JSONException, Exception {
  WebResource r = resource();
  MockNM nm1 = rm.registerNode("h1:1234", 5120);
  MockNM nm2 = rm.registerNode("h2:1235", 5121);
  rm.sendNodeStarted(nm1);
  rm.NMwaitForState(nm1.getNodeId(), NodeState.RUNNING);
  rm.NMwaitForState(nm2.getNodeId(), NodeState.NEW);
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("nodes").queryParam("states", "UNHEALTHY")
      .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());
  assertEquals("nodes is not null", JSONObject.NULL, json.get("nodes"));
}
项目:hadoop    文件:TestAMWebServicesJobs.java   
@Test
public void testJobAttemptsXML() throws 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("mapreduce").path("jobs").path(jobId).path("jobattempts")
        .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 attempts = dom.getElementsByTagName("jobAttempts");
    assertEquals("incorrect number of elements", 1, attempts.getLength());
    NodeList info = dom.getElementsByTagName("jobAttempt");
    verifyJobAttemptsXML(info, jobsMap.get(id));
  }
}
项目:fuck_zookeeper    文件:SessionTest.java   
@Test
public void testCreateEphemeralZNode() 
throws KeeperException, InterruptedException, IOException {
    ZSession session = createSession("30");

    WebResource wr = znodesr.path("/")
        .queryParam("op", "create")
        .queryParam("name", "ephemeral-test")
        .queryParam("ephemeral", "true")
        .queryParam("session", session.id)
        .queryParam("null", "true");

    Builder b = wr.accept(MediaType.APPLICATION_JSON);
    ClientResponse cr = b.post(ClientResponse.class);
    assertEquals(ClientResponse.Status.CREATED, cr.getClientResponseStatus());

    Stat stat = new Stat();
    zk.getData("/ephemeral-test", false, stat);

    ZooKeeper sessionZK = ZooKeeperService.getClient(CONTEXT_PATH, session.id);
    assertEquals(stat.getEphemeralOwner(), sessionZK.getSessionId());
}
项目:hadoop    文件:TestAHSWebServices.java   
@Test
public void testInvalidUri() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr =
        r.path("ws").path("v1").path("applicationhistory").path("bogus")
          .queryParam("user.name", USERS[round])
          .accept(MediaType.APPLICATION_JSON).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());

    WebServicesTestUtils.checkStringMatch(
      "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestNMWebServices.java   
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("node")
        .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
        response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestAMWebServicesJobs.java   
@Test
public void testJobAttemptsDefault() 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("mapreduce").path("jobs").path(jobId).path("jobattempts")
        .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("jobAttempts");
    verifyJobAttempts(info, jobsMap.get(id));
  }
}
项目:hadoop    文件:TestHsWebServicesTasks.java   
@Test
public void testTasksDefault() 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")
        .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", 2, arr.length());

    verifyHsTask(arr, jobsMap.get(id), null);
  }
}
项目:hadoop    文件:TestHsWebServices.java   
@Test
public void testInvalidAccept() throws JSONException, Exception {
  WebResource r = resource();
  String responseStr = "";
  try {
    responseStr = r.path("ws").path("v1").path("history")
        .accept(MediaType.TEXT_PLAIN).get(String.class);
    fail("should have thrown exception on invalid uri");
  } catch (UniformInterfaceException ue) {
    ClientResponse response = ue.getResponse();
    assertEquals(Status.INTERNAL_SERVER_ERROR,
        response.getClientResponseStatus());
    WebServicesTestUtils.checkStringMatch(
        "error string exists and shouldn't", "", responseStr);
  }
}
项目:hadoop    文件:TestHsWebServicesTasks.java   
@Test
public void testTaskIdSlash() 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 + "/").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 info = json.getJSONObject("task");
      verifyHsSingleTask(info, task);
    }
  }
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryStartTimeNegative() throws JSONException, Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("startedTimeBegin", String.valueOf(-1000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  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: startedTimeBegin must be greater than 0",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:hadoop    文件:TestAMWebServicesAttempts.java   
@Test
public void testTaskAttempts() 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("mapreduce")
          .path("jobs").path(jobId).path("tasks").path(tid).path("attempts")
          .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
      assertEquals(MediaType.APPLICATION_JSON_TYPE, response.getType());
      JSONObject json = response.getEntity(JSONObject.class);
      verifyAMTaskAttempts(json, task);
    }
  }
}
项目:hadoop    文件:TestHsWebServicesTasks.java   
@Test
public void testTaskIdDefault() 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)
          .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("task");
      verifyHsSingleTask(info, task);
    }
  }
}
项目:hadoop    文件:TestRMWebServicesApps.java   
@Test
public void testAppsQueryStatesNone() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("apps")
      .queryParam("states", YarnApplicationState.RUNNING.toString())
      .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());
  assertEquals("apps is not null", JSONObject.NULL, json.get("apps"));
  rm.stop();
}
项目:hadoop    文件:TestHsWebServicesTasks.java   
@Test
public void testTasksQueryMap() throws JSONException, Exception {
  WebResource r = resource();
  Map<JobId, Job> jobsMap = appContext.getAllJobs();
  for (JobId id : jobsMap.keySet()) {
    String jobId = MRApps.toString(id);
    String type = "m";
    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);
  }
}
项目:hadoop    文件:TestNMWebServicesApps.java   
@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);
  }
}
项目:hadoop    文件:TestRMWebServicesCapacitySched.java   
@Test
public void testClusterSchedulerDefault() 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);
  verifyClusterScheduler(json);
}
项目:hadoop    文件:TestRMWebServices.java   
@Test
public void testClusterSchedulerFifoXML() throws JSONException, Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("cluster")
      .path("scheduler").accept(MediaType.APPLICATION_XML)
      .get(ClientResponse.class);

  assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
  String xml = response.getEntity(String.class);
  verifySchedulerFifoXML(xml);
}
项目:hadoop    文件:TestRMWebServices.java   
@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);
}
项目:hadoop    文件:TestRMWebServicesApps.java   
@Test
public void testAppsQueryFinalStatusInvalid() throws JSONException, Exception {
  rm.start();
  MockNM amNodeManager = rm.registerNode("127.0.0.1:1234", 2048);
  rm.submitApp(CONTAINER_MB);
  amNodeManager.nodeHeartbeat(true);
  WebResource r = resource();

  try {
    r.path("ws").path("v1").path("cluster").path("apps")
        .queryParam("finalStatus", "INVALID_test")
        .accept(MediaType.APPLICATION_JSON).get(JSONObject.class);
    fail("should have thrown exception on invalid state 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
        .checkStringContains(
            "exception message",
            "org.apache.hadoop.yarn.api.records.FinalApplicationStatus.INVALID_test",
            message);
    WebServicesTestUtils.checkStringMatch("exception type",
        "IllegalArgumentException", type);
    WebServicesTestUtils.checkStringMatch("exception classname",
        "java.lang.IllegalArgumentException", classname);

  } finally {
    rm.stop();
  }
}
项目:hadoop    文件:TestHsWebServicesJobsQuery.java   
@Test
public void testJobsQueryFinishTimeBeginEndInvalid() throws JSONException,
    Exception {
  WebResource r = resource();
  Long now = System.currentTimeMillis();
  ClientResponse response = r.path("ws").path("v1").path("history")
      .path("mapreduce").path("jobs")
      .queryParam("finishedTimeBegin", String.valueOf(now))
      .queryParam("finishedTimeEnd", String.valueOf(40000))
      .accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
  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: finishedTimeEnd must be greater than finishedTimeBegin",
          message);
  WebServicesTestUtils.checkStringMatch("exception type",
      "BadRequestException", type);
  WebServicesTestUtils.checkStringMatch("exception classname",
      "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
项目:fuck_zookeeper    文件:SessionTest.java   
@Test
public void testDeleteSession() {
    ZSession session = createSession("30");

    WebResource wr = sessionsr.path(session.id);
    Builder b = wr.accept(MediaType.APPLICATION_JSON);

    assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
    ClientResponse cr = b.delete(ClientResponse.class, null);
    assertEquals(ClientResponse.Status.NO_CONTENT, 
            cr.getClientResponseStatus());

    assertFalse(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
}
项目:hadoop    文件:TestAMWebServices.java   
@Test
public void testBlacklistedNodesXML() throws Exception {
  WebResource r = resource();
  ClientResponse response = r.path("ws").path("v1").path("mapreduce")
      .path("blacklistednodes").accept(MediaType.APPLICATION_XML)
      .get(ClientResponse.class);
  assertEquals(MediaType.APPLICATION_XML_TYPE, response.getType());
  String xml = response.getEntity(String.class);
  verifyBlacklistedNodesInfoXML(xml, appContext);
}
项目:hadoop    文件:TestAMWebServicesAttempts.java   
private void testTaskAttemptIdErrorGeneric(String attid, String error)
    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());

      try {
        r.path("ws").path("v1").path("mapreduce").path("jobs").path(jobId)
            .path("tasks").path(tid).path("attempts").path(attid)
            .accept(MediaType.APPLICATION_JSON).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", error,
            message);
        WebServicesTestUtils.checkStringMatch("exception type",
            "NotFoundException", type);
        WebServicesTestUtils.checkStringMatch("exception classname",
            "org.apache.hadoop.yarn.webapp.NotFoundException", classname);
      }
    }
  }
}