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 */ 18 19 package org.apache.hadoop.mapred; 20 21 import java.io.IOException; 22 import java.util.Collection; 23 24 import org.apache.hadoop.mapreduce.TaskType; 25 26 /** 27 * Dummy implementation of Schedulable for unit testing. 28 */ 29 public class FakeSchedulable extends Schedulable { 30 private int demand; 31 private int runningTasks; 32 private int minShare; 33 private double weight; 34 private JobPriority priority; 35 private long startTime; 36 FakeSchedulable()37 public FakeSchedulable() { 38 this(0, 0, 1, 0, 0, JobPriority.NORMAL, 0); 39 } 40 FakeSchedulable(int demand)41 public FakeSchedulable(int demand) { 42 this(demand, 0, 1, 0, 0, JobPriority.NORMAL, 0); 43 } 44 FakeSchedulable(int demand, int minShare)45 public FakeSchedulable(int demand, int minShare) { 46 this(demand, minShare, 1, 0, 0, JobPriority.NORMAL, 0); 47 } 48 FakeSchedulable(int demand, int minShare, double weight)49 public FakeSchedulable(int demand, int minShare, double weight) { 50 this(demand, minShare, weight, 0, 0, JobPriority.NORMAL, 0); 51 } 52 FakeSchedulable(int demand, int minShare, double weight, int fairShare, int runningTasks, JobPriority priority, long startTime)53 public FakeSchedulable(int demand, int minShare, double weight, int fairShare, 54 int runningTasks, JobPriority priority, long startTime) { 55 this.demand = demand; 56 this.minShare = minShare; 57 this.weight = weight; 58 setFairShare(fairShare); 59 this.runningTasks = runningTasks; 60 this.priority = priority; 61 this.startTime = startTime; 62 } 63 64 @Override assignTask(TaskTrackerStatus tts, long currentTime, Collection<JobInProgress> visited)65 public Task assignTask(TaskTrackerStatus tts, long currentTime, 66 Collection<JobInProgress> visited) throws IOException { 67 return null; 68 } 69 70 @Override getDemand()71 public int getDemand() { 72 return demand; 73 } 74 75 @Override getName()76 public String getName() { 77 return "FakeSchedulable" + this.hashCode(); 78 } 79 80 @Override getPriority()81 public JobPriority getPriority() { 82 return priority; 83 } 84 85 @Override getRunningTasks()86 public int getRunningTasks() { 87 return runningTasks; 88 } 89 90 @Override getStartTime()91 public long getStartTime() { 92 return startTime; 93 } 94 95 @Override getWeight()96 public double getWeight() { 97 return weight; 98 } 99 100 @Override getMinShare()101 public int getMinShare() { 102 return minShare; 103 } 104 105 @Override redistributeShare()106 public void redistributeShare() {} 107 108 @Override updateDemand()109 public void updateDemand() {} 110 111 @Override getTaskType()112 public TaskType getTaskType() { 113 return TaskType.MAP; 114 } 115 116 @Override getMetricsContextName()117 protected String getMetricsContextName() { 118 return "fake"; 119 } 120 121 @Override updateMetrics()122 void updateMetrics() { 123 } 124 } 125