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 | package org.apache.hadoop.conf; |
---|
19 | |
---|
20 | import junit.framework.Assert; |
---|
21 | import junit.framework.TestCase; |
---|
22 | |
---|
23 | import org.apache.hadoop.mapred.JobConf; |
---|
24 | |
---|
25 | public class TestJobConf extends TestCase { |
---|
26 | |
---|
27 | public void testProfileParamsDefaults() { |
---|
28 | JobConf configuration = new JobConf(); |
---|
29 | |
---|
30 | Assert.assertNull(configuration.get("mapred.task.profile.params")); |
---|
31 | |
---|
32 | String result = configuration.getProfileParams(); |
---|
33 | |
---|
34 | Assert.assertNotNull(result); |
---|
35 | Assert.assertTrue(result.contains("file=%s")); |
---|
36 | Assert.assertTrue(result.startsWith("-agentlib:hprof")); |
---|
37 | } |
---|
38 | |
---|
39 | public void testProfileParamsSetter() { |
---|
40 | JobConf configuration = new JobConf(); |
---|
41 | |
---|
42 | configuration.setProfileParams("test"); |
---|
43 | Assert.assertEquals("test", configuration.get("mapred.task.profile.params")); |
---|
44 | } |
---|
45 | |
---|
46 | public void testProfileParamsGetter() { |
---|
47 | JobConf configuration = new JobConf(); |
---|
48 | |
---|
49 | configuration.set("mapred.task.profile.params", "test"); |
---|
50 | Assert.assertEquals("test", configuration.getProfileParams()); |
---|
51 | } |
---|
52 | |
---|
53 | /** |
---|
54 | * Testing mapred.task.maxvmem replacement with new values |
---|
55 | * |
---|
56 | */ |
---|
57 | public void testMemoryConfigForMapOrReduceTask(){ |
---|
58 | JobConf configuration = new JobConf(); |
---|
59 | configuration.set("mapred.job.map.memory.mb",String.valueOf(300)); |
---|
60 | configuration.set("mapred.job.reduce.memory.mb",String.valueOf(300)); |
---|
61 | Assert.assertEquals(configuration.getMemoryForMapTask(),300); |
---|
62 | Assert.assertEquals(configuration.getMemoryForReduceTask(),300); |
---|
63 | |
---|
64 | configuration.set("mapred.task.maxvmem" , String.valueOf(2*1024 * 1024)); |
---|
65 | configuration.set("mapred.job.map.memory.mb",String.valueOf(300)); |
---|
66 | configuration.set("mapred.job.reduce.memory.mb",String.valueOf(300)); |
---|
67 | Assert.assertEquals(configuration.getMemoryForMapTask(),2); |
---|
68 | Assert.assertEquals(configuration.getMemoryForReduceTask(),2); |
---|
69 | |
---|
70 | configuration = new JobConf(); |
---|
71 | configuration.set("mapred.task.maxvmem" , "-1"); |
---|
72 | configuration.set("mapred.job.map.memory.mb",String.valueOf(300)); |
---|
73 | configuration.set("mapred.job.reduce.memory.mb",String.valueOf(300)); |
---|
74 | Assert.assertEquals(configuration.getMemoryForMapTask(),-1); |
---|
75 | Assert.assertEquals(configuration.getMemoryForReduceTask(),-1); |
---|
76 | |
---|
77 | configuration = new JobConf(); |
---|
78 | configuration.set("mapred.task.maxvmem" , String.valueOf(2*1024 * 1024)); |
---|
79 | configuration.set("mapred.job.map.memory.mb","-1"); |
---|
80 | configuration.set("mapred.job.reduce.memory.mb","-1"); |
---|
81 | Assert.assertEquals(configuration.getMemoryForMapTask(),2); |
---|
82 | Assert.assertEquals(configuration.getMemoryForReduceTask(),2); |
---|
83 | |
---|
84 | configuration = new JobConf(); |
---|
85 | configuration.set("mapred.task.maxvmem" , String.valueOf(-1)); |
---|
86 | configuration.set("mapred.job.map.memory.mb","-1"); |
---|
87 | configuration.set("mapred.job.reduce.memory.mb","-1"); |
---|
88 | Assert.assertEquals(configuration.getMemoryForMapTask(),-1); |
---|
89 | Assert.assertEquals(configuration.getMemoryForReduceTask(),-1); |
---|
90 | |
---|
91 | configuration = new JobConf(); |
---|
92 | configuration.set("mapred.task.maxvmem" , String.valueOf(2*1024 * 1024)); |
---|
93 | Assert.assertEquals(configuration.getMemoryForMapTask(),2); |
---|
94 | Assert.assertEquals(configuration.getMemoryForReduceTask(),2); |
---|
95 | } |
---|
96 | |
---|
97 | /** |
---|
98 | * Test deprecated accessor and mutator method for mapred.task.maxvmem |
---|
99 | */ |
---|
100 | public void testMaxVirtualMemoryForTask() { |
---|
101 | JobConf configuration = new JobConf(); |
---|
102 | |
---|
103 | //get test case |
---|
104 | configuration.set("mapred.job.map.memory.mb", String.valueOf(300)); |
---|
105 | configuration.set("mapred.job.reduce.memory.mb", String.valueOf(-1)); |
---|
106 | Assert.assertEquals( |
---|
107 | configuration.getMaxVirtualMemoryForTask(), 300 * 1024 * 1024); |
---|
108 | |
---|
109 | configuration = new JobConf(); |
---|
110 | configuration.set("mapred.job.map.memory.mb", String.valueOf(-1)); |
---|
111 | configuration.set("mapred.job.reduce.memory.mb", String.valueOf(200)); |
---|
112 | Assert.assertEquals( |
---|
113 | configuration.getMaxVirtualMemoryForTask(), 200 * 1024 * 1024); |
---|
114 | |
---|
115 | configuration = new JobConf(); |
---|
116 | configuration.set("mapred.job.map.memory.mb", String.valueOf(-1)); |
---|
117 | configuration.set("mapred.job.reduce.memory.mb", String.valueOf(-1)); |
---|
118 | configuration.set("mapred.task.maxvmem", String.valueOf(1 * 1024 * 1024)); |
---|
119 | Assert.assertEquals( |
---|
120 | configuration.getMaxVirtualMemoryForTask(), 1 * 1024 * 1024); |
---|
121 | |
---|
122 | configuration = new JobConf(); |
---|
123 | configuration.set("mapred.task.maxvmem", String.valueOf(1 * 1024 * 1024)); |
---|
124 | Assert.assertEquals( |
---|
125 | configuration.getMaxVirtualMemoryForTask(), 1 * 1024 * 1024); |
---|
126 | |
---|
127 | //set test case |
---|
128 | |
---|
129 | configuration = new JobConf(); |
---|
130 | configuration.setMaxVirtualMemoryForTask(2 * 1024 * 1024); |
---|
131 | Assert.assertEquals(configuration.getMemoryForMapTask(), 2); |
---|
132 | Assert.assertEquals(configuration.getMemoryForReduceTask(), 2); |
---|
133 | |
---|
134 | configuration = new JobConf(); |
---|
135 | configuration.set("mapred.job.map.memory.mb", String.valueOf(300)); |
---|
136 | configuration.set("mapred.job.reduce.memory.mb", String.valueOf(400)); |
---|
137 | configuration.setMaxVirtualMemoryForTask(2 * 1024 * 1024); |
---|
138 | Assert.assertEquals(configuration.getMemoryForMapTask(), 2); |
---|
139 | Assert.assertEquals(configuration.getMemoryForReduceTask(), 2); |
---|
140 | } |
---|
141 | } |
---|