Search in sources :

Example 91 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestHsWebServicesJobsQuery method testJobsQueryLimit.

@Test
public void testJobsQueryLimit() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").queryParam("limit", "2").accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject jobs = json.getJSONObject("jobs");
    JSONArray arr = jobs.getJSONArray("job");
    // make sure we get 2 back
    assertEquals("incorrect number of elements", 2, arr.length());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 92 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestHsWebServicesJobsQuery method testJobsQueryFinishTimeBeginNegative.

@Test
public void testJobsQueryFinishTimeBeginNegative() throws JSONException, Exception {
    WebResource r = resource();
    ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").queryParam("finishedTimeBegin", String.valueOf(-1000)).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    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: finishedTimeBegin must be greater than 0", message);
    WebServicesTestUtils.checkStringMatch("exception type", "BadRequestException", type);
    WebServicesTestUtils.checkStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException", classname);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 93 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestHsWebServicesJobsQuery method testJobsQueryFinishTimeBeginEndInvalid.

@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);
    assertResponseStatusCode(Status.BAD_REQUEST, response.getStatusInfo());
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    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);
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Example 94 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestHsWebServicesJobsQuery method testJobsQueryStartTimeBeginEnd.

@Test
public void testJobsQueryStartTimeBeginEnd() throws JSONException, Exception {
    WebResource r = resource();
    Map<JobId, Job> jobsMap = appContext.getAllJobs();
    int size = jobsMap.size();
    ArrayList<Long> startTime = new ArrayList<Long>(size);
    // figure out the middle start Time
    for (Map.Entry<JobId, Job> entry : jobsMap.entrySet()) {
        startTime.add(entry.getValue().getReport().getStartTime());
    }
    Collections.sort(startTime);
    assertTrue("Error we must have atleast 3 jobs", size >= 3);
    long midStartTime = startTime.get(size - 2);
    ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").queryParam("startedTimeBegin", String.valueOf(40000)).queryParam("startedTimeEnd", String.valueOf(midStartTime)).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    JSONObject jobs = json.getJSONObject("jobs");
    JSONArray arr = jobs.getJSONArray("job");
    assertEquals("incorrect number of elements", size - 1, arr.length());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) ArrayList(java.util.ArrayList) JSONArray(org.codehaus.jettison.json.JSONArray) WebResource(com.sun.jersey.api.client.WebResource) JSONObject(org.codehaus.jettison.json.JSONObject) Job(org.apache.hadoop.mapreduce.v2.app.job.Job) Map(java.util.Map) JobId(org.apache.hadoop.mapreduce.v2.api.records.JobId) Test(org.junit.Test)

Example 95 with JSONObject

use of org.codehaus.jettison.json.JSONObject in project hadoop by apache.

the class TestHsWebServicesJobsQuery method testJobsQueryStartTimeBegin.

@Test
public void testJobsQueryStartTimeBegin() throws JSONException, Exception {
    WebResource r = resource();
    // the mockJobs start time is the current time - some random amount
    Long now = System.currentTimeMillis();
    ClientResponse response = r.path("ws").path("v1").path("history").path("mapreduce").path("jobs").queryParam("startedTimeBegin", String.valueOf(now)).accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
    assertEquals(MediaType.APPLICATION_JSON_TYPE + "; " + JettyUtils.UTF_8, response.getType().toString());
    JSONObject json = response.getEntity(JSONObject.class);
    assertEquals("incorrect number of elements", 1, json.length());
    assertEquals("jobs is not empty", new JSONObject().toString(), json.get("jobs").toString());
}
Also used : ClientResponse(com.sun.jersey.api.client.ClientResponse) JSONObject(org.codehaus.jettison.json.JSONObject) WebResource(com.sun.jersey.api.client.WebResource) Test(org.junit.Test)

Aggregations

JSONObject (org.codehaus.jettison.json.JSONObject)1464 Test (org.junit.Test)457 JSONException (org.codehaus.jettison.json.JSONException)411 ClientResponse (com.sun.jersey.api.client.ClientResponse)402 JSONArray (org.codehaus.jettison.json.JSONArray)385 WebResource (com.sun.jersey.api.client.WebResource)308 Test (org.testng.annotations.Test)263 BaseTest (org.xdi.oxauth.BaseTest)200 Parameters (org.testng.annotations.Parameters)191 Response (javax.ws.rs.core.Response)185 Builder (javax.ws.rs.client.Invocation.Builder)173 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)173 HashMap (java.util.HashMap)133 IOException (java.io.IOException)94 Job (org.apache.hadoop.mapreduce.v2.app.job.Job)88 ArrayList (java.util.ArrayList)86 JobId (org.apache.hadoop.mapreduce.v2.api.records.JobId)81 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)73 RegisterRequest (org.xdi.oxauth.client.RegisterRequest)69 Map (java.util.Map)62