source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestSubmitJob.java @ 120

Last change on this file since 120 was 120, checked in by (none), 14 years ago

Added the mail files for the Hadoop JUNit Project

  • Property svn:executable set to *
File size: 3.8 KB
Line 
1/**
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements.  See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership.  The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License.  You may obtain a copy of the License at
9 *
10 *     http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18package org.apache.hadoop.mapred;
19
20import java.io.IOException;
21
22import org.apache.hadoop.examples.SleepJob;
23import org.apache.hadoop.ipc.RemoteException;
24import org.apache.hadoop.util.ToolRunner;
25
26import junit.framework.TestCase;
27
28public class TestSubmitJob extends TestCase {
29  private MiniMRCluster miniMRCluster;
30
31  @Override
32  protected void tearDown()
33      throws Exception {
34    if (miniMRCluster != null) {
35      miniMRCluster.shutdown();
36    }
37  }
38
39  /**
40   * Test to verify that jobs with invalid memory requirements are killed at the
41   * JT.
42   *
43   * @throws Exception
44   */
45  public void testJobWithInvalidMemoryReqs()
46      throws Exception {
47    JobConf jtConf = new JobConf();
48    jtConf
49        .setLong(JobTracker.MAPRED_CLUSTER_MAP_MEMORY_MB_PROPERTY, 1 * 1024L);
50    jtConf.setLong(JobTracker.MAPRED_CLUSTER_REDUCE_MEMORY_MB_PROPERTY,
51        2 * 1024L);
52    jtConf.setLong(JobTracker.MAPRED_CLUSTER_MAX_MAP_MEMORY_MB_PROPERTY,
53        3 * 1024L);
54    jtConf.setLong(JobTracker.MAPRED_CLUSTER_MAX_REDUCE_MEMORY_MB_PROPERTY,
55        4 * 1024L);
56
57    miniMRCluster = new MiniMRCluster(0, "file:///", 0, null, null, jtConf);
58
59    JobConf clusterConf = miniMRCluster.createJobConf();
60
61    // No map-memory configuration
62    JobConf jobConf = new JobConf(clusterConf);
63    jobConf.setMemoryForReduceTask(1 * 1024L);
64    runJobAndVerifyFailure(jobConf, JobConf.DISABLED_MEMORY_LIMIT, 1 * 1024L,
65        "Invalid job requirements.");
66
67    // No reduce-memory configuration
68    jobConf = new JobConf(clusterConf);
69    jobConf.setMemoryForMapTask(1 * 1024L);
70    runJobAndVerifyFailure(jobConf, 1 * 1024L, JobConf.DISABLED_MEMORY_LIMIT,
71        "Invalid job requirements.");
72
73    // Invalid map-memory configuration
74    jobConf = new JobConf(clusterConf);
75    jobConf.setMemoryForMapTask(4 * 1024L);
76    jobConf.setMemoryForReduceTask(1 * 1024L);
77    runJobAndVerifyFailure(jobConf, 4 * 1024L, 1 * 1024L,
78        "Exceeds the cluster's max-memory-limit.");
79
80    // No reduce-memory configuration
81    jobConf = new JobConf(clusterConf);
82    jobConf.setMemoryForMapTask(1 * 1024L);
83    jobConf.setMemoryForReduceTask(5 * 1024L);
84    runJobAndVerifyFailure(jobConf, 1 * 1024L, 5 * 1024L,
85        "Exceeds the cluster's max-memory-limit.");
86  }
87
88  private void runJobAndVerifyFailure(JobConf jobConf, long memForMapTasks,
89      long memForReduceTasks, String expectedMsg)
90      throws Exception,
91      IOException {
92    String[] args = { "-m", "0", "-r", "0", "-mt", "0", "-rt", "0" };
93    boolean throwsException = false;
94    String msg = null;
95    try {
96      ToolRunner.run(jobConf, new SleepJob(), args);
97    } catch (RemoteException re) {
98      throwsException = true;
99      msg = re.unwrapRemoteException().getMessage();
100    }
101    assertTrue(throwsException);
102    assertNotNull(msg);
103
104    String overallExpectedMsg =
105        "(" + memForMapTasks + " memForMapTasks " + memForReduceTasks
106            + " memForReduceTasks): " + expectedMsg;
107    assertTrue("Observed message - " + msg
108        + " - doesn't contain expected message - " + overallExpectedMsg, msg
109        .contains(overallExpectedMsg));
110  }
111}
Note: See TracBrowser for help on using the repository browser.