org.apache.hadoop.mapreduce.v2.app.AppContext Java Examples
The following examples show how to use
org.apache.hadoop.mapreduce.v2.app.AppContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TestRMContainerAllocator.java From big-c with Apache License 2.0 | 6 votes |
private static AppContext createAppContext( ApplicationAttemptId appAttemptId, Job job) { AppContext context = mock(AppContext.class); ApplicationId appId = appAttemptId.getApplicationId(); when(context.getApplicationID()).thenReturn(appId); when(context.getApplicationAttemptId()).thenReturn(appAttemptId); when(context.getJob(isA(JobId.class))).thenReturn(job); when(context.getClusterInfo()).thenReturn( new ClusterInfo(Resource.newInstance(10240, 1))); when(context.getEventHandler()).thenReturn(new EventHandler() { @Override public void handle(Event event) { // Only capture interesting events. if (event instanceof TaskAttemptContainerAssignedEvent) { events.add((TaskAttemptContainerAssignedEvent) event); } else if (event instanceof TaskAttemptKillEvent) { taskAttemptKillEvents.add((TaskAttemptKillEvent)event); } else if (event instanceof JobUpdatedNodesEvent) { jobUpdatedNodeEvents.add((JobUpdatedNodesEvent)event); } else if (event instanceof JobEvent) { jobEvents.add((JobEvent)event); } } }); return context; }
Example #2
Source File: TestHsWebServicesJobsQuery.java From hadoop with Apache License 2.0 | 6 votes |
@Override protected void configureServlets() { appContext = new MockHistoryContext(3, 2, 1); webApp = mock(HsWebApp.class); when(webApp.name()).thenReturn("hsmockwebapp"); bind(JAXBContextResolver.class); bind(HsWebServices.class); bind(GenericExceptionHandler.class); bind(WebApp.class).toInstance(webApp); bind(AppContext.class).toInstance(appContext); bind(HistoryContext.class).toInstance(appContext); bind(Configuration.class).toInstance(conf); serve("/*").with(GuiceContainer.class); }
Example #3
Source File: TestHsWebServicesAttempts.java From hadoop with Apache License 2.0 | 6 votes |
@Override protected void configureServlets() { appContext = new MockHistoryContext(0, 1, 2, 1); webApp = mock(HsWebApp.class); when(webApp.name()).thenReturn("hsmockwebapp"); bind(JAXBContextResolver.class); bind(HsWebServices.class); bind(GenericExceptionHandler.class); bind(WebApp.class).toInstance(webApp); bind(AppContext.class).toInstance(appContext); bind(HistoryContext.class).toInstance(appContext); bind(Configuration.class).toInstance(conf); serve("/*").with(GuiceContainer.class); }
Example #4
Source File: TestHsWebServicesJobs.java From big-c with Apache License 2.0 | 6 votes |
@Override protected void configureServlets() { appContext = new MockHistoryContext(0, 1, 2, 1, false); webApp = mock(HsWebApp.class); when(webApp.name()).thenReturn("hsmockwebapp"); bind(JAXBContextResolver.class); bind(HsWebServices.class); bind(GenericExceptionHandler.class); bind(WebApp.class).toInstance(webApp); bind(AppContext.class).toInstance(appContext); bind(HistoryContext.class).toInstance(appContext); bind(Configuration.class).toInstance(conf); serve("/*").with(GuiceContainer.class); }
Example #5
Source File: TestBlocks.java From big-c with Apache License 2.0 | 6 votes |
/** * test HsJobsBlock's rendering. */ @Test public void testHsJobsBlock() { AppContext ctx = mock(AppContext.class); Map<JobId, Job> jobs = new HashMap<JobId, Job>(); Job job = getJob(); jobs.put(job.getID(), job); when(ctx.getAllJobs()).thenReturn(jobs); HsJobsBlock block = new HsJobsBlockForTest(ctx); PrintWriter pWriter = new PrintWriter(data); Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false); block.render(html); pWriter.flush(); assertTrue(data.toString().contains("JobName")); assertTrue(data.toString().contains("UserName")); assertTrue(data.toString().contains("QueueName")); assertTrue(data.toString().contains("SUCCEEDED")); }
Example #6
Source File: TestHsWebServices.java From hadoop with Apache License 2.0 | 6 votes |
@Override protected void configureServlets() { appContext = new MockHistoryContext(0, 1, 1, 1); JobHistory jobHistoryService = new JobHistory(); HistoryContext historyContext = (HistoryContext) jobHistoryService; webApp = new HsWebApp(historyContext); bind(JAXBContextResolver.class); bind(HsWebServices.class); bind(GenericExceptionHandler.class); bind(WebApp.class).toInstance(webApp); bind(AppContext.class).toInstance(appContext); bind(HistoryContext.class).toInstance(appContext); bind(Configuration.class).toInstance(conf); serve("/*").with(GuiceContainer.class); }
Example #7
Source File: TestHsWebServices.java From hadoop with Apache License 2.0 | 6 votes |
public void verifyHSInfoXML(String xml, AppContext ctx) throws JSONException, Exception { 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("historyInfo"); assertEquals("incorrect number of elements", 1, nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); verifyHsInfoGeneric( WebServicesTestUtils.getXmlString(element, "hadoopVersionBuiltOn"), WebServicesTestUtils.getXmlString(element, "hadoopBuildVersion"), WebServicesTestUtils.getXmlString(element, "hadoopVersion"), WebServicesTestUtils.getXmlLong(element, "startedOn")); } }
Example #8
Source File: TestAMWebApp.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testSingleTaskCounterView() { AppContext appContext = new MockAppContext(0, 1, 1, 2); Map<String, String> params = getTaskParams(appContext); params.put(AMParams.COUNTER_GROUP, "org.apache.hadoop.mapreduce.FileSystemCounter"); params.put(AMParams.COUNTER_NAME, "HDFS_WRITE_OPS"); // remove counters from one task attempt // to test handling of missing counters TaskId taskID = MRApps.toTaskID(params.get(AMParams.TASK_ID)); Job job = appContext.getJob(taskID.getJobId()); Task task = job.getTask(taskID); TaskAttempt attempt = task.getAttempts().values().iterator().next(); attempt.getReport().setCounters(null); WebAppTests.testPage(SingleCounterPage.class, AppContext.class, appContext, params); }
Example #9
Source File: TestHSWebApp.java From big-c with Apache License 2.0 | 6 votes |
@Test public void testLogsView2() throws IOException { LOG.info("HsLogsPage with data"); MockAppContext ctx = new MockAppContext(0, 1, 1, 1); Map<String, String> params = new HashMap<String, String>(); params.put(CONTAINER_ID, MRApp.newContainerId(1, 1, 333, 1) .toString()); params.put(NM_NODENAME, NodeId.newInstance(MockJobs.NM_HOST, MockJobs.NM_PORT).toString()); params.put(ENTITY_STRING, "container_10_0001_01_000001"); params.put(APP_OWNER, "owner"); Injector injector = WebAppTests.testPage(AggregatedLogsPage.class, AppContext.class, ctx, params); PrintWriter spyPw = WebAppTests.getPrintWriter(injector); verify(spyPw).write( "Aggregation is not enabled. Try the nodemanager at " + MockJobs.NM_HOST + ":" + MockJobs.NM_PORT); }
Example #10
Source File: TestHSWebApp.java From hadoop with Apache License 2.0 | 6 votes |
@Test public void testLogsViewBadStartEnd() throws IOException { LOG.info("HsLogsPage with bad start/end params"); MockAppContext ctx = new MockAppContext(0, 1, 1, 1); Map<String, String> params = new HashMap<String, String>(); params.put("start", "foo"); params.put("end", "bar"); params.put(CONTAINER_ID, MRApp.newContainerId(1, 1, 333, 1) .toString()); params.put(NM_NODENAME, NodeId.newInstance(MockJobs.NM_HOST, MockJobs.NM_PORT).toString()); params.put(ENTITY_STRING, "container_10_0001_01_000001"); params.put(APP_OWNER, "owner"); Injector injector = WebAppTests.testPage(AggregatedLogsPage.class, AppContext.class, ctx, params); PrintWriter spyPw = WebAppTests.getPrintWriter(injector); verify(spyPw).write("Invalid log start value: foo"); verify(spyPw).write("Invalid log end value: bar"); }
Example #11
Source File: TestAMWebServices.java From big-c with Apache License 2.0 | 6 votes |
public void verifyBlacklistedNodesInfoXML(String xml, AppContext ctx) throws JSONException, Exception { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); InputSource is = new InputSource(); is.setCharacterStream(new StringReader(xml)); Document dom = db.parse(is); NodeList infonodes = dom.getElementsByTagName("blacklistednodesinfo"); assertEquals("incorrect number of elements", 1, infonodes.getLength()); NodeList nodes = dom.getElementsByTagName("blacklistedNodes"); Set<String> blacklistedNodes = ctx.getBlacklistedNodes(); assertEquals("incorrect number of elements", blacklistedNodes.size(), nodes.getLength()); for (int i = 0; i < nodes.getLength(); i++) { Element element = (Element) nodes.item(i); assertTrue( blacklistedNodes.contains(element.getFirstChild().getNodeValue())); } }
Example #12
Source File: TestLocalContainerAllocator.java From big-c with Apache License 2.0 | 6 votes |
private static AppContext createAppContext() { ApplicationId appId = ApplicationId.newInstance(1, 1); ApplicationAttemptId attemptId = ApplicationAttemptId.newInstance(appId, 1); Job job = mock(Job.class); @SuppressWarnings("rawtypes") EventHandler eventHandler = mock(EventHandler.class); AppContext ctx = mock(AppContext.class); when(ctx.getApplicationID()).thenReturn(appId); when(ctx.getApplicationAttemptId()).thenReturn(attemptId); when(ctx.getJob(isA(JobId.class))).thenReturn(job); when(ctx.getClusterInfo()).thenReturn( new ClusterInfo(Resource.newInstance(10240, 1))); when(ctx.getEventHandler()).thenReturn(eventHandler); return ctx; }
Example #13
Source File: TestMapReduceChildJVM.java From big-c with Apache License 2.0 | 6 votes |
@Override protected ContainerLauncher createContainerLauncher(AppContext context) { return new MockContainerLauncher() { @Override public void handle(ContainerLauncherEvent event) { if (event.getType() == EventType.CONTAINER_REMOTE_LAUNCH) { ContainerRemoteLaunchEvent launchEvent = (ContainerRemoteLaunchEvent) event; ContainerLaunchContext launchContext = launchEvent.getContainerLaunchContext(); String cmdString = launchContext.getCommands().toString(); LOG.info("launchContext " + cmdString); myCommandLine = cmdString; cmdEnvironment = launchContext.getEnvironment(); } super.handle(event); } }; }
Example #14
Source File: HsWebApp.java From big-c with Apache License 2.0 | 5 votes |
@Override public void setup() { bind(HsWebServices.class); bind(JAXBContextResolver.class); bind(GenericExceptionHandler.class); bind(AppContext.class).toInstance(history); bind(HistoryContext.class).toInstance(history); route("/", HsController.class); route("/app", HsController.class); route(pajoin("/job", JOB_ID), HsController.class, "job"); route(pajoin("/conf", JOB_ID), HsController.class, "conf"); route(pajoin("/jobcounters", JOB_ID), HsController.class, "jobCounters"); route(pajoin("/singlejobcounter",JOB_ID, COUNTER_GROUP, COUNTER_NAME), HsController.class, "singleJobCounter"); route(pajoin("/tasks", JOB_ID, TASK_TYPE), HsController.class, "tasks"); route(pajoin("/attempts", JOB_ID, TASK_TYPE, ATTEMPT_STATE), HsController.class, "attempts"); route(pajoin("/task", TASK_ID), HsController.class, "task"); route(pajoin("/taskcounters", TASK_ID), HsController.class, "taskCounters"); route(pajoin("/singletaskcounter",TASK_ID, COUNTER_GROUP, COUNTER_NAME), HsController.class, "singleTaskCounter"); route("/about", HsController.class, "about"); route(pajoin("/logs", NM_NODENAME, CONTAINER_ID, ENTITY_STRING, APP_OWNER, CONTAINER_LOG_TYPE), HsController.class, "logs"); route(pajoin("/nmlogs", NM_NODENAME, CONTAINER_ID, ENTITY_STRING, APP_OWNER, CONTAINER_LOG_TYPE), HsController.class, "nmlogs"); }
Example #15
Source File: TestHSWebApp.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testLogsView1() throws IOException { LOG.info("HsLogsPage"); Injector injector = WebAppTests.testPage(AggregatedLogsPage.class, AppContext.class, new MockAppContext(0, 1, 1, 1)); PrintWriter spyPw = WebAppTests.getPrintWriter(injector); verify(spyPw).write("Cannot get container logs without a ContainerId"); verify(spyPw).write("Cannot get container logs without a NodeId"); verify(spyPw).write("Cannot get container logs without an app owner"); }
Example #16
Source File: TestTaskImpl.java From big-c with Apache License 2.0 | 5 votes |
public MockTaskAttemptImpl(TaskId taskId, int id, EventHandler eventHandler, TaskAttemptListener taskAttemptListener, Path jobFile, int partition, JobConf conf, Token<JobTokenIdentifier> jobToken, Credentials credentials, Clock clock, AppContext appContext, TaskType taskType) { super(taskId, id, eventHandler, taskAttemptListener, jobFile, partition, conf, dataLocations, jobToken, credentials, clock, appContext); this.taskType = taskType; }
Example #17
Source File: AppInfo.java From big-c with Apache License 2.0 | 5 votes |
public AppInfo(App app, AppContext context) { this.appId = context.getApplicationID().toString(); this.name = context.getApplicationName().toString(); this.user = context.getUser().toString(); this.startedOn = context.getStartTime(); this.elapsedTime = Times.elapsed(this.startedOn, 0); }
Example #18
Source File: TestContainerLauncher.java From big-c with Apache License 2.0 | 5 votes |
@Override protected ContainerLauncher createContainerLauncher(final AppContext context) { return new ContainerLauncherImpl(context) { @Override public ContainerManagementProtocolProxyData getCMProxy( String containerMgrBindAddr, ContainerId containerId) throws IOException { InetSocketAddress addr = NetUtils.getConnectAddress(server); String containerManagerBindAddr = addr.getHostName() + ":" + addr.getPort(); Token token = tokenSecretManager.createNMToken( containerId.getApplicationAttemptId(), NodeId.newInstance(addr.getHostName(), addr.getPort()), "user"); ContainerManagementProtocolProxy cmProxy = new ContainerManagementProtocolProxy(conf); ContainerManagementProtocolProxyData proxy = cmProxy.new ContainerManagementProtocolProxyData( YarnRPC.create(conf), containerManagerBindAddr, containerId, token); return proxy; } }; }
Example #19
Source File: TestBlocks.java From big-c with Apache License 2.0 | 5 votes |
/** * Test rendering for ConfBlock */ @Test public void testConfigurationBlock() throws Exception { AppContext ctx = mock(AppContext.class); Job job = mock(Job.class); Path path = new Path("conf"); Configuration configuration = new Configuration(); configuration.set("Key for test", "Value for test"); when(job.getConfFile()).thenReturn(path); when(job.loadConfFile()).thenReturn(configuration); when(ctx.getJob(any(JobId.class))).thenReturn(job); ConfBlockForTest configurationBlock = new ConfBlockForTest(ctx); PrintWriter pWriter = new PrintWriter(data); Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false); configurationBlock.render(html); pWriter.flush(); assertTrue(data.toString().contains( "Sorry, can't do anything without a JobID")); configurationBlock.addParameter(AMParams.JOB_ID, "job_01_01"); data.reset(); configurationBlock.render(html); pWriter.flush(); assertTrue(data.toString().contains("Key for test")); assertTrue(data.toString().contains("Value for test")); }
Example #20
Source File: TestBlocks.java From big-c with Apache License 2.0 | 5 votes |
/** * test HsTasksBlock's rendering. */ @Test public void testHsTasksBlock() { Task task = getTask(0); Map<TaskId, Task> tasks = new HashMap<TaskId, Task>(); tasks.put(task.getID(), task); AppContext ctx = mock(AppContext.class); AppForTest app = new AppForTest(ctx); Job job = mock(Job.class); when(job.getTasks()).thenReturn(tasks); app.setJob(job); HsTasksBlockForTest block = new HsTasksBlockForTest(app); block.addParameter(AMParams.TASK_TYPE, "r"); PrintWriter pWriter = new PrintWriter(data); Block html = new BlockForTest(new HtmlBlockForTest(), pWriter, 0, false); block.render(html); pWriter.flush(); // should be printed information about task assertTrue(data.toString().contains("task_0_0001_r_000000")); assertTrue(data.toString().contains("SUCCEEDED")); assertTrue(data.toString().contains("100001")); assertTrue(data.toString().contains("100011")); assertTrue(data.toString().contains("")); }
Example #21
Source File: TestHSWebApp.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testTasksView() { LOG.info("HsTasksPage"); AppContext appContext = new MockAppContext(0, 1, 1, 1); Map<String, String> params = TestAMWebApp.getTaskParams(appContext); WebAppTests.testPage(HsTasksPage.class, AppContext.class, appContext, params); }
Example #22
Source File: TestJobImpl.java From hadoop with Apache License 2.0 | 5 votes |
private static StubbedJob createRunningStubbedJob(Configuration conf, Dispatcher dispatcher, int numSplits, AppContext appContext) { StubbedJob job = createStubbedJob(conf, dispatcher, numSplits, appContext); job.handle(new JobEvent(job.getID(), JobEventType.JOB_INIT)); assertJobState(job, JobStateInternal.INITED); job.handle(new JobStartEvent(job.getID())); assertJobState(job, JobStateInternal.RUNNING); return job; }
Example #23
Source File: RMCommunicator.java From hadoop with Apache License 2.0 | 5 votes |
public RMCommunicator(ClientService clientService, AppContext context) { super("RMCommunicator"); this.clientService = clientService; this.context = context; this.eventHandler = context.getEventHandler(); this.applicationId = context.getApplicationID(); this.stopped = new AtomicBoolean(false); this.heartbeatCallbacks = new ConcurrentLinkedQueue<Runnable>(); this.schedulerResourceTypes = EnumSet.of(SchedulerResourceTypes.MEMORY); }
Example #24
Source File: TestHSWebApp.java From hadoop with Apache License 2.0 | 5 votes |
@Test public void testJobCounterViewForKilledJob() { LOG.info("JobCounterViewForKilledJob"); AppContext appContext = new MockAppContext(0, 1, 1, 1, true); Map<String, String> params = TestAMWebApp.getJobParams(appContext); WebAppTests.testPage(HsCountersPage.class, AppContext.class, appContext, params); }
Example #25
Source File: TestAppController.java From big-c with Apache License 2.0 | 5 votes |
@Before public void setUp() throws IOException { AppContext context = mock(AppContext.class); when(context.getApplicationID()).thenReturn( ApplicationId.newInstance(0, 0)); when(context.getApplicationName()).thenReturn("AppName"); when(context.getUser()).thenReturn("User"); when(context.getStartTime()).thenReturn(System.currentTimeMillis()); job = mock(Job.class); Task task = mock(Task.class); when(job.getTask(any(TaskId.class))).thenReturn(task); JobId jobID = MRApps.toJobID("job_01_01"); when(context.getJob(jobID)).thenReturn(job); when(job.checkAccess(any(UserGroupInformation.class), any(JobACL.class))) .thenReturn(true); App app = new App(context); Configuration configuration = new Configuration(); ctx = mock(RequestContext.class); appController = new AppControllerForTest(app, configuration, ctx); appController.getProperty().put(AMParams.JOB_ID, "job_01_01"); appController.getProperty().put(AMParams.TASK_ID, "task_01_01_m01_01"); }
Example #26
Source File: TestHSWebApp.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testJobCounterView() { LOG.info("JobCounterView"); AppContext appContext = new MockAppContext(0, 1, 1, 1); Map<String, String> params = TestAMWebApp.getJobParams(appContext); WebAppTests.testPage(HsCountersPage.class, AppContext.class, appContext, params); }
Example #27
Source File: TestJobImpl.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testTransitionsAtFailed() throws IOException { Configuration conf = new Configuration(); AsyncDispatcher dispatcher = new AsyncDispatcher(); dispatcher.init(conf); dispatcher.start(); OutputCommitter committer = mock(OutputCommitter.class); doThrow(new IOException("forcefail")) .when(committer).setupJob(any(JobContext.class)); CommitterEventHandler commitHandler = createCommitterEventHandler(dispatcher, committer); commitHandler.init(conf); commitHandler.start(); AppContext mockContext = mock(AppContext.class); when(mockContext.hasSuccessfullyUnregistered()).thenReturn(false); JobImpl job = createStubbedJob(conf, dispatcher, 2, mockContext); JobId jobId = job.getID(); job.handle(new JobEvent(jobId, JobEventType.JOB_INIT)); assertJobState(job, JobStateInternal.INITED); job.handle(new JobStartEvent(jobId)); assertJobState(job, JobStateInternal.FAILED); job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_COMPLETED)); assertJobState(job, JobStateInternal.FAILED); job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_ATTEMPT_COMPLETED)); assertJobState(job, JobStateInternal.FAILED); job.handle(new JobEvent(jobId, JobEventType.JOB_MAP_TASK_RESCHEDULED)); assertJobState(job, JobStateInternal.FAILED); job.handle(new JobEvent(jobId, JobEventType.JOB_TASK_ATTEMPT_FETCH_FAILURE)); assertJobState(job, JobStateInternal.FAILED); Assert.assertEquals(JobState.RUNNING, job.getState()); when(mockContext.hasSuccessfullyUnregistered()).thenReturn(true); Assert.assertEquals(JobState.FAILED, job.getState()); dispatcher.stop(); commitHandler.stop(); }
Example #28
Source File: TestHSWebApp.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testLogsViewSingle() throws IOException { LOG.info("HsLogsPage with params for single log and data limits"); MockAppContext ctx = new MockAppContext(0, 1, 1, 1); Map<String, String> params = new HashMap<String, String>(); final Configuration conf = new YarnConfiguration(); conf.setBoolean(YarnConfiguration.LOG_AGGREGATION_ENABLED, true); params.put("start", "-2048"); params.put("end", "-1024"); params.put(CONTAINER_LOG_TYPE, "syslog"); params.put(CONTAINER_ID, MRApp.newContainerId(1, 1, 333, 1) .toString()); params.put(NM_NODENAME, NodeId.newInstance(MockJobs.NM_HOST, MockJobs.NM_PORT).toString()); params.put(ENTITY_STRING, "container_10_0001_01_000001"); params.put(APP_OWNER, "owner"); Injector injector = WebAppTests.testPage(AggregatedLogsPage.class, AppContext.class, ctx, params, new AbstractModule() { @Override protected void configure() { bind(Configuration.class).toInstance(conf); } }); PrintWriter spyPw = WebAppTests.getPrintWriter(injector); verify(spyPw).write( "Logs not available for container_10_0001_01_000001." + " Aggregation may not be complete, " + "Check back later or try the nodemanager at " + MockJobs.NM_HOST + ":" + MockJobs.NM_PORT); }
Example #29
Source File: TestHSWebApp.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testAppControllerIndex() { MockAppContext ctx = new MockAppContext(0, 1, 1, 1); Injector injector = WebAppTests.createMockInjector(AppContext.class, ctx); HsController controller = injector.getInstance(HsController.class); controller.index(); assertEquals(ctx.getApplicationID().toString(), controller.get(APP_ID,"")); }
Example #30
Source File: TestHsWebServicesJobs.java From big-c with Apache License 2.0 | 5 votes |
@Test public void testJobCountersForKilledJob() throws Exception { WebResource r = resource(); appContext = new MockHistoryContext(0, 1, 1, 1, true); injector = Guice.createInjector(new ServletModule() { @Override protected void configureServlets() { webApp = mock(HsWebApp.class); when(webApp.name()).thenReturn("hsmockwebapp"); bind(JAXBContextResolver.class); bind(HsWebServices.class); bind(GenericExceptionHandler.class); bind(WebApp.class).toInstance(webApp); bind(AppContext.class).toInstance(appContext); bind(HistoryContext.class).toInstance(appContext); bind(Configuration.class).toInstance(conf); serve("/*").with(GuiceContainer.class); } }); 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("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("jobCounters"); WebServicesTestUtils.checkStringMatch("id", MRApps.toString(id), info.getString("id")); assertTrue("Job shouldn't contain any counters", info.length() == 1); } }