MAPREDUCE-6625. TestCLI#testGetJob fails occasionally (haibochen via rkanter)
This commit is contained in:
parent
bf6f4a3b98
commit
ad256beb50
@ -31,9 +31,10 @@
|
|||||||
import org.apache.hadoop.mapreduce.JobPriority;
|
import org.apache.hadoop.mapreduce.JobPriority;
|
||||||
import org.apache.hadoop.mapreduce.JobStatus;
|
import org.apache.hadoop.mapreduce.JobStatus;
|
||||||
import org.apache.hadoop.mapreduce.JobStatus.State;
|
import org.apache.hadoop.mapreduce.JobStatus.State;
|
||||||
import org.apache.hadoop.util.Time;
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
import static org.mockito.Mockito.times;
|
import static org.mockito.Mockito.times;
|
||||||
@ -162,25 +163,33 @@ private Job mockJob(Cluster mockCluster, String jobId, State jobState)
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetJob() throws Exception {
|
public void testGetJobWithoutRetry() throws Exception {
|
||||||
Configuration conf = new Configuration();
|
Configuration conf = new Configuration();
|
||||||
long sleepTime = 100;
|
conf.setInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, 0);
|
||||||
conf.setLong(MRJobConfig.MR_CLIENT_JOB_RETRY_INTERVAL, sleepTime);
|
|
||||||
Cluster mockCluster = mock(Cluster.class);
|
|
||||||
JobID jobId1 = JobID.forName("job_1234654654_001");
|
|
||||||
when(mockCluster.getJob(jobId1)).thenReturn(null);
|
|
||||||
|
|
||||||
for (int i = 0; i < 2; ++i) {
|
final Cluster mockCluster = mock(Cluster.class);
|
||||||
conf.setInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, i);
|
when(mockCluster.getJob(any(JobID.class))).thenReturn(null);
|
||||||
CLI cli = spy(new CLI(conf));
|
CLI cli = new CLI(conf);
|
||||||
cli.cluster = mockCluster;
|
cli.cluster = mockCluster;
|
||||||
doReturn(mockCluster).when(cli).createCluster();
|
|
||||||
long start = Time.monotonicNow();
|
Job job = cli.getJob(JobID.forName("job_1234654654_001"));
|
||||||
cli.getJob(jobId1);
|
Assert.assertTrue("job is not null", job == null);
|
||||||
long end = Time.monotonicNow();
|
}
|
||||||
Assert.assertTrue(end - start > (i * sleepTime));
|
|
||||||
Assert.assertTrue(end - start < ((i + 1) * sleepTime));
|
@Test
|
||||||
}
|
public void testGetJobWithRetry() throws Exception {
|
||||||
|
Configuration conf = new Configuration();
|
||||||
|
conf.setInt(MRJobConfig.MR_CLIENT_JOB_MAX_RETRIES, 1);
|
||||||
|
|
||||||
|
final Cluster mockCluster = mock(Cluster.class);
|
||||||
|
final Job mockJob = Job.getInstance(conf);
|
||||||
|
when(mockCluster.getJob(any(JobID.class))).thenReturn(
|
||||||
|
null).thenReturn(mockJob);
|
||||||
|
CLI cli = new CLI(conf);
|
||||||
|
cli.cluster = mockCluster;
|
||||||
|
|
||||||
|
Job job = cli.getJob(JobID.forName("job_1234654654_001"));
|
||||||
|
Assert.assertTrue("job is null", job != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user