当前位置: 首页>>代码示例>>Java>>正文


Java WebResource类代码示例

本文整理汇总了Java中com.sun.jersey.api.client.WebResource的典型用法代码示例。如果您正苦于以下问题:Java WebResource类的具体用法?Java WebResource怎么用?Java WebResource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


WebResource类属于com.sun.jersey.api.client包,在下文中一共展示了WebResource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSendHeartbeat

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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));
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:18,代码来源:SessionTest.java

示例2: testJobsQueryStateNone

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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"));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestHsWebServicesJobsQuery.java

示例3: testCreate

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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));
}
 
开发者ID:l294265421,项目名称:ZooKeeper,代码行数:26,代码来源:RootTest.java

示例4: testNodeAppsState

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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);

}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestNMWebServicesApps.java

示例5: testInvalidAttempt

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestAHSWebServices.java

示例6: testTaskIdCounters

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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);
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestAMWebServicesTasks.java

示例7: testNonexistNodeDefault

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:26,代码来源:TestRMWebServicesNodes.java

示例8: testTasksQueryMap

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestAMWebServicesTasks.java

示例9: testTaskIdSlash

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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);
    }
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:21,代码来源:TestAMWebServicesTasks.java

示例10: doPostingObject

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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");
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:17,代码来源:TimelineClientImpl.java

示例11: testTasksXML

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:TestHsWebServicesTasks.java

示例12: testJobAttemptsSlash

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:TestHsWebServicesJobs.java

示例13: testJobConf

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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));
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:19,代码来源:TestHsWebServicesJobConf.java

示例14: testFromId

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestTimelineWebServices.java

示例15: testTasksSlash

import com.sun.jersey.api.client.WebResource; //导入依赖的package包/类
@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);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:20,代码来源:TestHsWebServicesTasks.java


注:本文中的com.sun.jersey.api.client.WebResource类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。