source: proiecte/HadoopJUnit/hadoop-0.20.1/src/test/org/apache/hadoop/mapred/TestResourceEstimation.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.7 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 junit.framework.TestCase;
21import org.apache.hadoop.mapred.JobClient.RawSplit;
22
23public class TestResourceEstimation extends TestCase {
24 
25
26  public void testResourceEstimator() throws Exception {
27    final int maps = 100;
28    final int reduces = 2;
29    final int singleMapOutputSize = 1000;
30    JobConf jc = new JobConf();
31    JobID jid = new JobID("testJT", 0);
32    jc.setNumMapTasks(maps);
33    jc.setNumReduceTasks(reduces);
34   
35    JobInProgress jip = new JobInProgress(jid, jc);
36    //unfortunately, we can't set job input size from here.
37    ResourceEstimator re = new ResourceEstimator(jip);
38   
39    for(int i = 0; i < maps / 10 ; ++i) {
40
41      long estOutSize = re.getEstimatedMapOutputSize();
42      System.out.println(estOutSize);
43      assertEquals(0, estOutSize);
44     
45      TaskStatus ts = new MapTaskStatus();
46      ts.setOutputSize(singleMapOutputSize);
47      RawSplit split = new RawSplit();
48      split.setDataLength(0);
49      TaskInProgress tip = new TaskInProgress(jid, "", split, null, jc, jip, 0);
50      re.updateWithCompletedTask(ts, tip);
51    }
52    assertEquals(2* singleMapOutputSize, re.getEstimatedMapOutputSize());
53    assertEquals(2* singleMapOutputSize * maps / reduces, re.getEstimatedReduceInputSize());
54   
55  }
56 
57  public void testWithNonZeroInput() throws Exception {
58    final int maps = 100;
59    final int reduces = 2;
60    final int singleMapOutputSize = 1000;
61    final int singleMapInputSize = 500;
62    JobConf jc = new JobConf();
63    JobID jid = new JobID("testJT", 0);
64    jc.setNumMapTasks(maps);
65    jc.setNumReduceTasks(reduces);
66   
67    JobInProgress jip = new JobInProgress(jid, jc) {
68      long getInputLength() {
69        return singleMapInputSize*desiredMaps();
70      }
71    };
72    ResourceEstimator re = new ResourceEstimator(jip);
73   
74    for(int i = 0; i < maps / 10 ; ++i) {
75
76      long estOutSize = re.getEstimatedMapOutputSize();
77      System.out.println(estOutSize);
78      assertEquals(0, estOutSize);
79     
80      TaskStatus ts = new MapTaskStatus();
81      ts.setOutputSize(singleMapOutputSize);
82      RawSplit split = new RawSplit();
83      split.setDataLength(singleMapInputSize);
84      TaskInProgress tip = new TaskInProgress(jid, "", split, null, jc, jip, 0);
85      re.updateWithCompletedTask(ts, tip);
86    }
87   
88    assertEquals(2* singleMapOutputSize, re.getEstimatedMapOutputSize());
89    assertEquals(2* singleMapOutputSize * maps / reduces, re.getEstimatedReduceInputSize());
90
91    //add one more map task with input size as 0
92    TaskStatus ts = new MapTaskStatus();
93    ts.setOutputSize(singleMapOutputSize);
94    RawSplit split = new RawSplit();
95    split.setDataLength(0);
96    TaskInProgress tip = new TaskInProgress(jid, "", split, null, jc, jip, 0);
97    re.updateWithCompletedTask(ts, tip);
98   
99    long expectedTotalMapOutSize = (singleMapOutputSize*11) * 
100      ((maps*singleMapInputSize)+maps)/((singleMapInputSize+1)*10+1);
101    assertEquals(2* expectedTotalMapOutSize/maps, re.getEstimatedMapOutputSize());
102  }
103
104}
Note: See TracBrowser for help on using the repository browser.